]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / slider.qc
1 #include "slider.qh"
2 #ifndef SLIDER_H
3 #define SLIDER_H
4 #include "../item/slider.qc"
5 CLASS(XonoticSlider, Slider)
6         METHOD(XonoticSlider, configureXonoticSlider, void(entity, float, float, float, string, string));
7         METHOD(XonoticSlider, setValue, void(entity, float));
8         METHOD(XonoticSlider, setValue_noAnim, void(entity, float));
9         ATTRIB(XonoticSlider, fontSize, float, SKINFONTSIZE_NORMAL)
10         ATTRIB(XonoticSlider, valueSpace, float, SKINWIDTH_SLIDERTEXT)
11         ATTRIB(XonoticSlider, image, string, SKINGFX_SLIDER)
12         ATTRIB(XonoticSlider, tolerance, vector, SKINTOLERANCE_SLIDER)
13         ATTRIB(XonoticSlider, align, float, 0.5)
14         ATTRIB(XonoticSlider, color, vector, SKINCOLOR_SLIDER_N)
15         ATTRIB(XonoticSlider, colorC, vector, SKINCOLOR_SLIDER_C)
16         ATTRIB(XonoticSlider, colorF, vector, SKINCOLOR_SLIDER_F)
17         ATTRIB(XonoticSlider, colorD, vector, SKINCOLOR_SLIDER_D)
18         ATTRIB(XonoticSlider, color2, vector, SKINCOLOR_SLIDER_S)
19
20         ATTRIB(XonoticSlider, cvarName, string, string_null)
21         METHOD(XonoticSlider, loadCvars, void(entity));
22         METHOD(XonoticSlider, saveCvars, void(entity));
23         ATTRIB(XonoticSlider, sendCvars, float, 0)
24
25         ATTRIB(XonoticSlider, alpha, float, SKINALPHA_TEXT)
26         ATTRIB(XonoticSlider, disabledAlpha, float, SKINALPHA_DISABLED)
27 ENDCLASS(XonoticSlider)
28 entity makeXonoticSlider_T(float, float, float, string, string theTooltip);
29 entity makeXonoticSlider(float, float, float, string);
30 #endif
31
32 #ifdef IMPLEMENTATION
33 entity makeXonoticSlider_T(float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
34 {
35         entity me;
36         me = NEW(XonoticSlider);
37         me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar, theTooltip);
38         return me;
39 }
40 entity makeXonoticSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
41 {
42         return makeXonoticSlider_T(theValueMin, theValueMax, theValueStep, theCvar, string_null);
43 }
44 void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float theValueMax, float theValueStep, string theCvar, string theTooltip)
45 {
46         float vp;
47         vp = theValueStep * 10;
48         while(fabs(vp) < fabs(theValueMax - theValueMin) / 40)
49                 vp *= 10;
50
51         me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
52
53         me.cvarName = (theCvar) ? theCvar : string_null;
54         if(theCvar)
55                 // Prevent flickering of the slider button by initialising the
56                 // slider out of bounds to hide the button before loading the cvar
57                 me.configureSliderValues(me, theValueMin, theValueMin-theValueStep, theValueMax, theValueStep, theValueStep, vp);
58         else
59                 me.configureSliderValues(me, theValueMin, theValueMin, theValueMax, theValueStep, theValueStep, vp);
60         me.loadCvars(me);
61         setZonedTooltip(me, theTooltip, theCvar);
62 }
63 void XonoticSlider_setValue(entity me, float val)
64 {
65         if(val != me.value)
66         {
67                 SUPER(XonoticSlider).setValue( me, val );
68                 me.saveCvars(me);
69         }
70 }
71 void XonoticSlider_setValue_noAnim(entity me, float val)
72 {
73         if(val != me.value)
74         {
75                 SUPER(XonoticSlider).setValue_noAnim(me, val);
76                 me.saveCvars(me);
77         }
78 }
79 void XonoticSlider_loadCvars(entity me)
80 {
81         if (!me.cvarName)
82                 return;
83
84         me.setValue_noAnim(me, cvar(me.cvarName));
85 }
86 void XonoticSlider_saveCvars(entity me)
87 {
88         if (!me.cvarName)
89                 return;
90
91         cvar_set(me.cvarName, ftos(me.value));
92
93         CheckSendCvars(me, me.cvarName);
94 }
95 #endif