forked from DKU-EmbeddedSystem-Lab/2025_DKU_OpenSourceBasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelcetionInputHandler.cpp
More file actions
47 lines (42 loc) · 1.58 KB
/
SelcetionInputHandler.cpp
File metadata and controls
47 lines (42 loc) · 1.58 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
45
46
47
#include "MenuInputHelper.hpp"
#include "inputmanager.hpp"
#include "button.hpp"
#include "game.hpp"
void SelectionInputHandler::handle(InputManager* input, std::vector<Button*>& buttons, size_t& index,StateID& nextStateID) {
while (input->pollAction()) {
if (input->isGameExiting())
{
nextStateID = STATE_EXIT;
break;
}
switch (input->getAction()) {
case Action::move_up:
if (index > 0) --index;
break;
case Action::move_down:
if (index < buttons.size() - 1) ++index;
break;
case Action::select:
buttons[index]->callbackFunction();
break;
case Action::back:
Game::getInstance()->popState();
break;
default:
break;
}
}
}
void SelectionInputHandler::renderHighlight(std::vector<Button*>& buttons, size_t index) {
if (index >= buttons.size()) return;
SDL_Rect highlight_box = {
buttons[index]->getX(),
buttons[index]->getY(),
buttons[index]->getWidth(),
buttons[index]->getHeight()
};
SDL_SetRenderDrawBlendMode(Game::getInstance()->mRenderer->mSDLRenderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(Game::getInstance()->mRenderer->mSDLRenderer, 255, 255, 255, config::transparency_alpha - 20);
SDL_RenderFillRect(Game::getInstance()->mRenderer->mSDLRenderer, &highlight_box);
SDL_SetRenderDrawBlendMode(Game::getInstance()->mRenderer->mSDLRenderer, SDL_BLENDMODE_NONE);
}