-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.cpp
More file actions
44 lines (41 loc) · 1.29 KB
/
Copy pathinput.cpp
File metadata and controls
44 lines (41 loc) · 1.29 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
#include <iostream>
#include "input.h"
Input::Input() {
SDL_EnableKeyRepeat(0, 0);
memset(keys_down, 0, sizeof(keys_down));
memset(keys_pressed, 0, sizeof(keys_pressed));
memset(keys_released, 0, sizeof(keys_released));
mouse_down_ = mouse_pressed_ = mouse_released_ = 0;
quitting = false;
}
void Input::update() {
memset(keys_pressed, 0, sizeof(keys_pressed));
memset(keys_released, 0, sizeof(keys_released));
mouse_pressed_ = mouse_released_ = 0;
SDL_GetMouseState(&mouse_x_, &mouse_y_);
quitting = false;
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
mouse_down_ |= SDL_BUTTON(event.button.button);
mouse_pressed_ |= SDL_BUTTON(event.button.button);
break;
case SDL_MOUSEBUTTONUP:
mouse_down_ &= ~SDL_BUTTON(event.button.button);
mouse_released_ |= SDL_BUTTON(event.button.button);
break;
case SDL_KEYDOWN:
keys_down[event.key.keysym.sym] = true;
keys_pressed[event.key.keysym.sym] = true;
break;
case SDL_KEYUP:
keys_down[event.key.keysym.sym] = false;
keys_released[event.key.keysym.sym] = true;
break;
case SDL_QUIT:
quitting = true;
}
}
//return (!quitting && !key_pressed(SDLK_ESCAPE));
}