2 CLASS(Button) EXTENDS(Label)
3 METHOD(Button, configureButton, void(entity, string, float, string))
4 METHOD(Button, draw, void(entity))
5 METHOD(Button, showNotify, void(entity))
6 METHOD(Button, resizeNotify, void(entity, vector, vector, vector, vector))
7 METHOD(Button, keyDown, float(entity, float, float, float))
8 METHOD(Button, mousePress, float(entity, vector))
9 METHOD(Button, mouseDrag, float(entity, vector))
10 METHOD(Button, mouseRelease, float(entity, vector))
11 ATTRIB(Button, onClick, void(entity, entity), SUB_Null)
12 ATTRIB(Button, onClickEntity, entity, NULL)
13 ATTRIB(Button, src, string, "")
14 ATTRIB(Button, srcMulti, float, 1)
15 ATTRIB(Button, focusable, float, 1)
16 ATTRIB(Button, pressed, float, 0)
17 ATTRIB(Button, clickTime, float, 0)
18 ATTRIB(Button, disabled, float, 0)
19 ATTRIB(Button, forcePressed, float, 0)
20 ATTRIB(Button, color, vector, '1 1 1')
22 ATTRIB(Button, origin, vector, '0 0 0')
23 ATTRIB(Button, size, vector, '0 0 0')
28 void resizeNotifyButton(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
30 resizeNotifyLabel(me, relOrigin, relSize, absOrigin, absSize);
31 me.origin = absOrigin;
34 void configureButtonButton(entity me, string txt, float sz, string gfx)
36 configureLabelLabel(me, txt, sz, 0.5);
39 float keyDownButton(entity me, float key, float ascii, float shift)
41 if(key == K_ENTER || key == K_SPACE)
43 me.clickTime = 0.1; // delayed for effect
48 float mouseDragButton(entity me, vector pos)
51 if(pos_x < 0) me.pressed = 0;
52 if(pos_y < 0) me.pressed = 0;
53 if(pos_x >= 1) me.pressed = 0;
54 if(pos_y >= 1) me.pressed = 0;
57 float mousePressButton(entity me, vector pos)
59 me.mouseDrag(me, pos); // verify coordinates
62 float mouseReleaseButton(entity me, vector pos)
64 me.mouseDrag(me, pos); // verify coordinates
68 me.onClick(me, me.onClickEntity);
73 void showNotifyButton(entity me)
75 me.focusable = !me.disabled;
77 void drawButton(entity me)
79 me.focusable = !me.disabled;
86 draw_ButtonPicture('0 0 0', strcat(me.src, "_d"), '1 1 0', '1 1 1', 1);
87 else if(me.forcePressed || me.pressed || me.clickTime > 0)
88 draw_ButtonPicture('0 0 0', strcat(me.src, "_c"), '1 1 0', me.color, 1);
90 draw_ButtonPicture('0 0 0', strcat(me.src, "_f"), '1 1 0', me.color, 1);
92 draw_ButtonPicture('0 0 0', strcat(me.src, "_n"), '1 1 0', me.color, 1);
97 draw_Picture('0 0 0', strcat(me.src, "_d"), '1 1 0', '1 1 1', 1);
98 else if(me.forcePressed || me.pressed || me.clickTime > 0)
99 draw_Picture('0 0 0', strcat(me.src, "_c"), '1 1 0', me.color, 1);
101 draw_Picture('0 0 0', strcat(me.src, "_f"), '1 1 0', me.color, 1);
103 draw_Picture('0 0 0', strcat(me.src, "_n"), '1 1 0', me.color, 1);
107 if(me.clickTime > 0 && me.clickTime < frametime)
109 // keyboard click timer expired? Fire the event then.
111 me.onClick(me, me.onClickEntity);
113 me.clickTime -= frametime;