From 37d9e4fa26981942d934edb64fadd634cd5a950e Mon Sep 17 00:00:00 2001 From: Learath Date: Fri, 20 Sep 2019 23:57:35 +0300 Subject: [PATCH] Add a saner way to select angles. Close #1916 --- src/base/math.h | 6 ++++++ src/game/editor/editor.cpp | 28 ++++++++++------------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/base/math.h b/src/base/math.h index 47d5c7cd0..dcc700804 100644 --- a/src/base/math.h +++ b/src/base/math.h @@ -3,6 +3,7 @@ #ifndef BASE_MATH_H #define BASE_MATH_H +#include #include template @@ -32,6 +33,11 @@ inline int round_truncate(float f) return (int)f; } +inline int round_ceil(float f) +{ + return (int)ceilf(f); +} + template inline T mix(const T a, const T b, TB amount) { diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index f64737dfa..0e07a7350 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -3045,30 +3045,22 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int * Shifter.VSplitRight(10.0f, &Shifter, &Inc); Shifter.VSplitLeft(10.0f, &Dec, &Shifter); bool Shift = Input()->KeyIsPressed(KEY_LSHIFT) || Input()->KeyIsPressed(KEY_RSHIFT); + int Step = Shift ? 1 : 45; int Value = pProps[i].m_Value; - const void *activeItem = UI()->ActiveItem(); - if(!Shift && UI()->MouseButton(0) && (activeItem == &pIDs[i] || activeItem == &pIDs[i]+1 || activeItem == &pIDs[i]+2)) - Value = (Value / 45) * 45; - int NewValue = UiDoValueSelector(&pIDs[i], &Shifter, "", Value, pProps[i].m_Min, Shift ? pProps[i].m_Max : 315, Shift ? 1 : 45, Shift ? 1.0f : 10.0f, "Use left mouse button to drag and change the value. Hold shift to be more precise. Rightclick to edit as text.", false, false, 0); - if(NewValue != pProps[i].m_Value) - { - *pNewVal = NewValue; - Change = i; - } + + int NewValue = UiDoValueSelector(&pIDs[i], &Shifter, "", Value, pProps[i].m_Min, pProps[i].m_Max, Shift ? 1 : 45, Shift ? 1.0f : 10.0f, "Use left mouse button to drag and change the value. Hold shift to be more precise. Rightclick to edit as text.", false, false, 0); if(DoButton_ButtonDec(&pIDs[i]+1, 0, 0, &Dec, 0, "Decrease")) { - if(!Shift) - *pNewVal = pProps[i].m_Value - 45; - else - *pNewVal = pProps[i].m_Value - 1; - Change = i; + NewValue = (round_ceil((pProps[i].m_Value / (float)Step)) - 1) * Step; + if(NewValue < 0) + NewValue += 360; } if(DoButton_ButtonInc(&pIDs[i]+ 2, 0, 0, &Inc, 0, "Increase")) + NewValue = (pProps[i].m_Value + Step) / Step * Step; + + if(NewValue != pProps[i].m_Value) { - if(!Shift) - *pNewVal = pProps[i].m_Value + 45; - else - *pNewVal = pProps[i].m_Value + 1; + *pNewVal = NewValue % 360; Change = i; } }