Skip to content

Commit 0819c42

Browse files
committed
Style working well. New screenshots added.
1 parent 2ebefe4 commit 0819c42

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

Examples/GameMenu_sample/tests/sample_menu.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ namespace test {
1212
}
1313

1414
void main() {
15-
sf::RenderWindow w( sf::VideoMode( 500, 500 ), "Test", sf::Style::Close);
15+
sf::RenderWindow w( sf::VideoMode( 800, 600 ), "Sample Title", sf::Style::Close);
1616
std::vector<gmenu::MenuItem> itemList;
17-
std::string text[3] = { "Hello", "World","!!!" };
17+
std::string text[4] = { "Option1", "Option2","Option3", "Option4" };
1818
gmenu::MenuItem item;
1919
sf::Font font;
2020
font.loadFromFile( "sansation.ttf" );
2121
gmenu::Style style( font, font );
22-
style.layout = gmenu::Layout::TitleRight|gmenu::Layout::ItemRight;
23-
for ( int i = 0; i < 3; ++i ) {
22+
style.layout = gmenu::Layout::TitleLeft|gmenu::Layout::ItemLeft;
23+
style.TitleColor = sf::Color::White;
24+
style.ItemColor = sf::Color::Cyan;
25+
style.Selected = sf::Color::Yellow;
26+
style.PaddingTitle.top = 250;
27+
style.PaddingItems.top = 30;
28+
style.PaddingItems.left = -100;
29+
for ( int i = 0; i < 4; ++i ) {
2430
item.title = text[i];
2531
item.action = std::make_shared < test::testAction>();
2632
itemList.push_back( item );

Screenshots/2016-12-22 (1).png

17.3 KB
Loading

Screenshots/2016-12-22 (2).png

16.6 KB
Loading

Screenshots/2016-12-22.png

13.4 KB
Loading

Screenshots/Thumbs.db

33 KB
Binary file not shown.

include/GameMenu/GameMenu.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace gmenu {
4444
ItemRight = 1 << 4,
4545
ItemLeft = 1 << 5,
4646

47-
Default = TitleCentre | ItemCentre
47+
Default = TitleCentre | ItemCentre,
4848

4949
};
5050

@@ -60,16 +60,16 @@ namespace gmenu {
6060
unsigned int TitleFontSize = 50;
6161
unsigned int ItemFontSize = 20;
6262

63-
float MenuTitleScaleFactor = 0.125;
63+
float MenuTitleScaleFactor = 1.25;
6464
float MenuItemScaleFactor = 0.25;
6565

6666
struct {
67-
unsigned int top, left;
68-
} Padding;
67+
signed int top, left;
68+
} PaddingItems, PaddingTitle;
6969

7070
int layout = Layout::Default;
7171
Style(sf::Font &mf, sf::Font &itmf):
72-
TitleFont( mf ), ItemFont( itmf ), Padding {10,0}
72+
TitleFont( mf ), ItemFont( itmf ), PaddingTitle {10,0}, PaddingItems {0,0}
7373
{
7474
}
7575
};

src/GameMenu/GameMenu.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ namespace gmenu {
7272
text.setOrigin(textRect.width / 2.0f,0);
7373
if ( x - textRect.width / 2.0f < 0 ) {
7474
//std::cout << x << " " << textRect.width / 2.0f;
75-
x = textRect.width / 2 + style.Padding.left;
75+
x = textRect.width / 2 + style.PaddingTitle.left;
7676
}
7777
if ( x + textRect.width / 2.0f > window.getSize().x ) {
7878
//std::cout << x << " " << textRect.width / 2.0f;
79-
x = window.getSize().x - textRect.width/2 + style.Padding.left;
79+
x = window.getSize().x - textRect.width/2 + style.PaddingTitle.left;
8080
}
8181
text.setPosition(sf::Vector2f(x,y));
8282
window.draw(text);
@@ -93,21 +93,22 @@ namespace gmenu {
9393
if ( style.layout & Layout::TitleCentre ) offset_coefficient = 0.5;
9494
else if ( style.layout & Layout::TitleLeft ) offset_coefficient = 0.25;
9595
else if ( style.layout & Layout::TitleRight ) offset_coefficient = 0.75;
96-
float x = (float) window.getSize().x * offset_coefficient, y = style.Padding.top;
97-
title_location.x = (x + style.Padding.left);
96+
float x = (float) window.getSize().x * offset_coefficient, y = style.PaddingTitle.top;
97+
title_location.x = (x + style.PaddingTitle.left);
9898
title_location.y = y;
9999
std::cout << "title_location:" << title_location.x << " "<<title_location.y<<offset_coefficient<<std::endl;
100100
}
101101

102-
unsigned int menu_screen_height =(int) window.getSize().y * (1 - style.MenuTitleScaleFactor);
103-
unsigned int block_height = (int) menu_screen_height / menuItems.size() * style.MenuItemScaleFactor;
102+
unsigned int menu_screen_height =(int) window.getSize().y - title_location.y + style.PaddingItems.top ;
103+
std::cout << "Screen hieght" << menu_screen_height << std::endl;
104+
unsigned int block_height = (int) menu_screen_height/menuItems.size() * style.MenuItemScaleFactor;
104105

105106
float offset_coefficient = 0.5;
106107
if ( style.layout & Layout::ItemCentre ) offset_coefficient = 0.5;
107108
else if ( style.layout & Layout::ItemLeft ) offset_coefficient = 0.25;
108109
else if ( style.layout & Layout::ItemRight ) offset_coefficient = 0.75;
109110

110-
float x = (float)window.getSize().x * offset_coefficient + style.Padding.left;
111+
float x = (float)window.getSize().x * offset_coefficient + style.PaddingItems.left;
111112
float y = ((float)window.getSize().y) - 0.75 * menu_screen_height + block_height * 1 / 8;
112113
/* Calculating Menu item locations */
113114
for (int8_t i = 0; i < menuItems.size(); ++i) {

0 commit comments

Comments
 (0)