Etterna 0.74.4
Loading...
Searching...
No Matches
InputFilter.h
1/* InputFilter - Checks RageInput and generates a list of InputEvents,
2 * representing button presses, releases, and repeats. */
3
4#ifndef INPUT_FILTER_H
5#define INPUT_FILTER_H
6
7#include "RageUtil/Misc/RageInputDevice.h"
8
9enum InputEventType
10{
11 // The device was just pressed.
12 IET_FIRST_PRESS,
13
14 /* The device is auto-repeating. This event is guaranteed to be sent only
15 * between IET_FIRST_PRESS and IET_RELEASE pairs. */
16 IET_REPEAT,
17
18 /* The device is no longer pressed. Exactly one IET_RELEASE event will be
19 * sent for each IET_FIRST_PRESS. */
20 IET_RELEASE,
21
22 NUM_InputEventType,
23 InputEventType_Invalid
24};
25
26const std::string&
27InputEventTypeToString(InputEventType cat);
28const std::string&
29InputEventTypeToLocalizedString(InputEventType cat);
30LuaDeclareType(InputEventType);
31
33{
34 InputEvent() = default;
35
36 DeviceInput di;
37 InputEventType type{ IET_FIRST_PRESS };
38
39 // A list of all buttons that were pressed at the time of this event:
40 DeviceInputList m_ButtonState;
41};
42
44{
45 float fX;
46 float fY;
47 float fZ;
48};
49
50class RageMutex;
51struct ButtonState;
53{
54 public:
55 void ButtonPressed(const DeviceInput& di);
56 void SetButtonComment(const DeviceInput& di,
57 const std::string& sComment = "");
58 void ResetDevice(InputDevice dev);
59
62 void Reset();
63 void Update(float fDeltaTime);
64
65 void SetRepeatRate(float fRepeatRate);
66 void SetRepeatDelay(float fDelay);
67 void ResetRepeatRate();
68 void ResetKeyRepeat(const DeviceInput& di);
69 void RepeatStopKey(const DeviceInput& di);
70
71 // If aButtonState is NULL, use the last reported state.
72 bool IsBeingPressed(const DeviceInput& di,
73 const DeviceInputList* pButtonState = nullptr) const;
74 bool IsKBKeyPressed(DeviceButton k) const;
75 bool IsControlPressed() const;
76 bool IsShiftPressed() const;
77 float GetSecsHeld(const DeviceInput& di,
78 const DeviceInputList* pButtonState = nullptr) const;
79 float GetLevel(const DeviceInput& di,
80 const DeviceInputList* pButtonState = nullptr) const;
81 std::string GetButtonComment(const DeviceInput& di) const;
82
83 void GetInputEvents(std::vector<InputEvent>& aEventOut);
84 void GetPressedButtons(std::vector<DeviceInput>& array) const;
85
86 // cursor
87 void UpdateCursorLocation(float _fX, float _fY);
88 void UpdateMouseWheel(float _fZ);
89 float GetCursorX() { return m_MouseCoords.fX; }
90 float GetCursorY() { return m_MouseCoords.fY; }
91 float GetMouseWheel() { return m_MouseCoords.fZ; }
92
93 // Lua
94 void PushSelf(lua_State* L);
95
96 bool IsCapsLockEnabled() { return capsLockEnabled; }
97
98 private:
99 void CheckButtonChange(ButtonState& bs,
100 DeviceInput di,
101 const std::chrono::steady_clock::time_point& now);
102 void ReportButtonChange(const DeviceInput& di, InputEventType t);
103 void MakeButtonStateList(std::vector<DeviceInput>& aInputOut) const;
104
105 std::vector<InputEvent> queue;
106 RageMutex* queuemutex;
107 MouseCoordinates m_MouseCoords;
108
109 InputFilter(const InputFilter& rhs);
110 InputFilter& operator=(const InputFilter& rhs);
111
112 bool capsLockEnabled = false;
113};
114
115extern InputFilter*
116 INPUTFILTER; // global and accessible from anywhere in our program
117
118#endif
Definition InputFilter.h:53
void ResetDevice(InputDevice dev)
Release all buttons on the given device.
Definition InputFilter.cpp:254
void RepeatStopKey(const DeviceInput &di)
Stop repeating the specified key until released.
Definition InputFilter.cpp:489
Definition RageThreads.h:232
Definition InputFilter.cpp:31
Definition RageInputDevice.h:390
Definition InputFilter.h:33
Definition InputFilter.h:44