Added argument-less layout() function which uses the last argument given to the other layout() function, and fixed a typo.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1313 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
ebc96833ad
commit
95093755b9
@ -33,7 +33,7 @@ WidgetManager *widget_manager;
|
||||
const int WidgetManager::WGT_NONE = -1;
|
||||
|
||||
WidgetManager::WidgetManager() :
|
||||
m_x( -1 ), m_y( -1 ), m_selected_wgt_token( WGT_NONE )
|
||||
prev_layout_pos(WGT_AREA_NONE), m_x( -1 ), m_y( -1 ), m_selected_wgt_token( WGT_NONE )
|
||||
{
|
||||
init_fonts();
|
||||
restore_default_states();
|
||||
@ -326,9 +326,29 @@ int WidgetManager::calc_height() const
|
||||
return total_height;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WidgetManager::layout()
|
||||
{
|
||||
if( prev_layout_pos == WGT_AREA_NONE )
|
||||
{
|
||||
std::cerr << "WARNING: tried to call layout() with the previous " <<
|
||||
"layout position, but layout(WidgetArea POSITION) has never " <<
|
||||
"been called.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return layout(prev_layout_pos);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WidgetManager::layout(const WidgetArea POSITION)
|
||||
{
|
||||
if( POSITION == WGT_AREA_NONE )
|
||||
{
|
||||
std::cerr << "WARNING: called layout with WGT_AREA_NONE.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
const int NUM_WIDGETS = m_widgets.size();
|
||||
if( NUM_WIDGETS < 0 ) return true;
|
||||
|
||||
@ -358,7 +378,7 @@ bool WidgetManager::layout(const WidgetArea POSITION)
|
||||
{
|
||||
std::cerr << "WARNING: total width of the widgets is bigger than " <<
|
||||
"the screen, because the total minimum width given is bigger " <<
|
||||
"than 100%,\n";
|
||||
"than 100%.\n";
|
||||
}
|
||||
if( WGTS_HEIGHT > SCREEN_HEIGHT )
|
||||
{
|
||||
@ -412,12 +432,14 @@ bool WidgetManager::layout(const WidgetArea POSITION)
|
||||
m_y = 0;
|
||||
break;
|
||||
|
||||
//A layout of WGT_AREA_NONE should probably just do nothing.
|
||||
case WGT_AREA_NONE:
|
||||
case WGT_AREA_ALL:
|
||||
m_x = (int)(SCREEN_WIDTH * 0.5f - WGTS_WIDTH * 0.5f );
|
||||
m_y = (int)(SCREEN_HEIGHT * 0.5 + WGTS_HEIGHT * 0.5f );
|
||||
break;
|
||||
|
||||
//This is just here to avoid a warning
|
||||
case WGT_AREA_NONE:
|
||||
break;
|
||||
}
|
||||
|
||||
//This formula seems not to have much theory behind it, we pick the
|
||||
|
@ -80,6 +80,8 @@ class WidgetManager
|
||||
std::vector<WidgetElement> m_elems;
|
||||
std::vector<WidgetID> m_widgets;
|
||||
|
||||
WidgetArea prev_layout_pos;
|
||||
|
||||
int m_x;
|
||||
int m_y;
|
||||
|
||||
@ -149,8 +151,10 @@ public:
|
||||
|
||||
void update(const float DELTA);
|
||||
|
||||
//TODO: WGT_AREA_NONE and WGT_AREA_ALL should have some difference.
|
||||
//Both WGT_AREA_NONE and WGT_AREA_ALL will produce centered widgets.
|
||||
bool layout(); //This calls the other layout() function with the
|
||||
//POSITION given to the previous call to any of the two
|
||||
//layout functions. Fails if no previous call to the
|
||||
//layout(POSITION) function has been done.
|
||||
bool layout( const WidgetArea POSITION );
|
||||
|
||||
//TODO: make all get functions const
|
||||
|
Loading…
Reference in New Issue
Block a user