]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/checkbox_slider_invalid.qc
Merge branch 'master' into terencehill/slider_anim_improvements
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / checkbox_slider_invalid.qc
1 #ifndef CHECKBOX_SLIDER_INVALID_H
2 #define CHECKBOX_SLIDER_INVALID_H
3 #include "../item/checkbox.qc"
4 CLASS(XonoticSliderCheckBox, CheckBox)
5         METHOD(XonoticSliderCheckBox, configureXonoticSliderCheckBox, void(entity, float, float, entity, string));
6         METHOD(XonoticSliderCheckBox, setChecked, void(entity, float));
7         METHOD(XonoticSliderCheckBox, draw, void(entity));
8         ATTRIB(XonoticSliderCheckBox, fontSize, float, SKINFONTSIZE_NORMAL)
9         ATTRIB(XonoticSliderCheckBox, image, string, SKINGFX_CHECKBOX)
10
11         ATTRIB(XonoticSliderCheckBox, color, vector, SKINCOLOR_CHECKBOX_N)
12         ATTRIB(XonoticSliderCheckBox, colorC, vector, SKINCOLOR_CHECKBOX_C)
13         ATTRIB(XonoticSliderCheckBox, colorF, vector, SKINCOLOR_CHECKBOX_F)
14         ATTRIB(XonoticSliderCheckBox, colorD, vector, SKINCOLOR_CHECKBOX_D)
15
16         ATTRIB(XonoticSliderCheckBox, alpha, float, SKINALPHA_TEXT)
17         ATTRIB(XonoticSliderCheckBox, disabledAlpha, float, SKINALPHA_DISABLED)
18
19         ATTRIB(XonoticSliderCheckBox, controlledSlider, entity, NULL)
20         ATTRIB(XonoticSliderCheckBox, offValue, float, -1)
21         ATTRIB(XonoticSliderCheckBox, inverted, float, 0)
22         ATTRIB(XonoticSliderCheckBox, savedValue, float, -1)
23 ENDCLASS(XonoticSliderCheckBox)
24 entity makeXonoticSliderCheckBox(float, float, entity, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 entity makeXonoticSliderCheckBox(float theOffValue, float isInverted, entity theControlledSlider, string theText)
29 {
30         entity me;
31         me = NEW(XonoticSliderCheckBox);
32         me.configureXonoticSliderCheckBox(me, theOffValue, isInverted, theControlledSlider, theText);
33         return me;
34 }
35 void XonoticSliderCheckBox_configureXonoticSliderCheckBox(entity me, float theOffValue, float isInverted, entity theControlledSlider, string theText)
36 {
37         me.offValue = theOffValue;
38         me.inverted = isInverted;
39         me.checked = (theControlledSlider.value == theOffValue);
40         if(theControlledSlider.value == median(theControlledSlider.valueMin, theControlledSlider.value, theControlledSlider.valueMax))
41                 me.savedValue = theControlledSlider.value;
42         else
43                 me.savedValue = theControlledSlider.valueMin;
44         me.controlledSlider = theControlledSlider;
45         me.configureCheckBox(me, theText, me.fontSize, me.image);
46         me.tooltip = theControlledSlider.tooltip;
47         me.cvarName = theControlledSlider.cvarName; // in case we want to display the cvar in the tooltip
48 }
49 void XonoticSliderCheckBox_draw(entity me)
50 {
51         me.checked = ((me.controlledSlider.value == me.offValue) != me.inverted);
52         if(me.controlledSlider.value == median(me.controlledSlider.valueMin, me.controlledSlider.value, me.controlledSlider.valueMax))
53                 me.savedValue = me.controlledSlider.value;
54         SUPER(XonoticSliderCheckBox).draw(me);
55 }
56 void XonoticSliderCheckBox_setChecked(entity me, float val)
57 {
58         if(me.checked == val)
59                 return;
60         me.checked = val;
61         if(val == me.inverted)
62                 me.controlledSlider.setValue(me.controlledSlider, median(me.controlledSlider.valueMin, me.savedValue, me.controlledSlider.valueMax));
63         else
64                 me.controlledSlider.setValue(me.controlledSlider, me.offValue);
65 }
66
67 #endif