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