]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu-div0test/item/checkbox.c
fix minor visual glitch
[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         METHOD(CheckBox, toString, string(entity))
8         METHOD(CheckBox, setChecked, void(entity, float))
9         ATTRIB(CheckBox, checked, float, 0)
10         ATTRIB(CheckBox, onClick, void(entity, entity), CheckBox_Click)
11         ATTRIB(CheckBox, srcMulti, float, 0)
12 ENDCLASS(CheckBox)
13 #endif
14
15 #ifdef IMPLEMENTATION
16 void setCheckedCheckBox(entity me, float val)
17 {
18         me.checked = val;
19 }
20 void CheckBox_Click(entity me, entity other)
21 {
22         me.setChecked(me, !me.checked);
23 }
24 string toStringCheckBox(entity me)
25 {
26         return strcat(toStringLabel(me), ", ", me.checked ? "checked" : "unchecked");
27 }
28 void configureCheckBoxCheckBox(entity me, string txt, float sz, string gfx)
29 {
30         me.configureButton(me, txt, sz, gfx);
31         me.align = 0;
32 }
33 void resizeNotifyCheckBox(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
34 {
35         me.keepspaceLeft = min(0.8, absSize_y / absSize_x);
36         resizeNotifyButton(me, relOrigin, relSize, absOrigin, absSize);
37 }
38 void drawCheckBox(entity me)
39 {
40         vector cbOrigin;
41         vector cbSize;
42
43         cbOrigin = eY * (0.5 * (1 - me.realFontSize_y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize_x));
44         cbSize = me.realFontSize;
45         if(me.checked)
46         {
47                 if(me.forcePressed || me.pressed || me.clickTime > 0)
48                         draw_Picture(cbOrigin, strcat(me.src, "_c1"), cbSize, '1 1 1', 1);
49                 else if(me.focused)
50                         draw_Picture(cbOrigin, strcat(me.src, "_f1"), cbSize, '1 1 1', 1);
51                 else
52                         draw_Picture(cbOrigin, strcat(me.src, "_n1"), cbSize, '1 1 1', 1);
53         }
54         else
55         {
56                 if(me.forcePressed || me.pressed || me.clickTime > 0)
57                         draw_Picture(cbOrigin, strcat(me.src, "_c0"), cbSize, '1 1 1', 1);
58                 else if(me.focused)
59                         draw_Picture(cbOrigin, strcat(me.src, "_f0"), cbSize, '1 1 1', 1);
60                 else
61                         draw_Picture(cbOrigin, strcat(me.src, "_n0"), cbSize, '1 1 1', 1);
62         }
63         drawLabel(me); // skip drawButton!
64
65         if(me.clickTime > 0 && me.clickTime < frametime)
66         {
67                 // keyboard click timer expired? Fire the event then.
68                 me.onClick(me, me.onClickEntity);
69         }
70         me.clickTime -= frametime;
71 }
72 #endif