-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
44 lines (35 loc) · 1.6 KB
/
Copy pathinput.h
File metadata and controls
44 lines (35 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef INPUT_H
#define INPUT_H
#include <Qt>
#include <QPoint>
class Input
{
public:
enum InputState { InputInvalid, InputRegistered, InputUnregistered, InputTriggered, InputPressed, InputReleased };
static InputState keyState(Qt::Key key);
static bool keyTriggered(Qt::Key key);
static bool keyPressed(Qt::Key key);
static bool keyReleased(Qt::Key key);
static InputState buttonState(Qt::MouseButton button);
static bool buttonTriggered(Qt::MouseButton button);
static bool buttonPressed(Qt::MouseButton button);
static bool buttonReleased(Qt::MouseButton button);
static QPoint mousePosition();
static QPoint mouseDelta();
private:
static void update();
static void registerKeyPressed(int key);
static void registerKeyReleased(int key);
static void registerMousePressed(Qt::MouseButton button);
static void registerMouseReleased(Qt::MouseButton button);
static void reset();
friend class Window;
Input();
};
inline bool Input::keyTriggered(Qt::Key key) { return keyState(key) == InputTriggered; }
inline bool Input::keyPressed(Qt::Key key) { return keyState(key) == InputPressed; }
inline bool Input::keyReleased(Qt::Key key) { return keyState(key) == InputReleased; }
inline bool Input::buttonTriggered(Qt::MouseButton button) { return buttonState(button) == InputTriggered; }
inline bool Input::buttonPressed(Qt::MouseButton button) { return buttonState(button) == InputPressed; }
inline bool Input::buttonReleased(Qt::MouseButton button) { return buttonState(button) == InputReleased; }
#endif // INPUT_H