]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/checkbox.c
add a multi-cvar single-value tgo the text slider
[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.tooltip = getZonedTooltipForIdentifier(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
84         if not(me.cvarName)
85                 return;
86
87         m = (me.yesValue + me.noValue) * 0.5;
88         d = (cvar(me.cvarName) - m) / (me.yesValue - m);
89         me.checked = (d > 0);
90 }
91 void saveCvarsNexuizCheckBox(entity me)
92 {
93         if not(me.cvarName)
94                 return;
95
96         if(me.checked)
97                 cvar_set(me.cvarName, ftos(me.yesValue));
98         else
99                 cvar_set(me.cvarName, ftos(me.noValue));
100 }
101 #endif