blob: cdaf30b5043b92f2a6167ce3e70f88ea6168929a (
plain)
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
|
#include <algorithm>
#include "commands.h"
Commands_sdl::Commands_sdl () {
for (int i=0; i<3; i++) {
mclick[i] = 0;
mheld[i] = 0;
}
}
Commands_sdl::~Commands_sdl () {
}
bool Commands_sdl::check_keydown (SDL_Scancode key) {
return std::find(keysdown.begin(), keysdown.end(), key) != keysdown.end();
}
bool Commands_sdl::check_key (SDL_Scancode key) {
return std::find(keys.begin(), keys.end(), key) != keys.end();
}
bool Commands_sdl::process_events () {
SDL_GetMouseState(&mx, &my);
resx = -1; resy = -1;
SDL_Event e;
while(SDL_PollEvent(&e) != 0) {
if(e.type == SDL_QUIT) {
return true;
}
if(e.type == SDL_KEYDOWN && e.key.repeat == 0) {
keys.push_back(e.key.keysym.scancode);
keysdown.push_back(e.key.keysym.scancode);
}
if(e.type == SDL_KEYUP) {
keysdown.erase(std::remove(keysdown.begin(), keysdown.end(),
e.key.keysym.scancode), keysdown.end());
}
if(e.type == SDL_MOUSEBUTTONDOWN) {
if (e.button.button == SDL_BUTTON_LEFT) { mclick[0] = 1; }
if (e.button.button == SDL_BUTTON_MIDDLE) { mclick[1] = 1; }
if (e.button.button == SDL_BUTTON_RIGHT) { mclick[2] = 1; }
}
if(e.type == SDL_MOUSEBUTTONUP) {
if (e.button.button == SDL_BUTTON_LEFT) { mclick[0] = 0; }
if (e.button.button == SDL_BUTTON_MIDDLE) { mclick[1] = 0; }
if (e.button.button == SDL_BUTTON_RIGHT) { mclick[2] = 0; }
}
if(e.type == SDL_WINDOWEVENT
&& e.window.event == SDL_WINDOWEVENT_RESIZED ) {
resx = e.window.data1; resy = e.window.data2;
}
}
return false;
}
void Commands_sdl::process_clicks () {
for (int i=0; i<3; i++) {
if (mclick[i] > 0) { mheld[i] += 1; }
else if (mheld[i] > 0) { mheld[i] = -1; }
else { mheld[i] = 0; }
}
}
void Commands_sdl::process_keys () {
keys.clear();
}
|