autorepeat scrollbar

actorid
Sebastian Wick 12 years ago
parent 72b7e113cc
commit e3d8bdbafe

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

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

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

@ -6,6 +6,7 @@
#include <MyGUI_Button.h>
#include <MyGUI_EditBox.h>
#include <MyGUI_ScrollBar.h>
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);
};
}
}

@ -142,6 +142,7 @@ namespace MWGui
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ImageButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::ExposedWindow>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWScrollView>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWScrollBar>("Widget");
BookPage::registerMyGUIComponents ();
ItemView::registerComponents();

@ -16,7 +16,7 @@
<Widget type="AutoSizedTextBox" skin="SandText" name="HourText">
</Widget>
<Widget type="ScrollBar" skin="MW_HScroll" name="HourSlider" position="0 0 0 18">
<Widget type="MWScrollBar" skin="MW_HScroll" name="HourSlider" position="0 0 0 18">
<Property key="MoveToClick" value="true"/>
<Property key="Range" value="24"/>
<UserString key="HStretch" value="true"/>

Loading…
Cancel
Save