nsnake
Classic snake game for the terminal
Loading...
Searching...
No Matches
Menu.hpp
1#ifndef MENU_H_DEFINED
2#define MENU_H_DEFINED
3
4#include <Interface/Window.hpp>
5#include <Interface/Menu/MenuItem.hpp>
6#include <Interface/Menu/MenuItemLabel.hpp>
7#include <Interface/Menu/MenuItemCheckbox.hpp>
8#include <Interface/Menu/MenuItemNumberbox.hpp>
9#include <Interface/Menu/MenuItemTextbox.hpp>
10#include <Interface/Menu/MenuItemTextlist.hpp>
11
12#include <vector>
13#include <string>
14
28class Menu
29{
30public:
35 Menu(int x, int y, int width, int height);
36
37 virtual ~Menu();
38
39 void add(MenuItem* item);
40 void addBlank();
41
43 void removeByID(int id);
44
52 void removeByLabel(std::string label);
53
55 void draw(Window* window);
56
59 void handleInput();
60
64 void goNext();
65
69 void goPrevious();
70
71 void goFirst();
72 void goLast();
73 void goRandom();
74
76 bool willQuit();
77
79 std::string currentLabel();
80
82 int currentID();
83
86 bool getBool(int id);
87
90 int getInt(int id);
91
95 std::string getString(int id);
96
103 void reset();
104
105 // FIXME: create an iterator so I dont need to expose
106 // this vector
107
109 std::vector<MenuItem*> item;
110
116
117protected:
119 unsigned int currentIndex;
120
121 int x;
122 int y;
123 int width;
124 int height;
125
128
131};
132
133#endif //MENU_H_DEFINED
134
List of selectable items.
Definition Menu.hpp:29
void goPrevious()
Makes the menu select the previous item.
Definition Menu.cpp:259
void draw(Window *window)
Draws the whole Menu on #window.
Definition Menu.cpp:95
unsigned int currentIndex
Index of the currently selected item.
Definition Menu.hpp:119
std::string currentLabel()
Returns the label of the currently selected item.
Definition Menu.cpp:336
bool getBool(int id)
Returns the bool internal value of item that has #id.
Definition Menu.cpp:350
bool willQuit()
Tells if the user selected an item that quits the menu.
Definition Menu.cpp:330
void handleInput()
Makes the menu react to input, as seen on the global InputManager.
Definition Menu.cpp:183
std::vector< MenuItem * > item
Container of all the options inside the menu.
Definition Menu.hpp:109
int currentID()
Returns the user-specified id of the selected item.
Definition Menu.cpp:343
bool selected
Tells if the user selected an item (pressed Enter).
Definition Menu.hpp:127
int getInt(int id)
Returns the integer value of the item that has #id.
Definition Menu.cpp:372
MenuItem * selectedItem
Specifies which item the user pressed Enter on.
Definition Menu.hpp:130
std::string getString(int id)
Returns the string value of the item that has #id.
Definition Menu.cpp:394
MenuItem * current
Current item selected.
Definition Menu.hpp:115
Menu(int x, int y, int width, int height)
Creates a menu at x and y with width and height.
Definition Menu.cpp:6
void removeByID(int id)
Removes the menu item with #id.
Definition Menu.cpp:47
void removeByLabel(std::string label)
Removes the menu item with #label.
Definition Menu.cpp:71
void reset()
Makes the menu able to be selected again.
Definition Menu.cpp:424
void goNext()
Makes the menu select the next item.
Definition Menu.cpp:226
A segment of the terminal screen (2D char matrix).
Definition Window.hpp:17
Simplest type of item possible, with a label and user-defined id.
Definition MenuItem.hpp:12