]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/checkbox.c
the usual (forgot two files)
[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                 me.loadCvars(me);
68         }
69         me.configureCheckBox(me, theText, me.fontSize, me.image);
70 }
71 void setCheckedNexuizCheckBox(entity me, float val)
72 {
73         if(val != me.checked)
74         {
75                 me.checked = val;
76                 me.saveCvars(me);
77         }
78 }
79 void loadCvarsNexuizCheckBox(entity me)
80 {
81         float m, d;
82         m = (me.yesValue + me.noValue) * 0.5;
83         d = (cvar(me.cvarName) - m) / (me.yesValue - m);
84         me.checked = (d > 0);
85 }
86 void saveCvarsNexuizCheckBox(entity me)
87 {
88         if(me.checked)
89                 cvar_set(me.cvarName, ftos(me.yesValue));
90         else
91                 cvar_set(me.cvarName, ftos(me.noValue));
92 }
93 #endif