From cfc57d0fe0e0fd6b187f9ce29f4b4a378a5753f3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 13 Sep 2014 04:07:40 +0200 Subject: [PATCH] Use MyGUI's castType for widget casts --- apps/openmw/mwgui/dialogue.cpp | 2 +- apps/openmw/mwgui/inventorywindow.cpp | 4 ++-- apps/openmw/mwgui/list.cpp | 2 +- apps/openmw/mwgui/settingswindow.cpp | 6 +++--- apps/openmw/mwgui/statswindow.cpp | 6 +++--- apps/openmw/mwgui/statswindow.hpp | 2 +- apps/openmw/mwgui/tradewindow.cpp | 2 +- apps/openmw/mwgui/waitdialog.cpp | 5 ++++- apps/openmw/mwgui/widgets.cpp | 24 ++++++++++++------------ apps/openmw/mwgui/widgets.hpp | 10 +++++----- apps/openmw/mwgui/windowpinnablebase.cpp | 2 +- 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 94b2c4b0e..33b768dfc 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -266,7 +266,7 @@ namespace MWGui BookPage::ClickCallback callback = boost::bind (&DialogueWindow::notifyLinkClicked, this, _1); mHistory->adviseLinkClicked(callback); - static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize); + mMainWidget->castType()->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize); } void DialogueWindow::exit() diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 441d8c28f..4490f3db2 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -42,7 +42,7 @@ namespace MWGui , mSelectedItem(-1) , mGuiMode(GM_Inventory) { - static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); + mMainWidget->castType()->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); getWidget(mAvatar, "Avatar"); getWidget(mAvatarImage, "AvatarImage"); @@ -368,7 +368,7 @@ namespace MWGui mItemView->update(); - static_cast(_sender)->setStateSelected(true); + _sender->castType()->setStateSelected(true); } void InventoryWindow::onPinToggled() diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp index e88d43534..ff14bcf61 100644 --- a/apps/openmw/mwgui/list.cpp +++ b/apps/openmw/mwgui/list.cpp @@ -154,7 +154,7 @@ namespace MWGui void MWList::onItemSelected(MyGUI::Widget* _sender) { - std::string name = static_cast(_sender)->getCaption(); + std::string name = _sender->castType()->getCaption(); int id = *_sender->getUserData(); eventItemSelected(name, id); eventWidgetSelected(_sender); diff --git a/apps/openmw/mwgui/settingswindow.cpp b/apps/openmw/mwgui/settingswindow.cpp index abeb6b86c..c3fbe88ab 100644 --- a/apps/openmw/mwgui/settingswindow.cpp +++ b/apps/openmw/mwgui/settingswindow.cpp @@ -370,10 +370,10 @@ namespace MWGui void SettingsWindow::onShaderModeToggled(MyGUI::Widget* _sender) { - std::string val = static_cast(_sender)->getCaption(); + std::string val = _sender->castType()->getCaption(); val = hlslGlsl(); - static_cast(_sender)->setCaption(val); + _sender->castType()->setCaption(val); Settings::Manager::setString("shader mode", "General", val); @@ -483,7 +483,7 @@ namespace MWGui { int actionId = *_sender->getUserData(); - static_cast(_sender)->setCaptionWithReplacing("#{sNone}"); + _sender->castType()->setCaptionWithReplacing("#{sNone}"); MWBase::Environment::get().getWindowManager ()->staticMessageBox ("#{sControlsMenu3}"); MWBase::Environment::get().getWindowManager ()->disallowMouse(); diff --git a/apps/openmw/mwgui/statswindow.cpp b/apps/openmw/mwgui/statswindow.cpp index edc85e8df..f55c96705 100644 --- a/apps/openmw/mwgui/statswindow.cpp +++ b/apps/openmw/mwgui/statswindow.cpp @@ -66,7 +66,7 @@ namespace MWGui mSkillWidgetMap.insert(std::pair(i, (MyGUI::TextBox*)NULL)); } - MyGUI::WindowPtr t = static_cast(mMainWidget); + MyGUI::Window* t = mMainWidget->castType(); t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); } @@ -90,7 +90,7 @@ namespace MWGui void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max) { - MyGUI::ProgressPtr pt; + MyGUI::ProgressBar* pt; getWidget(pt, name); pt->setProgressRange(max); pt->setProgressPosition(val); @@ -102,7 +102,7 @@ namespace MWGui void StatsWindow::setPlayerName(const std::string& playerName) { - static_cast(mMainWidget)->setCaption(playerName); + mMainWidget->castType()->setCaption(playerName); adjustWindowCaption(); } diff --git a/apps/openmw/mwgui/statswindow.hpp b/apps/openmw/mwgui/statswindow.hpp index 1a62b6d6b..f41995ac0 100644 --- a/apps/openmw/mwgui/statswindow.hpp +++ b/apps/openmw/mwgui/statswindow.hpp @@ -37,7 +37,7 @@ namespace MWGui void setBounty (int bounty) { if (bounty != mBounty) mChanged = true; this->mBounty = bounty; } void updateSkillArea(); - virtual void open() { onWindowResize(static_cast(mMainWidget)); } + virtual void open() { onWindowResize(mMainWidget->castType()); } private: void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 67bdc14ac..9393446f1 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -138,7 +138,7 @@ namespace MWGui mFilterMagic->setStateSelected(false); mFilterMisc->setStateSelected(false); - static_cast(_sender)->setStateSelected(true); + _sender->castType()->setStateSelected(true); mItemView->update(); } diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index ac70d3eed..f95ec5675 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -192,7 +192,10 @@ namespace MWGui mSleeping = canRest; - dynamic_cast(mMainWidget)->notifyChildrenSizeChanged(); + Gui::Box* box = dynamic_cast(mMainWidget); + if (box == NULL) + throw std::runtime_error("main widget must be a box"); + box->notifyChildrenSizeChanged(); center(); } diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 5c5b9b894..b45f7d59c 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -59,18 +59,18 @@ namespace MWGui { if (mSkillId == ESM::Skill::Length) { - static_cast(mSkillNameWidget)->setCaption(""); + mSkillNameWidget->setCaption(""); } else { const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], ""); - static_cast(mSkillNameWidget)->setCaption(name); + mSkillNameWidget->setCaption(name); } } if (mSkillValueWidget) { SkillValue::Type modified = mValue.getModified(), base = mValue.getBase(); - static_cast(mSkillValueWidget)->setCaption(boost::lexical_cast(modified)); + mSkillValueWidget->setCaption(boost::lexical_cast(modified)); if (modified > base) mSkillValueWidget->_setWidgetState("increased"); else if (modified < base) @@ -145,7 +145,7 @@ namespace MWGui { if (mId < 0 || mId >= 8) { - static_cast(mAttributeNameWidget)->setCaption(""); + mAttributeNameWidget->setCaption(""); } else { @@ -160,13 +160,13 @@ namespace MWGui "sAttributeLuck" }; const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], ""); - static_cast(mAttributeNameWidget)->setCaption(name); + mAttributeNameWidget->setCaption(name); } } if (mAttributeValueWidget) { int modified = mValue.getModified(), base = mValue.getBase(); - static_cast(mAttributeValueWidget)->setCaption(boost::lexical_cast(modified)); + mAttributeValueWidget->setCaption(boost::lexical_cast(modified)); if (modified > base) mAttributeValueWidget->_setWidgetState("increased"); else if (modified < base) @@ -256,9 +256,9 @@ namespace MWGui const ESM::Spell *spell = store.get().search(mId); if (spell) - static_cast(mSpellNameWidget)->setCaption(spell->mName); + mSpellNameWidget->setCaption(spell->mName); else - static_cast(mSpellNameWidget)->setCaption(""); + mSpellNameWidget->setCaption(""); } } @@ -310,7 +310,7 @@ namespace MWGui // ... then adjust the size for all widgets for (std::vector::iterator it = effects.begin(); it != effects.end(); ++it) { - effect = static_cast(*it); + effect = (*it)->castType(); bool needcenter = center && (maxwidth > effect->getRequestedWidth()); int diff = maxwidth - effect->getRequestedWidth(); if (needcenter) @@ -470,7 +470,7 @@ namespace MWGui } } - static_cast(mTextWidget)->setCaptionWithReplacing(spellLine); + mTextWidget->setCaptionWithReplacing(spellLine); mRequestedWidth = mTextWidget->getTextSize().width + 24; mImageWidget->setImageTexture(Misc::ResourceHelpers::correctIconPath(magicEffect->mIcon)); @@ -515,13 +515,13 @@ namespace MWGui { std::stringstream out; out << mValue << "/" << mMax; - static_cast(mBarTextWidget)->setCaption(out.str().c_str()); + mBarTextWidget->setCaption(out.str().c_str()); } } void MWDynamicStat::setTitle(const std::string& text) { if (mTextWidget) - static_cast(mTextWidget)->setCaption(text); + mTextWidget->setCaption(text); } MWDynamicStat::~MWDynamicStat() diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 10b723cae..fc13b7ce5 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -122,8 +122,8 @@ namespace MWGui ESM::Skill::SkillEnum mSkillId; SkillValue mValue; - MyGUI::Widget* mSkillNameWidget; - MyGUI::Widget* mSkillValueWidget; + MyGUI::TextBox* mSkillNameWidget; + MyGUI::TextBox* mSkillValueWidget; }; typedef MWSkill* MWSkillPtr; @@ -162,8 +162,8 @@ namespace MWGui int mId; AttributeValue mValue; - MyGUI::Widget* mAttributeNameWidget; - MyGUI::Widget* mAttributeValueWidget; + MyGUI::TextBox* mAttributeNameWidget; + MyGUI::TextBox* mAttributeValueWidget; }; typedef MWAttribute* MWAttributePtr; @@ -293,7 +293,7 @@ namespace MWGui int mValue, mMax; MyGUI::TextBox* mTextWidget; - MyGUI::ProgressPtr mBarWidget; + MyGUI::ProgressBar* mBarWidget; MyGUI::TextBox* mBarTextWidget; }; typedef MWDynamicStat* MWDynamicStatPtr; diff --git a/apps/openmw/mwgui/windowpinnablebase.cpp b/apps/openmw/mwgui/windowpinnablebase.cpp index 92ba5876d..f9bbca665 100644 --- a/apps/openmw/mwgui/windowpinnablebase.cpp +++ b/apps/openmw/mwgui/windowpinnablebase.cpp @@ -7,7 +7,7 @@ namespace MWGui WindowPinnableBase::WindowPinnableBase(const std::string& parLayout) : WindowBase(parLayout), mPinned(false) { - ExposedWindow* window = static_cast(mMainWidget); + ExposedWindow* window = mMainWidget->castType(); mPinButton = window->getSkinWidget ("Button"); mPinButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WindowPinnableBase::onPinButtonClicked);