-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
46 lines (39 loc) · 1.21 KB
/
Copy pathmenu.cpp
File metadata and controls
46 lines (39 loc) · 1.21 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
#include <SDL2/SDL.h>
#include "menu.hpp"
namespace dungeon
{
void Menu::Run() {
SDL_Event e;
if (SDL_PollEvent(&e)) {
if (e.type == SDL_KEYDOWN) {
switch (e.key.keysym.sym) {
case SDLK_UP:
if (m_selectedItem == 0) {
m_selectedItem = m_items.size() - 1;
} else {
m_selectedItem--;
}
break;
case SDLK_DOWN:
if (m_selectedItem == m_items.size() - 1) {
m_selectedItem = 0;
} else {
m_selectedItem++;
}
break;
case SDLK_RETURN:
OnActivateItem(m_items[m_selectedItem]->GetId());
break;
}
}
}
}
void Menu::Draw() const
{
for (auto &&item : m_items) {
// Work out if this is the selected item.
bool selected = (item == m_items[m_selectedItem]);
item->Draw(selected);
}
}
}