KeyEventHandler.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 _KEY_EVENT_HANDLER_HH_
18 #define _KEY_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 GAZEBO_VISIBLE KeyEventHandler : public SingletonT<KeyEventHandler>
35  {
38  public: typedef boost::function<bool (const common::KeyEvent &_event)>
39  KeyEventFilter;
40 
43  private: class Filter
44  {
48  public: Filter(const std::string &_name,
49  KeyEventFilter _func)
50  : name(_name), func(_func) {}
51 
55  public: bool operator==(const Filter &_f) const
56  {
57  return this->name == _f.name;
58  }
59 
63  public: bool operator==(const std::string &_f) const
64  {
65  return this->name == _f;
66  }
67 
69  public: std::string name;
70 
72  public: KeyEventFilter func;
73  };
74 
76  private: KeyEventHandler();
77 
79  private: virtual ~KeyEventHandler();
80 
84  public: void AddPressFilter(const std::string &_name,
85  KeyEventFilter _filter);
86 
90  public: void AddReleaseFilter(const std::string &_name,
91  KeyEventFilter _filter);
92 
95  public: void RemovePressFilter(const std::string &_name);
96 
99  public: void RemoveReleaseFilter(const std::string &_name);
100 
104  public: bool HandlePress(const common::KeyEvent &_event);
105 
109  public: bool HandleRelease(const common::KeyEvent &_event);
110 
113  public: bool GetAutoRepeat() const;
114 
117  public: void SetAutoRepeat(const bool _autorepeat);
118 
123  private: void Add(const std::string &_name, KeyEventFilter _filter,
124  std::list<Filter> &_list);
125 
129  private: void Remove(const std::string &_name, std::list<Filter> &_list);
130 
135  private: bool Handle(const common::KeyEvent &_event,
136  std::list<Filter> &_list);
137 
139  private: std::list<Filter> pressFilters;
140 
142  private: std::list<Filter> releaseFilters;
143 
145  private: friend class SingletonT<KeyEventHandler>;
146 
149  private: bool autoRepeat;
150  };
151  }
152 }
153 #endif
Singleton template class.
Definition: SingletonT.hh:33
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:66