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 
28 namespace gazebo
29 {
30  namespace gui
31  {
34  class GZ_GUI_VISIBLE MouseEventHandler
35  : public SingletonT<MouseEventHandler>
36  {
39  public: typedef boost::function<bool (const common::MouseEvent &_event)>
40  MouseEventFilter;
41 
44  private: class Filter
45  {
49  public: Filter(const std::string &_name,
50  MouseEventFilter _func)
51  : name(_name), func(_func) {}
52 
56  public: bool operator==(const Filter &_f) const
57  {
58  return this->name == _f.name;
59  }
60 
64  public: bool operator==(const std::string &_f) const
65  {
66  return this->name == _f;
67  }
68 
70  public: std::string name;
71 
73  public: MouseEventFilter func;
74  };
75 
77  private: MouseEventHandler();
78 
80  private: virtual ~MouseEventHandler();
81 
85  public: void AddPressFilter(const std::string &_name,
86  MouseEventFilter _filter);
87 
91  public: void AddReleaseFilter(const std::string &_name,
92  MouseEventFilter _filter);
93 
97  public: void AddMoveFilter(const std::string &_name,
98  MouseEventFilter _filter);
99 
103  public: void AddDoubleClickFilter(const std::string &_name,
104  MouseEventFilter _filter);
105 
108  public: void RemovePressFilter(const std::string &_name);
109 
112  public: void RemoveReleaseFilter(const std::string &_name);
113 
116  public: void RemoveMoveFilter(const std::string &_name);
117 
120  public: void RemoveDoubleClickFilter(const std::string &_name);
121 
124  public: void HandlePress(const common::MouseEvent &_event);
125 
128  public: void HandleRelease(const common::MouseEvent &_event);
129 
132  public: void HandleMove(const common::MouseEvent &_event);
133 
136  public: void HandleDoubleClick(const common::MouseEvent &_event);
137 
142  private: void Add(const std::string &_name, MouseEventFilter _filter,
143  std::list<Filter> &_list);
144 
148  private: void Remove(const std::string &_name, std::list<Filter> &_list);
149 
153  private: void Handle(const common::MouseEvent &_event,
154  std::list<Filter> &_list);
155 
157  private: std::list<Filter> pressFilters;
158 
160  private: std::list<Filter> releaseFilters;
161 
163  private: std::list<Filter> moveFilters;
164 
166  private: std::list<Filter> doubleClickFilters;
167 
169  private: friend class SingletonT<MouseEventHandler>;
170  };
171  }
172 }
173 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33