KeyEventHandler.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 _GAZEBO_GUI_KEYEVENTHANDLER_HH_
18 #define _GAZEBO_GUI_KEYEVENTHANDLER_HH_
19 
20 #include <list>
21 #include <memory>
22 #include <string>
23 #include <boost/function.hpp>
24 
26 #include "gazebo/util/system.hh"
27 
28 namespace gazebo
29 {
30  namespace common
31  {
32  class KeyEvent;
33  }
34 
35  namespace gui
36  {
37  class KeyEventHandlerPrivate;
38 
41  class GZ_GUI_VISIBLE KeyEventHandler : public SingletonT<KeyEventHandler>
42  {
45  public: typedef boost::function<bool (const common::KeyEvent &_event)>
46  KeyEventFilter;
47 
50  public: class Filter
51  {
55  public: Filter(const std::string &_name,
56  KeyEventFilter _func)
57  : name(_name), func(_func) {}
58 
62  public: bool operator==(const Filter &_f) const
63  {
64  return this->name == _f.name;
65  }
66 
70  public: bool operator==(const std::string &_f) const
71  {
72  return this->name == _f;
73  }
74 
76  public: std::string name;
77 
79  public: KeyEventFilter func;
80  };
81 
83  private: KeyEventHandler();
84 
86  private: virtual ~KeyEventHandler();
87 
91  public: void AddPressFilter(const std::string &_name,
92  KeyEventFilter _filter);
93 
97  public: void AddReleaseFilter(const std::string &_name,
98  KeyEventFilter _filter);
99 
102  public: void RemovePressFilter(const std::string &_name);
103 
106  public: void RemoveReleaseFilter(const std::string &_name);
107 
111  public: bool HandlePress(const common::KeyEvent &_event);
112 
116  public: bool HandleRelease(const common::KeyEvent &_event);
117 
120  public: bool AutoRepeat() const;
121 
124  public: void SetAutoRepeat(const bool _autorepeat);
125 
130  private: void Add(const std::string &_name, KeyEventFilter _filter,
131  std::list<Filter> &_list);
132 
136  private: void Remove(const std::string &_name, std::list<Filter> &_list);
137 
142  private: bool Handle(const common::KeyEvent &_event,
143  std::list<Filter> &_list);
144 
146  private: friend class SingletonT<KeyEventHandler>;
147 
150  private: std::unique_ptr<KeyEventHandlerPrivate> dataPtr;
151  };
152  }
153 }
154 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33