MouseEventHandler.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _MOUSE_EVENT_HANDLER_HH_
18 #define _MOUSE_EVENT_HANDLER_HH_
19 
20 #include <boost/function.hpp>
21 #include <string>
22 #include <list>
23 
26 #include "gazebo/util/system.hh"
27 
29 GZ_SINGLETON_DECLARE(GZ_GUI_VISIBLE, gazebo, gui, MouseEventHandler)
30 
31 namespace gazebo
32 {
33  namespace gui
34  {
37  class GZ_GUI_VISIBLE MouseEventHandler
38  : public SingletonT<MouseEventHandler>
39  {
42  public: typedef boost::function<bool (const common::MouseEvent &_event)>
43  MouseEventFilter;
44 
47  private: class Filter
48  {
52  public: Filter(const std::string &_name,
53  MouseEventFilter _func)
54  : name(_name), func(_func) {}
55 
59  public: bool operator==(const Filter &_f) const
60  {
61  return this->name == _f.name;
62  }
63 
67  public: bool operator==(const std::string &_f) const
68  {
69  return this->name == _f;
70  }
71 
73  public: std::string name;
74 
76  public: MouseEventFilter func;
77  };
78 
80  private: MouseEventHandler();
81 
83  private: virtual ~MouseEventHandler();
84 
88  public: void AddPressFilter(const std::string &_name,
89  MouseEventFilter _filter);
90 
94  public: void AddReleaseFilter(const std::string &_name,
95  MouseEventFilter _filter);
96 
100  public: void AddMoveFilter(const std::string &_name,
101  MouseEventFilter _filter);
102 
106  public: void AddDoubleClickFilter(const std::string &_name,
107  MouseEventFilter _filter);
108 
111  public: void RemovePressFilter(const std::string &_name);
112 
115  public: void RemoveReleaseFilter(const std::string &_name);
116 
119  public: void RemoveMoveFilter(const std::string &_name);
120 
123  public: void RemoveDoubleClickFilter(const std::string &_name);
124 
127  public: void HandlePress(const common::MouseEvent &_event);
128 
131  public: void HandleRelease(const common::MouseEvent &_event);
132 
135  public: void HandleMove(const common::MouseEvent &_event);
136 
139  public: void HandleDoubleClick(const common::MouseEvent &_event);
140 
145  private: void Add(const std::string &_name, MouseEventFilter _filter,
146  std::list<Filter> &_list);
147 
151  private: void Remove(const std::string &_name, std::list<Filter> &_list);
152 
156  private: void Handle(const common::MouseEvent &_event,
157  std::list<Filter> &_list);
158 
160  private: std::list<Filter> pressFilters;
161 
163  private: std::list<Filter> releaseFilters;
164 
166  private: std::list<Filter> moveFilters;
167 
169  private: std::list<Filter> doubleClickFilters;
170 
172  private: friend class SingletonT<MouseEventHandler>;
173  };
174  }
175 }
176 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33
gui
Definition: MouseEventHandler.hh:29
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61