Pixel-Composer/scripts/buttonGroup/buttonGroup.gml

43 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-01-13 05:24:03 +01:00
function buttonGroup(_data, _onClick) {
return new buttonGroupClass(_data, _onClick);
}
function buttonGroupClass(_data, _onClick) constructor {
data = _data;
onClick = _onClick;
hover = false;
active = false;
for(var i = 0; i < array_length(data); i++) {
buttons[i] = button(-1);
}
2022-01-24 02:21:25 +01:00
static draw = function(_x, _y, _w, _h, _seleting, _m) {
2022-01-13 05:24:03 +01:00
var amo = array_length(data);
var ww = _w / amo;
for(var i = 0; i < amo; i++) {
buttons[i].hover = hover;
buttons[i].active = active;
var bx = _x + ww * i;
2022-11-18 03:20:31 +01:00
var spr = i == 0 ? THEME.button_left : (i == amo - 1? THEME.button_right : THEME.button_middle);
2022-01-13 05:24:03 +01:00
if(_seleting == i) {
draw_sprite_stretched(spr, 2, bx, _y, ww, _h);
} else if(buttons[i].draw(bx, _y, ww, _h, _m, spr)) {
onClick(i);
}
if(is_string(data[i])) {
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_center, fa_center, COLORS._main_text);
2022-01-13 05:24:03 +01:00
draw_text(bx + ww / 2, _y + _h / 2, data[i]);
} else if(sprite_exists(data[i])) {
2022-11-03 11:44:49 +01:00
draw_sprite_ui_uniform(data[i], i, bx + ww / 2, _y + _h / 2);
2022-01-13 05:24:03 +01:00
}
}
hover = false;
active = false;
}
}