Sliders can ignore cvar value's sign, if needed

Gyro sensitivity sliders need this, since their values can be negative
to invert pitch and yaw.
This commit is contained in:
Jaime Moreira 2022-09-19 11:24:06 -03:00
parent e29d37956a
commit 54eb9e441d
3 changed files with 15 additions and 1 deletions

View file

@ -113,6 +113,7 @@ typedef struct
float maxvalue;
float slidestep;
char * printformat;
qboolean abs;
} menuslider_s;
typedef struct

View file

@ -1699,6 +1699,7 @@ Gyro_MenuInit(void)
s_gyro_yawsensitivity_slider.cvar = "gyro_yawsensitivity";
s_gyro_yawsensitivity_slider.minvalue = 0.1f;
s_gyro_yawsensitivity_slider.maxvalue = 8.0f;
s_gyro_yawsensitivity_slider.abs = true;
s_gyro_pitchsensitivity_slider.generic.type = MTYPE_SLIDER;
s_gyro_pitchsensitivity_slider.generic.x = 0;
@ -1707,6 +1708,7 @@ Gyro_MenuInit(void)
s_gyro_pitchsensitivity_slider.cvar = "gyro_pitchsensitivity";
s_gyro_pitchsensitivity_slider.minvalue = 0.1f;
s_gyro_pitchsensitivity_slider.maxvalue = 8.0f;
s_gyro_pitchsensitivity_slider.abs = true;
s_calibrating_text[0].generic.type = MTYPE_SEPARATOR;
s_calibrating_text[0].generic.x = 48 * scale + 32;

View file

@ -661,13 +661,20 @@ Slider_DoSlide(menuslider_s *s, int dir)
{
float value = Cvar_VariableValue(s->cvar);
float step = 0.1f;
float sign = 1.0f;
if (s->slidestep)
{
step = s->slidestep;
}
if (s->abs && value < 0) // absolute value treatment
{
value = -value;
sign = -1.0f;
}
value += dir * step;
Cvar_SetValue(s->cvar, ClampCvar(s->minvalue, s->maxvalue, value));
Cvar_SetValue(s->cvar, ClampCvar(s->minvalue, s->maxvalue, value) * sign);
if (s->generic.callback)
{
@ -688,6 +695,10 @@ Slider_Draw(menuslider_s *s)
int y = s->generic.parent->y + s->generic.y;
float value = Cvar_VariableValue(s->cvar);
if (s->abs && value < 0) // absolute value
{
value = -value;
}
float range = (ClampCvar(s->minvalue, s->maxvalue, value) - s->minvalue) /
(s->maxvalue - s->minvalue);