55*/
66
77#include < GameMenu/GameMenu.h>
8-
8+ # include < iostream >
99namespace gmenu {
1010
1111
@@ -72,31 +72,50 @@ namespace gmenu {
7272 text.setCharacterSize (size);
7373 sf::FloatRect textRect = text.getLocalBounds ();
7474 text.setOrigin (textRect.width / 2 .0f ,0 );
75+ if ( x - textRect.width / 2 .0f < 0 ) {
76+ // std::cout << x << " " << textRect.width / 2.0f;
77+ x = textRect.width / 2 + style.Padding .left ;
78+ }
7579 text.setPosition (sf::Vector2f (x,y));
7680 window->draw (text);
7781 } // writeText(...)
7882
7983 void Menu::setMenu () {
8084
85+ std::cout << " screen size:" << window->getSize ().x << " " << window->getSize ().y << std::endl;
86+
8187 /* Setting title of menu */
8288 {
8389 /* Small scope just to be able to freely use the variable names */
84- float x = (float ) window->getSize ().x / 2 , y = 0 ;
85- title_location.x = x;
90+ int offset_coefficient = 0.5 ;
91+ if ( style.layout & Layout::TitleCentre == Layout::TitleCentre ) offset_coefficient = 0.5 ;
92+ else if ( style.layout & Layout::TitleLeft == Layout::TitleLeft ) offset_coefficient = 0.25 ;
93+ 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 ;
95+ title_location.x = (x + style.Padding .left );
8696 title_location.y = y;
97+ std::cout << " title_location:" << title_location.x << " " <<title_location.y <<offset_coefficient<<std::endl;
8798 }
8899
89- unsigned int menu_screen_height =(int ) window->getSize ().y * (1 - MenuTitleScaleFactor);
90- unsigned int block_height = (int ) menu_screen_height / menu_items.size * MenuItemScaleFactor;
91- float x = (float )window->getSize ().x / 2 ;
92- float y = (float )window->getSize ().y - 0.75 * menu_screen_height + block_height * 1 / 8 ;
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 ;
102+
103+ float offset_coefficient = 0.5 ;
104+ if ( style.layout & Layout::ItemCentre == Layout::ItemCentre ) offset_coefficient = 0.5 ;
105+ else if ( style.layout & Layout::ItemLeft == Layout::ItemLeft ) offset_coefficient = 0.25 ;
106+ else if ( style.layout & Layout::ItemRight == Layout::ItemRight) offset_coefficient = 0.75 ;
107+
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 ;
93110 /* Calculating Menu item locations */
94111 for (int8_t i = 0 ; i < menu_items.size ; ++i) {
95112 coordinates crd ;
96113 crd.x = x;
97114 crd.y = y;
98115 item_location.push_back ( crd );
116+ std::cout << " menu location:" << x << " " << y <<offset_coefficient<< std::endl;
99117 y += block_height;
118+
100119 }
101120
102121 } // setMenu()
@@ -116,4 +135,5 @@ namespace gmenu {
116135 } // drawMenu()
117136
118137
138+
119139} // namespace sui
0 commit comments