diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index ad2b4710c..f9a03de71 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -15,8 +15,6 @@ #include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/npcstats.hpp" -#include "widgets.hpp" - namespace MWGui { @@ -53,15 +51,14 @@ namespace MWGui getWidget(mDateTimeText, "DateTimeText"); getWidget(mRestText, "RestText"); getWidget(mHourText, "HourText"); - getWidget(mHourSlider, "HourSlider"); getWidget(mUntilHealedButton, "UntilHealedButton"); getWidget(mWaitButton, "WaitButton"); getWidget(mCancelButton, "CancelButton"); + getWidget(mHourSlider, "HourSlider"); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onCancelButtonClicked); mUntilHealedButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onUntilHealedButtonClicked); mWaitButton->eventMouseButtonClick += MyGUI::newDelegate(this, &WaitDialog::onWaitButtonClicked); - mHourSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &WaitDialog::onHourSliderChangedPosition); mProgressBar.setVisible (false); @@ -231,6 +228,8 @@ namespace MWGui void WaitDialog::onFrame(float dt) { + mHourSlider->updateTime(dt); + if (!mWaiting) return; diff --git a/apps/openmw/mwgui/waitdialog.hpp b/apps/openmw/mwgui/waitdialog.hpp index d06d7d112..2723f7a80 100644 --- a/apps/openmw/mwgui/waitdialog.hpp +++ b/apps/openmw/mwgui/waitdialog.hpp @@ -2,6 +2,7 @@ #define MWGUI_WAIT_DIALOG_H #include "windowbase.hpp" +#include "widgets.hpp" namespace MWGui { @@ -38,10 +39,10 @@ namespace MWGui MyGUI::TextBox* mDateTimeText; MyGUI::TextBox* mRestText; MyGUI::TextBox* mHourText; - MyGUI::ScrollBar* mHourSlider; MyGUI::Button* mUntilHealedButton; MyGUI::Button* mWaitButton; MyGUI::Button* mCancelButton; + MWGui::Widgets::MWScrollBar* mHourSlider; bool mWaiting; bool mSleeping; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 1662c0597..7752b6a94 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -893,5 +893,97 @@ namespace MWGui { align(); } + + MWScrollBar::MWScrollBar() + : mEnableRepeat(true) + , mRepeatTriggerTime(0.5) + , mRepeatStepTime(0.1) + , mStepDecrease(0) + , mStepIncrease(0) + { + } + + MWScrollBar::~MWScrollBar() + { + } + + void MWScrollBar::initialiseOverride() + { + Base::initialiseOverride(); + + mWidgetStart->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonPressed); + mWidgetStart->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onDecreaseButtonReleased); + mWidgetEnd->eventMouseButtonPressed += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonPressed); + mWidgetEnd->eventMouseButtonReleased += MyGUI::newDelegate(this, &MWScrollBar::onIncreaseButtonReleased); + } + + void MWScrollBar::setEnableRepeat(bool enable) + { + mEnableRepeat = enable; + } + + bool MWScrollBar::getEnableRepeat() + { + return mEnableRepeat; + } + + void MWScrollBar::getRepeat(float &trigger, float &step) + { + trigger = mRepeatTriggerTime; + step = mRepeatStepTime; + } + + void MWScrollBar::setRepeat(float trigger, float step) + { + mRepeatTriggerTime = trigger; + mRepeatStepTime = step; + } + + void MWScrollBar::updateTime(float dt) + { + if(!mEnableRepeat) + return; + + if(mStepDecrease > 0) + { + mStepDecrease -= dt; + if(mStepDecrease <= 0 && mScrollPosition > 0) + { + mScrollPosition -= 1; + eventScrollChangePosition(this, mScrollPosition); + mStepDecrease += mRepeatStepTime; + } + } + if(mStepIncrease > 0) + { + mStepIncrease -= dt; + if(mStepIncrease <= 0 && mScrollPosition < mScrollRange-1) + { + mScrollPosition += 1; + eventScrollChangePosition(this, mScrollPosition); + mStepIncrease += mRepeatStepTime; + } + } + } + + void MWScrollBar::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepDecrease = mRepeatTriggerTime; + } + + void MWScrollBar::onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepDecrease = 0; + } + + void MWScrollBar::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepIncrease = mRepeatTriggerTime; + } + + void MWScrollBar::onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) + { + mStepIncrease = 0; + } } } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 156794691..362746ae2 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace MyGUI { @@ -407,6 +408,36 @@ namespace MWGui virtual void onWidgetCreated(MyGUI::Widget* _widget); }; + + class MWScrollBar : public MyGUI::ScrollBar + { + MYGUI_RTTI_DERIVED(MWScrollBar) + + public: + MWScrollBar(); + + void setEnableRepeat(bool enable); + bool getEnableRepeat(); + void getRepeat(float &trigger, float &step); + void setRepeat(float trigger, float step); + void updateTime(float dt); + + protected: + virtual ~MWScrollBar(); + virtual void initialiseOverride(); + + bool mEnableRepeat; + float mRepeatTriggerTime; + float mRepeatStepTime; + float mStepDecrease; + float mStepIncrease; + + private: + void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + void onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + void onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); + }; } } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 38efbbff0..06fb96c12 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -142,6 +142,7 @@ namespace MWGui MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); BookPage::registerMyGUIComponents (); ItemView::registerComponents(); diff --git a/files/mygui/openmw_wait_dialog.layout b/files/mygui/openmw_wait_dialog.layout index 66e0ec22f..eeb7012eb 100644 --- a/files/mygui/openmw_wait_dialog.layout +++ b/files/mygui/openmw_wait_dialog.layout @@ -16,7 +16,7 @@ - +