From 66cc077beb94d113d7ee04fc44cca4bb189e735e Mon Sep 17 00:00:00 2001 From: auria <auria@178a84e3-b1eb-0310-8ba1-8eac791a3b58> Date: Sat, 2 May 2009 19:34:07 +0000 Subject: [PATCH] improved layout in preferences to adapt to more resolutions. added max_width/max_height properties git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3446 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/help1.stkgui | 2 +- data/gui/help2.stkgui | 2 +- data/gui/help3.stkgui | 3 +-- data/gui/options_av.stkgui | 2 +- data/gui/options_input.stkgui | 2 +- data/gui/options_players.stkgui | 2 +- src/gui/engine.hpp | 5 ++++- src/gui/screen.cpp | 12 ++++++++++++ src/gui/screen_loader.cpp | 3 +++ src/gui/widget.cpp | 13 +++++++++++++ src/gui/widget.hpp | 2 ++ 11 files changed, 40 insertions(+), 8 deletions(-) diff --git a/data/gui/help1.stkgui b/data/gui/help1.stkgui index 12c795ddf..6003b7b49 100644 --- a/data/gui/help1.stkgui +++ b/data/gui/help1.stkgui @@ -2,7 +2,7 @@ <label align="center" text="SuperTuxKart Help"/> -<tabs id="category" height="130" width="75%" align="center"> +<tabs id="category" height="15%" max_height="150" width="75%" align="center"> <icon-button id="page1" width="128" height="128" icon="gui/track_random.png" text="General"/> <icon-button id="page2" width="128" height="128" icon="gui/mode_normal.png" text="Weapons"/> <icon-button id="page3" width="128" height="128" icon="gui/mode_ftl.png" text="Game Modes"/> diff --git a/data/gui/help2.stkgui b/data/gui/help2.stkgui index 2a7673b7b..6fabaee7f 100644 --- a/data/gui/help2.stkgui +++ b/data/gui/help2.stkgui @@ -2,7 +2,7 @@ <label align="center" text="SuperTuxKart Help"/> -<tabs id="category" height="130" width="75%" align="center"> +<tabs id="category" height="15%" max_height="150" width="75%" align="center"> <icon-button id="page1" width="128" height="128" icon="gui/track_random.png" text="General"/> <icon-button id="page2" width="128" height="128" icon="gui/mode_normal.png" text="Weapons"/> <icon-button id="page3" width="128" height="128" icon="gui/mode_ftl.png" text="Game Modes"/> diff --git a/data/gui/help3.stkgui b/data/gui/help3.stkgui index 019f09e3f..4f719ba5a 100644 --- a/data/gui/help3.stkgui +++ b/data/gui/help3.stkgui @@ -1,9 +1,8 @@ - <div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" > <label align="center" text="SuperTuxKart Help"/> -<tabs id="category" height="130" width="75%" align="center"> +<tabs id="category" height="15%" max_height="150" width="75%" align="center"> <icon-button id="page1" width="128" height="128" icon="gui/track_random.png" text="General"/> <icon-button id="page2" width="128" height="128" icon="gui/mode_normal.png" text="Weapons"/> <icon-button id="page3" width="128" height="128" icon="gui/mode_ftl.png" text="Game Modes"/> diff --git a/data/gui/options_av.stkgui b/data/gui/options_av.stkgui index 72c76e9ec..bc2f4c10c 100644 --- a/data/gui/options_av.stkgui +++ b/data/gui/options_av.stkgui @@ -2,7 +2,7 @@ <label align="center" text="SuperTuxKart Options"/> -<tabs id="options_choice" height="130" width="75%" align="center"> +<tabs id="options_choice" height="15%" max_height="150" width="75%" align="center"> <icon-button id="audio_video" width="128" height="128" icon="gui/options_audio_video.png" text="Audio/Video"/> <icon-button id="players" width="128" height="128" icon="gui/options_players.png" text="Players"/> <icon-button id="controls" width="128" height="128" icon="gui/options_input.png" text="Controls"/> diff --git a/data/gui/options_input.stkgui b/data/gui/options_input.stkgui index 8eca2ca59..757e18ff9 100644 --- a/data/gui/options_input.stkgui +++ b/data/gui/options_input.stkgui @@ -2,7 +2,7 @@ <label align="center" text="SuperTuxKart Options"/> -<tabs id="options_choice" height="130" width="75%" align="center"> +<tabs id="options_choice" height="15%" max_height="150" width="75%" align="center"> <icon-button id="audio_video" width="128" height="128" icon="gui/options_audio_video.png" text="Audio/Video"/> <icon-button id="players" width="128" height="128" icon="gui/options_players.png" text="Players"/> <icon-button id="controls" width="128" height="128" icon="gui/options_input.png" text="Controls"/> diff --git a/data/gui/options_players.stkgui b/data/gui/options_players.stkgui index 3cac01432..c0d748408 100644 --- a/data/gui/options_players.stkgui +++ b/data/gui/options_players.stkgui @@ -2,7 +2,7 @@ <label align="center" text="SuperTuxKart Options"/> -<tabs id="options_choice" height="130" width="75%" align="center"> +<tabs id="options_choice" height="15%" max_height="150" width="75%" align="center"> <icon-button id="audio_video" width="128" height="128" icon="gui/options_audio_video.png" text="Audio/Video"/> <icon-button id="players" width="128" height="128" icon="gui/options_players.png" text="Players"/> <icon-button id="controls" width="128" height="128" icon="gui/options_input.png" text="Controls"/> diff --git a/src/gui/engine.hpp b/src/gui/engine.hpp index 8a09dec5e..9d57b3616 100644 --- a/src/gui/engine.hpp +++ b/src/gui/engine.hpp @@ -119,7 +119,10 @@ for you (see PROP_LAYOUT). In addition, sizes are automatically calculated for w and/or text like labels and plain icons. Other widgets will also automativally manage the position and size of their children, for instance ribbons. - +PROP_MAX_WIDTH "max_width" +PROP_MAX_HEIGHT "max_height" +The maximum size a widget can take; especially useful when using percentages and proportions. + PROP_CHILD_WIDTH "child_width" PROP_CHILD_HEIGHT "child_height" Used exclusively by the ribbon grid widget. See docs for this widget above. diff --git a/src/gui/screen.cpp b/src/gui/screen.cpp index 36ba8d2c3..974f27799 100644 --- a/src/gui/screen.cpp +++ b/src/gui/screen.cpp @@ -127,12 +127,24 @@ void Screen::calculateLayout(ptr_vector<Widget>& widgets, Widget* parent) widgets[n].y = y; widgets[n].w = (int)(left_space*fraction); + if(widgets[n].m_properties[PROP_MAX_WIDTH].size() > 0) + { + const int max_width = atoi( widgets[n].m_properties[PROP_MAX_WIDTH].c_str() ); + if(widgets[n].w > max_width) widgets[n].w = max_width; + } + x += widgets[n].w; } else { widgets[n].h = (int)(left_space*fraction); + if(widgets[n].m_properties[PROP_MAX_HEIGHT].size() > 0) + { + const int max_height = atoi( widgets[n].m_properties[PROP_MAX_HEIGHT].c_str() ); + if(widgets[n].h > max_height) widgets[n].h = max_height; + } + std::string align = widgets[n].m_properties[ PROP_ALIGN ]; if(align.size() < 1 || align == "left") widgets[n].x = x; else if(align == "center") widgets[n].x = x + w/2 - widgets[n].w/2; diff --git a/src/gui/screen_loader.cpp b/src/gui/screen_loader.cpp index 526fadb68..6c8fcc20c 100644 --- a/src/gui/screen_loader.cpp +++ b/src/gui/screen_loader.cpp @@ -146,6 +146,9 @@ if(prop_name != NULL) widget.m_properties[prop_flag] = prop_name; else widget.m_ READ_PROPERTY(min_value, PROP_MIN_VALUE); READ_PROPERTY(max_value, PROP_MAX_VALUE); READ_PROPERTY(square_items, PROP_SQUARE); + + READ_PROPERTY(max_width, PROP_MAX_WIDTH); + READ_PROPERTY(max_height, PROP_MAX_HEIGHT); #undef READ_PROPERTY /* a new div starts here, continue parsing with this new div as new parent */ diff --git a/src/gui/widget.cpp b/src/gui/widget.cpp index 8e2a8e712..72ddcab47 100644 --- a/src/gui/widget.cpp +++ b/src/gui/widget.cpp @@ -196,6 +196,19 @@ void Widget::readCoords(Widget* parent) this->w = (int)(this->w*ratio); this->h = (int)(this->h*ratio); } + + // ------ check for given max size + if(m_properties[PROP_MAX_WIDTH].size() > 0) + { + const int max_width = atoi( this->m_properties[PROP_MAX_WIDTH].c_str() ); + if(this->w > max_width) this->w = max_width; + } + + if(m_properties[PROP_MAX_HEIGHT].size() > 0) + { + const int max_height = atoi( this->m_properties[PROP_MAX_HEIGHT].c_str() ); + if(this->h > max_height) this->h = max_height; + } } diff --git a/src/gui/widget.hpp b/src/gui/widget.hpp index 9701937e2..2fbee2f5b 100644 --- a/src/gui/widget.hpp +++ b/src/gui/widget.hpp @@ -47,6 +47,8 @@ namespace GUIEngine PROP_TEXT_ALIGN, PROP_MIN_VALUE, PROP_MAX_VALUE, + PROP_MAX_WIDTH, + PROP_MAX_HEIGHT, PROP_SQUARE };