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