-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cc
More file actions
36 lines (31 loc) · 1010 Bytes
/
menu.cc
File metadata and controls
36 lines (31 loc) · 1010 Bytes
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
#include <memory>
#include "menu.h"
#include "resources.h"
#define clip(x,a,b) (x < a ? a : (x > b ? b : x))
Menu::Menu(Game &g) : GameState{g}, cursor{0} {
setKeymap({
{ {}, {sf::Keyboard::Up}, std::make_shared<Commands::Menu::CursorUp>(*this)},
{ {}, {sf::Keyboard::Down}, std::make_shared<Commands::Menu::CursorDown>(*this)},
{ {}, {sf::Keyboard::Return}, std::make_shared<Commands::Menu::Select>(*this)}
});
};
void Menu::moveCursor(int delta) {
cursor = clip(cursor + delta, 0, (int)menu_option.size()-1);
}
void Menu::update() {}
void Menu::draw() {
window.clear();
sf::Font f = getResource<sf::Font>("resources/fonts/DejaVuSans.ttf");
int i = 0;
for (std::string option : menu_option) {
sf::Text t(option, f);
t.setCharacterSize(24);
t.setPosition({400, 200 + 32.f * i});
if (cursor == i) {
t.setFillColor(sf::Color::Green);
}
window.draw(t);
i++;
}
window.display();
}