diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 501e5c5ae5..6dbc3e28fb 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -33,7 +33,7 @@ add_openmw_dir (mwgui enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview - tradeitemmodel companionitemmodel pickpocketitemmodel fontloader + tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/controllers.cpp b/apps/openmw/mwgui/controllers.cpp new file mode 100644 index 0000000000..2c3ef4ae0e --- /dev/null +++ b/apps/openmw/mwgui/controllers.cpp @@ -0,0 +1,54 @@ +#include "controllers.hpp" + +namespace MWGui +{ + namespace Controllers + { + + ControllerRepeatClick::ControllerRepeatClick() : + mInit(0.5), + mStep(0.1), + mEnabled(true), + mTimeLeft(0) + { + } + + ControllerRepeatClick::~ControllerRepeatClick() + { + } + + bool ControllerRepeatClick::addTime(MyGUI::Widget* _widget, float _time) + { + if(mTimeLeft == 0) + mTimeLeft = mInit; + + mTimeLeft -= _time; + if(mTimeLeft <= 0) + { + mTimeLeft = mStep; + eventRepeatClick(_widget, this); + } + return true; + } + + void ControllerRepeatClick::setRepeat(float init, float step) + { + mInit = init; + mStep = step; + } + + void ControllerRepeatClick::setEnabled(bool enable) + { + mEnabled = enable; + } + + void ControllerRepeatClick::setProperty(const std::string& _key, const std::string& _value) + { + } + + void ControllerRepeatClick::prepareItem(MyGUI::Widget* _widget) + { + } + + } +} diff --git a/apps/openmw/mwgui/controllers.hpp b/apps/openmw/mwgui/controllers.hpp new file mode 100644 index 0000000000..798acde622 --- /dev/null +++ b/apps/openmw/mwgui/controllers.hpp @@ -0,0 +1,46 @@ +#ifndef MWGUI_CONTROLLERS_H +#define MWGUI_CONTROLLERS_H + +#include +#include + + +namespace MWGui +{ + namespace Controllers + { + class ControllerRepeatClick : + public MyGUI::ControllerItem + { + MYGUI_RTTI_DERIVED( ControllerRepeatClick ) + + public: + ControllerRepeatClick(); + virtual ~ControllerRepeatClick(); + + void setRepeat(float init, float step); + void setEnabled(bool enable); + virtual void setProperty(const std::string& _key, const std::string& _value); + + // Events + typedef MyGUI::delegates::CMultiDelegate2 EventHandle_RepeatClickVoid; + + /** Event : Repeat Click.\n + signature : void method(MyGUI::Widget* _sender, MyGUI::ControllerItem *_controller)\n + */ + EventHandle_RepeatClickVoid eventRepeatClick; + + private: + bool addTime(MyGUI::Widget* _widget, float _time); + void prepareItem(MyGUI::Widget* _widget); + + private: + float mInit; + float mStep; + bool mEnabled; + float mTimeLeft; + }; + } +} + +#endif diff --git a/apps/openmw/mwgui/waitdialog.cpp b/apps/openmw/mwgui/waitdialog.cpp index f9a03de716..97c869b07d 100644 --- a/apps/openmw/mwgui/waitdialog.cpp +++ b/apps/openmw/mwgui/waitdialog.cpp @@ -228,8 +228,6 @@ namespace MWGui void WaitDialog::onFrame(float dt) { - mHourSlider->updateTime(dt); - if (!mWaiting) return; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 7752b6a94d..d147b28b1d 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" @@ -898,8 +899,6 @@ namespace MWGui : mEnableRepeat(true) , mRepeatTriggerTime(0.5) , mRepeatStepTime(0.1) - , mStepDecrease(0) - , mStepIncrease(0) { } @@ -939,51 +938,50 @@ namespace MWGui mRepeatStepTime = step; } - void MWScrollBar::updateTime(float dt) + void MWScrollBar::repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller) { - if(!mEnableRepeat) - return; - - if(mStepDecrease > 0) + if(mIsIncreasing && mScrollPosition < mScrollRange-1) { - mStepDecrease -= dt; - if(mStepDecrease <= 0 && mScrollPosition > 0) - { - mScrollPosition -= 1; - eventScrollChangePosition(this, mScrollPosition); - mStepDecrease += mRepeatStepTime; - } + mScrollPosition += 1; + eventScrollChangePosition(this, mScrollPosition); } - if(mStepIncrease > 0) + else if(!mIsIncreasing && mScrollPosition > 0) { - mStepIncrease -= dt; - if(mStepIncrease <= 0 && mScrollPosition < mScrollRange-1) - { - mScrollPosition += 1; - eventScrollChangePosition(this, mScrollPosition); - mStepIncrease += mRepeatStepTime; - } + mScrollPosition -= 1; + eventScrollChangePosition(this, mScrollPosition); } } void MWScrollBar::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepDecrease = mRepeatTriggerTime; + mIsIncreasing = false; + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatClick::getClassTypeName()); + MWGui::Controllers::ControllerRepeatClick* controller = item->castType(); + controller->eventRepeatClick += newDelegate(this, &MWScrollBar::repeatClick); + controller->setEnabled(mEnableRepeat); + controller->setRepeat(mRepeatTriggerTime, mRepeatStepTime); + MyGUI::ControllerManager::getInstance().addItem(this, controller); } void MWScrollBar::onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepDecrease = 0; + MyGUI::ControllerManager::getInstance().removeItem(this); } void MWScrollBar::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepIncrease = mRepeatTriggerTime; + mIsIncreasing = true; + MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(MWGui::Controllers::ControllerRepeatClick::getClassTypeName()); + MWGui::Controllers::ControllerRepeatClick* controller = item->castType(); + controller->eventRepeatClick += newDelegate(this, &MWScrollBar::repeatClick); + controller->setEnabled(mEnableRepeat); + controller->setRepeat(mRepeatTriggerTime, mRepeatStepTime); + MyGUI::ControllerManager::getInstance().addItem(this, controller); } void MWScrollBar::onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id) { - mStepIncrease = 0; + MyGUI::ControllerManager::getInstance().removeItem(this); } } } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 362746ae2f..1630ab3c9f 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -3,6 +3,7 @@ #include "../mwworld/esmstore.hpp" #include "../mwmechanics/stat.hpp" +#include "controllers.hpp" #include #include @@ -415,22 +416,21 @@ namespace MWGui public: MWScrollBar(); + virtual ~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(); + void repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller); bool mEnableRepeat; float mRepeatTriggerTime; float mRepeatStepTime; - float mStepDecrease; - float mStepIncrease; + bool mIsIncreasing; private: void onDecreaseButtonPressed(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 06fb96c128..f20f03611f 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -146,6 +146,8 @@ namespace MWGui BookPage::registerMyGUIComponents (); ItemView::registerComponents(); + MyGUI::FactoryManager::getInstance().registerFactory("Controller"); + MyGUI::FactoryManager::getInstance().registerFactory("Resource", "ResourceImageSetPointer"); MyGUI::ResourceManager::getInstance().load("core.xml");