From 5114c18b790e20cf9449e04313abd78250827469 Mon Sep 17 00:00:00 2001 From: cutealien Date: Wed, 28 Sep 2022 14:56:22 +0000 Subject: [PATCH] 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 --- source/Irrlicht/CGUISpinBox.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/source/Irrlicht/CGUISpinBox.cpp b/source/Irrlicht/CGUISpinBox.cpp index 06083777..453722e2 100644 --- a/source/Irrlicht/CGUISpinBox.cpp +++ b/source/Irrlicht/CGUISpinBox.cpp @@ -56,8 +56,6 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* envir EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT); refreshSprites(); - - OldValue = getValue(); } @@ -106,8 +104,6 @@ IGUIEditBox* CGUISpinBox::getEditBox() const void CGUISpinBox::setValue(f32 val) { - OldValue = val; - wchar_t str[100]; swprintf_irr(str, 99, FormatString.c_str(), val); EditBox->setText(str); @@ -201,7 +197,6 @@ bool CGUISpinBox::OnEvent(const SEvent& event) { if (IsEnabled) { - f32 oldValue = OldValue; bool changeEvent = false; bool eatEvent = false; switch(event.EventType) @@ -211,7 +206,8 @@ bool CGUISpinBox::OnEvent(const SEvent& event) { 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); changeEvent = true; eatEvent = true; @@ -228,15 +224,15 @@ bool CGUISpinBox::OnEvent(const SEvent& event) { if (event.GUIEvent.Caller == ButtonSpinUp) { - f32 val = getValue(); - val += StepSize; + OldValue = getValue(); + f32 val = OldValue + StepSize; setValue(val); changeEvent = true; } else if ( event.GUIEvent.Caller == ButtonSpinDown) { - f32 val = getValue(); - val -= StepSize; + OldValue = getValue(); + f32 val = OldValue - StepSize; setValue(val); changeEvent = true; } @@ -268,9 +264,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event) e.GUIEvent.Element = 0; e.GUIEvent.EventType = EGET_SPINBOX_CHANGED; - core::swap(oldValue, OldValue); Parent->OnEvent(e); - core::swap(oldValue, OldValue); } if ( eatEvent ) return true;