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 
29 GZ_SINGLETON_DECLARE(GZ_GUI_VISIBLE, gazebo, gui, KeyEventHandler)
30 
31 namespace gazebo
32 {
33  namespace common
34  {
35  class KeyEvent;
36  }
37 
38  namespace gui
39  {
40  class KeyEventHandlerPrivate;
41 
44  class GZ_GUI_VISIBLE KeyEventHandler : public SingletonT<KeyEventHandler>
45  {
48  public: typedef boost::function<bool (const common::KeyEvent &_event)>
49  KeyEventFilter;
50 
53  public: class Filter
54  {
58  public: Filter(const std::string &_name,
59  KeyEventFilter _func)
60  : name(_name), func(_func) {}
61 
65  public: bool operator==(const Filter &_f) const
66  {
67  return this->name == _f.name;
68  }
69 
73  public: bool operator==(const std::string &_f) const
74  {
75  return this->name == _f;
76  }
77 
79  public: std::string name;
80 
82  public: KeyEventFilter func;
83  };
84 
86  private: KeyEventHandler();
87 
89  private: virtual ~KeyEventHandler();
90 
94  public: void AddPressFilter(const std::string &_name,
95  KeyEventFilter _filter);
96 
100  public: void AddReleaseFilter(const std::string &_name,
101  KeyEventFilter _filter);
102 
105  public: void RemovePressFilter(const std::string &_name);
106 
109  public: void RemoveReleaseFilter(const std::string &_name);
110 
114  public: bool HandlePress(const common::KeyEvent &_event);
115 
119  public: bool HandleRelease(const common::KeyEvent &_event);
120 
123  public: bool AutoRepeat() const;
124 
127  public: void SetAutoRepeat(const bool _autorepeat);
128 
133  private: void Add(const std::string &_name, KeyEventFilter _filter,
134  std::list<Filter> &_list);
135 
139  private: void Remove(const std::string &_name, std::list<Filter> &_list);
140 
145  private: bool Handle(const common::KeyEvent &_event,
146  std::list<Filter> &_list);
147 
149  private: friend class SingletonT<KeyEventHandler>;
150 
153  private: std::unique_ptr<KeyEventHandlerPrivate> dataPtr;
154  };
155  }
156 }
157 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33
gui
Definition: KeyEventHandler.hh:29
common
Definition: FuelModelDatabase.hh:37
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61