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