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