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