KeyEventHandler.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
27 #include "gazebo/util/system.hh"
28 
29 namespace gazebo
30 {
31  namespace common
32  {
33  class KeyEvent;
34  }
35 
36  namespace gui
37  {
38  class KeyEventHandlerPrivate;
39 
42  class GZ_GUI_VISIBLE KeyEventHandler : public SingletonT<KeyEventHandler>
43  {
46  public: typedef boost::function<bool (const common::KeyEvent &_event)>
47  KeyEventFilter;
48 
51  public: class Filter
52  {
56  public: Filter(const std::string &_name,
57  KeyEventFilter _func)
58  : name(_name), func(_func) {}
59 
63  public: bool operator==(const Filter &_f) const
64  {
65  return this->name == _f.name;
66  }
67 
71  public: bool operator==(const std::string &_f) const
72  {
73  return this->name == _f;
74  }
75 
77  public: std::string name;
78 
80  public: KeyEventFilter func;
81  };
82 
84  private: KeyEventHandler();
85 
87  private: virtual ~KeyEventHandler();
88 
92  public: void AddPressFilter(const std::string &_name,
93  KeyEventFilter _filter);
94 
98  public: void AddReleaseFilter(const std::string &_name,
99  KeyEventFilter _filter);
100 
103  public: void RemovePressFilter(const std::string &_name);
104 
107  public: void RemoveReleaseFilter(const std::string &_name);
108 
112  public: bool HandlePress(const common::KeyEvent &_event);
113 
117  public: bool HandleRelease(const common::KeyEvent &_event);
118 
122  public: bool GetAutoRepeat() const GAZEBO_DEPRECATED(7.0);
123 
126  public: bool AutoRepeat() const;
127 
130  public: void SetAutoRepeat(const bool _autorepeat);
131 
136  private: void Add(const std::string &_name, KeyEventFilter _filter,
137  std::list<Filter> &_list);
138 
142  private: void Remove(const std::string &_name, std::list<Filter> &_list);
143 
148  private: bool Handle(const common::KeyEvent &_event,
149  std::list<Filter> &_list);
150 
152  private: friend class SingletonT<KeyEventHandler>;
153 
156  private: std::unique_ptr<KeyEventHandlerPrivate> dataPtr;
157  };
158  }
159 }
160 #endif
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
Singleton template class.
Definition: SingletonT.hh:33