Debian Codegraph @

src/gengine/InputHandler.h

raw
1 #ifndef HEADER_INPUTHANDLER_H
2 #define HEADER_INPUTHANDLER_H
3
4 class KeyStroke;
5 class MouseStroke;
6
7 #include "NoCopy.h"
8 #include "InputProvider.h"
9
10 /**
11 * Handle input events.
12 * Events:
13 * - keyEvent() is called when new key is pressed.
14 * - mouseEvent() is called when there is a mouse click.
15 * - mouseState() is called every cycle to update mouse position
16 *
17 * Pressed keys are stored in m_pressed array, this array is shared
18 * and updated by InputAgent.
19 */
20 class InputHandler : public InputProvider, public NoCopy {
21 private:
22 Uint8 *m_pressed;
23 Uint8 m_buttons;
24 V2 m_mouseLoc;
25 public:
26 InputHandler();
27 void takePressed(Uint8 *pressed) { m_pressed = pressed; }
28 void mouseState(const V2 &loc, Uint8 buttons);
29
30 virtual void keyEvent(const KeyStroke &/*stroke*/) {}
31 virtual void keyUp(const KeyStroke &/*stroke*/) {}
32 virtual void mouseEvent(const MouseStroke &/*buttons*/) {}
33
34 virtual bool isPressed(SDLKey key) const;
35 virtual bool isLeftPressed() const;
36 virtual bool isMiddlePressed() const;
37 virtual bool isRightPressed() const;
38 virtual V2 getMouseLoc() const { return m_mouseLoc; }
39
40 virtual std::string toString() const;
41 };
42
43 #endif