-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBind.cpp
More file actions
127 lines (109 loc) · 4.73 KB
/
Copy pathBind.cpp
File metadata and controls
127 lines (109 loc) · 4.73 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
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
125
126
127
//Bind.cpp
#include "Bind.h"
#include <iostream>
static const int SDL_CUSTOM_CTRL = 1001;
static const int SDL_CUSTOM_SHIFT = 1002;
static const int SDL_CUSTOM_ALT = 1003;
static const int SDL_CUSTOM_LMB = 1004;
static const int SDL_CUSTOM_RMB = 1005;
static const int SDL_CUSTOM_MMB = 1006;
static const int SDL_CUSTOM_X1MB = 1007;
static const int SDL_CUSTOM_X2MB = 1008;
static const int SDL_CUSTOM_WHEELUP = 1009;
static const int SDL_CUSTOM_WHEELDOWN = 1010;
namespace sdlGUI {
Bind::Bind() {
Next = Previous = NULL;
Key = Modifier = SDL_SCANCODE_UNKNOWN;
Repeat = false;
}
SDL_Scancode Bind::GetKey() {
return Key;
}
SDL_Scancode Bind::GetModifier() {
return Modifier;
}
int Bind::OnInput(SDL_Event &Event) {
int Input = 0;
if (State) {
if (Event.type == SDL_KEYDOWN || Event.type == SDL_KEYUP) {
if (Event.key.keysym.scancode == Key && (Event.key.repeat == 0 || Repeat)) {
const Uint8 *KeyboardState = SDL_GetKeyboardState(NULL);
bool ModifierCheck = true;
if (Modifier == SDL_CUSTOM_CTRL) {
ModifierCheck = (KeyboardState[SDL_SCANCODE_LCTRL] || KeyboardState[SDL_SCANCODE_RCTRL]);
} else if (Modifier == SDL_CUSTOM_SHIFT) {
ModifierCheck = (KeyboardState[SDL_SCANCODE_LSHIFT] || KeyboardState[SDL_SCANCODE_RSHIFT]);
} else if (Modifier == SDL_CUSTOM_ALT) {
ModifierCheck = (KeyboardState[SDL_SCANCODE_LALT] || KeyboardState[SDL_SCANCODE_RALT]);
} else if (Modifier) {
ModifierCheck = KeyboardState[Modifier];
}
if (ModifierCheck || !Modifier) {
if (Event.type == SDL_KEYDOWN) {
EventQueue.push_back(Events::Press);
//Input = Events::Press;
} else {
EventQueue.push_back(Events::Release);
//Input = Events::Release;
}
}
}
} else if (Event.type == SDL_MOUSEBUTTONDOWN || Event.type == SDL_MOUSEBUTTONUP) {
int Key = this->Key;
if (Key == SDL_CUSTOM_MMB) {
Key = SDL_BUTTON_MIDDLE;
} else if (Key == SDL_CUSTOM_X1MB) {
Key = SDL_BUTTON_X1;
} else if (Key == SDL_CUSTOM_X2MB) {
Key = SDL_BUTTON_X2;
}
if (Event.button.button == Key) {
const Uint8 *KeyboardState = SDL_GetKeyboardState(NULL);
bool ModifierCheck = false;
if (Modifier == SDL_CUSTOM_CTRL) {
ModifierCheck = (KeyboardState[SDL_SCANCODE_LCTRL] || KeyboardState[SDL_SCANCODE_RCTRL]);
} else if (Modifier == SDL_CUSTOM_SHIFT) {
ModifierCheck = (KeyboardState[SDL_SCANCODE_LSHIFT] || KeyboardState[SDL_SCANCODE_RSHIFT]);
} else if (Modifier == SDL_CUSTOM_ALT) {
ModifierCheck = (KeyboardState[SDL_SCANCODE_LALT] || KeyboardState[SDL_SCANCODE_RALT]);
} else {
ModifierCheck = KeyboardState[Modifier];
}
if (ModifierCheck || !Modifier) {
if (Event.type == SDL_MOUSEBUTTONDOWN) {
EventQueue.push_back(Events::Press);
//Input = Events::Press;
} else {
EventQueue.push_back(Events::Release);
//Input = Events::Release;
}
}
}
} else if (Event.type == SDL_MOUSEWHEEL) {
if (Key == SDL_CUSTOM_WHEELDOWN && Event.wheel.y < 0) {
EventQueue.push_back(Events::Press);
//Input = Events::Press;
} else if (Key == SDL_CUSTOM_WHEELUP && Event.wheel.y > 0) {
EventQueue.push_back(Events::Press);
//Input = Events::Press;
}
}
}
return Input;
}
void Bind::SetKey(SDL_Scancode Key) {
this->Key = Key;
}
void Bind::SetModifier(SDL_Scancode Modifier) {
this->Modifier = Modifier;
}
void Bind::SetRepeat(bool Repeat) {
this->Repeat = Repeat;
}
Bind::~Bind() {
Next = Previous = NULL;
Key = Modifier = SDL_SCANCODE_UNKNOWN;
Repeat = false;
}
}