]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/slider.qc
Merge branch 'master' into Penguinum/Antiwall
[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))
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(float, float, float, string);
27 #endif
28
29 #ifdef IMPLEMENTATION
30 entity makeXonoticSlider(float theValueMin, float theValueMax, float theValueStep, string theCvar)
31 {
32         entity me;
33         me = NEW(XonoticSlider);
34         me.configureXonoticSlider(me, theValueMin, theValueMax, theValueStep, theCvar);
35         return me;
36 }
37 void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float theValueMax, float theValueStep, string theCvar)
38 {
39         float vp;
40         vp = theValueStep * 10;
41         while(fabs(vp) < fabs(theValueMax - theValueMin) / 40)
42                 vp *= 10;
43
44         me.configureSliderVisuals(me, me.fontSize, me.align, me.valueSpace, me.image);
45
46         if(theCvar)
47         {
48                 // Prevent flickering of the slider button by initialising the
49                 // slider out of bounds to hide the button before loading the cvar
50                 me.configureSliderValues(me, theValueMin, theValueMin-theValueStep, theValueMax, theValueStep, theValueStep, vp);
51                 me.cvarName = theCvar;
52                 me.loadCvars(me);
53                 me.tooltip = getZonedTooltipForIdentifier(theCvar);
54         }
55         else
56                 me.configureSliderValues(me, theValueMin, theValueMin, theValueMax, theValueStep, theValueStep, vp);
57 }
58 void XonoticSlider_setValue(entity me, float val)
59 {
60         if(val != me.value)
61         {
62                 SUPER(XonoticSlider).setValue( me, val );
63                 me.saveCvars(me);
64         }
65 }
66 void XonoticSlider_loadCvars(entity me)
67 {
68         if (!me.cvarName)
69                 return;
70
71         me.setValue( me, cvar(me.cvarName) );
72 }
73 void XonoticSlider_saveCvars(entity me)
74 {
75         if (!me.cvarName)
76                 return;
77
78         cvar_set(me.cvarName, ftos(me.value));
79
80         CheckSendCvars(me, me.cvarName);
81 }
82 #endif