Cleanun in grid ribbons to allow for future visible improvements

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3917 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-08-26 16:06:38 +00:00
parent 452808838a
commit edf6760b75
5 changed files with 114 additions and 77 deletions

View File

@ -1,6 +1,7 @@
<div x="2%" y="1%" width="96%" height="99%" layout="vertical-row" >
<label width="100%" height="25" text="Choose a Kart (more players can join by pressing 'fire' now)" align="center" text_align="center" />
<label width="100%" height="25" text="Choose a Kart (more players can join by pressing 'fire' now)"
align="center" text_align="center" />
<div id="playerskarts" width="100%" proportion="4">
<!-- Contents is added programatically -->
@ -9,7 +10,8 @@
<spacer height="15" width="25"/>
<box proportion="2" width="100%" layout="vertical-row"/>
<ribbon_grid id="karts" proportion="1" square_items="true" width="90%" align="center" child_width="80" child_height="80"/>
<ribbon_grid id="karts" proportion="1" square_items="true" width="100%" align="center"
child_width="80" child_height="80"/>
</box>
<tabs width="100%" height="25" id="kartgroups">
<button id="standard" text="Standard"/>

View File

@ -12,7 +12,7 @@
<label width="100%" height="25" text="All Tracks" align="center" text_align="center" />
<box proportion="1" width="100%" layout="vertical-row"/>
<ribbon_grid id="tracks" proportion="1" width="95%" square_items="true" text="bottom" align="center" child_width="160" child_height="120" />
<ribbon_grid id="tracks" proportion="1" width="100%" square_items="true" text="bottom" align="center" child_width="160" child_height="120" />
<spacer width="20" height="13" />
</box>

View File

@ -43,7 +43,8 @@ using namespace gui;
namespace GUIEngine
{
// -----------------------------------------------------------------------------
static unsigned int id_counter = 0;
static unsigned int id_counter_2 = 1000; // for items that can't be reached with keyboard navigation but can be clicked
@ -56,14 +57,6 @@ int Widget::getNewNoFocusID()
return id_counter_2++;
}
// -----------------------------------------------------------------------------
/** When switching to a new screen, this function will be called to reset ID counters
* (so we start again from ID 0, and don't grow to big numbers) */
void Widget::resetIDCounters()
{
id_counter = 0;
id_counter_2 = 1000;
}
// -----------------------------------------------------------------------------
Widget::Widget()
{
@ -80,6 +73,14 @@ Widget::Widget()
m_parent = NULL;
}
// -----------------------------------------------------------------------------
/** When switching to a new screen, this function will be called to reset ID counters
* (so we start again from ID 0, and don't grow to big numbers) */
void Widget::resetIDCounters()
{
id_counter = 0;
id_counter_2 = 1000;
}
// -----------------------------------------------------------------------------
/**
* Receives as string the raw property value retrieved from XML file.
* Will try to make sense of it, as an absolute value or a percentage.

View File

@ -42,18 +42,86 @@ RibbonGridWidget::RibbonGridWidget(const bool combo, const int max_rows)
// -----------------------------------------------------------------------------
void RibbonGridWidget::add()
{
// Work-around for FIXME below... first clear children to avoid duplicates since we're adding everything again everytime
m_children.clearAndDeleteAll();
m_rows.clearWithoutDeleting();
m_has_label = m_properties[PROP_TEXT] == "bottom";
const int label_height = m_has_label ? 25 : 0;
m_label_height = m_has_label ? 25 : 0; // FIXME : get height from font, don't hardcode
// ----- add dynamic label at bottom
if (m_has_label)
{
// leave room for many lines, just in case
rect<s32> label_size = rect<s32>(x, y + h - m_label_height, x+w, y+h+m_label_height*5);
m_label = GUIEngine::getGUIEnv()->addStaticText(L" ", label_size, false, true /* word wrap */, NULL, -1);
m_label->setTextAlignment( EGUIA_CENTER, EGUIA_UPPERLEFT );
m_label->setWordWrap(true);
}
// ---- add arrow buttons on each side
// FIXME? these arrow buttons are outside of the widget's boundaries
if (m_left_widget != NULL)
{
// FIXME - do proper memory management, find why it crashes when i try to clean-up
//delete m_left_widget;
//delete m_right_widget;
}
m_left_widget = new Widget();
m_right_widget = new Widget();
const int average_y = y + (h-m_label_height)/2;
m_arrows_w = 30;
const int button_h = 50;
// right arrow
rect<s32> right_arrow_location = rect<s32>(x + w - m_arrows_w,
average_y - button_h/2,
x + w,
average_y + button_h/2);
stringw rmessage = ">>";
IGUIButton* right_arrow = GUIEngine::getGUIEnv()->addButton(right_arrow_location, NULL, getNewNoFocusID(), rmessage.c_str(), L"");
right_arrow->setTabStop(false);
m_right_widget->m_element = right_arrow;
m_right_widget->m_event_handler = this;
m_right_widget->m_properties[PROP_ID] = "right";
m_right_widget->id = right_arrow->getID();
m_children.push_back( m_right_widget );
// left arrow
rect<s32> left_arrow_location = rect<s32>(x,
average_y - button_h/2,
x + m_arrows_w,
average_y + button_h/2);
stringw lmessage = "<<";
IGUIButton* left_arrow = GUIEngine::getGUIEnv()->addButton(left_arrow_location, NULL, getNewNoFocusID(), lmessage.c_str(), L"");
left_arrow->setTabStop(false);
m_left_widget->m_element = left_arrow;
m_left_widget->m_event_handler = this;
m_left_widget->m_properties[PROP_ID] = "left";
m_left_widget->id = left_arrow->getID();
m_children.push_back( m_left_widget );
setSubElements();
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::setSubElements()
{
// Work-around for FIXME below... first clear children to avoid duplicates since we're adding everything again everytime
for (int i=0; i<m_children.size(); i++)
{
IGUIElement* elem = m_children[i].m_element;
if (elem != NULL && m_children[i].m_type == WTYPE_RIBBON)
{
elem->remove();
m_children.erase(i);
i--;
if (i<0) i = 0;
}
}
m_rows.clearWithoutDeleting(); // rows already deleted above, don't double-delete
int child_width, child_height;
child_width = atoi(m_properties[PROP_CHILD_WIDTH].c_str());
child_height = atoi(m_properties[PROP_CHILD_HEIGHT].c_str());
if( child_width == 0 || child_height == 0 )
if (child_width == 0 || child_height == 0)
{
std::cerr << "/!\\ Warning /!\\ : ribbon grid widgets require 'child_width' and 'child_height' arguments" << std::endl;
child_width = 256;
@ -61,13 +129,13 @@ void RibbonGridWidget::add()
}
// decide how many rows and column we can show in the available space
int row_amount = (int)round((h-label_height) / (float)child_height);
int row_amount = (int)round((h-m_label_height) / (float)child_height);
//if(row_amount < 2) row_amount = 2;
if(row_amount > m_max_rows) row_amount = m_max_rows;
if (row_amount > m_max_rows) row_amount = m_max_rows;
const float row_height = (float)(h - label_height)/(float)row_amount;
const float row_height = (float)(h - m_label_height)/(float)row_amount;
float ratio_zoom = (float)row_height / (float)(child_height - label_height);
float ratio_zoom = (float)row_height / (float)(child_height - m_label_height);
m_col_amount = (int)round( w / ( child_width*ratio_zoom ) );
// std::cout << "w=" << w << " child_width=" << child_width << " ratio_zoom="<< ratio_zoom << " m_col_amount=" << m_col_amount << std::endl;
@ -78,13 +146,13 @@ void RibbonGridWidget::add()
for(int n=0; n<row_amount; n++)
{
RibbonWidget* ribbon;
if(m_combo)
if (m_combo)
ribbon = new RibbonWidget(RIBBON_COMBO);
else
ribbon = new RibbonWidget(RIBBON_TOOLBAR);
ribbon->x = x;
ribbon->x = x + m_arrows_w;
ribbon->y = y + (int)(n*row_height);
ribbon->w = w;
ribbon->w = w - m_arrows_w*2;
ribbon->h = (int)(row_height);
ribbon->m_type = WTYPE_RIBBON;
ribbon->m_properties[PROP_ID] = this->m_properties[PROP_ID];
@ -111,55 +179,7 @@ void RibbonGridWidget::add()
ribbon->add();
}
// add dynamic label at bottom
if(m_has_label)
{
// leave room for many lines, just in case
rect<s32> label_size = rect<s32>(x, y + h - label_height, x+w, y+h+label_height*5);
m_label = GUIEngine::getGUIEnv()->addStaticText(L" ", label_size, false, true /* word wrap */, NULL, -1);
m_label->setTextAlignment( EGUIA_CENTER, EGUIA_UPPERLEFT );
m_label->setWordWrap(true);
}
// add arrow buttons on each side
// FIXME? these arrow buttons are outside of the widget's boundaries
if(m_left_widget != NULL)
{
// FIXME - do proper memory management, find why it crashes when i try to clean-up
//delete m_left_widget;
//delete m_right_widget;
}
m_left_widget = new Widget();
m_right_widget = new Widget();
const int average_y = y + (h-label_height)/2;
const int button_w = 30, button_h = 50;
rect<s32> right_arrow_location = rect<s32>(x + w,
average_y - button_h/2,
x + w + button_w,
average_y + button_h/2);
stringw rmessage = ">>";
IGUIButton* right_arrow = GUIEngine::getGUIEnv()->addButton(right_arrow_location, NULL, getNewNoFocusID(), rmessage.c_str(), L"");
right_arrow->setTabStop(false);
m_right_widget->m_element = right_arrow;
m_right_widget->m_event_handler = this;
m_right_widget->m_properties[PROP_ID] = "right";
m_right_widget->id = right_arrow->getID();
m_children.push_back( m_right_widget );
rect<s32> left_arrow_location = rect<s32>(x - button_w,
average_y - button_h/2,
x,
average_y + button_h/2);
stringw lmessage = "<<";
IGUIButton* left_arrow = GUIEngine::getGUIEnv()->addButton(left_arrow_location, NULL, getNewNoFocusID(), lmessage.c_str(), L"");
left_arrow->setTabStop(false);
m_left_widget->m_element = left_arrow;
m_left_widget->m_event_handler = this;
m_left_widget->m_properties[PROP_ID] = "left";
m_left_widget->id = left_arrow->getID();
m_children.push_back( m_left_widget );
}
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::registerHoverListener(RibbonGridHoverListener* listener)
{

View File

@ -57,21 +57,35 @@ namespace GUIEngine
virtual ~RibbonGridWidget() {}
/* reference pointers only, the actual instances are owned by m_children */
/** reference pointers only, the actual instances are owned by m_children */
ptr_vector<RibbonWidget, REF> m_rows;
std::vector<ItemDescription> m_items;
/** Used for ribbon grids that have a label */
bool m_has_label;
IGUIStaticText* m_label;
int m_label_height;
std::vector<ItemDescription> m_items;
int m_arrows_w;
RibbonWidget* getSelectedRibbon() const;
RibbonWidget* getRowContaining(Widget* w) const;
void updateLabel(RibbonWidget* from_this_ribbon=NULL);
/** Even though the ribbon grid widget looks like a grid, it is really a vertical stack of
independant ribbons. When moving selection horizontally, this method is used to notify
other rows above and below of which column is selected, so that moving vertically to
another row keeps the same selected column. */
void propagateSelection();
void focused();
bool transmitEvent(Widget* w, std::string& originator);
void setSubElements();
void scroll(const int x_delta);
int m_scroll_offset;
@ -80,7 +94,7 @@ namespace GUIEngine
int m_max_rows;
bool m_combo;
bool m_has_label;
/* reference pointers only, the actual instances are owned by m_children */
Widget* m_left_widget;