use a mygui controller for scrollbar repeat

actorid
Sebastian Wick 12 years ago
parent e3d8bdbafe
commit b43f41c2bd

@ -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

@ -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)
{
}
}
}

@ -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)
{
mHourSlider->updateTime(dt);
if (!mWaiting)
return;

@ -4,6 +4,7 @@
#include <MyGUI_ProgressBar.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_ControllerManager.h>
#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<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)
{
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<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)
{
mStepIncrease = 0;
MyGUI::ControllerManager::getInstance().removeItem(this);
}
}
}

@ -3,6 +3,7 @@
#include "../mwworld/esmstore.hpp"
#include "../mwmechanics/stat.hpp"
#include "controllers.hpp"
#include <MyGUI_Button.h>
#include <MyGUI_EditBox.h>
@ -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);

@ -146,6 +146,8 @@ namespace MWGui
BookPage::registerMyGUIComponents ();
ItemView::registerComponents();
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Controllers::ControllerRepeatClick>("Controller");
MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
MyGUI::ResourceManager::getInstance().load("core.xml");

Loading…
Cancel
Save