2 CLASS(Button) EXTENDS(Label)
3 METHOD(Button, configureButton, void(entity, string, float, string))
4 METHOD(Button, draw, void(entity))
5 METHOD(Button, resizeNotify, void(entity, vector, vector, vector, vector))
6 METHOD(Button, keyDown, float(entity, float, float, float))
7 METHOD(Button, mousePress, float(entity, vector))
8 METHOD(Button, mouseDrag, float(entity, vector))
9 METHOD(Button, mouseRelease, float(entity, vector))
10 ATTRIB(Button, onClick, void(entity, entity), SUB_Null)
11 ATTRIB(Button, onClickEntity, entity, NULL)
12 ATTRIB(Button, src, string, "")
13 ATTRIB(Button, focusable, float, 1)
14 ATTRIB(Button, pressed, float, 0)
15 ATTRIB(Button, clickTime, float, 0)
16 ATTRIB(Button, forcePressed, float, 0)
18 ATTRIB(Button, origin, vector, '0 0 0')
19 ATTRIB(Button, size, vector, '0 0 0')
24 void resizeNotifyButton(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
26 resizeNotifyLabel(me, relOrigin, relSize, absOrigin, absSize);
27 me.origin = absOrigin;
30 void configureButtonButton(entity me, string txt, float sz, string gfx)
32 configureLabelLabel(me, txt, sz, 0.5);
35 float keyDownButton(entity me, float key, float ascii, float shift)
37 if(key == K_ENTER || key == K_SPACE)
39 me.onClick(me, me.onClickEntity);
45 float mouseDragButton(entity me, vector pos)
48 if(pos_x < 0) me.pressed = 0;
49 if(pos_y < 0) me.pressed = 0;
50 if(pos_x >= 1) me.pressed = 0;
51 if(pos_y >= 1) me.pressed = 0;
54 float mousePressButton(entity me, vector pos)
56 me.mouseDrag(me, pos); // verify coordinates
59 float mouseReleaseButton(entity me, vector pos)
61 me.mouseDrag(me, pos); // verify coordinates
64 me.onClick(me, me.onClickEntity);
69 void drawButton(entity me)
72 division = min(0.5, 0.5 * me.size_y / me.size_x);
73 if(me.forcePressed || me.pressed || me.clickTime > 0)
75 draw_Picture('0 0 0', strcat(me.src, "_cl"), eX * division + eY, '1 1 1', 1);
77 draw_Picture('0 0 0' + eX * division, strcat(me.src, "_cm"), eX * (1 - 2 * division) + eY, '1 1 1', 1);
78 draw_Picture(eX * (1 - division), strcat(me.src, "_cr"), eX * division + eY, '1 1 1', 1);
82 draw_Picture('0 0 0', strcat(me.src, "_fl"), eX * division + eY, '1 1 1', 1);
84 draw_Picture('0 0 0' + eX * division, strcat(me.src, "_fm"), eX * (1 - 2 * division) + eY, '1 1 1', 1);
85 draw_Picture(eX * (1 - division), strcat(me.src, "_fr"), eX * division + eY, '1 1 1', 1);
89 draw_Picture('0 0 0', strcat(me.src, "_nl"), eX * division + eY, '1 1 1', 1);
91 draw_Picture('0 0 0' + eX * division, strcat(me.src, "_nm"), eX * (1 - 2 * division) + eY, '1 1 1', 1);
92 draw_Picture(eX * (1 - division), strcat(me.src, "_nr"), eX * division + eY, '1 1 1', 1);
94 me.clickTime -= frametime;