-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgame_menu_impl.h
More file actions
56 lines (47 loc) · 1.29 KB
/
game_menu_impl.h
File metadata and controls
56 lines (47 loc) · 1.29 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
48
49
50
51
52
53
54
55
56
#ifndef GMENU_IMPL_H
#define GMENU_IMPL_H
#include "SFML/Graphics/RenderTarget.hpp"
#include "SFML/Graphics/RenderWindow.hpp"
#include "game_menu/game_menu.h"
#include "SFML/Graphics.hpp"
#include <string>
#include <vector>
#include <iostream>
namespace game_menu {
struct coordinates {
float x = 0;
float y = 0;
};
struct Item {
MenuItem data;
coordinates location;
sf::Text textObj;
};
class Menu {
public:
Menu(sf::RenderTarget &window, MenuConfig config)
: _window(window), _style(config.style), _title(config.title) {
for (auto &menu_item : config.items) {
_items.push_back({menu_item, {0, 0}});
std::cout << " Processing item " << menu_item.name << std::endl;
}
std::cout << "Size of items : " << _items.size() << std::endl;
}
void handleEvent(sf::Event &event);
void render();
private:
void setMenu();
void drawMenu();
sf::Text writeText(std::string str, sf::Font* font, unsigned int size, float x,
float y, const Color color);
void changeCurrSelectedItem(const bool moveUp);
void performCurrSelectedItemAction();
sf::RenderTarget &_window;
Style _style;
std::string _title;
std::vector<Item> _items;
coordinates _title_location;
int _currently_selected_item = 0;
};
} // namespace game_menu
#endif // GMENU_IMPL_H