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