]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/radiobutton.qc
dac17b1415643f8c522cd100a668ad719f78c5aa
[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) me.setChecked(me, 0);
27                 }
28                 else
29                 {
30                         entity e;
31                         for (e = me.parent.firstChild; e; e = e.nextSibling)
32                                 if (e != me)
33                                         if (e.group == me.group) e.setChecked(e, 0);
34                         me.setChecked(me, 1);
35                 }
36         }
37 #endif