Skip to content

Commit d52fab7

Browse files
committed
Layout working. Style is almost complete. Now only Title sprite needed.
1 parent 8382817 commit d52fab7

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

Examples/GameMenu_sample/tests/sample_menu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void main() {
1919
sf::Font font;
2020
font.loadFromFile( "sansation.ttf" );
2121
gmenu::Style style( font, font );
22-
style.layout = gmenu::Layout::TitleCentre|gmenu::Layout::ItemRight;
22+
style.layout = gmenu::Layout::TitleRight|gmenu::Layout::ItemRight;
2323
for ( int i = 0; i < 3; ++i ) {
2424
item.title = text[i];
2525
item.action = std::make_shared < test::testAction>();

include/GameMenu/GameMenu.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,33 @@ namespace gmenu {
140140

141141
}; // Menu
142142

143+
144+
/*==================================================*
145+
* Operator overload *
146+
*===================================================*/
147+
template<class T> inline T operator~ ( T a ) {
148+
return (T) ~(int) a;
149+
}
150+
template<class T> inline T operator| ( T a, T b ) {
151+
return (T) ((int) a | (int) b);
152+
}
153+
template<class T> inline T operator& ( T a, T b ) {
154+
return (T) ((int) a & (int) b);
155+
}
156+
template<class T> inline T operator^ ( T a, T b ) {
157+
return (T) ((int) a ^ (int) b);
158+
}
159+
template<class T> inline T& operator|= ( T& a, T b ) {
160+
return (T&) ((int&) a |= (int) b);
161+
}
162+
template<class T> inline T& operator&= ( T& a, T b ) {
163+
return (T&) ((int&) a &= (int) b);
164+
}
165+
template<class T> inline T& operator^= ( T& a, T b ) {
166+
return (T&) ((int&) a ^= (int) b);
167+
}
168+
169+
143170
} // namespace gmenu
144171

145172
#endif

src/GameMenu/GameMenu.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ namespace gmenu {
7474
//std::cout << x << " " << textRect.width / 2.0f;
7575
x = textRect.width / 2 + style.Padding.left;
7676
}
77+
if ( x + textRect.width / 2.0f > window.getSize().x ) {
78+
//std::cout << x << " " << textRect.width / 2.0f;
79+
x = window.getSize().x - textRect.width/2 + style.Padding.left;
80+
}
7781
text.setPosition(sf::Vector2f(x,y));
7882
window.draw(text);
7983
} //writeText(...)
@@ -86,9 +90,9 @@ namespace gmenu {
8690
{
8791
/* Small scope just to be able to freely use the variable names */
8892
float offset_coefficient = 0.5;
89-
if ( style.layout & Layout::TitleCentre == Layout::TitleCentre ) offset_coefficient = 0.5;
90-
else if ( style.layout & Layout::TitleLeft == Layout::TitleLeft ) offset_coefficient = 0.25;
91-
else if ( style.layout & Layout::TitleRight == Layout::TitleRight ) offset_coefficient = 0.75;
93+
if ( style.layout & Layout::TitleCentre ) offset_coefficient = 0.5;
94+
else if ( style.layout & Layout::TitleLeft ) offset_coefficient = 0.25;
95+
else if ( style.layout & Layout::TitleRight ) offset_coefficient = 0.75;
9296
float x = (float) window.getSize().x * offset_coefficient, y = style.Padding.top;
9397
title_location.x = (x + style.Padding.left);
9498
title_location.y = y;
@@ -99,9 +103,9 @@ namespace gmenu {
99103
unsigned int block_height = (int) menu_screen_height / menuItems.size() * style.MenuItemScaleFactor;
100104

101105
float offset_coefficient = 0.5;
102-
if ( style.layout & Layout::ItemCentre == Layout::ItemCentre ) offset_coefficient = 0.5;
103-
else if ( style.layout & Layout::ItemLeft == Layout::ItemLeft ) offset_coefficient = 0.25;
104-
else if ( style.layout & Layout::ItemRight == Layout::ItemRight) offset_coefficient = 0.75;
106+
if ( style.layout & Layout::ItemCentre ) offset_coefficient = 0.5;
107+
else if ( style.layout & Layout::ItemLeft ) offset_coefficient = 0.25;
108+
else if ( style.layout & Layout::ItemRight ) offset_coefficient = 0.75;
105109

106110
float x = (float)window.getSize().x * offset_coefficient + style.Padding.left;
107111
float y = ((float)window.getSize().y) - 0.75 * menu_screen_height + block_height * 1 / 8;

0 commit comments

Comments
 (0)