]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider.qc
Merge branch 'master' into terencehill/hud_fixes
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider.qc
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.cvarName = (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 }
41 void XonoticSlider_setValue_noAnim(entity me, float val)
42 {
43         if(val != me.value)
44         {
45                 SUPER(XonoticSlider).setValue_noAnim(me, val);
46                 me.saveCvars(me);
47         }
48 }
49 void XonoticSlider_loadCvars(entity me)
50 {
51         if (!me.cvarName)
52                 return;
53
54         me.setValue_noAnim(me, cvar(me.cvarName));
55 }
56 void XonoticSlider_saveCvars(entity me)
57 {
58         if (!me.cvarName)
59                 return;
60
61         cvar_set(me.cvarName, ftos(me.value));
62
63         CheckSendCvars(me, me.cvarName);
64 }