5 METHOD(Button, configureButton, void(entity, string, float, string));
6 METHOD(Button, draw, void(entity));
7 METHOD(Button, showNotify, void(entity));
8 METHOD(Button, resizeNotify, void(entity, vector, vector, vector, vector));
9 METHOD(Button, keyDown, float(entity, float, float, float));
10 METHOD(Button, mousePress, float(entity, vector));
11 METHOD(Button, mouseDrag, float(entity, vector));
12 METHOD(Button, mouseRelease, float(entity, vector));
13 METHOD(Button, playClickSound, void(entity));
14 ATTRIB(Button, onClick, void(entity, entity), func_null)
15 ATTRIB(Button, onClickEntity, entity, NULL)
16 ATTRIB(Button, src, string, string_null)
17 ATTRIB(Button, srcSuffix, string, string_null)
18 ATTRIB(Button, src2, string, string_null) // is centered, same aspect, and stretched to label size
19 ATTRIB(Button, src2scale, float, 1)
20 ATTRIB(Button, srcMulti, float, 1) // 0: button square left, text right; 1: button stretched, text over it
21 ATTRIB(Button, buttonLeftOfText, float, 0)
22 ATTRIB(Button, focusable, float, 1)
23 ATTRIB(Button, allowFocusSound, float, 1)
24 ATTRIB(Button, pressed, float, 0)
25 ATTRIB(Button, clickTime, float, 0)
26 ATTRIB(Button, disabled, float, 0)
27 ATTRIB(Button, disabledAlpha, float, 0.3)
28 ATTRIB(Button, forcePressed, float, 0)
29 ATTRIB(Button, color, vector, '1 1 1')
30 ATTRIB(Button, colorC, vector, '1 1 1')
31 ATTRIB(Button, colorF, vector, '1 1 1')
32 ATTRIB(Button, colorD, vector, '1 1 1')
33 ATTRIB(Button, color2, vector, '1 1 1')
34 ATTRIB(Button, alpha2, float, 1)
36 ATTRIB(Button, origin, vector, '0 0 0')
37 ATTRIB(Button, size, vector, '0 0 0')
42 void Button_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
47 me.keepspaceLeft = min(0.8, absSize.y / absSize.x);
48 SUPER(Button).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
50 void Button_configureButton(entity me, string txt, float sz, string gfx)
52 SUPER(Button).configureLabel(me, txt, sz, me.srcMulti ? 0.5 : 0);
55 float Button_keyDown(entity me, float key, float ascii, float shift)
57 if(key == K_ENTER || key == K_SPACE || key == K_KP_ENTER)
59 me.playClickSound(me);
60 me.clickTime = 0.1; // delayed for effect
65 float Button_mouseDrag(entity me, vector pos)
68 if(pos.x < 0) me.pressed = 0;
69 if(pos.y < 0) me.pressed = 0;
70 if(pos.x >= 1) me.pressed = 0;
71 if(pos.y >= 1) me.pressed = 0;
74 float Button_mousePress(entity me, vector pos)
76 me.mouseDrag(me, pos); // verify coordinates
79 float Button_mouseRelease(entity me, vector pos)
81 me.mouseDrag(me, pos); // verify coordinates
86 me.playClickSound(me);
88 me.onClick(me, me.onClickEntity);
94 void Button_showNotify(entity me)
96 me.focusable = !me.disabled;
98 void Button_draw(entity me)
100 vector bOrigin, bSize;
103 me.focusable = !me.disabled;
107 draw_alpha *= me.disabledAlpha;
116 draw_ButtonPicture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
117 else if(me.forcePressed || me.pressed || me.clickTime > 0)
118 draw_ButtonPicture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
120 draw_ButtonPicture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
122 draw_ButtonPicture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
126 if(me.realFontSize_y == 0)
133 bOrigin = eY * (0.5 * (1 - me.realFontSize.y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize.x));
134 bSize = me.realFontSize;
137 draw_Picture(bOrigin, strcat(me.src, "_d", me.srcSuffix), bSize, me.colorD, 1);
138 else if(me.forcePressed || me.pressed || me.clickTime > 0)
139 draw_Picture(bOrigin, strcat(me.src, "_c", me.srcSuffix), bSize, me.colorC, 1);
141 draw_Picture(bOrigin, strcat(me.src, "_f", me.srcSuffix), bSize, me.colorF, 1);
143 draw_Picture(bOrigin, strcat(me.src, "_n", me.srcSuffix), bSize, me.color, 1);
148 bOrigin = me.keepspaceLeft * eX;
149 bSize = eY + eX * (1 - me.keepspaceLeft);
151 bOrigin += bSize * (0.5 - 0.5 * me.src2scale);
152 bSize = bSize * me.src2scale;
154 draw_Picture(bOrigin, me.src2, bSize, me.color2, me.alpha2);
159 if(me.clickTime > 0 && me.clickTime <= frametime)
161 // keyboard click timer expired? Fire the event then.
164 me.onClick(me, me.onClickEntity);
166 me.clickTime -= frametime;
168 SUPER(Button).draw(me);
170 void Dialog_Close(entity button, entity me);
171 void Button_playClickSound(entity me)
173 if(me.onClick == DialogOpenButton_Click)
174 m_play_click_sound(MENU_SOUND_OPEN);
175 else if(me.onClick == Dialog_Close)
176 m_play_click_sound(MENU_SOUND_CLOSE);
178 m_play_click_sound(MENU_SOUND_EXECUTE);