mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 18:45:33 +00:00
use a mygui controller for scrollbar repeat
This commit is contained in:
parent
e3d8bdbafe
commit
b43f41c2bd
7 changed files with 131 additions and 33 deletions
|
@ -33,7 +33,7 @@ add_openmw_dir (mwgui
|
||||||
enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons
|
enchantingdialog trainingwindow travelwindow imagebutton exposedwindow cursor spellicons
|
||||||
merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks
|
merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks
|
||||||
keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview
|
keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview
|
||||||
tradeitemmodel companionitemmodel pickpocketitemmodel fontloader
|
tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers
|
||||||
)
|
)
|
||||||
|
|
||||||
add_openmw_dir (mwdialogue
|
add_openmw_dir (mwdialogue
|
||||||
|
|
54
apps/openmw/mwgui/controllers.cpp
Normal file
54
apps/openmw/mwgui/controllers.cpp
Normal file
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
46
apps/openmw/mwgui/controllers.hpp
Normal file
46
apps/openmw/mwgui/controllers.hpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
#ifndef MWGUI_CONTROLLERS_H
|
||||||
|
#define MWGUI_CONTROLLERS_H
|
||||||
|
|
||||||
|
#include <MyGUI_Widget.h>
|
||||||
|
#include <MyGUI_ControllerItem.h>
|
||||||
|
|
||||||
|
|
||||||
|
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<MyGUI::Widget*, MyGUI::ControllerItem*> 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
|
|
@ -228,8 +228,6 @@ namespace MWGui
|
||||||
|
|
||||||
void WaitDialog::onFrame(float dt)
|
void WaitDialog::onFrame(float dt)
|
||||||
{
|
{
|
||||||
mHourSlider->updateTime(dt);
|
|
||||||
|
|
||||||
if (!mWaiting)
|
if (!mWaiting)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <MyGUI_ProgressBar.h>
|
#include <MyGUI_ProgressBar.h>
|
||||||
#include <MyGUI_ImageBox.h>
|
#include <MyGUI_ImageBox.h>
|
||||||
|
#include <MyGUI_ControllerManager.h>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
@ -898,8 +899,6 @@ namespace MWGui
|
||||||
: mEnableRepeat(true)
|
: mEnableRepeat(true)
|
||||||
, mRepeatTriggerTime(0.5)
|
, mRepeatTriggerTime(0.5)
|
||||||
, mRepeatStepTime(0.1)
|
, mRepeatStepTime(0.1)
|
||||||
, mStepDecrease(0)
|
|
||||||
, mStepIncrease(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,51 +938,50 @@ namespace MWGui
|
||||||
mRepeatStepTime = step;
|
mRepeatStepTime = step;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScrollBar::updateTime(float dt)
|
void MWScrollBar::repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller)
|
||||||
{
|
{
|
||||||
if(!mEnableRepeat)
|
if(mIsIncreasing && mScrollPosition < mScrollRange-1)
|
||||||
return;
|
|
||||||
|
|
||||||
if(mStepDecrease > 0)
|
|
||||||
{
|
{
|
||||||
mStepDecrease -= dt;
|
mScrollPosition += 1;
|
||||||
if(mStepDecrease <= 0 && mScrollPosition > 0)
|
eventScrollChangePosition(this, mScrollPosition);
|
||||||
{
|
|
||||||
mScrollPosition -= 1;
|
|
||||||
eventScrollChangePosition(this, mScrollPosition);
|
|
||||||
mStepDecrease += mRepeatStepTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(mStepIncrease > 0)
|
else if(!mIsIncreasing && mScrollPosition > 0)
|
||||||
{
|
{
|
||||||
mStepIncrease -= dt;
|
mScrollPosition -= 1;
|
||||||
if(mStepIncrease <= 0 && mScrollPosition < mScrollRange-1)
|
eventScrollChangePosition(this, mScrollPosition);
|
||||||
{
|
|
||||||
mScrollPosition += 1;
|
|
||||||
eventScrollChangePosition(this, mScrollPosition);
|
|
||||||
mStepIncrease += mRepeatStepTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MWScrollBar::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
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<MWGui::Controllers::ControllerRepeatClick>();
|
||||||
|
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)
|
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)
|
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<MWGui::Controllers::ControllerRepeatClick>();
|
||||||
|
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)
|
void MWScrollBar::onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
{
|
{
|
||||||
mStepIncrease = 0;
|
MyGUI::ControllerManager::getInstance().removeItem(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
#include "../mwmechanics/stat.hpp"
|
#include "../mwmechanics/stat.hpp"
|
||||||
|
#include "controllers.hpp"
|
||||||
|
|
||||||
#include <MyGUI_Button.h>
|
#include <MyGUI_Button.h>
|
||||||
#include <MyGUI_EditBox.h>
|
#include <MyGUI_EditBox.h>
|
||||||
|
@ -415,22 +416,21 @@ namespace MWGui
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MWScrollBar();
|
MWScrollBar();
|
||||||
|
virtual ~MWScrollBar();
|
||||||
|
|
||||||
void setEnableRepeat(bool enable);
|
void setEnableRepeat(bool enable);
|
||||||
bool getEnableRepeat();
|
bool getEnableRepeat();
|
||||||
void getRepeat(float &trigger, float &step);
|
void getRepeat(float &trigger, float &step);
|
||||||
void setRepeat(float trigger, float step);
|
void setRepeat(float trigger, float step);
|
||||||
void updateTime(float dt);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~MWScrollBar();
|
|
||||||
virtual void initialiseOverride();
|
virtual void initialiseOverride();
|
||||||
|
void repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller);
|
||||||
|
|
||||||
bool mEnableRepeat;
|
bool mEnableRepeat;
|
||||||
float mRepeatTriggerTime;
|
float mRepeatTriggerTime;
|
||||||
float mRepeatStepTime;
|
float mRepeatStepTime;
|
||||||
float mStepDecrease;
|
bool mIsIncreasing;
|
||||||
float mStepIncrease;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
||||||
|
|
|
@ -146,6 +146,8 @@ namespace MWGui
|
||||||
BookPage::registerMyGUIComponents ();
|
BookPage::registerMyGUIComponents ();
|
||||||
ItemView::registerComponents();
|
ItemView::registerComponents();
|
||||||
|
|
||||||
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Controllers::ControllerRepeatClick>("Controller");
|
||||||
|
|
||||||
MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
|
MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
|
||||||
MyGUI::ResourceManager::getInstance().load("core.xml");
|
MyGUI::ResourceManager::getInstance().load("core.xml");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue