1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-01 11:45:34 +00:00

Use MyGUI's castType for widget casts

This commit is contained in:
scrawl 2014-09-13 04:07:40 +02:00
parent 9d05718515
commit cfc57d0fe0
11 changed files with 34 additions and 31 deletions

View file

@ -266,7 +266,7 @@ namespace MWGui
BookPage::ClickCallback callback = boost::bind (&DialogueWindow::notifyLinkClicked, this, _1); BookPage::ClickCallback callback = boost::bind (&DialogueWindow::notifyLinkClicked, this, _1);
mHistory->adviseLinkClicked(callback); mHistory->adviseLinkClicked(callback);
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize); mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &DialogueWindow::onWindowResize);
} }
void DialogueWindow::exit() void DialogueWindow::exit()

View file

@ -42,7 +42,7 @@ namespace MWGui
, mSelectedItem(-1) , mSelectedItem(-1)
, mGuiMode(GM_Inventory) , mGuiMode(GM_Inventory)
{ {
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); mMainWidget->castType<MyGUI::Window>()->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);
getWidget(mAvatar, "Avatar"); getWidget(mAvatar, "Avatar");
getWidget(mAvatarImage, "AvatarImage"); getWidget(mAvatarImage, "AvatarImage");
@ -368,7 +368,7 @@ namespace MWGui
mItemView->update(); mItemView->update();
static_cast<MyGUI::Button*>(_sender)->setStateSelected(true); _sender->castType<MyGUI::Button>()->setStateSelected(true);
} }
void InventoryWindow::onPinToggled() void InventoryWindow::onPinToggled()

View file

@ -154,7 +154,7 @@ namespace MWGui
void MWList::onItemSelected(MyGUI::Widget* _sender) void MWList::onItemSelected(MyGUI::Widget* _sender)
{ {
std::string name = static_cast<MyGUI::Button*>(_sender)->getCaption(); std::string name = _sender->castType<MyGUI::Button>()->getCaption();
int id = *_sender->getUserData<int>(); int id = *_sender->getUserData<int>();
eventItemSelected(name, id); eventItemSelected(name, id);
eventWidgetSelected(_sender); eventWidgetSelected(_sender);

View file

@ -370,10 +370,10 @@ namespace MWGui
void SettingsWindow::onShaderModeToggled(MyGUI::Widget* _sender) void SettingsWindow::onShaderModeToggled(MyGUI::Widget* _sender)
{ {
std::string val = static_cast<MyGUI::Button*>(_sender)->getCaption(); std::string val = _sender->castType<MyGUI::Button>()->getCaption();
val = hlslGlsl(); val = hlslGlsl();
static_cast<MyGUI::Button*>(_sender)->setCaption(val); _sender->castType<MyGUI::Button>()->setCaption(val);
Settings::Manager::setString("shader mode", "General", val); Settings::Manager::setString("shader mode", "General", val);
@ -483,7 +483,7 @@ namespace MWGui
{ {
int actionId = *_sender->getUserData<int>(); int actionId = *_sender->getUserData<int>();
static_cast<MyGUI::Button*>(_sender)->setCaptionWithReplacing("#{sNone}"); _sender->castType<MyGUI::Button>()->setCaptionWithReplacing("#{sNone}");
MWBase::Environment::get().getWindowManager ()->staticMessageBox ("#{sControlsMenu3}"); MWBase::Environment::get().getWindowManager ()->staticMessageBox ("#{sControlsMenu3}");
MWBase::Environment::get().getWindowManager ()->disallowMouse(); MWBase::Environment::get().getWindowManager ()->disallowMouse();

View file

@ -66,7 +66,7 @@ namespace MWGui
mSkillWidgetMap.insert(std::pair<int, MyGUI::TextBox*>(i, (MyGUI::TextBox*)NULL)); mSkillWidgetMap.insert(std::pair<int, MyGUI::TextBox*>(i, (MyGUI::TextBox*)NULL));
} }
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget); MyGUI::Window* t = mMainWidget->castType<MyGUI::Window>();
t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); 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) void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max)
{ {
MyGUI::ProgressPtr pt; MyGUI::ProgressBar* pt;
getWidget(pt, name); getWidget(pt, name);
pt->setProgressRange(max); pt->setProgressRange(max);
pt->setProgressPosition(val); pt->setProgressPosition(val);
@ -102,7 +102,7 @@ namespace MWGui
void StatsWindow::setPlayerName(const std::string& playerName) void StatsWindow::setPlayerName(const std::string& playerName)
{ {
static_cast<MyGUI::Window*>(mMainWidget)->setCaption(playerName); mMainWidget->castType<MyGUI::Window>()->setCaption(playerName);
adjustWindowCaption(); adjustWindowCaption();
} }

View file

@ -37,7 +37,7 @@ namespace MWGui
void setBounty (int bounty) { if (bounty != mBounty) mChanged = true; this->mBounty = bounty; } void setBounty (int bounty) { if (bounty != mBounty) mChanged = true; this->mBounty = bounty; }
void updateSkillArea(); void updateSkillArea();
virtual void open() { onWindowResize(static_cast<MyGUI::Window*>(mMainWidget)); } virtual void open() { onWindowResize(mMainWidget->castType<MyGUI::Window>()); }
private: private:
void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);

View file

@ -138,7 +138,7 @@ namespace MWGui
mFilterMagic->setStateSelected(false); mFilterMagic->setStateSelected(false);
mFilterMisc->setStateSelected(false); mFilterMisc->setStateSelected(false);
static_cast<MyGUI::Button*>(_sender)->setStateSelected(true); _sender->castType<MyGUI::Button>()->setStateSelected(true);
mItemView->update(); mItemView->update();
} }

View file

@ -192,7 +192,10 @@ namespace MWGui
mSleeping = canRest; mSleeping = canRest;
dynamic_cast<Gui::Box*>(mMainWidget)->notifyChildrenSizeChanged(); Gui::Box* box = dynamic_cast<Gui::Box*>(mMainWidget);
if (box == NULL)
throw std::runtime_error("main widget must be a box");
box->notifyChildrenSizeChanged();
center(); center();
} }

View file

@ -59,18 +59,18 @@ namespace MWGui
{ {
if (mSkillId == ESM::Skill::Length) if (mSkillId == ESM::Skill::Length)
{ {
static_cast<MyGUI::TextBox*>(mSkillNameWidget)->setCaption(""); mSkillNameWidget->setCaption("");
} }
else else
{ {
const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], ""); const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], "");
static_cast<MyGUI::TextBox*>(mSkillNameWidget)->setCaption(name); mSkillNameWidget->setCaption(name);
} }
} }
if (mSkillValueWidget) if (mSkillValueWidget)
{ {
SkillValue::Type modified = mValue.getModified(), base = mValue.getBase(); SkillValue::Type modified = mValue.getModified(), base = mValue.getBase();
static_cast<MyGUI::TextBox*>(mSkillValueWidget)->setCaption(boost::lexical_cast<std::string>(modified)); mSkillValueWidget->setCaption(boost::lexical_cast<std::string>(modified));
if (modified > base) if (modified > base)
mSkillValueWidget->_setWidgetState("increased"); mSkillValueWidget->_setWidgetState("increased");
else if (modified < base) else if (modified < base)
@ -145,7 +145,7 @@ namespace MWGui
{ {
if (mId < 0 || mId >= 8) if (mId < 0 || mId >= 8)
{ {
static_cast<MyGUI::TextBox*>(mAttributeNameWidget)->setCaption(""); mAttributeNameWidget->setCaption("");
} }
else else
{ {
@ -160,13 +160,13 @@ namespace MWGui
"sAttributeLuck" "sAttributeLuck"
}; };
const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], ""); const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], "");
static_cast<MyGUI::TextBox*>(mAttributeNameWidget)->setCaption(name); mAttributeNameWidget->setCaption(name);
} }
} }
if (mAttributeValueWidget) if (mAttributeValueWidget)
{ {
int modified = mValue.getModified(), base = mValue.getBase(); int modified = mValue.getModified(), base = mValue.getBase();
static_cast<MyGUI::TextBox*>(mAttributeValueWidget)->setCaption(boost::lexical_cast<std::string>(modified)); mAttributeValueWidget->setCaption(boost::lexical_cast<std::string>(modified));
if (modified > base) if (modified > base)
mAttributeValueWidget->_setWidgetState("increased"); mAttributeValueWidget->_setWidgetState("increased");
else if (modified < base) else if (modified < base)
@ -256,9 +256,9 @@ namespace MWGui
const ESM::Spell *spell = store.get<ESM::Spell>().search(mId); const ESM::Spell *spell = store.get<ESM::Spell>().search(mId);
if (spell) if (spell)
static_cast<MyGUI::TextBox*>(mSpellNameWidget)->setCaption(spell->mName); mSpellNameWidget->setCaption(spell->mName);
else else
static_cast<MyGUI::TextBox*>(mSpellNameWidget)->setCaption(""); mSpellNameWidget->setCaption("");
} }
} }
@ -310,7 +310,7 @@ namespace MWGui
// ... then adjust the size for all widgets // ... then adjust the size for all widgets
for (std::vector<MyGUI::Widget*>::iterator it = effects.begin(); it != effects.end(); ++it) for (std::vector<MyGUI::Widget*>::iterator it = effects.begin(); it != effects.end(); ++it)
{ {
effect = static_cast<MWSpellEffectPtr>(*it); effect = (*it)->castType<MWSpellEffect>();
bool needcenter = center && (maxwidth > effect->getRequestedWidth()); bool needcenter = center && (maxwidth > effect->getRequestedWidth());
int diff = maxwidth - effect->getRequestedWidth(); int diff = maxwidth - effect->getRequestedWidth();
if (needcenter) if (needcenter)
@ -470,7 +470,7 @@ namespace MWGui
} }
} }
static_cast<MyGUI::TextBox*>(mTextWidget)->setCaptionWithReplacing(spellLine); mTextWidget->setCaptionWithReplacing(spellLine);
mRequestedWidth = mTextWidget->getTextSize().width + 24; mRequestedWidth = mTextWidget->getTextSize().width + 24;
mImageWidget->setImageTexture(Misc::ResourceHelpers::correctIconPath(magicEffect->mIcon)); mImageWidget->setImageTexture(Misc::ResourceHelpers::correctIconPath(magicEffect->mIcon));
@ -515,13 +515,13 @@ namespace MWGui
{ {
std::stringstream out; std::stringstream out;
out << mValue << "/" << mMax; out << mValue << "/" << mMax;
static_cast<MyGUI::TextBox*>(mBarTextWidget)->setCaption(out.str().c_str()); mBarTextWidget->setCaption(out.str().c_str());
} }
} }
void MWDynamicStat::setTitle(const std::string& text) void MWDynamicStat::setTitle(const std::string& text)
{ {
if (mTextWidget) if (mTextWidget)
static_cast<MyGUI::TextBox*>(mTextWidget)->setCaption(text); mTextWidget->setCaption(text);
} }
MWDynamicStat::~MWDynamicStat() MWDynamicStat::~MWDynamicStat()

View file

@ -122,8 +122,8 @@ namespace MWGui
ESM::Skill::SkillEnum mSkillId; ESM::Skill::SkillEnum mSkillId;
SkillValue mValue; SkillValue mValue;
MyGUI::Widget* mSkillNameWidget; MyGUI::TextBox* mSkillNameWidget;
MyGUI::Widget* mSkillValueWidget; MyGUI::TextBox* mSkillValueWidget;
}; };
typedef MWSkill* MWSkillPtr; typedef MWSkill* MWSkillPtr;
@ -162,8 +162,8 @@ namespace MWGui
int mId; int mId;
AttributeValue mValue; AttributeValue mValue;
MyGUI::Widget* mAttributeNameWidget; MyGUI::TextBox* mAttributeNameWidget;
MyGUI::Widget* mAttributeValueWidget; MyGUI::TextBox* mAttributeValueWidget;
}; };
typedef MWAttribute* MWAttributePtr; typedef MWAttribute* MWAttributePtr;
@ -293,7 +293,7 @@ namespace MWGui
int mValue, mMax; int mValue, mMax;
MyGUI::TextBox* mTextWidget; MyGUI::TextBox* mTextWidget;
MyGUI::ProgressPtr mBarWidget; MyGUI::ProgressBar* mBarWidget;
MyGUI::TextBox* mBarTextWidget; MyGUI::TextBox* mBarTextWidget;
}; };
typedef MWDynamicStat* MWDynamicStatPtr; typedef MWDynamicStat* MWDynamicStatPtr;

View file

@ -7,7 +7,7 @@ namespace MWGui
WindowPinnableBase::WindowPinnableBase(const std::string& parLayout) WindowPinnableBase::WindowPinnableBase(const std::string& parLayout)
: WindowBase(parLayout), mPinned(false) : WindowBase(parLayout), mPinned(false)
{ {
ExposedWindow* window = static_cast<ExposedWindow*>(mMainWidget); ExposedWindow* window = mMainWidget->castType<ExposedWindow>();
mPinButton = window->getSkinWidget ("Button"); mPinButton = window->getSkinWidget ("Button");
mPinButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WindowPinnableBase::onPinButtonClicked); mPinButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WindowPinnableBase::onPinButtonClicked);