]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/item/checkbox.qc
17bc50103e262850a8707a281fa9615f0af060c9
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / item / checkbox.qc
1 #ifndef ITEM_CHECKBOX_H
2         #define ITEM_CHECKBOX_H
3         #include "button.qc"
4         void CheckBox_Click(entity me, entity other);
5         CLASS(CheckBox, Button)
6                 METHOD(CheckBox, configureCheckBox, void(entity, string, float, string));
7                 METHOD(CheckBox, draw, void(entity));
8                 METHOD(CheckBox, playClickSound, void(entity));
9                 METHOD(CheckBox, toString, string(entity));
10                 METHOD(CheckBox, setChecked, void(entity, float));
11                 ATTRIB(CheckBox, useDownAsChecked, float, 0)
12                 ATTRIB(CheckBox, checked, float, 0)
13                 ATTRIB(CheckBox, onClick, void(entity, entity), CheckBox_Click)
14                 ATTRIB(CheckBox, srcMulti, float, 0)
15                 ATTRIB(CheckBox, disabled, float, 0)
16         ENDCLASS(CheckBox)
17 #endif
18
19 #ifdef IMPLEMENTATION
20         void CheckBox_setChecked(entity me, float val)
21         {
22                 me.checked = val;
23         }
24         void CheckBox_Click(entity me, entity other)
25         {
26                 me.setChecked(me, !me.checked);
27         }
28         string CheckBox_toString(entity me)
29         {
30                 return strcat(SUPER(CheckBox).toString(me), ", ", me.checked ? "checked" : "unchecked");
31         }
32         void CheckBox_configureCheckBox(entity me, string txt, float sz, string gfx)
33         {
34                 me.configureButton(me, txt, sz, gfx);
35                 me.align = 0;
36         }
37         void CheckBox_draw(entity me)
38         {
39                 float s;
40                 s = me.pressed;
41                 if (me.useDownAsChecked)
42                 {
43                         me.srcSuffix = string_null;
44                         me.forcePressed = me.checked;
45                 }
46                 else
47                 {
48                         me.srcSuffix = (me.checked ? "1" : "0");
49                 }
50                 me.pressed = s;
51                 SUPER(CheckBox).draw(me);
52         }
53         void CheckBox_playClickSound(entity me)
54         {
55                 m_play_click_sound(MENU_SOUND_SELECT);
56         }
57 #endif