MCPcopy Create free account
hub / github.com/diasurgical/devilution / GetMenuAction

Function GetMenuAction

SourceX/controls/menu_controls.cpp:7–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5namespace dvl {
6
7MenuAction GetMenuAction(const SDL_Event &event)
8{
9 const ControllerButtonEvent ctrl_event = ToControllerButtonEvent(event);
10 if (ctrl_event.button != ControllerButton::NONE)
11 sgbControllerActive = true;
12
13 if (!ctrl_event.up) {
14 switch (ctrl_event.button) {
15 case ControllerButton::IGNORE:
16 return MenuAction::NONE;
17 case ControllerButton::BUTTON_B: // Right button
18 case ControllerButton::BUTTON_START:
19 return MenuAction::SELECT;
20 case ControllerButton::BUTTON_BACK:
21 case ControllerButton::BUTTON_A: // Bottom button
22 return MenuAction::BACK;
23 case ControllerButton::BUTTON_X: // Left button
24 return MenuAction::DELETE;
25 case ControllerButton::BUTTON_DPAD_UP:
26 return MenuAction::UP;
27 case ControllerButton::BUTTON_DPAD_DOWN:
28 return MenuAction::DOWN;
29 case ControllerButton::BUTTON_DPAD_LEFT:
30 return MenuAction::LEFT;
31 case ControllerButton::BUTTON_DPAD_RIGHT:
32 return MenuAction::RIGHT;
33 case ControllerButton::BUTTON_LEFTSHOULDER:
34 return MenuAction::PAGE_UP;
35 case ControllerButton::BUTTON_RIGHTSHOULDER:
36 return MenuAction::PAGE_DOWN;
37 default:
38 break;
39 }
40 }
41
42#if HAS_KBCTRL == 0
43 if (event.type >= SDL_KEYDOWN && event.type < SDL_JOYAXISMOTION)
44 sgbControllerActive = false;
45
46 if (event.type == SDL_KEYDOWN) {
47 switch (event.key.keysym.sym) {
48 case SDLK_UP:
49 return MenuAction::UP;
50 case SDLK_DOWN:
51 return MenuAction::DOWN;
52 case SDLK_TAB:
53 if (SDL_GetModState() & KMOD_SHIFT)
54 return MenuAction::UP;
55 else
56 return MenuAction::DOWN;
57 case SDLK_PAGEUP:
58 return MenuAction::PAGE_UP;
59 case SDLK_PAGEDOWN:
60 return MenuAction::PAGE_DOWN;
61 case SDLK_RETURN: {
62 const Uint8 *state = SDLC_GetKeyState();
63 if (!state[SDLC_KEYSTATE_LALT] && !state[SDLC_KEYSTATE_RALT]) {
64 return MenuAction::SELECT;

Callers 4

DialogLoopFunction · 0.85
UiTitleDialogFunction · 0.85
UiCreditsDialogFunction · 0.85
UiFocusNavigationFunction · 0.85

Calls 3

ToControllerButtonEventFunction · 0.85
SDLC_GetKeyStateFunction · 0.85
SDL_IsTextInputActiveFunction · 0.85

Tested by

no test coverage detected