]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/radiobutton.qc
Merge branch 'master' into terencehill/slider_anim_improvements
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / radiobutton.qc
1 #ifndef ITEM_RADIOBUTTON_H
2 #define ITEM_RADIOBUTTON_H
3 #include "checkbox.qc"
4 void RadioButton_Click(entity me, entity other);
5 CLASS(RadioButton, CheckBox)
6         METHOD(RadioButton, configureRadioButton, void(entity, string, float, string, float, float));
7         ATTRIB(RadioButton, checked, float, 0)
8         ATTRIB(RadioButton, group, float, 0)
9         ATTRIB(RadioButton, allowDeselect, float, 0)
10         ATTRIB(RadioButton, onClick, void(entity, entity), RadioButton_Click)
11 ENDCLASS(RadioButton)
12 #endif
13
14 #ifdef IMPLEMENTATION
15 void RadioButton_configureRadioButton(entity me, string txt, float sz, string gfx, float theGroup, float doAllowDeselect)
16 {
17         me.configureCheckBox(me, txt, sz, gfx);
18         me.align = 0;
19         me.group = theGroup;
20         me.allowDeselect = doAllowDeselect;
21 }
22 void RadioButton_Click(entity me, entity other)
23 {
24         if(me.checked)
25         {
26                 if(me.allowDeselect)
27                         me.setChecked(me, 0);
28         }
29         else
30         {
31                 entity e;
32                 for(e = me.parent.firstChild; e; e = e.nextSibling)
33                         if(e != me)
34                                 if(e.group == me.group)
35                                         e.setChecked(e, 0);
36                 me.setChecked(me, 1);
37         }
38 }
39 #endif