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