Pixel-Composer/scripts/buttonGradient/buttonGradient.gml
2023-03-02 13:59:14 +07:00

52 lines
1.3 KiB
Plaintext

function buttonGradient(_onApply, dialog = noone) : widget() constructor {
onApply = _onApply;
parentDialog = dialog;
current_gradient = noone;
function apply(value) {
if(!interactable) return;
onApply(value);
}
static trigger = function() {
var dialog = dialogCall(o_dialog_gradient, WIN_W / 2, WIN_H / 2);
dialog.setDefault(current_gradient);
dialog.onApply = apply;
dialog.interactable = interactable;
if(parentDialog)
parentDialog.addChildren(dialog);
}
static draw = function(_x, _y, _w, _h, _gradient, _m) {
x = _x;
y = _y;
w = _w;
h = _h;
current_gradient = _gradient;
var click = false;
if(ihover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h)) {
draw_sprite_stretched(THEME.button, 1, _x, _y, _w, _h);
if(mouse_press(mb_left, iactive)) {
trigger();
click = true;
}
if(mouse_click(mb_left, iactive))
draw_sprite_stretched(THEME.button, 2, _x, _y, _w, _h);
} else {
draw_sprite_stretched(THEME.button, 0, _x, _y, _w, _h);
if(mouse_press(mb_left)) deactivate();
}
_gradient.draw(_x + ui(6), _y + ui(6), _w - ui(12), _h - ui(12));
if(WIDGET_CURRENT == self)
draw_sprite_stretched(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6));
resetFocus();
return click;
}
}