]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/radiobutton.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / radiobutton.qc
1 #include "radiobutton.qh"
2 #ifndef ITEM_RADIOBUTTON_H
3         #define ITEM_RADIOBUTTON_H
4         #include "checkbox.qc"
5         void RadioButton_Click(entity me, entity other);
6         CLASS(RadioButton, CheckBox)
7                 METHOD(RadioButton, configureRadioButton, void(entity, string, float, string, float, float));
8                 ATTRIB(RadioButton, checked, float, 0)
9                 ATTRIB(RadioButton, group, float, 0)
10                 ATTRIB(RadioButton, allowDeselect, float, 0)
11                 ATTRIB(RadioButton, onClick, void(entity, entity), RadioButton_Click)
12         ENDCLASS(RadioButton)
13 #endif
14
15 #ifdef IMPLEMENTATION
16         void RadioButton_configureRadioButton(entity me, string txt, float sz, string gfx, float theGroup, float doAllowDeselect)
17         {
18                 me.configureCheckBox(me, txt, sz, gfx);
19                 me.align = 0;
20                 me.group = theGroup;
21                 me.allowDeselect = doAllowDeselect;
22         }
23         void RadioButton_Click(entity me, entity other)
24         {
25                 if (me.checked)
26                 {
27                         if (me.allowDeselect) 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) e.setChecked(e, 0);
35                         me.setChecked(me, 1);
36                 }
37         }
38 #endif