]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/radiobutton.c
the usual (forgot two files)
[divverent/nexuiz.git] / data / qcsrc / menu / nexuiz / radiobutton.c
1 #ifdef INTERFACE
2 CLASS(NexuizRadioButton) EXTENDS(RadioButton)
3         METHOD(NexuizRadioButton, configureNexuizRadioButton, void(entity, float, string, string, string))
4         METHOD(NexuizRadioButton, draw, void(entity))
5         METHOD(NexuizRadioButton, setChecked, void(entity, float))
6         ATTRIB(NexuizRadioButton, fontSize, float, SKINFONTSIZE_NORMAL)
7         ATTRIB(NexuizRadioButton, image, string, SKINGFX_RADIOBUTTON)
8         ATTRIB(NexuizRadioButton, color, vector, SKINCOLOR_RADIOBUTTON_N)
9         ATTRIB(NexuizRadioButton, colorC, vector, SKINCOLOR_RADIOBUTTON_C)
10         ATTRIB(NexuizRadioButton, colorF, vector, SKINCOLOR_RADIOBUTTON_F)
11         ATTRIB(NexuizRadioButton, colorD, vector, SKINCOLOR_RADIOBUTTON_D)
12
13         ATTRIB(NexuizRadioButton, cvarName, string, string_null)
14         ATTRIB(NexuizRadioButton, cvarValue, string, string_null)
15         METHOD(NexuizRadioButton, loadCvars, void(entity))
16         METHOD(NexuizRadioButton, saveCvars, void(entity))
17
18         ATTRIB(NexuizRadioButton, alpha, float, SKINALPHA_TEXT)
19         ATTRIB(NexuizRadioButton, disabledAlpha, float, SKINALPHA_DISABLED)
20 ENDCLASS(NexuizRadioButton)
21 entity makeNexuizRadioButton(float, string, string, string);
22 #endif
23
24 #ifdef IMPLEMENTATION
25 entity makeNexuizRadioButton(float theGroup, string theCvar, string theValue, string theText)
26 {
27         entity me;
28         me = spawnNexuizRadioButton();
29         me.configureNexuizRadioButton(me, theGroup, theCvar, theValue, theText);
30         return me;
31 }
32 void configureNexuizRadioButtonNexuizRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText)
33 {
34         if(theCvar)
35         {
36                 me.cvarName = theCvar;
37                 me.cvarValue = theValue;
38                 me.loadCvars(me);
39         }
40         me.configureRadioButton(me, theText, me.fontSize, me.image, theGroup, 0);
41 }
42 void setCheckedNexuizRadioButton(entity me, float val)
43 {
44         if(val != me.checked)
45         {
46                 me.checked = val;
47                 me.saveCvars(me);
48         }
49 }
50 void loadCvarsNexuizRadioButton(entity me)
51 {
52         if(me.cvarValue)
53                 me.checked = (cvar_string(me.cvarName) == me.cvarValue);
54         else
55         {
56                 if(me.cvarName)
57                 {
58                         me.checked = !!cvar(me.cvarName);
59                 }
60                 else
61                 {
62                         // this is difficult
63                         // this is the "generic" selection... but at this time, not
64                         // everything is constructed yet.
65                         // we need to set this later in draw()
66                         me.checked = 0;
67                 }
68         }
69 }
70 void drawNexuizRadioButton(entity me)
71 {
72         if not(me.cvarValue)
73                 if not(me.cvarName)
74                 {
75                         // this is the "other" option
76                         // always select this if none other is
77                         entity e;
78                         float found;
79                         found = 0;
80                         for(e = me.parent.firstChild; e; e = e.nextSibling)
81                                 if(e.group == me.group)
82                                         if(e.checked)
83                                                 found = 1;
84                         if(!found)
85                                 me.setChecked(me, 1);
86                 }
87         drawCheckBox(me);
88 }
89 void saveCvarsNexuizRadioButton(entity me)
90 {
91         if(me.cvarValue)
92         {
93                 if(me.checked)
94                         cvar_set(me.cvarName, me.cvarValue);
95         }
96         else
97         {
98                 if(me.cvarName)
99                 {
100                         cvar_set(me.cvarName, ftos(me.checked));
101                 }
102         }
103 }
104 #endif