-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
36 lines (31 loc) · 1001 Bytes
/
Menu.cpp
File metadata and controls
36 lines (31 loc) · 1001 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 "Menu.h"
Menu::Menu(const std::vector<std::string>& options, float width, float height)
: options(options), selectedIndex(0) {
font.loadFromFile("Arial.ttf");
menuText.setFont(font);
menuText.setCharacterSize(24);
menuText.setFillColor(sf::Color::White);
menuText.setPosition(width / 4, height / 4);
}
void Menu::draw(sf::RenderWindow& window, const sf::Font& font) {
for (size_t i = 0; i < options.size(); ++i) {
menuText.setString(options[i]);
menuText.setFont(font); // Se asegura de usar la fuente proporcionada
menuText.setFillColor(i == selectedIndex ? sf::Color::Red : sf::Color::White);
menuText.setPosition(200, 100 + i * 50);
window.draw(menuText);
}
}
void Menu::moveUp() {
if (selectedIndex > 0) {
selectedIndex--;
}
}
void Menu::moveDown() {
if (selectedIndex < options.size() - 1) {
selectedIndex++;
}
}
int Menu::getSelectedIndex() const {
return selectedIndex;
}