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