-
Notifications
You must be signed in to change notification settings - Fork 59
/
InputEvents.h
124 lines (90 loc) · 2.48 KB
/
InputEvents.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
OpenLieroX
input (keyboard, mouse, ...) events and related stuff
code under LGPL
created 01-05-2007
by Albert Zeyer and Dark Charlie
*/
#ifndef __INPUTEVENTS_H__
#define __INPUTEVENTS_H__
#include <vector>
#include <SDL.h>
#include "Unicode.h"
#include "Event.h"
#include "EventQueue.h"
// application has focus
// These vars are like events, they got true once in a frame when the specific event occured.
// TODO: remove them
extern bool bActivated;
extern bool bDeactivated;
#define MAX_KEYQUEUE 256
#define MAX_MOUSEBUTTONS 8 // SDL_GetMouseState returns UInt8 bitmask
// State of modifier keys (ctrl, alt and shift)
struct ModifiersState {
ModifiersState() { clear(); }
void clear() { bShift = bCtrl = bAlt = bGui = false; }
bool bShift;
bool bCtrl;
bool bAlt;
bool bGui;
};
struct KeyboardEvent {
SDL_Keycode sym;
UnicodeChar ch;
bool down;
ModifiersState state;
KeyboardEvent() : sym(0), ch(0), down(false) {}
};
// Keyboard structure
struct keyboard_t {
int queueLength;
KeyboardEvent keyQueue[MAX_KEYQUEUE];
};
// Mouse structure
struct mouse_t {
int X,Y;
int deltaX,deltaY;
int Button;
// HINT: the following three variables cannot be bool
// because they contain info about the pressed button (left, right, ...)
// as well
// TODO: change this immediatly
int Up;
int Down;
int FirstDown;
bool WheelScrollUp;
bool WheelScrollDown;
};
enum MouseButton {
mbLeft,
mbRight,
mbMiddle,
mbExtra1,
mbExtra2
};
MouseButton SDLButtonToMouseButton(int sdlbut);
MouseButton SDLButtonStateToMouseButton(int sdlbut);
typedef Event<SDL_Event*> SDLEvent;
// All main SDL events. You can add your own global handlers here. Though that should
// not be needed in most cases.
// If you want to add a user event, DON'T add the handler here. Use SendSDLUserEvent()
// and your event will get called automatically.
extern std::map<SDL_EventType, SDLEvent> sdlEvents;
extern bool processedEvent;
void InitEventSystem();
void ShutdownEventSystem();
void ProcessEvents(); // returns false if no new event
bool EventSystemInited();
bool IsWaitingForEvent();
void WakeupIfNeeded();
keyboard_t *GetKeyboard();
mouse_t *GetMouse();
SDL_Event *GetEvent();
ModifiersState *GetCurrentModstate();
bool WasKeyboardEventHappening(SDL_Keycode key, bool down = true);
class CInput;
void RegisterCInput(CInput* input);
void UnregisterCInput(CInput* input);
bool ApplicationHasFocus();
extern Event<> onDummyEvent;
#endif