added more documentation to GUI code

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3400 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-04-18 23:38:29 +00:00
parent 54c61cb569
commit 5e249e0aed
3 changed files with 35 additions and 14 deletions

View File

@ -50,12 +50,18 @@ void Screen::addWidgets()
if(w != NULL) GUIEngine::getGUIEnv()->setFocus( w->m_element );
}
// -----------------------------------------------------------------------------
/* small shortcut so this method can be called without arguments */
void Screen::calculateLayout()
{
// build layout
calculateLayout( m_widgets );
}
// -----------------------------------------------------------------------------
/*
* Recursive call that lays out children widget within parent (or screen if none)
* Manages 'horizontal-row' and 'vertical-row' layouts, along with the proportions
* of the remaining children, as well as absolute sizes and locations.
*/
void Screen::calculateLayout(ptr_vector<Widget>& widgets, Widget* parent)
{
const unsigned short widgets_amount = widgets.size();
@ -402,8 +408,14 @@ bool Screen::OnEvent(const SEvent& event)
Widget* parent = w->m_event_handler;
if(w->m_event_handler != NULL)
{
while(parent->m_event_handler != NULL && parent->m_event_handler != parent) parent = parent->m_event_handler; // Find topmost parent
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall
in an infinite loop (this can happen e.g. in checkboxes, where they need to be
notified of clicks onto themselves so they can toggle their state. ) */
while(parent->m_event_handler != NULL && parent->m_event_handler != parent)
parent = parent->m_event_handler;
/* notify the found event event handler, and also notify the main callback if the
parent event handler says so */
if(parent->transmitEvent(w, w->m_properties[PROP_ID]))
transmitEvent(parent, parent->m_properties[PROP_ID]);
}

View File

@ -32,6 +32,7 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
{
WidgetType type;
/* find which type of widget is specified by the current tag, and instanciate it */
if (!strcmp("div", xml->getNodeName()))
{
type = WTYPE_DIV;
@ -113,9 +114,12 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
continue;
}
/* retrieve teh created widget */
Widget& widget = append_to[append_to.size()-1];
widget.m_type = type;
/* read widget properties using macro magic */
#define READ_PROPERTY( prop_name, prop_flag ) const char* prop_name = xml->getAttributeValue( #prop_name ); \
if(prop_name != NULL) widget.m_properties[prop_flag] = prop_name; else widget.m_properties[prop_flag] = ""
@ -138,10 +142,8 @@ if(prop_name != NULL) widget.m_properties[prop_flag] = prop_name; else widget.m_
READ_PROPERTY(max_value, PROP_MAX_VALUE);
READ_PROPERTY(square_items, PROP_SQUARE);
#undef READ_PROPERTY
//std::cout << "loaded widget " << id << std::endl;
// new div, continue parsing with this new div as new parent
/* a new div starts here, continue parsing with this new div as new parent */
if( widget.m_type == WTYPE_DIV || widget.m_type == WTYPE_RIBBON)
parseScreenFileDiv( xml, append_to[append_to.size()-1].m_children );
}// end case EXN_ELEMENT

View File

@ -45,10 +45,15 @@ Widget::Widget()
m_event_handler = NULL;
}
// -----------------------------------------------------------------------------
/** will write to either absolute or percentage, depending on the case.
* returns false if couldn't convert to either
/**
* 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.
*
* Return values :
* Will write to either absolute or percentage, depending on the case.
* Returns false if couldn't convert to either
*/
bool Widget::convertToCoord(std::string& x, int* absolute, int* percentage)
bool Widget::convertToCoord(std::string& x, int* absolute /* out */, int* percentage /* out */)
{
bool is_number;
int i;
@ -75,12 +80,14 @@ bool Widget::convertToCoord(std::string& x, int* absolute, int* percentage)
*/
void Widget::readCoords(Widget* parent)
{
// determine widget position and size if not already done by sizers
/* determine widget position and size if not already done by sizers */
std::string x = m_properties[PROP_X];
std::string y = m_properties[PROP_Y];
std::string width = m_properties[PROP_WIDTH];
std::string height = m_properties[PROP_HEIGHT];
/* retrieve parent size (or screen size if none). Will be useful for layout
and especially for percentages. */
unsigned int parent_w, parent_h, parent_x, parent_y;
if(parent == NULL)
{
@ -98,7 +105,7 @@ void Widget::readCoords(Widget* parent)
parent_y = parent->y;
}
// ---- try converting to number; if it works it means they're plain numbers so we can use them directly.
// ---- try converting to number
// x coord
{
int abs_x = -1, percent_x = -1;
@ -121,7 +128,7 @@ void Widget::readCoords(Widget* parent)
}
}
// if this widget has an icon, get icon size. this can helpful determine its optimal size
// ---- if this widget has an icon, get icon size. this can helpful determine its optimal size
int texture_w = -1, texture_h = -1;
if(m_properties[PROP_ICON].size() > 0)
@ -136,7 +143,7 @@ void Widget::readCoords(Widget* parent)
}
}
// if this widget has a label, get text length. this can helpful determine its optimal size
// ---- if this widget has a label, get text length. this can helpful determine its optimal size
int label_w = -1, label_h = -1;
if(m_properties[PROP_TEXT].size() > 0)
{
@ -148,6 +155,7 @@ void Widget::readCoords(Widget* parent)
label_h = dim.Height;
}
// ---- read dimension
// width
{
int abs_w = -1, percent_w = -1;
@ -173,8 +181,7 @@ void Widget::readCoords(Widget* parent)
else if(label_h > -1) this->h = label_h;
}
// can't make widget bigger than parent
// ---- can't make widget bigger than parent
if(this->h > (int)parent_h)
{
float ratio = (float)parent_h/this->h;