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, srcMulti, float, 1)
14 ATTRIB(Button, focusable, float, 1)
15 ATTRIB(Button, pressed, float, 0)
16 ATTRIB(Button, clickTime, float, 0)
17 ATTRIB(Button, forcePressed, float, 0)
19 ATTRIB(Button, origin, vector, '0 0 0')
20 ATTRIB(Button, size, vector, '0 0 0')
25 void resizeNotifyButton(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
27 resizeNotifyLabel(me, relOrigin, relSize, absOrigin, absSize);
28 me.origin = absOrigin;
31 void configureButtonButton(entity me, string txt, float sz, string gfx)
33 configureLabelLabel(me, txt, sz, 0.5);
36 float keyDownButton(entity me, float key, float ascii, float shift)
38 if(key == K_ENTER || key == K_SPACE)
40 me.onClick(me, me.onClickEntity);
46 float mouseDragButton(entity me, vector pos)
49 if(pos_x < 0) me.pressed = 0;
50 if(pos_y < 0) me.pressed = 0;
51 if(pos_x >= 1) me.pressed = 0;
52 if(pos_y >= 1) me.pressed = 0;
55 float mousePressButton(entity me, vector pos)
57 me.mouseDrag(me, pos); // verify coordinates
60 float mouseReleaseButton(entity me, vector pos)
62 me.mouseDrag(me, pos); // verify coordinates
65 me.onClick(me, me.onClickEntity);
70 void drawButton(entity me)
75 division = min(0.5, 0.5 * me.size_y / me.size_x);
76 if(me.forcePressed || me.pressed || me.clickTime > 0)
78 draw_Picture('0 0 0', strcat(me.src, "_cl"), eX * division + eY, '1 1 1', 1);
80 draw_Picture('0 0 0' + eX * division, strcat(me.src, "_cm"), eX * (1 - 2 * division) + eY, '1 1 1', 1);
81 draw_Picture(eX * (1 - division), strcat(me.src, "_cr"), eX * division + eY, '1 1 1', 1);
85 draw_Picture('0 0 0', strcat(me.src, "_fl"), eX * division + eY, '1 1 1', 1);
87 draw_Picture('0 0 0' + eX * division, strcat(me.src, "_fm"), eX * (1 - 2 * division) + eY, '1 1 1', 1);
88 draw_Picture(eX * (1 - division), strcat(me.src, "_fr"), eX * division + eY, '1 1 1', 1);
92 draw_Picture('0 0 0', strcat(me.src, "_nl"), eX * division + eY, '1 1 1', 1);
94 draw_Picture('0 0 0' + eX * division, strcat(me.src, "_nm"), eX * (1 - 2 * division) + eY, '1 1 1', 1);
95 draw_Picture(eX * (1 - division), strcat(me.src, "_nr"), eX * division + eY, '1 1 1', 1);
100 if(me.forcePressed || me.pressed || me.clickTime > 0)
101 draw_Picture('0 0 0', strcat(me.src, "_c"), '1 1 0', '1 1 1', 1);
103 draw_Picture('0 0 0', strcat(me.src, "_f"), '1 1 0', '1 1 1', 1);
105 draw_Picture('0 0 0', strcat(me.src, "_n"), '1 1 0', '1 1 1', 1);
107 me.clickTime -= frametime;