@@ -14,12 +14,11 @@ namespace gmenu {
1414 *===================================================*/
1515
1616 void Menu::setTitle (std::string title) {
17- menu_title = title;
17+ menuTitle = title;
1818 }
1919
2020 void Menu::setMenuItems ( std::vector<MenuItem> items ) {
21- menu_items.entries = items;
22- menu_items.size = items.size ();
21+ menuItems = items;
2322 }
2423
2524
@@ -30,30 +29,29 @@ namespace gmenu {
3029 void Menu::createMenu () {
3130 setMenu ();
3231 bool cont = true ;
33- while (window-> isOpen () && cont)
32+ while (window. isOpen () && cont)
3433 {
35-
3634 sf::Event event;
37- while (window-> pollEvent (event)) {
35+ while (window. pollEvent (event)) {
3836 if (event.type == sf::Event::Closed)
39- window-> close ();
37+ window. close ();
4038 else if (event.type == sf::Event::KeyPressed) {
4139 if (event.key .code == sf::Keyboard::Up) {
42- currently_selected_item = (currently_selected_item + menu_items .size - 1 ) % (menu_items .size );
40+ currently_selected_item = (currently_selected_item + menuItems .size () - 1 ) % (menuItems .size () );
4341 }
4442 else if (event.key .code == sf::Keyboard::Down) {
45- currently_selected_item = (currently_selected_item + 1 ) % (menu_items .size );
43+ currently_selected_item = (currently_selected_item + 1 ) % (menuItems .size () );
4644 }
4745 else if (event.key .code == sf::Keyboard::Return) {
48- cont = menu_items. entries [currently_selected_item].action ->start ();
46+ cont = menuItems [currently_selected_item].action ->start ();
4947 }
5048 }
5149 } // while( pollEvent )
5250
53- window-> clear ();
51+ window. clear ();
5452 drawMenu ();
55- window-> display ();
56- } // while window open
53+ window. display ();
54+ } // while window open
5755 } // create menu
5856
5957
@@ -77,12 +75,12 @@ namespace gmenu {
7775 x = textRect.width / 2 + style.Padding .left ;
7876 }
7977 text.setPosition (sf::Vector2f (x,y));
80- window-> draw (text);
78+ window. draw (text);
8179 } // writeText(...)
8280
8381 void Menu::setMenu () {
8482
85- std::cout << " screen size:" << window-> getSize ().x << " " << window-> getSize ().y << std::endl;
83+ std::cout << " screen size:" << window. getSize ().x << " " << window. getSize ().y << std::endl;
8684
8785 /* Setting title of menu */
8886 {
@@ -91,24 +89,24 @@ namespace gmenu {
9189 if ( style.layout & Layout::TitleCentre == Layout::TitleCentre ) offset_coefficient = 0.5 ;
9290 else if ( style.layout & Layout::TitleLeft == Layout::TitleLeft ) offset_coefficient = 0.25 ;
9391 else if ( style.layout & Layout::TitleRight == Layout::TitleRight ) offset_coefficient = 0.75 ;
94- float x = (float ) window-> getSize ().x * offset_coefficient, y = style.Padding .top ;
92+ float x = (float ) window. getSize ().x * offset_coefficient, y = style.Padding .top ;
9593 title_location.x = (x + style.Padding .left );
9694 title_location.y = y;
9795 std::cout << " title_location:" << title_location.x << " " <<title_location.y <<offset_coefficient<<std::endl;
9896 }
9997
100- unsigned int menu_screen_height =(int ) window-> getSize ().y * (1 - style.MenuTitleScaleFactor );
101- unsigned int block_height = (int ) menu_screen_height / menu_items .size * style.MenuItemScaleFactor ;
98+ unsigned int menu_screen_height =(int ) window. getSize ().y * (1 - style.MenuTitleScaleFactor );
99+ unsigned int block_height = (int ) menu_screen_height / menuItems .size () * style.MenuItemScaleFactor ;
102100
103101 float offset_coefficient = 0.5 ;
104102 if ( style.layout & Layout::ItemCentre == Layout::ItemCentre ) offset_coefficient = 0.5 ;
105103 else if ( style.layout & Layout::ItemLeft == Layout::ItemLeft ) offset_coefficient = 0.25 ;
106104 else if ( style.layout & Layout::ItemRight == Layout::ItemRight) offset_coefficient = 0.75 ;
107105
108- float x = (float )window-> getSize ().x * offset_coefficient + style.Padding .left ;
109- float y = ((float )window-> getSize ().y ) - 0.75 * menu_screen_height + block_height * 1 / 8 ;
106+ float x = (float )window. getSize ().x * offset_coefficient + style.Padding .left ;
107+ float y = ((float )window. getSize ().y ) - 0.75 * menu_screen_height + block_height * 1 / 8 ;
110108 /* Calculating Menu item locations */
111- for (int8_t i = 0 ; i < menu_items .size ; ++i) {
109+ for (int8_t i = 0 ; i < menuItems .size () ; ++i) {
112110 coordinates crd ;
113111 crd.x = x;
114112 crd.y = y;
@@ -121,14 +119,14 @@ namespace gmenu {
121119 } // setMenu()
122120
123121 void Menu::drawMenu () {
124- writeText (menu_title , style.ItemFont , style.TitleFontSize , title_location.x , title_location.y , style.TitleColor );
122+ writeText (menuTitle , style.ItemFont , style.TitleFontSize , title_location.x , title_location.y , style.TitleColor );
125123 sf::Color color = style.ItemColor ;
126- for (int i = 0 ; i < menu_items .size ; ++i)
124+ for (int i = 0 ; i < menuItems .size () ; ++i)
127125 {
128126 if (i == currently_selected_item) {
129127 color = style.Selected ;
130128 }
131- writeText (menu_items. entries [i].title , style.ItemFont , style.ItemFontSize , item_location[i].x , item_location[i].y , color);
129+ writeText ( menuItems [i].title , style.ItemFont , style.ItemFontSize , item_location[i].x , item_location[i].y , color);
132130 color = style.ItemColor ;
133131 }
134132
0 commit comments