]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/nexuiz/radiobutton.c
-scmenu; make mapinfo default
[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, disabledAlpha, float, SKINALPHA_DISABLED)
19 ENDCLASS(NexuizRadioButton)
20 entity makeNexuizRadioButton(float, string, string, string);
21 #endif
22
23 #ifdef IMPLEMENTATION
24 entity makeNexuizRadioButton(float theGroup, string theCvar, string theValue, string theText)
25 {
26         entity me;
27         me = spawnNexuizRadioButton();
28         me.configureNexuizRadioButton(me, theGroup, theCvar, theValue, theText);
29         return me;
30 }
31 void configureNexuizRadioButtonNexuizRadioButton(entity me, float theGroup, string theCvar, string theValue, string theText)
32 {
33         if(theCvar)
34         {
35                 me.cvarName = theCvar;
36                 me.cvarValue = theValue;
37                 me.loadCvars(me);
38         }
39         me.configureRadioButton(me, theText, me.fontSize, me.image, theGroup, 0);
40 }
41 void setCheckedNexuizRadioButton(entity me, float val)
42 {
43         if(val != me.checked)
44         {
45                 me.checked = val;
46                 me.saveCvars(me);
47         }
48 }
49 void loadCvarsNexuizRadioButton(entity me)
50 {
51         if(me.cvarValue)
52                 me.checked = (cvar_string(me.cvarName) == me.cvarValue);
53         else
54         {
55                 if(me.cvarName)
56                 {
57                         me.checked = !!cvar(me.cvarName);
58                 }
59                 else
60                 {
61                         // this is difficult
62                         // this is the "generic" selection... but at this time, not
63                         // everything is constructed yet.
64                         // we need to set this later in draw()
65                         me.checked = 0;
66                 }
67         }
68 }
69 void drawNexuizRadioButton(entity me)
70 {
71         if not(me.cvarValue)
72                 if not(me.cvarName)
73                 {
74                         // this is the "other" option
75                         // always select this if none other is
76                         entity e;
77                         float found;
78                         found = 0;
79                         for(e = me.parent.firstChild; e; e = e.nextSibling)
80                                 if(e.group == me.group)
81                                         if(e.checked)
82                                                 found = 1;
83                         if(!found)
84                                 me.setChecked(me, 1);
85                 }
86         drawCheckBox(me);
87 }
88 void saveCvarsNexuizRadioButton(entity me)
89 {
90         if(me.cvarValue)
91         {
92                 if(me.checked)
93                         cvar_set(me.cvarName, me.cvarValue);
94         }
95         else
96         {
97                 if(me.cvarName)
98                 {
99                         cvar_set(me.cvarName, ftos(me.checked));
100                 }
101         }
102 }
103 #endif