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