]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/colorbutton.c
try fixing the addition of CA
[divverent/nexuiz.git] / data / qcsrc / menu / 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         METHOD(NexuizColorButton, draw, void(entity))
6         ATTRIB(NexuizColorButton, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(NexuizColorButton, image, string, SKINGFX_COLORBUTTON)
8         ATTRIB(NexuizColorButton, image2, string, SKINGFX_COLORBUTTON_COLOR)
9
10         ATTRIB(NexuizColorButton, useDownAsChecked, float, 1)
11
12         ATTRIB(NexuizColorButton, cvarPart, float, 0)
13         ATTRIB(NexuizColorButton, cvarName, string, string_null)
14         ATTRIB(NexuizColorButton, cvarValueFloat, float, 0)
15         METHOD(NexuizColorButton, loadCvars, void(entity))
16         METHOD(NexuizColorButton, saveCvars, void(entity))
17 ENDCLASS(NexuizColorButton)
18 entity makeNexuizColorButton(float, float, float);
19 #endif
20
21 #ifdef IMPLEMENTATION
22 entity makeNexuizColorButton(float theGroup, float theColor, float theValue)
23 {
24         entity me;
25         me = spawnNexuizColorButton();
26         me.configureNexuizColorButton(me, theGroup, theColor, theValue);
27         return me;
28 }
29 void configureNexuizColorButtonNexuizColorButton(entity me, float theGroup, float theColor, float theValue)
30 {
31         me.cvarName = "_cl_color";
32         me.cvarValueFloat = theValue;
33         me.cvarPart = theColor;
34         me.loadCvars(me);
35         me.configureRadioButton(me, string_null, me.fontSize, me.image, theGroup, 0);
36         me.srcMulti = 1;
37         me.src2 = me.image2;
38 }
39 void setCheckedNexuizColorButton(entity me, float val)
40 {
41         if(val != me.checked)
42         {
43                 me.checked = val;
44                 me.saveCvars(me);
45         }
46 }
47 void loadCvarsNexuizColorButton(entity me)
48 {
49         if not(me.cvarName)
50                 return;
51
52         if(me.cvarPart == 1)
53                 me.checked = (cvar(me.cvarName) & 240) == me.cvarValueFloat * 16;
54         else
55                 me.checked = (cvar(me.cvarName) & 15) == me.cvarValueFloat;
56 }
57 void saveCvarsNexuizColorButton(entity me)
58 {
59         if not(me.cvarName)
60                 return;
61
62         if(me.checked)
63         {
64                 if(me.cvarPart == 1)
65                         cvar_set(me.cvarName, ftos(cvar(me.cvarName) & 15 + me.cvarValueFloat * 16));
66                 else
67                         cvar_set(me.cvarName, ftos(cvar(me.cvarName) & 240 + me.cvarValueFloat));
68         }
69         // TODO on an apply button, read _cl_color and execute the color command for it
70 }
71 void drawNexuizColorButton(entity me)
72 {
73         me.color2 = colormapPaletteColor(me.cvarValueFloat, me.cvarPart);
74         drawCheckBox(me);
75 }
76 #endif