More code cleanup and documentation

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5271 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2010-04-25 19:07:56 +00:00
parent e4fcbd4535
commit 281036fc3c
7 changed files with 71 additions and 30 deletions

View File

@@ -50,10 +50,17 @@ namespace GUIEngine
WTYPE_TEXTBOX
};
const int LOCKED_BADGE = 0x1;
const int OK_BADGE = 0x2;
const int BAD_BADGE = 0x4;
const int TROPHY_BADGE = 0x8;
enum BadgeType
{
/** display a lock on the widget, to mean a certain game feature is locked */
LOCKED_BADGE = 0x1,
/** display a green check on a widget, useful e.g. to display confirmation */
OK_BADGE = 0x2,
/** display a red mark badge on the widget, useful e.g. to warn of an invalid choice */
BAD_BADGE = 0x4,
/** display a trophy badge on the widget, useful e.g. for challenges */
TROPHY_BADGE = 0x8
};
enum Property
@@ -105,6 +112,8 @@ namespace GUIEngine
class Widget : public SkinWidgetContainer
{
protected:
friend void GUIEngine::parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_to);
unsigned int m_magic_number;
friend class EventHandler;
@@ -212,6 +221,17 @@ namespace GUIEngine
/** Type of this widget */
WidgetType m_type;
/**
* If this widget has any children, they go here. Children can be either
* specified in the XML file (e.g. Ribbon or Div children), or can also
* be created automatically for logical widgets built with more than
* one irrlicht widgets (e.g. Spinner)
*/
ptr_vector<Widget> m_children;
/** A bitmask of which badges to show, if any; choices are *_BADGE, defined above */
int m_badges;
public:
/**
* This is set to NULL by default; set to something else in a widget to mean
@@ -222,7 +242,6 @@ namespace GUIEngine
*/
Widget* m_event_handler;
/**
* Whether this widget supports multiplayer interaction (i.e. whether this widget can be
* used by players other than by the game master)
@@ -232,6 +251,9 @@ namespace GUIEngine
/** Instead of searching for widget IDs smaller/greater than that of this object, navigation
through widgets will start from these IDs (if they are set). */
int m_tab_down_root;
/** Instead of searching for widget IDs smaller/greater than that of this object, navigation
through widgets will start from these IDs (if they are set). */
int m_tab_up_root;
/** Coordinates of the widget once added (the difference between those x/h and PROP_WIDTH/PROP_HEIGHT is
@@ -242,16 +264,30 @@ namespace GUIEngine
/** Whether to show a bounding box around this widget (used for sections) */
bool m_show_bounding_box;
/** A bitmask of which badges to show, if any; choices are *_BADGE, defined above */
int m_badges;
void setBadge(int badge_bit)
/** \brief adds a particular badge to this widget
* The STK widget toolkit has support for "badges". Badges are icon overlays displayed
* on the corner of a widget; they are useful to convey information visually.
*/
void setBadge(BadgeType badge_bit)
{
m_badges |= badge_bit;
m_badges |= int(badge_bit);
}
void unsetBadge(int badge_bit)
/** \brief removes a particular bade from this widget, if it had it
* \see GUIEngine::Widget::setBadge for more info on badge support
*/
void unsetBadge(BadgeType badge_bit)
{
m_badges &= (~badge_bit);
m_badges &= (~int(badge_bit));
}
/** \brief sets this widget to have no badge
* \see GUIEngine::Widget::setBadge for more info on badge support
*/
void resetAllBadges()
{
m_badges = 0;
}
/** Set to false if widget is something that should not receieve focus */
@@ -298,13 +334,6 @@ namespace GUIEngine
void setParent(irr::gui::IGUIElement* parent);
/**
* If this widget has any children, they go here. Children can be either
* specified in the XML file (e.g. Ribbon or Div children), or can also
* be created automatically for logical widgets built with more than
* one irrlicht widgets (e.g. Spinner)
*/
ptr_vector<Widget> m_children;
/** A map that holds values for all specified widget properties (in the XML file)*/
std::map<Property, std::string> m_properties;

View File

@@ -279,6 +279,13 @@ void RibbonWidget::addIconChild(const wchar_t* text, const std::string id,
// -----------------------------------------------------------------------------
void RibbonWidget::clearAllChildren()
{
m_children.clearAndDeleteAll();
}
// -----------------------------------------------------------------------------
void RibbonWidget::select(std::string item, const int mousePlayerID)
{
const int subbuttons_amount = m_children.size();

View File

@@ -134,6 +134,11 @@ namespace GUIEngine
void addIconChild(const wchar_t* text, const std::string id,
const int w, const int h, const std::string icon,
const IconButtonWidget::IconPathType iconPathType=IconButtonWidget::ICON_PATH_TYPE_RELATIVE);
/**
* \brief clear all children of this ribbon (likely because new ones will be added soon after)
*/
void clearAllChildren();
};
}

View File

@@ -42,7 +42,7 @@ ArenasScreen::ArenasScreen() : Screen("arenas.stkgui")
RibbonWidget* tabs = this->getWidget<RibbonWidget>("trackgroups");
assert( tabs != NULL );
tabs->m_children.clearAndDeleteAll();
tabs->clearAllChildren();
//FIXME: this returns groups for arenas but tracks too. this means that some of them
// may contain only tracks, no arenas, and thus add an empty tab here...

View File

@@ -716,7 +716,7 @@ KartSelectionScreen::KartSelectionScreen() : Screen("karts.stkgui")
RibbonWidget* tabs = this->getWidget<RibbonWidget>("kartgroups");
assert( tabs != NULL );
tabs->m_children.clearAndDeleteAll();
tabs->clearAllChildren();
const std::vector<std::string>& groups = kart_properties_manager->getAllGroups();

View File

@@ -72,7 +72,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -88,7 +88,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -104,7 +104,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -120,7 +120,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
@@ -149,7 +149,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -165,7 +165,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -181,7 +181,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -197,7 +197,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}
{
@@ -213,7 +213,7 @@ void OptionsScreenInput::updateInputButtons(DeviceConfig* config)
else
{
existing_bindings.insert(binding_name);
btn->m_badges = 0;
btn->resetAllBadges();
}
}

View File

@@ -44,7 +44,7 @@ TracksScreen::TracksScreen() : Screen("tracks.stkgui")
RibbonWidget* tabs = this->getWidget<RibbonWidget>("trackgroups");
assert( tabs != NULL );
tabs->m_children.clearAndDeleteAll();
tabs->clearAllChildren();
const std::vector<std::string>& groups = track_manager->getAllGroups();