mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 14:36:13 +01:00
70 lines
No EOL
1.8 KiB
Text
70 lines
No EOL
1.8 KiB
Text
function toggleGroup(_data, _onClick) : widget() constructor {
|
|
data = _data;
|
|
onClick = _onClick;
|
|
buttonSpr = [ THEME.button_left, THEME.button_middle, THEME.button_right ];
|
|
font = f_p0;
|
|
fColor = COLORS._main_text;
|
|
value = 0;
|
|
|
|
for(var i = 0; i < array_length(data); i++)
|
|
buttons[i] = button(-1);
|
|
|
|
static trigger = function() {}
|
|
|
|
static setInteract = function(interactable = noone) {
|
|
self.interactable = interactable;
|
|
for(var i = 0; i < array_length(data); i++)
|
|
buttons[i].interactable = interactable;
|
|
}
|
|
|
|
static register = function(parent = noone) {
|
|
array_push(WIDGET_ACTIVE, self);
|
|
self.parent = parent;
|
|
}
|
|
|
|
static drawParam = function(params) {
|
|
return draw(params.x, params.y, params.w, params.h, params.data, params.m, params.rx, params.ry);
|
|
}
|
|
|
|
static draw = function(_x, _y, _w, _h, _data, _m, _rx = 0, _ry = 0) {
|
|
x = _x;
|
|
y = _y;
|
|
w = _w;
|
|
h = _h;
|
|
value = _data;
|
|
|
|
if(is_array(_data)) return 0;
|
|
|
|
var amo = array_length(data);
|
|
var ww = _w / amo;
|
|
|
|
for(var i = 0; i < amo; i++) {
|
|
buttons[i].setFocusHover(active, hover);
|
|
|
|
var bx = _x + ww * i;
|
|
var spr = i == 0 ? buttonSpr[0] : (i == amo - 1? buttonSpr[2] : buttonSpr[1]);
|
|
var tog = _data & (1 << i);
|
|
|
|
buttons[i].toggled = tog;
|
|
buttons[i].draw(bx, _y, ww, _h, _m, spr);
|
|
if(buttons[i].clicked) {
|
|
value ^= (1 << i);
|
|
onClick(value);
|
|
}
|
|
|
|
if(is_string(data[i])) {
|
|
draw_set_text(font, fa_center, fa_center, fColor);
|
|
draw_text(bx + ww / 2, _y + _h / 2, data[i]);
|
|
} else if(sprite_exists(data[i])) {
|
|
draw_sprite_ui_uniform(data[i], i, bx + ww / 2, _y + _h / 2);
|
|
}
|
|
}
|
|
|
|
if(WIDGET_CURRENT == self)
|
|
draw_sprite_stretched_ext(THEME.widget_selecting, 0, x - ui(3), y - ui(3), w + ui(6), h + ui(6), COLORS._main_accent, 1);
|
|
|
|
resetFocus();
|
|
|
|
return h;
|
|
}
|
|
} |