]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/nexuiz/colorbutton.c
fix selection bugs when enabling/disabling the checkboxes
[divverent/nexuiz.git] / data / qcsrc / menu-div0test / nexuiz / colorbutton.c
1 #ifdef INTERFACE
2 CLASS(NexuizColorButton) EXTENDS(RadioButton)
3         METHOD(NexuizColorButton, configureNexuizColorButton, void(entity, float, float, float))
4         METHOD(NexuizColorButton, setChecked, void(entity, float))
5         ATTRIB(NexuizColorButton, fontSize, float, SKINFONTSIZE_NORMAL)
6         ATTRIB(NexuizColorButton, image, string, SKINGFX_COLORBUTTON)
7         ATTRIB(NexuizColorButton, image2, string, SKINGFX_COLORBUTTON_COLOR)
8
9         ATTRIB(NexuizColorButton, useDownAsChecked, float, 1)
10
11         ATTRIB(NexuizColorButton, cvarPart, float, 0)
12         ATTRIB(NexuizColorButton, cvarName, string, string_null)
13         ATTRIB(NexuizColorButton, cvarValueFloat, float, 0)
14         METHOD(NexuizColorButton, loadCvars, void(entity))
15         METHOD(NexuizColorButton, saveCvars, void(entity))
16 ENDCLASS(NexuizColorButton)
17 entity makeNexuizColorButton(float, float, float);
18 #endif
19
20 #ifdef IMPLEMENTATION
21 entity makeNexuizColorButton(float theGroup, float theColor, float theValue)
22 {
23         entity me;
24         me = spawnNexuizColorButton();
25         me.configureNexuizColorButton(me, theGroup, theColor, theValue);
26         return me;
27 }
28 void configureNexuizColorButtonNexuizColorButton(entity me, float theGroup, float theColor, float theValue)
29 {
30         me.cvarName = "_cl_color";
31         me.cvarValueFloat = theValue;
32         me.cvarPart = theColor;
33         me.loadCvars(me);
34         me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
35         me.srcMulti = 1;
36         me.src2 = strzone(strcat(me.image2, ftos(me.cvarValueFloat)));
37 }
38 void setCheckedNexuizColorButton(entity me, float val)
39 {
40         if(val != me.checked)
41         {
42                 me.checked = val;
43                 me.saveCvars(me);
44         }
45 }
46 void loadCvarsNexuizColorButton(entity me)
47 {
48         if(me.cvarPart == 1)
49                 me.checked = (cvar(me.cvarName) & 240) == me.cvarValueFloat * 16;
50         else
51                 me.checked = (cvar(me.cvarName) & 15) == me.cvarValueFloat;
52 }
53 void saveCvarsNexuizColorButton(entity me)
54 {
55         if(me.checked)
56         {
57                 if(me.cvarPart == 1)
58                         cvar_set(me.cvarName, ftos(cvar(me.cvarName) & 15 + me.cvarValueFloat * 16));
59                 else
60                         cvar_set(me.cvarName, ftos(cvar(me.cvarName) & 240 + me.cvarValueFloat));
61         }
62         // TODO on an apply button, read _cl_color and execute the color command for it
63 }
64 #endif