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