]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/checkbox.c
vid_samples
[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         print("y = ", ftos(y), ", n = ", ftos(n), "\n");
51         return makeNexuizCheckBoxEx(y, n, theCvar, theText);
52 }
53 entity makeNexuizCheckBoxEx(float theYesValue, float theNoValue, string theCvar, string theText)
54 {
55         entity me;
56         me = spawnNexuizCheckBox();
57         me.configureNexuizCheckBox(me, theYesValue, theNoValue, theCvar, theText);
58         return me;
59 }
60 void configureNexuizCheckBoxNexuizCheckBox(entity me, float theYesValue, float theNoValue, string theCvar, string theText)
61 {
62         me.yesValue = theYesValue;
63         me.noValue = theNoValue;
64         me.checked = 0;
65         if(theCvar)
66         {
67                 me.cvarName = theCvar;
68                 me.loadCvars(me);
69         }
70         me.configureCheckBox(me, theText, me.fontSize, me.image);
71 }
72 void setCheckedNexuizCheckBox(entity me, float val)
73 {
74         if(val != me.checked)
75         {
76                 me.checked = val;
77                 me.saveCvars(me);
78         }
79 }
80 void loadCvarsNexuizCheckBox(entity me)
81 {
82         float m, d;
83         m = (me.yesValue + me.noValue) * 0.5;
84         d = (cvar(me.cvarName) - m) / (me.yesValue - m);
85         me.checked = (d > 0);
86 }
87 void saveCvarsNexuizCheckBox(entity me)
88 {
89         if(me.checked)
90                 cvar_set(me.cvarName, ftos(me.yesValue));
91         else
92                 cvar_set(me.cvarName, ftos(me.noValue));
93 }
94 #endif