@@ -33,24 +33,76 @@ namespace gmenu {
3333 sf::Font font;
3434 };
3535
36- /* Generic Menu - can be instantiated to generate a custom menu as needed over a sf::RenderWindow */
3736 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+
3864 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+ *===================================================*/
3986
40- /* structures to hold the menu item informtion */
4187 struct {
4288 MenuItem *entries;
4389 int8_t size;
4490 } menu_items;
4591
4692 struct coordinates {
47- coordinates () { x = y = 0 .f ; size = 0 ; }
93+ coordinates () {
94+ x = y = 0 .f ; size = 0 ;
95+ }
4896 float x;
4997 float y;
5098 int size;
5199 } *menu_location, title_location;
52100
53101
102+ /* ==================================================*
103+ * Data Members *
104+ *===================================================*/
105+
54106 int currently_selected_item = 0 ;
55107
56108 sf::Font MenuItemFont;
@@ -62,36 +114,6 @@ namespace gmenu {
62114 float MenuTitleScaleFactor = 0.125 ;
63115 float MenuItemScaleFactor = 0.25 ;
64116
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-
95117 }; // Menu
96118
97119} // namespace sui
0 commit comments