Improved scrolling, thought the changes are not visible to the user.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@1349 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1baec9cb8c
commit
55233a592b
@ -138,8 +138,6 @@ void CharSel::switchCharacter(int n)
|
||||
if (m_current_kart != n && kp != NULL)
|
||||
{
|
||||
widget_manager->set_wgt_text( WTOK_NAME, kp->getName().c_str());
|
||||
//FIXME: maybe this should be renamed from WGT_SCROLL_* to WGT_POS_*
|
||||
widget_manager->set_wgt_x_scroll_pos( WTOK_NAME, WGT_SCROLL_CENTER );
|
||||
|
||||
m_current_kart = n;
|
||||
ssgDeRefDelete(m_kart);
|
||||
|
@ -110,7 +110,6 @@ void GrandPrixSelect::update(float dt)
|
||||
|
||||
const CupData &cup = m_all_cups[CLICKED_TOKEN - WTOK_FIRSTPRIX];
|
||||
widget_manager->set_wgt_text(WTOK_DESCRIPTION, cup.getDescription());
|
||||
widget_manager->set_wgt_x_scroll_pos( WTOK_DESCRIPTION, WGT_SCROLL_CENTER );
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -76,7 +76,6 @@ Widget::Widget
|
||||
m_rect_list(0),
|
||||
m_round_corners(WGT_AREA_ALL),
|
||||
m_scroll_pos_x(0), m_scroll_pos_y(0),
|
||||
m_scroll_speed_x(0), m_scroll_speed_y(0.0f),
|
||||
m_text_scale(1.0f)
|
||||
{
|
||||
}
|
||||
@ -174,36 +173,11 @@ void Widget::update(const float DELTA)
|
||||
text_width = m_width;
|
||||
}
|
||||
|
||||
//Y-axis preset positions
|
||||
if( m_scroll_pos_y == WGT_SCROLL_START_TOP )
|
||||
{
|
||||
m_scroll_pos_y =(float)(Y_LIMIT / 2 - m_height);
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_START_BOTTOM )
|
||||
{
|
||||
m_scroll_pos_y = (float)(Y_LIMIT / 2);
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_CENTER )
|
||||
{
|
||||
m_scroll_pos_y = 0;
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_END_TOP )
|
||||
{
|
||||
m_scroll_pos_y = (float)(-Y_LIMIT / 2);
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_END_BOTTOM )
|
||||
{
|
||||
m_scroll_pos_y = (float)(-Y_LIMIT / 2 + m_height);
|
||||
}
|
||||
else if( m_scroll_pos_y > MAX_SCROLL )
|
||||
{
|
||||
std::cerr << "WARNING: text position too high to scroll!.\n";
|
||||
}
|
||||
else if( m_scroll_pos_y < -MAX_SCROLL )
|
||||
{
|
||||
std::cerr << "WARNING: text position too low to scroll!.\n";
|
||||
}
|
||||
|
||||
//With the preset positions, we do comparations with the equal sign on
|
||||
//floating point variables; however, no operations are done of the
|
||||
//variables between the assignment of these integer values and the
|
||||
//comparation and the values are small enough to fit in a few bytes,
|
||||
//so no inaccuracies because of floating point rounding should happen.
|
||||
//X-axis preset positions
|
||||
if( m_scroll_pos_x == WGT_SCROLL_START_LEFT )
|
||||
{
|
||||
@ -236,6 +210,36 @@ void Widget::update(const float DELTA)
|
||||
"to scroll!.\n";
|
||||
}
|
||||
|
||||
//Y-axis preset positions
|
||||
if( m_scroll_pos_y == WGT_SCROLL_START_TOP )
|
||||
{
|
||||
m_scroll_pos_y =(float)(Y_LIMIT / 2 - m_height);
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_START_BOTTOM )
|
||||
{
|
||||
m_scroll_pos_y = (float)(Y_LIMIT / 2);
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_CENTER )
|
||||
{
|
||||
m_scroll_pos_y = 0;
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_END_TOP )
|
||||
{
|
||||
m_scroll_pos_y = (float)(-Y_LIMIT / 2);
|
||||
}
|
||||
else if( m_scroll_pos_y == WGT_SCROLL_END_BOTTOM )
|
||||
{
|
||||
m_scroll_pos_y = (float)(-Y_LIMIT / 2 + m_height);
|
||||
}
|
||||
else if( m_scroll_pos_y > MAX_SCROLL )
|
||||
{
|
||||
std::cerr << "WARNING: text position too high to scroll!.\n";
|
||||
}
|
||||
else if( m_scroll_pos_y < -MAX_SCROLL )
|
||||
{
|
||||
std::cerr << "WARNING: text position too low to scroll!.\n";
|
||||
}
|
||||
|
||||
if(m_enable_scroll)
|
||||
{
|
||||
//TODO: constrain speed to sane values
|
||||
|
@ -71,6 +71,9 @@ bool WidgetManager::add_wgt
|
||||
new_id.min_width = MIN_WIDTH;
|
||||
new_id.min_height = MIN_HEIGHT;
|
||||
|
||||
new_id.last_preset_scroll_x = m_default_scroll_preset_x;
|
||||
new_id.last_preset_scroll_y = m_default_scroll_preset_y;
|
||||
|
||||
new_id.widget = new Widget(0, 0, 0, 0);
|
||||
|
||||
new_id.widget->m_enable_rect = m_default_show_rect;
|
||||
@ -84,8 +87,8 @@ bool WidgetManager::add_wgt
|
||||
new_id.widget->m_text_size = m_default_text_size;
|
||||
|
||||
new_id.widget->m_enable_scroll = m_default_enable_scroll;
|
||||
new_id.widget->m_scroll_pos_x = (float)m_default_scroll_x_pos;
|
||||
new_id.widget->m_scroll_pos_y = (float)m_default_scroll_y_pos;
|
||||
new_id.widget->m_scroll_pos_x = (float)m_default_scroll_preset_x;
|
||||
new_id.widget->m_scroll_pos_y = (float)m_default_scroll_preset_y;
|
||||
new_id.widget->m_scroll_speed_x = (float)m_default_scroll_x_speed;
|
||||
new_id.widget->m_scroll_speed_y = (float)m_default_scroll_y_speed;
|
||||
|
||||
@ -732,15 +735,15 @@ void WidgetManager::set_initial_text_state
|
||||
void WidgetManager::set_initial_scroll_state
|
||||
(
|
||||
const bool ENABLE,
|
||||
const int X_POS,
|
||||
const int Y_POS,
|
||||
const WidgetScrollPos X_POS,
|
||||
const WidgetScrollPos Y_POS,
|
||||
const int X_SPEED,
|
||||
const int Y_SPEED
|
||||
)
|
||||
{
|
||||
m_default_enable_scroll = ENABLE;
|
||||
m_default_scroll_x_pos = X_POS;
|
||||
m_default_scroll_y_pos = Y_POS;
|
||||
m_default_scroll_preset_x = X_POS;
|
||||
m_default_scroll_preset_y = Y_POS;
|
||||
m_default_scroll_x_speed = X_SPEED;
|
||||
m_default_scroll_y_speed = Y_SPEED;
|
||||
}
|
||||
@ -758,8 +761,8 @@ void WidgetManager::restore_default_states()
|
||||
m_default_text = "";
|
||||
m_default_text_size = WGT_FNT_MED;
|
||||
m_default_enable_scroll = false;
|
||||
m_default_scroll_x_pos = WGT_SCROLL_CENTER;
|
||||
m_default_scroll_y_pos = WGT_SCROLL_CENTER;
|
||||
m_default_scroll_preset_x = WGT_SCROLL_CENTER;
|
||||
m_default_scroll_preset_y = WGT_SCROLL_CENTER;
|
||||
m_default_scroll_x_speed = 0;
|
||||
m_default_scroll_y_speed = 0;
|
||||
}
|
||||
@ -891,7 +894,15 @@ void WidgetManager::hide_wgt_texture(const int TOKEN)
|
||||
void WidgetManager::set_wgt_text( const int TOKEN, const char* TEXT )
|
||||
{
|
||||
const int ID = find_id(TOKEN);
|
||||
if( ID != WGT_NONE ) m_widgets[ID].widget->m_text = TEXT;
|
||||
if( ID != WGT_NONE )
|
||||
{
|
||||
m_widgets[ID].widget->m_text = TEXT;
|
||||
|
||||
//Reset the scroll position, because it will be the wrong value if
|
||||
//new text has a different size
|
||||
m_widgets[ID].widget->m_scroll_pos_x = m_widgets[ID].last_preset_scroll_x;
|
||||
m_widgets[ID].widget->m_scroll_pos_y = m_widgets[ID].last_preset_scroll_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "WARNING: tried to set text to an unnamed widget " <<
|
||||
@ -902,13 +913,24 @@ void WidgetManager::set_wgt_text( const int TOKEN, const char* TEXT )
|
||||
//-----------------------------------------------------------------------------
|
||||
void WidgetManager::set_wgt_text( const int TOKEN, const std::string TEXT )
|
||||
{
|
||||
set_wgt_text( TOKEN, TEXT.c_str());
|
||||
#if 0
|
||||
const int ID = find_id(TOKEN);
|
||||
if( ID != WGT_NONE ) m_widgets[ID].widget->m_text = TEXT;
|
||||
if( ID != WGT_NONE )
|
||||
{
|
||||
m_widgets[ID].widget->m_text = TEXT;
|
||||
|
||||
//Reset the scroll position, because it will be the wrong value if
|
||||
//new text has a different size
|
||||
m_widgets[ID].widget->m_scroll_pos_x = m_widgets[ID].last_preset_scroll_x;
|
||||
m_widgets[ID].widget->m_scroll_pos_y = m_widgets[ID].last_preset_scroll_y;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "WARNING: tried to set the text of an unnamed widget with " <<
|
||||
"token " << TOKEN << '\n';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -996,7 +1018,11 @@ void WidgetManager::set_wgt_x_scroll_pos
|
||||
}
|
||||
|
||||
const int ID = find_id(TOKEN);
|
||||
if( ID != WGT_NONE ) m_widgets[ID].widget->m_scroll_pos_x = POS;
|
||||
if( ID != WGT_NONE )
|
||||
{
|
||||
m_widgets[ID].widget->m_scroll_pos_x = POS;
|
||||
m_widgets[ID].last_preset_scroll_x = POS;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "WARNING: tried to set the X scroll position of an " <<
|
||||
@ -1021,7 +1047,11 @@ void WidgetManager::set_wgt_y_scroll_pos
|
||||
}
|
||||
|
||||
const int ID = find_id(TOKEN);
|
||||
if( ID != WGT_NONE ) m_widgets[ID].widget->m_scroll_pos_y = POS;
|
||||
if( ID != WGT_NONE )
|
||||
{
|
||||
m_widgets[ID].widget->m_scroll_pos_y = POS;
|
||||
m_widgets[ID].last_preset_scroll_y = POS;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "WARNING: tried to set the Y scroll position of an " <<
|
||||
|
@ -52,6 +52,11 @@ class WidgetManager
|
||||
int min_width;
|
||||
int min_height;
|
||||
|
||||
//The last given preset scroll position is stored, to restore it in
|
||||
//case that the text is changed it needs to be restored.
|
||||
WidgetScrollPos last_preset_scroll_x;
|
||||
WidgetScrollPos last_preset_scroll_y;
|
||||
|
||||
Widget *widget;
|
||||
};
|
||||
|
||||
@ -87,7 +92,6 @@ class WidgetManager
|
||||
|
||||
int m_selected_wgt_token;
|
||||
|
||||
//TODO: change 'default' to 'initial'
|
||||
bool m_default_active;
|
||||
bool m_default_show_rect;
|
||||
bool m_default_rect_round_corners;
|
||||
@ -99,8 +103,8 @@ class WidgetManager
|
||||
WidgetFontSize m_default_text_size;
|
||||
|
||||
bool m_default_enable_scroll;
|
||||
int m_default_scroll_x_pos;
|
||||
int m_default_scroll_y_pos;
|
||||
WidgetScrollPos m_default_scroll_preset_x;
|
||||
WidgetScrollPos m_default_scroll_preset_y;
|
||||
int m_default_scroll_x_speed;
|
||||
int m_default_scroll_y_speed;
|
||||
|
||||
@ -174,8 +178,8 @@ public:
|
||||
void set_initial_scroll_state
|
||||
(
|
||||
const bool ENABLE,
|
||||
const int X_POS,
|
||||
const int Y_POS,
|
||||
const WidgetScrollPos X_POS,
|
||||
const WidgetScrollPos Y_POS,
|
||||
const int X_SPEED,
|
||||
const int Y_SPEED
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user