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:
cosmosninja 2007-12-03 23:11:07 +00:00
parent ebc96833ad
commit 95093755b9
2 changed files with 32 additions and 6 deletions

View File

@ -33,7 +33,7 @@ WidgetManager *widget_manager;
const int WidgetManager::WGT_NONE = -1; const int WidgetManager::WGT_NONE = -1;
WidgetManager::WidgetManager() : 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(); init_fonts();
restore_default_states(); restore_default_states();
@ -326,9 +326,29 @@ int WidgetManager::calc_height() const
return total_height; 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) 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(); const int NUM_WIDGETS = m_widgets.size();
if( NUM_WIDGETS < 0 ) return true; 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 " << std::cerr << "WARNING: total width of the widgets is bigger than " <<
"the screen, because the total minimum width given is bigger " << "the screen, because the total minimum width given is bigger " <<
"than 100%,\n"; "than 100%.\n";
} }
if( WGTS_HEIGHT > SCREEN_HEIGHT ) if( WGTS_HEIGHT > SCREEN_HEIGHT )
{ {
@ -412,12 +432,14 @@ bool WidgetManager::layout(const WidgetArea POSITION)
m_y = 0; m_y = 0;
break; break;
//A layout of WGT_AREA_NONE should probably just do nothing.
case WGT_AREA_NONE:
case WGT_AREA_ALL: case WGT_AREA_ALL:
m_x = (int)(SCREEN_WIDTH * 0.5f - WGTS_WIDTH * 0.5f ); m_x = (int)(SCREEN_WIDTH * 0.5f - WGTS_WIDTH * 0.5f );
m_y = (int)(SCREEN_HEIGHT * 0.5 + WGTS_HEIGHT * 0.5f ); m_y = (int)(SCREEN_HEIGHT * 0.5 + WGTS_HEIGHT * 0.5f );
break; 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 //This formula seems not to have much theory behind it, we pick the

View File

@ -80,6 +80,8 @@ class WidgetManager
std::vector<WidgetElement> m_elems; std::vector<WidgetElement> m_elems;
std::vector<WidgetID> m_widgets; std::vector<WidgetID> m_widgets;
WidgetArea prev_layout_pos;
int m_x; int m_x;
int m_y; int m_y;
@ -149,8 +151,10 @@ public:
void update(const float DELTA); void update(const float DELTA);
//TODO: WGT_AREA_NONE and WGT_AREA_ALL should have some difference. bool layout(); //This calls the other layout() function with the
//Both WGT_AREA_NONE and WGT_AREA_ALL will produce centered widgets. //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 ); bool layout( const WidgetArea POSITION );
//TODO: make all get functions const //TODO: make all get functions const