-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrols.cpp
66 lines (61 loc) · 1.36 KB
/
controls.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
#include "controls.h"
Controls::Controls(GamepadHandler &gamepadHdlr, Display &display) :
m_GamePadHandler(gamepadHdlr),
m_Display(display)
{}
void Controls::UpdateEvents(bool &quit)
{
SDL_Event e;
const struct {
SDL_Keycode sym;
GamepadHandler::GamePadButton_t button;
} mapping[] = {
{ SDLK_n, GamepadHandler::BUTTON_A},
{ SDLK_b, GamepadHandler::BUTTON_B},
{ SDLK_RETURN, GamepadHandler::BUTTON_START},
{ SDLK_BACKSPACE, GamepadHandler::BUTTON_SELECT},
{ SDLK_UP, GamepadHandler::BUTTON_UP},
{ SDLK_DOWN, GamepadHandler::BUTTON_DOWN},
{ SDLK_LEFT, GamepadHandler::BUTTON_LEFT},
{ SDLK_RIGHT, GamepadHandler::BUTTON_RIGHT},
};
if (!SDL_PollEvent(&e))
return;
switch (e.type)
{
case SDL_QUIT:
quit = true;
break;
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_CLOSE)
{
if (e.window.windowID == 1)
quit = true;
else
m_Display.toggleOAMWindow();
}
break;
case SDL_KEYUP:
if (e.key.keysym.sym == SDLK_F1)
{
m_Display.toggleOAMWindow();
break;
}
/* Fallthrough */
case SDL_KEYDOWN:
for (const auto& m : mapping)
{
if (e.key.keysym.sym == m.sym)
{
if (e.type == SDL_KEYUP)
m_GamePadHandler.buttonReleased(m.button);
else
m_GamePadHandler.buttonPressed(m.button);
break;
}
}
break;
default:
break;
}
}