OpenPolygon  1.0.0
OpenPolygon is a Rendering Engine
input.h
1 /*
2  Copyright (C) 2014 - 2016 Mutzii
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 #ifndef INPUTMANAGER_H
19 #define INPUTMANAGER_H
20 
21 #include "index.h"
22 
23 namespace Engine
24 {
25 
26 
32 {
33  public:
34  MouseEvent(void);
35  ~MouseEvent(void){}
36 
37  int getButton(void) const;
38 
39  bool isMousePressed(void) const;
40  bool isMouseReleased(void) const;
41  bool isShiftDown(void) const;
42  bool isControlDown(void) const;
43  bool isAltDown(void) const;
44  bool isSuperDown(void) const;
45 
46  int getAction(void) const;
47  int getMod(void) const;
48 
49  void setAction(int action);
50  void setMod(int mod);
51  void setButton(int button);
52  void setPosition(const Vector2f &vector);
53 
54  private:
55  int mButton, mMod, mAction;
56  Vector2f mPosition;
57 };
58 
59 
64 class KeyEvent
65 {
66  public:
67  KeyEvent(void);
68  ~KeyEvent(void){}
69 
70  void setMod(int mod);
71  void setAction(int action);
72  DEPRECATED void setKey(int key);
73  void setKeys( std::list< int > list );
74  void setKeyCode(int keycode);
75 
76  DEPRECATED int getKeyValue(void) const;
77  std::list< int > getKeys(void) const;
78 
79 
80  int getKeyScanCode(void) const;
81  bool isKeyPressed( int key) const;
82  bool isKeyReleased( int key) const;
83  bool isShiftDown(void) const;
84  bool isControlDown(void) const;
85  bool isAltDown(void) const;
86  bool isSuperDown(void) const;
87 
88  private:
89  int mMod , mAction , mKey , mKeyCode;
90  std::list< int > m_keys;
91 
92 };
93 
98 {
99  public:
100  virtual ~InputListener(){}
101 
107  virtual void onKeyEvent(const KeyEvent & event)=0;
108 
114  virtual void onMouseEvent(const MouseEvent & event)=0;
115 };
116 
117 
118 /* List of InputListener */
119 using IListenerList = std::list< InputListener * >;
120 
130 {
131 
132  private:
133 
134  static InputManager * ptrInstance;
135  InputManager( void );
136  InputManager( const InputManager &){}
137  void operator=(const InputManager &){}
138 
139  ~InputManager(void){}
140 
141  public:
142 
148  static InputManager * getSingletonPtr(void);
149  void PollEvents( GLFWwindow * window );
150 
151 
157  void addInputListener( InputListener * listener);
158 
164  void removeListener( InputListener * listener);
165 
172  void capture( int mouseX , int mouseY);
173 
182  void createKeyBoardEvent( int key , int scancode , int action , int mods);
183  void createKeyListEvent( std::list< int > keys );
184 
192  void createMouseEvent( int button , int action , int mods);
193 
199  Vector2f & getMousePosition(void);
200 
206  IListenerList & getListener();
207 
208  private:
209  Vector2f mMousePosition;
210  IListenerList mList;
212  //Last Values (MouseEvent)
213  int mLastButton;
214  int mLastAction;
215  int mLastMods;
216 
217  timeval mStartTimer;
218  double timeSinceLastFrame;
219  bool mTriggerFlag;
220 };
221 
222 }
223 #endif // INPUTMANAGER_H
void capture(int mouseX, int mouseY)
capture
Definition: InputManager.cpp:78
Vector2f & getMousePosition(void)
getMousePosition
Definition: InputManager.cpp:58
The InputManager controlled InputListener.
Definition: input.h:129
void addInputListener(InputListener *listener)
addInputListener
Definition: InputManager.cpp:68
virtual void onKeyEvent(const KeyEvent &event)=0
onKeyEvent
Definition: element.h:23
The InputListener - Interface class.
Definition: input.h:97
The KeyEvent - Event class.
Definition: input.h:64
void createKeyBoardEvent(int key, int scancode, int action, int mods)
createKeyBoardEvent
Definition: InputManager.cpp:100
static InputManager * getSingletonPtr(void)
getSingletonPtr
Definition: InputManager.cpp:31
void removeListener(InputListener *listener)
removeListener
Definition: InputManager.cpp:73
IListenerList & getListener()
getListener
Definition: InputManager.cpp:63
The MouseEvent - Event class.
Definition: input.h:31
void createMouseEvent(int button, int action, int mods)
createMouseEvent
Definition: InputManager.cpp:119
virtual void onMouseEvent(const MouseEvent &event)=0
onMouseEvent