Beginnings of supporting columns in the widget manager, for easier layout.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1304 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
59fb95e64b
commit
456e205494
@ -97,6 +97,54 @@ bool WidgetManager::add_wgt
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WidgetManager::insert_column()
|
||||
{
|
||||
const int NUM_WGTS = m_widgets.size();
|
||||
const int LAST_BREAK = m_breaks.size() - 1;
|
||||
|
||||
//Check if we are at the beginning of a line
|
||||
if( NUM_WGTS > 0)
|
||||
{
|
||||
if( LAST_BREAK < 0 || m_breaks[LAST_BREAK] != NUM_WGTS - 1)
|
||||
{
|
||||
std::cerr << "Warning: tried to add a column that is not at " <<
|
||||
"the beginning of a line, after widget with token " <<
|
||||
m_widgets[NUM_WGTS - 1].token << ".\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const int NUM_COLUMNS = m_columns.size();
|
||||
|
||||
if( NUM_COLUMNS > 0 )
|
||||
{
|
||||
if( !column_starts(NUM_WGTS) ) m_columns.push_back(NUM_WGTS);
|
||||
else
|
||||
{
|
||||
if( NUM_WGTS > 0 )
|
||||
{
|
||||
std::cerr << "Warning: tried to add a column twice at " <<
|
||||
"widget with token" << m_widgets[NUM_WGTS - 1].token <<
|
||||
".\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Warning: tried to add a column twice before" <<
|
||||
"the first widget.\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_columns.push_back(NUM_WGTS);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WidgetManager::break_line()
|
||||
{
|
||||
@ -143,6 +191,22 @@ void WidgetManager::delete_wgts()
|
||||
m_widgets.clear();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WidgetManager::column_starts( const int WGT ) const
|
||||
{
|
||||
const int NUM_COLUMNS = m_columns.size();
|
||||
|
||||
if( NUM_COLUMNS > 0)
|
||||
{
|
||||
for(int i = 0; i < NUM_COLUMNS; ++i )
|
||||
{
|
||||
if( m_columns[i] == WGT ) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool WidgetManager::line_breaks( const int WGT ) const
|
||||
{
|
||||
@ -232,9 +296,21 @@ int WidgetManager::calc_width() const
|
||||
curr_width = 0;
|
||||
}
|
||||
|
||||
if( column_starts(i) )
|
||||
{
|
||||
curr_width = calc_column_width(i);
|
||||
|
||||
//Jump to the next line break
|
||||
for(; i < NUM_WIDGETS; ++i)
|
||||
{
|
||||
if( line_breaks(i) ) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( curr_width > total_width ) total_width = curr_width;
|
||||
|
||||
std::cerr << total_width << " W" <<std::endl; //200
|
||||
return total_width;
|
||||
}
|
||||
|
||||
@ -256,6 +332,7 @@ int WidgetManager::calc_height() const
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << total_height << " H" <<std::endl; //294
|
||||
return total_height;
|
||||
}
|
||||
|
||||
@ -366,7 +443,7 @@ bool WidgetManager::layout(const WidgetArea POSITION)
|
||||
//biggest one, it might look bad for the smaller one, but it doesn't
|
||||
//happens the other way around, and it's divided by 60, maybe because
|
||||
//it results in small enough values to be of use, or maybe because it's
|
||||
//divided by 60 minutes?
|
||||
//divided by 60 minutes? The formula was taken from the old Widget Set.
|
||||
const int RADIUS = ( SCREEN_HEIGHT < SCREEN_WIDTH ? SCREEN_HEIGHT : SCREEN_WIDTH ) / 60;
|
||||
|
||||
//The widgets positions given are for the lower left corner.
|
||||
@ -431,6 +508,7 @@ int WidgetManager::calc_line_width( const int START_WGT ) const
|
||||
int WidgetManager::calc_line_height( const int START_WGT ) const
|
||||
{
|
||||
int line_height = 0;
|
||||
int column_height;
|
||||
const int NUM_WIDGETS = m_widgets.size();
|
||||
|
||||
for( int i = START_WGT; i < NUM_WIDGETS; ++i )
|
||||
@ -439,12 +517,55 @@ int WidgetManager::calc_line_height( const int START_WGT ) const
|
||||
{
|
||||
line_height = m_widgets[i].widget->m_height;
|
||||
}
|
||||
|
||||
if( column_starts(i) )
|
||||
{
|
||||
column_height = calc_column_height(i);
|
||||
if( line_height < column_height )
|
||||
{
|
||||
line_height = column_height;
|
||||
}
|
||||
}
|
||||
|
||||
if( line_breaks(i) ) break;
|
||||
}
|
||||
|
||||
return line_height;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int WidgetManager::calc_column_width(const int START_WGT) const
|
||||
{
|
||||
int column_width = 0;
|
||||
const int NUM_WIDGETS = m_widgets.size();
|
||||
|
||||
for( int i = START_WGT; i < NUM_WIDGETS; ++i )
|
||||
{
|
||||
if( column_width < m_widgets[i].widget->m_width )
|
||||
{
|
||||
column_width = m_widgets[i].widget->m_width;
|
||||
}
|
||||
if( line_breaks(i) ) break;
|
||||
}
|
||||
|
||||
return column_width;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int WidgetManager::calc_column_height(const int START_WGT) const
|
||||
{
|
||||
int total_height = 0;
|
||||
const int NUM_WIDGETS = m_widgets.size();
|
||||
|
||||
for( int i = START_WGT; i < NUM_WIDGETS; ++i )
|
||||
{
|
||||
total_height += m_widgets[i].widget->m_height;
|
||||
if( line_breaks(i) ) break;
|
||||
}
|
||||
|
||||
return total_height;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void WidgetManager::set_selected_wgt(const int TOKEN)
|
||||
{
|
||||
@ -938,6 +1059,7 @@ int WidgetManager::handle_joystick
|
||||
return m_selected_wgt_token;
|
||||
}
|
||||
|
||||
//FIXME: find_left_widget() doesn't works properly yet
|
||||
/** find_left_widget() returns the closest widget to the left of START_WGT.
|
||||
*/
|
||||
int WidgetManager::find_left_widget(const int START_WGT) const
|
||||
@ -1002,6 +1124,7 @@ int WidgetManager::find_left_widget(const int START_WGT) const
|
||||
return closest_wgt;
|
||||
}
|
||||
|
||||
//FIXME: find_right_widget() doesn't works properly yet
|
||||
/** find_right_widget() returns the closest widget to the right of START_WGT
|
||||
*/
|
||||
int WidgetManager::find_right_widget(const int START_WGT) const
|
||||
|
@ -57,6 +57,7 @@ class WidgetManager
|
||||
|
||||
std::vector<WidgetID> m_widgets;
|
||||
std::vector<int> m_breaks;
|
||||
std::vector<int> m_columns;
|
||||
|
||||
int m_x;
|
||||
int m_y;
|
||||
@ -82,13 +83,17 @@ class WidgetManager
|
||||
/* int m_default_scroll_x_speed;*/
|
||||
int m_default_scroll_y_speed;
|
||||
|
||||
bool column_starts( const int WGT ) const;
|
||||
bool line_breaks( const int WGT ) const;
|
||||
int get_next_line_break(const int START_WGT) const;
|
||||
|
||||
int find_id(const int TOKEN) const;
|
||||
int calc_width() const;
|
||||
int calc_height() const;
|
||||
int calc_line_width(const int START_WGT) const;
|
||||
int calc_line_height(const int START_WGT) const;
|
||||
int calc_column_width(const int START_WGT) const;
|
||||
int calc_column_height(const int START_WGT) const;
|
||||
|
||||
int find_left_widget(const int START_WGT) const;
|
||||
int find_right_widget(const int START_WGT) const;
|
||||
@ -105,12 +110,18 @@ public:
|
||||
bool add_wgt
|
||||
(
|
||||
const int TOKEN, //A number that names the widget.
|
||||
const int MIN_WIDTH, //These values are percentages not pixels. If
|
||||
//the widget is inside a container, 100%
|
||||
//represents container space, otherwise 100% is
|
||||
//the screen space.
|
||||
const int MIN_WIDTH, //These values are percentages not pixels. 100%
|
||||
//is the whole screen.
|
||||
const int MIN_HEIGHT
|
||||
);
|
||||
bool insert_column(); //This function changes the orientation from left to
|
||||
//right and top to bottom of the widgets at line
|
||||
//breaks, and switches it, making it from top to
|
||||
//bottom, and left to right at a line break,
|
||||
//until the next line break or the next layout()
|
||||
//call. It can only be used right at the beginning
|
||||
//of a line (that is, before any widgets have been
|
||||
//created, or just after a line break).
|
||||
bool break_line();
|
||||
|
||||
void delete_wgts();
|
||||
|
Loading…
Reference in New Issue
Block a user