Cleaned up widget code so type is automatically determined and does not need to be manually set

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3695 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-07-03 18:06:04 +00:00
parent 43ec7af757
commit c8e7c5b92b
4 changed files with 46 additions and 40 deletions

View File

@ -124,7 +124,6 @@ PressAKeyDialog::PressAKeyDialog(const float w, const float h) :
//label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
LabelWidget* widget = new LabelWidget();
widget->m_type = WTYPE_LABEL;
widget->m_properties[PROP_TEXT] = _("Press a key");
widget->m_properties[PROP_TEXT_ALIGN] = "center";
widget->x = 0;
@ -141,7 +140,6 @@ PressAKeyDialog::PressAKeyDialog(const float w, const float h) :
const int textHeight = font->getDimension(L"X").Height;
ButtonWidget* widget2 = new ButtonWidget();
widget2->m_type = WTYPE_BUTTON; // FIXME : shouldn't constructor set type?
widget2->m_properties[PROP_ID] = "cancel";
widget2->m_properties[PROP_TEXT] = _("Press ESC to cancel");
widget2->x = 15;
@ -181,7 +179,6 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
// label->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER);
LabelWidget* widget = new LabelWidget();
widget->m_type = WTYPE_LABEL;
widget->m_properties[PROP_TEXT] = _("Enter the new player's name");
widget->m_properties[PROP_TEXT_ALIGN] = "center";
widget->x = 0;
@ -201,7 +198,6 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
const int textAreaYFrom = m_area.getHeight()/2 - textHeight/2;
textCtrl = new TextBoxWidget();
textCtrl->m_type = WTYPE_BUTTON;
textCtrl->m_properties[PROP_TEXT] = "";
textCtrl->x = 50;
textCtrl->y = textAreaYFrom - 10;
@ -215,7 +211,6 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(const float w, const float h) :
// TODO : add Ok button
cancelButton = new ButtonWidget();
cancelButton->m_type = WTYPE_BUTTON; // FIXME : shouldn't constructor set type?
cancelButton->m_properties[PROP_ID] = "cancel";
cancelButton->m_properties[PROP_TEXT] = _("Cancel");
cancelButton->x = 15;
@ -297,7 +292,6 @@ TrackInfoDialog::TrackInfoDialog(const char* trackName, ITexture* screenshot, co
SpinnerWidget* widget = new SpinnerWidget();
widget->m_type = WTYPE_SPINNER;
widget->x = 0;
widget->y = y2;
widget->w = m_area.getWidth();
@ -386,7 +380,6 @@ void PlayerInfoDialog::showRegularDialog()
{
textCtrl = new TextBoxWidget();
textCtrl->m_type = WTYPE_BUTTON;
textCtrl->m_properties[PROP_ID] = "renameplayer";
textCtrl->m_properties[PROP_TEXT] = m_player->getName();
textCtrl->x = 50;
@ -401,7 +394,6 @@ void PlayerInfoDialog::showRegularDialog()
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "renameplayer";
widget->m_properties[PROP_TEXT] = _("Rename");
@ -417,7 +409,6 @@ void PlayerInfoDialog::showRegularDialog()
}
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "cancel";
widget->m_properties[PROP_TEXT] = _("Cancel");
@ -434,7 +425,6 @@ void PlayerInfoDialog::showRegularDialog()
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "removeplayer";
widget->m_properties[PROP_TEXT] = _("Remove");
@ -472,7 +462,6 @@ void PlayerInfoDialog::showConfirmDialog()
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "confirmremove";
widget->m_properties[PROP_TEXT] = _("Confirm Remove");
@ -489,7 +478,6 @@ void PlayerInfoDialog::showConfirmDialog()
{
ButtonWidget* widget = new ButtonWidget();
widget->m_type = WTYPE_BUTTON;
widget->m_properties[PROP_ID] = "cancelremove";
widget->m_properties[PROP_TEXT] = _("Cancel Remove");

View File

@ -48,101 +48,82 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
break;
case irr::io::EXN_ELEMENT:
{
WidgetType type;
/* find which type of widget is specified by the current tag, and instanciate it */
if (!strcmp("div", xml->getNodeName()))
{
type = WTYPE_DIV;
append_to.push_back(new Widget());
Widget* w = new Widget();
w->m_type = WTYPE_DIV;
append_to.push_back(w);
}
else if (!strcmp("box", xml->getNodeName()))
{
type = WTYPE_DIV;
Widget* w = new Widget();
w->m_type = WTYPE_DIV;
w->m_show_bounding_box = true;
append_to.push_back(w);
}
else if (!strcmp("ribbon", xml->getNodeName()))
{
type = WTYPE_RIBBON;
append_to.push_back(new RibbonWidget());
}
else if (!strcmp("buttonbar", xml->getNodeName()))
{
type = WTYPE_RIBBON;
append_to.push_back(new RibbonWidget(RIBBON_TOOLBAR));
}
else if (!strcmp("tabs", xml->getNodeName()))
{
type = WTYPE_RIBBON;
append_to.push_back(new RibbonWidget(RIBBON_TABS));
}
else if (!strcmp("spinner", xml->getNodeName()))
{
type = WTYPE_SPINNER;
append_to.push_back(new SpinnerWidget());
}
else if (!strcmp("button", xml->getNodeName()))
{
type = WTYPE_BUTTON;
append_to.push_back(new ButtonWidget());
}
else if (!strcmp("gauge", xml->getNodeName()))
{
//type = WTYPE_GAUGE;
//append_to.push_back(new GaugeWidget());
type = WTYPE_SPINNER;
append_to.push_back(new SpinnerWidget(true));
}
else if (!strcmp("icon-button", xml->getNodeName()))
{
type = WTYPE_ICON_BUTTON;
append_to.push_back(new IconButtonWidget());
}
else if (!strcmp("icon", xml->getNodeName()))
{
type = WTYPE_ICON_BUTTON;
append_to.push_back(new IconButtonWidget(false));
}
else if (!strcmp("checkbox", xml->getNodeName()))
{
type = WTYPE_CHECKBOX;
append_to.push_back(new CheckBoxWidget());
}
else if (!strcmp("label", xml->getNodeName()))
{
type = WTYPE_LABEL;
append_to.push_back(new LabelWidget());
}
else if (!strcmp("spacer", xml->getNodeName()))
{
type = WTYPE_NONE;
append_to.push_back(new Widget());
}
else if (!strcmp("ribbon_grid", xml->getNodeName()))
{
type = WTYPE_RIBBON_GRID;
append_to.push_back(new RibbonGridWidget());
}
else if (!strcmp("scrollable_ribbon", xml->getNodeName()))
{
type = WTYPE_RIBBON_GRID;
append_to.push_back(new RibbonGridWidget(true, 1));
}
else if (!strcmp("scrollable_toolbar", xml->getNodeName()))
{
type = WTYPE_RIBBON_GRID;
append_to.push_back(new RibbonGridWidget(false, 1));
}
else if (!strcmp("model", xml->getNodeName()))
{
type = WTYPE_MODEL_VIEW;
append_to.push_back(new ModelViewWidget());
}
else if (!strcmp("list", xml->getNodeName()))
{
type = WTYPE_LIST;
append_to.push_back(new ListWidget());
}
else
@ -151,9 +132,8 @@ void parseScreenFileDiv(irr::io::IrrXMLReader* xml, ptr_vector<Widget>& append_t
continue;
}
/* retrieve teh created widget */
/* retrieve the created widget */
Widget& widget = append_to[append_to.size()-1];
widget.m_type = type;
/* read widget properties using macro magic */

View File

@ -243,6 +243,11 @@ void Widget::setParent(IGUIElement* parent)
#pragma mark Button Widget
#endif
ButtonWidget::ButtonWidget()
{
m_type = WTYPE_BUTTON;
}
void ButtonWidget::add()
{
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
@ -263,6 +268,11 @@ void ButtonWidget::setLabel(const char* label)
#pragma mark Label Widget
#endif
LabelWidget::LabelWidget()
{
m_type = WTYPE_LABEL;
}
void LabelWidget::add()
{
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
@ -293,6 +303,7 @@ CheckBoxWidget::CheckBoxWidget()
{
m_state = true;
m_event_handler = this;
m_type = WTYPE_CHECKBOX;
}
void CheckBoxWidget::add()
@ -327,6 +338,7 @@ IconButtonWidget::IconButtonWidget(const bool clickable)
{
IconButtonWidget::clickable = clickable;
label = NULL;
m_type = WTYPE_ICON_BUTTON;
}
// -----------------------------------------------------------------------------
void IconButtonWidget::add()
@ -416,6 +428,8 @@ RibbonWidget::RibbonWidget(const RibbonType type)
m_ribbon_type = type;
m_focus = NULL;
updateSelection();
m_type = WTYPE_RIBBON;
}
// -----------------------------------------------------------------------------
void RibbonWidget::select(std::string item)
@ -699,6 +713,8 @@ void RibbonWidget::setLabel(const int id, std::string new_name)
SpinnerWidget::SpinnerWidget(const bool gauge)
{
m_gauge = gauge;
m_type = WTYPE_SPINNER;
}
void SpinnerWidget::add()
@ -860,6 +876,8 @@ RibbonGridWidget::RibbonGridWidget(const bool combo, const int max_rows)
m_left_widget = NULL;
m_right_widget = NULL;
m_type = WTYPE_RIBBON_GRID;
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::add()
@ -1135,7 +1153,7 @@ void RibbonGridWidget::setSelection(int item_id)
}
void RibbonGridWidget::setSelection(const std::string& code_name)
{
assert(false);
assert(false);
}
// -----------------------------------------------------------------------------
void RibbonGridWidget::updateItemDisplay()
@ -1243,6 +1261,10 @@ RibbonWidget* RibbonGridWidget::getSelectedRibbon() const
#endif
// -----------------------------------------------------------------------------
ModelViewWidget::ModelViewWidget()
{
m_type = WTYPE_MODEL_VIEW;
}
ModelViewWidget::~ModelViewWidget()
{
GUIEngine::needsUpdate.remove(this);
@ -1304,6 +1326,10 @@ void ModelViewWidget::update(float delta)
// -----------------------------------------------------------------------------
ListWidget::ListWidget()
{
m_type = WTYPE_LIST;
}
void ListWidget::add()
{
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);
@ -1345,7 +1371,10 @@ std::string ListWidget::getSelectionName() const
#endif
// -----------------------------------------------------------------------------
TextBoxWidget::TextBoxWidget()
{
m_type = WTYPE_TEXTBOX;
}
void TextBoxWidget::add()
{
rect<s32> widget_size = rect<s32>(x, y, x + w, y + h);

View File

@ -177,6 +177,8 @@ namespace GUIEngine
class ButtonWidget : public Widget
{
public:
ButtonWidget();
void add();
virtual ~ButtonWidget() {}
void setLabel(const char* label);
@ -185,6 +187,8 @@ namespace GUIEngine
class LabelWidget : public Widget
{
public:
LabelWidget();
void add();
virtual ~LabelWidget() {}
};
@ -269,6 +273,7 @@ namespace GUIEngine
public:
Widget* m_focus;
RibbonWidget(const RibbonType type=RIBBON_COMBO);
virtual ~RibbonWidget() {}
int getSelection() const { return m_selection; }
@ -280,7 +285,6 @@ namespace GUIEngine
const std::string& getSelectionText() { return m_children[m_selection].m_properties[PROP_TEXT]; }
void setLabel(const int id, std::string new_name);
RibbonWidget(const RibbonType type=RIBBON_COMBO);
};
struct ItemDescription
@ -352,6 +356,7 @@ namespace GUIEngine
video::ITexture* m_texture;
float angle;
public:
ModelViewWidget();
~ModelViewWidget();
void add();
@ -362,6 +367,8 @@ namespace GUIEngine
class ListWidget : public Widget
{
public:
ListWidget();
SkinWidgetContainer m_selection_skin_info;
void add();
@ -375,6 +382,8 @@ namespace GUIEngine
class TextBoxWidget : public Widget
{
public:
TextBoxWidget();
void add();
void addItem(const char* item);