]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/menu/voret/checkbox.c
Include gmqcc binaries for Windows and Linux
[voretournament/voretournament.git] / data / qcsrc / menu / voret / checkbox.c
1 #ifdef INTERFACE\r
2 CLASS(VoretCheckBox) EXTENDS(CheckBox)\r
3         METHOD(VoretCheckBox, configureVoretCheckBox, void(entity, float, float, string, string))\r
4         METHOD(VoretCheckBox, setChecked, void(entity, float))\r
5         ATTRIB(VoretCheckBox, fontSize, float, SKINFONTSIZE_NORMAL)\r
6         ATTRIB(VoretCheckBox, image, string, SKINGFX_CHECKBOX)\r
7         ATTRIB(VoretCheckBox, yesValue, float, 1)\r
8         ATTRIB(VoretCheckBox, noValue, float, 0)\r
9 \r
10         ATTRIB(VoretCheckBox, color, vector, SKINCOLOR_CHECKBOX_N)\r
11         ATTRIB(VoretCheckBox, colorC, vector, SKINCOLOR_CHECKBOX_C)\r
12         ATTRIB(VoretCheckBox, colorF, vector, SKINCOLOR_CHECKBOX_F)\r
13         ATTRIB(VoretCheckBox, colorD, vector, SKINCOLOR_CHECKBOX_D)\r
14 \r
15         ATTRIB(VoretCheckBox, cvarName, string, string_null)\r
16         METHOD(VoretCheckBox, loadCvars, void(entity))\r
17         METHOD(VoretCheckBox, saveCvars, void(entity))\r
18 \r
19         ATTRIB(VoretCheckBox, alpha, float, SKINALPHA_TEXT)\r
20         ATTRIB(VoretCheckBox, disabledAlpha, float, SKINALPHA_DISABLED)\r
21 ENDCLASS(VoretCheckBox)\r
22 entity makeVoretCheckBox(float, string, string);\r
23 entity makeVoretCheckBoxEx(float, float, string, string);\r
24 #endif\r
25 \r
26 #ifdef IMPLEMENTATION\r
27 entity makeVoretCheckBox(float isInverted, string theCvar, string theText)\r
28 {\r
29         float y, n;\r
30         if(isInverted > 1)\r
31         {\r
32                 n = isInverted - 1;\r
33                 y = -n;\r
34         }\r
35         else if(isInverted < -1)\r
36         {\r
37                 n = isInverted + 1;\r
38                 y = -n;\r
39         }\r
40         else if(isInverted == 1)\r
41         {\r
42                 n = 1;\r
43                 y = 0;\r
44         }\r
45         else\r
46         {\r
47                 n = 0;\r
48                 y = 1;\r
49         }\r
50         return makeVoretCheckBoxEx(y, n, theCvar, theText);\r
51 }\r
52 entity makeVoretCheckBoxEx(float theYesValue, float theNoValue, string theCvar, string theText)\r
53 {\r
54         entity me;\r
55         me = spawnVoretCheckBox();\r
56         me.configureVoretCheckBox(me, theYesValue, theNoValue, theCvar, theText);\r
57         return me;\r
58 }\r
59 void configureVoretCheckBoxVoretCheckBox(entity me, float theYesValue, float theNoValue, string theCvar, string theText)\r
60 {\r
61         me.yesValue = theYesValue;\r
62         me.noValue = theNoValue;\r
63         me.checked = 0;\r
64         if(theCvar)\r
65         {\r
66                 me.cvarName = theCvar;\r
67                 me.tooltip = getZonedTooltipForIdentifier(theCvar);\r
68                 me.loadCvars(me);\r
69         }\r
70         me.configureCheckBox(me, theText, me.fontSize, me.image);\r
71 }\r
72 void setCheckedVoretCheckBox(entity me, float val)\r
73 {\r
74         if(val != me.checked)\r
75         {\r
76                 me.checked = val;\r
77                 me.saveCvars(me);\r
78         }\r
79 }\r
80 void loadCvarsVoretCheckBox(entity me)\r
81 {\r
82         float m, d;\r
83 \r
84         if not(me.cvarName)\r
85                 return;\r
86 \r
87         m = (me.yesValue + me.noValue) * 0.5;\r
88         d = (cvar(me.cvarName) - m) / (me.yesValue - m);\r
89         me.checked = (d > 0);\r
90 }\r
91 void saveCvarsVoretCheckBox(entity me)\r
92 {\r
93         if not(me.cvarName)\r
94                 return;\r
95 \r
96         if(me.checked)\r
97                 cvar_set(me.cvarName, ftos(me.yesValue));\r
98         else\r
99                 cvar_set(me.cvarName, ftos(me.noValue));\r
100 }\r
101 #endif\r