-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinputhandler.h
61 lines (49 loc) · 1.63 KB
/
inputhandler.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef INPUTHANDLER_H
#define INPUTHANDLER_H
#include <QObject>
#include <QPoint>
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
class Renderer;
/**
* @brief This class leverages the renderer for all input. It filters out all events and provides the inputsystem and Javascript with what it needs.
*/
class InputHandler : public QObject
{
Q_OBJECT
public:
InputHandler(Renderer* renderer);
/**
* @brief Map holding all current input keys with a bool if it is pressed or not. Casted int from Qt::Key
*/
static std::map<int, bool> Keys;
/**
* @brief Holds the current cursor offset from the center of the render window.
*/
static QPoint MouseOffset;
/**
* @brief Resets mouse to middle and updates the mouse offset. Also keeps track of then to hide the cursor based on if the game is currently playing.
*/
void updateMouse(bool currentlyPlaying);
/**
* @brief Vector holding the string representation of pressed keys this frame. Used in Javascript for input events.
*/
std::vector<QString> inputPressedStrings;
/**
* @brief Vector holding the string representation of released keys this frame. Used in Javascript for input events.
*/
std::vector<QString> inputReleasedStrings;
signals:
void escapeKeyPressed();
void mousePress();
protected:
/**
* @brief Routes all events from the render window here. We only care about input events, so all others are sendt to the window.
*/
bool eventFilter(QObject* obj, QEvent* event) override;
private:
Renderer* mRenderer;
QPoint mCenter, mLastPos;
};
#endif // INPUTHANDLER_H