]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/checkbox.c
-scmenu; make mapinfo default
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / checkbox.c
1 #ifdef INTERFACE
2 CLASS(NexuizCheckBox) EXTENDS(CheckBox)
3         METHOD(NexuizCheckBox, configureNexuizCheckBox, void(entity, 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, inverted, float, 0)
8         // can be: 0   (off =  0, on =  1)
9         //         1   (off =  1, on =  0)
10         //         1+a (off =  a, on = -a)
11         //        -1-a (off = -a, on =  a)
12
13         ATTRIB(NexuizCheckBox, color, vector, SKINCOLOR_CHECKBOX_N)
14         ATTRIB(NexuizCheckBox, colorC, vector, SKINCOLOR_CHECKBOX_C)
15         ATTRIB(NexuizCheckBox, colorF, vector, SKINCOLOR_CHECKBOX_F)
16         ATTRIB(NexuizCheckBox, colorD, vector, SKINCOLOR_CHECKBOX_D)
17
18         ATTRIB(NexuizCheckBox, cvarName, string, string_null)
19         METHOD(NexuizCheckBox, loadCvars, void(entity))
20         METHOD(NexuizCheckBox, saveCvars, void(entity))
21
22         ATTRIB(NexuizCheckBox, disabledAlpha, float, SKINALPHA_DISABLED)
23 ENDCLASS(NexuizCheckBox)
24 entity makeNexuizCheckBox(float, string, string);
25 #endif
26
27 #ifdef IMPLEMENTATION
28 entity makeNexuizCheckBox(float isInverted, string theCvar, string theText)
29 {
30         entity me;
31         me = spawnNexuizCheckBox();
32         me.configureNexuizCheckBox(me, isInverted, theCvar, theText);
33         return me;
34 }
35 void configureNexuizCheckBoxNexuizCheckBox(entity me, float isInverted, string theCvar, string theText)
36 {
37         me.inverted = isInverted;
38         me.checked = 0;
39         if(theCvar)
40         {
41                 me.cvarName = theCvar;
42                 me.loadCvars(me);
43         }
44         me.configureCheckBox(me, theText, me.fontSize, me.image);
45 }
46 void setCheckedNexuizCheckBox(entity me, float val)
47 {
48         if(val != me.checked)
49         {
50                 me.checked = val;
51                 me.saveCvars(me);
52         }
53 }
54 void loadCvarsNexuizCheckBox(entity me)
55 {
56         if(me.inverted == 0)
57                 me.checked = cvar(me.cvarName);
58         else if(me.inverted == 1)
59                 me.checked = !cvar(me.cvarName);
60         else if(me.inverted > 1)
61                 me.checked = (cvar(me.cvarName) < 0);
62         else if(me.inverted < -1)
63                 me.checked = (cvar(me.cvarName) > 0);
64 }
65 void saveCvarsNexuizCheckBox(entity me)
66 {
67         if(me.inverted == 0)
68                 cvar_set(me.cvarName, me.checked ? "1" : "0");
69         else if(me.inverted == 1)
70                 cvar_set(me.cvarName, me.checked ? "0" : "1");
71         else if(me.inverted > 1)
72         {
73                 if(me.checked)
74                         cvar_set(me.cvarName, ftos(-(me.inverted - 1)));
75                 else
76                         cvar_set(me.cvarName, ftos(+(me.inverted - 1)));
77         }
78         else if(me.inverted < -1)
79         {
80                 if(me.checked)
81                         cvar_set(me.cvarName, ftos(-(me.inverted + 1)));
82                 else
83                         cvar_set(me.cvarName, ftos(+(me.inverted + 1)));
84         }
85 }
86 #endif