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