From a74317a1046591a2322ff787397f1498baa8e0ea Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 28 Dec 2014 21:35:07 +0000 Subject: [PATCH] Menus: When pressing left or right on a slider that has moved by the mouse to a position between the defined intervals, do not round to the nearest interval and then increment or decrement. Instead, check if rounding will satisfy the movement before moving further. git-svn-id: https://svn.eduke32.com/eduke32@4865 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/menus.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 1d4160525..63bf8313e 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -4607,12 +4607,15 @@ static void M_RunMenuInput_MenuEntryRangeInt32_MovementVerify(MenuEntry_t *entry static void M_RunMenuInput_MenuEntryRangeInt32_Movement(MenuEntry_t *entry, MenuRangeInt32_t *object, MenuMovement_t direction) { const float interval = ((float) (object->max - object->min)) / (object->steps - 1); - int32_t newValueIndex = Blrintf((float) (*object->variable - object->min) / interval); + const float currentPos = (float) (*object->variable - object->min) / interval; + int32_t newValueIndex = Blrintf(currentPos); + const int32_t newValueProjected = Blrintf(interval * newValueIndex + object->min); switch (direction) { case MM_Left: - --newValueIndex; + if (newValueIndex >= currentPos || *object->variable == newValueProjected) + --newValueIndex; if (newValueIndex >= 0) break; case MM_AllTheWayLeft: @@ -4620,7 +4623,8 @@ static void M_RunMenuInput_MenuEntryRangeInt32_Movement(MenuEntry_t *entry, Menu break; case MM_Right: - ++newValueIndex; + if (newValueIndex <= currentPos || *object->variable == newValueProjected) + ++newValueIndex; if (newValueIndex < object->steps) break; case MM_AllTheWayRight: @@ -4631,7 +4635,7 @@ static void M_RunMenuInput_MenuEntryRangeInt32_Movement(MenuEntry_t *entry, Menu break; } - M_RunMenuInput_MenuEntryRangeInt32_MovementVerify(entry, object, Blrintf(interval * newValueIndex + (object->min))); + M_RunMenuInput_MenuEntryRangeInt32_MovementVerify(entry, object, Blrintf(interval * newValueIndex + object->min)); } static void M_RunMenuInput_MenuEntryRangeFloat_MovementVerify(MenuEntry_t *entry, MenuRangeFloat_t *object, float newValue) @@ -4646,12 +4650,15 @@ static void M_RunMenuInput_MenuEntryRangeFloat_MovementVerify(MenuEntry_t *entry static void M_RunMenuInput_MenuEntryRangeFloat_Movement(MenuEntry_t *entry, MenuRangeFloat_t *object, MenuMovement_t direction) { const float interval = (object->max - object->min) / (object->steps - 1); - int32_t newValueIndex = Blrintf((*object->variable - object->min) / interval); + const float currentPos = (*object->variable - object->min) / interval; + int32_t newValueIndex = Blrintf(currentPos); + const float newValueProjected = interval * newValueIndex + object->min; switch (direction) { case MM_Left: - --newValueIndex; + if (newValueIndex >= currentPos || *object->variable == newValueProjected) + --newValueIndex; if (newValueIndex >= 0) break; case MM_AllTheWayLeft: @@ -4659,7 +4666,8 @@ static void M_RunMenuInput_MenuEntryRangeFloat_Movement(MenuEntry_t *entry, Menu break; case MM_Right: - ++newValueIndex; + if (newValueIndex <= currentPos || *object->variable == newValueProjected) + ++newValueIndex; if (newValueIndex < object->steps) break; case MM_AllTheWayRight: @@ -4682,12 +4690,15 @@ static void M_RunMenuInput_MenuEntryRangeDouble_MovementVerify(/*MenuEntry_t *en static void M_RunMenuInput_MenuEntryRangeDouble_Movement(/*MenuEntry_t *entry, */MenuRangeDouble_t *object, MenuMovement_t direction) { const double interval = (object->max - object->min) / (object->steps - 1); - int32_t newValueIndex = Blrintf((*object->variable - object->min) / interval); + const double currentPos = (*object->variable - object->min) / interval; + int32_t newValueIndex = Blrintf(currentPos); + const double newValueProjected = interval * newValueIndex + object->min; switch (direction) { case MM_Left: - --newValueIndex; + if (newValueIndex >= currentPos || *object->variable == newValueProjected) + --newValueIndex; if (newValueIndex >= 0) break; case MM_AllTheWayLeft: @@ -4695,7 +4706,8 @@ static void M_RunMenuInput_MenuEntryRangeDouble_Movement(/*MenuEntry_t *entry, * break; case MM_Right: - ++newValueIndex; + if (newValueIndex <= currentPos || *object->variable == newValueProjected) + ++newValueIndex; if (newValueIndex < object->steps) break; case MM_AllTheWayRight: