Xonotic
slider.qc
Go to the documentation of this file.
1 #include "slider.qh"
2 
3 entity makeXonoticSlider_T(float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
4 {
5  entity me;
6  me = NEW(XonoticSlider);
7  me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar, theTooltip);
8  return me;
9 }
10 entity makeXonoticSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
11 {
12  return makeXonoticSlider_T(theValueMin, theValueMax, theValueStep, theCvar, string_null);
13 }
14 void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
15 {
16  float vp;
17  vp = theValueStep * 10;
18  while(fabs(vp) < fabs(theValueMax - theValueMin) / 40)
19  vp *= 10;
20 
21  me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
22 
23  me.controlledCvar = (theCvar) ? theCvar : string_null;
24  if(theCvar)
25  // Prevent flickering of the slider button by initialising the
26  // slider out of bounds to hide the button before loading the cvar
27  me.configureSliderValues(me, theValueMin, theValueMin-theValueStep, theValueMax, theValueStep, theValueStep, vp);
28  else
29  me.configureSliderValues(me, theValueMin, theValueMin, theValueMax, theValueStep, theValueStep, vp);
30  me.loadCvars(me);
31  setZonedTooltip(me, theTooltip, theCvar);
32 }
33 void XonoticSlider_setValue(entity me, float val)
34 {
35  if(val != me.value)
36  {
37  SUPER(XonoticSlider).setValue( me, val );
38  me.saveCvars(me);
39  }
40 }
42 {
43  if(val != me.value)
44  {
45  SUPER(XonoticSlider).setValue_noAnim(me, val);
46  me.saveCvars(me);
47  }
48 }
50 {
51  if (!me.controlledCvar)
52  return;
53 
54  me.setValue_noAnim(me, cvar(me.controlledCvar));
55 }
57 {
58  if (!me.controlledCvar)
59  return;
60 
61  cvar_set(me.controlledCvar, ftos_mindecimals(me.value));
62 
63  CheckSendCvars(me, me.controlledCvar);
64 }
string string_null
Definition: nil.qh:9
void XonoticSlider_saveCvars(entity me)
Definition: slider.qc:56
#define NEW(cname,...)
Definition: oo.qh:105
void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
Definition: slider.qc:14
ERASEABLE string ftos_mindecimals(float number)
converts a number to a string with the minimum number of decimals
Definition: string.qh:461
entity() spawn
void XonoticSlider_loadCvars(entity me)
Definition: slider.qc:49
entity makeXonoticSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
Definition: slider.qc:10
void XonoticSlider_setValue(entity me, float val)
Definition: slider.qc:33
#define SUPER(cname)
Definition: oo.qh:219
entity makeXonoticSlider_T(float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
Definition: slider.qc:3
void XonoticSlider_setValue_noAnim(entity me, float val)
Definition: slider.qc:41