]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/item/checkbox.c
added checkbox, radio button; removed unnecessary setFocus override in Nexposee and...
[divverent/nexuiz.git] / data / qcsrc / menu-div0test / item / checkbox.c
1 #ifdef INTERFACE
2 void CheckBox_Click(entity me, entity other);
3 CLASS(CheckBox) EXTENDS(Button)
4         METHOD(CheckBox, configureCheckBox, void(entity, string, float, string))
5         METHOD(CheckBox, resizeNotify, void(entity, vector, vector, vector, vector))
6         METHOD(CheckBox, draw, void(entity))
7         ATTRIB(CheckBox, checked, float, 0)
8         ATTRIB(CheckBox, onClick, void(entity, entity), CheckBox_Click)
9         ATTRIB(CheckBox, srcMulti, float, 0)
10 ENDCLASS(CheckBox)
11 #endif
12
13 #ifdef IMPLEMENTATION
14 void CheckBox_Click(entity me, entity other)
15 {
16         me.checked = !me.checked;
17 }
18 void configureCheckBoxCheckBox(entity me, string txt, float sz, string gfx)
19 {
20         me.configureButton(me, txt, sz, gfx);
21         me.align = 0;
22 }
23 void resizeNotifyCheckBox(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
24 {
25         me.keepspaceLeft = min(0.8, absSize_y / absSize_x);
26         resizeNotifyButton(me, relOrigin, relSize, absOrigin, absSize);
27 }
28 void drawCheckBox(entity me)
29 {
30         vector cbOrigin;
31         vector cbSize;
32
33         cbOrigin = eY * (0.5 * (1 - me.realFontSize_y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize_x));
34         cbSize = me.realFontSize;
35         if(me.checked)
36         {
37                 if(me.forcePressed || me.pressed || me.clickTime > 0)
38                         draw_Picture(cbOrigin, strcat(me.src, "_c1"), cbSize, '1 1 1', 1);
39                 else if(me.focused)
40                         draw_Picture(cbOrigin, strcat(me.src, "_f1"), cbSize, '1 1 1', 1);
41                 else
42                         draw_Picture(cbOrigin, strcat(me.src, "_n1"), cbSize, '1 1 1', 1);
43         }
44         else
45         {
46                 if(me.forcePressed || me.pressed || me.clickTime > 0)
47                         draw_Picture(cbOrigin, strcat(me.src, "_c0"), cbSize, '1 1 1', 1);
48                 else if(me.focused)
49                         draw_Picture(cbOrigin, strcat(me.src, "_f0"), cbSize, '1 1 1', 1);
50                 else
51                         draw_Picture(cbOrigin, strcat(me.src, "_n0"), cbSize, '1 1 1', 1);
52         }
53         me.clickTime -= frametime;
54         drawLabel(me); // skip drawButton!
55 }
56 #endif