@@ -33,24 +33,76 @@ namespace gmenu {
33
33
sf::Font font;
34
34
};
35
35
36
- /* Generic Menu - can be instantiated to generate a custom menu as needed over a sf::RenderWindow */
37
36
class Menu {
37
+ /* Generic Menu - can be instantiated to generate a custom menu as needed over a sf::RenderWindow */
38
+
39
+ public:
40
+
41
+ /* Only accesible constructor */
42
+ Menu (sf::RenderWindow *window, std::string title,sf::Font titleFont, MenuItem* items, int8_t length)
43
+ : Menu(window, title, titleFont) {
44
+ setMenuItems (items, length);
45
+ }
46
+
47
+
48
+
49
+ /* This method is will start the menu and handover the screen control to it.
50
+ The Event loop will be controlled by this function after the call, and
51
+ only after Back/exit on the menu will the control be returned.
52
+
53
+ The control is returned when an "gmenu::Action" object is called
54
+ whose start return "false" */
55
+ void createMenu ();
56
+
57
+ /* In case menu items needs to be changed */
58
+ void setMenuItems (MenuItem *, int8_t );
59
+
60
+ /* In case the title needs to be changed */
61
+ void setTitle (std::string title, sf::Font font);
62
+
63
+
38
64
private:
65
+
66
+ Menu ( sf::RenderWindow *wnd ) {
67
+ window = wnd;
68
+ }
69
+
70
+
71
+ Menu ( sf::RenderWindow *window, std::string title, sf::Font titleFont ) : Menu( window ) {
72
+ setTitle ( title, titleFont );
73
+ }
74
+
75
+ void writeText ( std::string string, sf::Font font, unsigned int size, float x, float y,
76
+ const sf::Color &color = sf::Color::White );
77
+
78
+ void setMenu ();
79
+
80
+ void drawMenu ();
81
+
82
+
83
+ /* ==================================================*
84
+ * Internal structuers *
85
+ *===================================================*/
39
86
40
- /* structures to hold the menu item informtion */
41
87
struct {
42
88
MenuItem *entries;
43
89
int8_t size;
44
90
} menu_items;
45
91
46
92
struct coordinates {
47
- coordinates () { x = y = 0 .f ; size = 0 ; }
93
+ coordinates () {
94
+ x = y = 0 .f ; size = 0 ;
95
+ }
48
96
float x;
49
97
float y;
50
98
int size;
51
99
} *menu_location, title_location;
52
100
53
101
102
+ /* ==================================================*
103
+ * Data Members *
104
+ *===================================================*/
105
+
54
106
int currently_selected_item = 0 ;
55
107
56
108
sf::Font MenuItemFont;
@@ -62,36 +114,6 @@ namespace gmenu {
62
114
float MenuTitleScaleFactor = 0.125 ;
63
115
float MenuItemScaleFactor = 0.25 ;
64
116
65
-
66
- void writeText (std::string string, sf::Font font, unsigned int size, float x, float y,
67
- const sf::Color &color = sf::Color::White);
68
-
69
- void setMenu ();
70
-
71
- void drawMenu ();
72
-
73
-
74
- public:
75
- Menu (sf::RenderWindow *wnd) {
76
- window = wnd;
77
- }
78
-
79
- Menu (sf::RenderWindow *window, std::string title, sf::Font titleFont) : Menu(window) {
80
- setTitle (title,titleFont);
81
- }
82
-
83
- Menu (sf::RenderWindow *window, std::string title,sf::Font titleFont, MenuItem* items, int8_t length)
84
- : Menu(window, title, titleFont) {
85
- setMenuItems (items, length);
86
- }
87
-
88
- void setMenuItems (MenuItem *, int8_t );
89
-
90
- void setTitle (std::string title, sf::Font font);
91
-
92
- void createMenu ();
93
-
94
-
95
117
}; // Menu
96
118
97
119
} // namespace sui
0 commit comments