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
This commit is contained in:
hendricks266 2014-12-28 21:35:07 +00:00
parent 571a44cd8d
commit a74317a104

View file

@ -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) 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); 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) switch (direction)
{ {
case MM_Left: case MM_Left:
--newValueIndex; if (newValueIndex >= currentPos || *object->variable == newValueProjected)
--newValueIndex;
if (newValueIndex >= 0) if (newValueIndex >= 0)
break; break;
case MM_AllTheWayLeft: case MM_AllTheWayLeft:
@ -4620,7 +4623,8 @@ static void M_RunMenuInput_MenuEntryRangeInt32_Movement(MenuEntry_t *entry, Menu
break; break;
case MM_Right: case MM_Right:
++newValueIndex; if (newValueIndex <= currentPos || *object->variable == newValueProjected)
++newValueIndex;
if (newValueIndex < object->steps) if (newValueIndex < object->steps)
break; break;
case MM_AllTheWayRight: case MM_AllTheWayRight:
@ -4631,7 +4635,7 @@ static void M_RunMenuInput_MenuEntryRangeInt32_Movement(MenuEntry_t *entry, Menu
break; 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) 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) 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); 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) switch (direction)
{ {
case MM_Left: case MM_Left:
--newValueIndex; if (newValueIndex >= currentPos || *object->variable == newValueProjected)
--newValueIndex;
if (newValueIndex >= 0) if (newValueIndex >= 0)
break; break;
case MM_AllTheWayLeft: case MM_AllTheWayLeft:
@ -4659,7 +4666,8 @@ static void M_RunMenuInput_MenuEntryRangeFloat_Movement(MenuEntry_t *entry, Menu
break; break;
case MM_Right: case MM_Right:
++newValueIndex; if (newValueIndex <= currentPos || *object->variable == newValueProjected)
++newValueIndex;
if (newValueIndex < object->steps) if (newValueIndex < object->steps)
break; break;
case MM_AllTheWayRight: 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) 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); 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) switch (direction)
{ {
case MM_Left: case MM_Left:
--newValueIndex; if (newValueIndex >= currentPos || *object->variable == newValueProjected)
--newValueIndex;
if (newValueIndex >= 0) if (newValueIndex >= 0)
break; break;
case MM_AllTheWayLeft: case MM_AllTheWayLeft:
@ -4695,7 +4706,8 @@ static void M_RunMenuInput_MenuEntryRangeDouble_Movement(/*MenuEntry_t *entry, *
break; break;
case MM_Right: case MM_Right:
++newValueIndex; if (newValueIndex <= currentPos || *object->variable == newValueProjected)
++newValueIndex;
if (newValueIndex < object->steps) if (newValueIndex < object->steps)
break; break;
case MM_AllTheWayRight: case MM_AllTheWayRight: