-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputManager.cpp
executable file
·75 lines (72 loc) · 1.84 KB
/
InputManager.cpp
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
#include "InputManager.h"
InputManager::InputManager()
{
}
InputManager::~InputManager()
{
}
void InputManager::update()
{
previousKeys = keys;
SDL_Event event;
while (SDL_PollEvent(&event) != 0)
{
switch (event.type)
{
case SDL_QUIT:
closing = true;
exit(0);
//game_state = 0; // set game state to done,(do what you want here)
break;
case SDL_KEYDOWN:
case SDL_KEYUP:
{
string code(SDL_GetKeyName(event.key.keysym.sym));
keys[code] = (event.type == SDL_KEYDOWN);
if (event.key.keysym.sym == SDLK_F4 && (event.key.keysym.mod == KMOD_LALT || event.key.keysym.mod == KMOD_ALT))
{
closing = true;
exit(0);
}
break;
}
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
bool press = (event.type == SDL_MOUSEBUTTONDOWN);
switch (event.button.button)
{
case SDL_BUTTON_LEFT:
keys["CLICKLEFT"] = press;
break;
case SDL_BUTTON_MIDDLE:
keys["CLICKMIDDLE"] = press;
break;
case SDL_BUTTON_RIGHT:
keys["CLICKRIGHT"] = press;
break;
}
break;
}
case SDL_MOUSEMOTION:
{
mouse.x = event.motion.x;
mouse.y = event.motion.y;
mouseDelta.x = event.motion.xrel;
mouseDelta.y = event.motion.yrel;
break;
}
case SDL_WINDOWEVENT:
{
if (event.window.event == SDL_WINDOWEVENT_CLOSE)
{
closing = true;
exit(0);
}
break;
}
default:
break;
}
}
}