forked from Mirrorlandia_minetest/irrlicht
Fix and simplify IGUISpinBox::getOldValue
Was going wrong when setValue was called inside an event function for EGET_SPINBOX_CHANGED. But last solution was overly complicated anyway as I tried too hard to avoid extra getValue calculations. But noticing now those calculations got done anyway in all places where the event is triggered. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6430 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
a883d464f9
commit
5114c18b79
@ -56,8 +56,6 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* envir
|
|||||||
EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
||||||
|
|
||||||
refreshSprites();
|
refreshSprites();
|
||||||
|
|
||||||
OldValue = getValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,8 +104,6 @@ IGUIEditBox* CGUISpinBox::getEditBox() const
|
|||||||
|
|
||||||
void CGUISpinBox::setValue(f32 val)
|
void CGUISpinBox::setValue(f32 val)
|
||||||
{
|
{
|
||||||
OldValue = val;
|
|
||||||
|
|
||||||
wchar_t str[100];
|
wchar_t str[100];
|
||||||
swprintf_irr(str, 99, FormatString.c_str(), val);
|
swprintf_irr(str, 99, FormatString.c_str(), val);
|
||||||
EditBox->setText(str);
|
EditBox->setText(str);
|
||||||
@ -201,7 +197,6 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
|||||||
{
|
{
|
||||||
if (IsEnabled)
|
if (IsEnabled)
|
||||||
{
|
{
|
||||||
f32 oldValue = OldValue;
|
|
||||||
bool changeEvent = false;
|
bool changeEvent = false;
|
||||||
bool eatEvent = false;
|
bool eatEvent = false;
|
||||||
switch(event.EventType)
|
switch(event.EventType)
|
||||||
@ -211,7 +206,8 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
|||||||
{
|
{
|
||||||
case EMIE_MOUSE_WHEEL:
|
case EMIE_MOUSE_WHEEL:
|
||||||
{
|
{
|
||||||
f32 val = getValue() + (StepSize * (event.MouseInput.Wheel < 0 ? -1.f : 1.f));
|
OldValue = getValue();
|
||||||
|
f32 val = OldValue + (StepSize * (event.MouseInput.Wheel < 0 ? -1.f : 1.f));
|
||||||
setValue(val);
|
setValue(val);
|
||||||
changeEvent = true;
|
changeEvent = true;
|
||||||
eatEvent = true;
|
eatEvent = true;
|
||||||
@ -228,15 +224,15 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
|||||||
{
|
{
|
||||||
if (event.GUIEvent.Caller == ButtonSpinUp)
|
if (event.GUIEvent.Caller == ButtonSpinUp)
|
||||||
{
|
{
|
||||||
f32 val = getValue();
|
OldValue = getValue();
|
||||||
val += StepSize;
|
f32 val = OldValue + StepSize;
|
||||||
setValue(val);
|
setValue(val);
|
||||||
changeEvent = true;
|
changeEvent = true;
|
||||||
}
|
}
|
||||||
else if ( event.GUIEvent.Caller == ButtonSpinDown)
|
else if ( event.GUIEvent.Caller == ButtonSpinDown)
|
||||||
{
|
{
|
||||||
f32 val = getValue();
|
OldValue = getValue();
|
||||||
val -= StepSize;
|
f32 val = OldValue - StepSize;
|
||||||
setValue(val);
|
setValue(val);
|
||||||
changeEvent = true;
|
changeEvent = true;
|
||||||
}
|
}
|
||||||
@ -268,9 +264,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
|||||||
e.GUIEvent.Element = 0;
|
e.GUIEvent.Element = 0;
|
||||||
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
|
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
|
||||||
|
|
||||||
core::swap(oldValue, OldValue);
|
|
||||||
Parent->OnEvent(e);
|
Parent->OnEvent(e);
|
||||||
core::swap(oldValue, OldValue);
|
|
||||||
}
|
}
|
||||||
if ( eatEvent )
|
if ( eatEvent )
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user