Pixel-Composer/scripts/buttonGradient/buttonGradient.gml

62 lines
1.7 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function buttonGradient(_onApply, dialog = noone) : widget() constructor {
2022-01-13 05:24:03 +01:00
onApply = _onApply;
2023-02-28 09:43:01 +01:00
parentDialog = dialog;
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
current_gradient = noone;
2023-02-28 09:43:01 +01:00
function apply(value) {
if(!interactable) return;
onApply(value);
}
2023-01-17 08:11:55 +01:00
static trigger = function() {
var dialog = dialogCall(o_dialog_gradient, WIN_W / 2, WIN_H / 2);
2023-03-02 07:59:14 +01:00
dialog.setDefault(current_gradient);
2023-02-28 09:43:01 +01:00
dialog.onApply = apply;
dialog.interactable = interactable;
if(parentDialog)
parentDialog.addChildren(dialog);
2023-01-17 08:11:55 +01:00
}
2023-03-02 07:59:14 +01:00
static draw = function(_x, _y, _w, _h, _gradient, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
2023-05-28 20:00:51 +02:00
if(!is_instanceof(_gradient, gradientObject)) return;
2023-01-17 08:11:55 +01:00
current_gradient = _gradient;
2022-01-13 05:24:03 +01:00
var click = false;
2023-03-26 07:13:36 +02:00
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h);
if(ihover && hoverRect) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.button, 1, _x, _y, _w, _h);
2023-02-14 05:32:32 +01:00
if(mouse_press(mb_left, iactive)) {
2023-01-17 08:11:55 +01:00
trigger();
2022-01-13 05:24:03 +01:00
click = true;
}
2023-04-08 20:06:27 +02:00
if(mouse_click(mb_left, iactive)) {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.button, 2, _x, _y, _w, _h);
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.button, 3, _x, _y, _w, _h, COLORS._main_accent, 1);
}
2022-01-13 05:24:03 +01:00
} else {
2022-11-18 03:20:31 +01:00
draw_sprite_stretched(THEME.button, 0, _x, _y, _w, _h);
2023-01-17 08:11:55 +01:00
if(mouse_press(mb_left)) deactivate();
2022-01-13 05:24:03 +01:00
}
2023-03-02 07:59:14 +01:00
_gradient.draw(_x + ui(6), _y + ui(6), _w - ui(12), _h - ui(12));
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
if(WIDGET_CURRENT == self)
2023-04-08 20:06:27 +02:00
draw_sprite_stretched_ext(THEME.widget_selecting, 0, _x - ui(3), _y - ui(3), _w + ui(6), _h + ui(6), COLORS._main_accent, 1);
2023-01-17 08:11:55 +01:00
2023-03-26 07:13:36 +02:00
if(DRAGGING && DRAGGING.type == "Gradient" && hover && hoverRect) {
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, _x, _y, _w, _h, COLORS._main_value_positive, 1);
if(mouse_release(mb_left))
onApply(DRAGGING.data);
}
2022-01-13 05:24:03 +01:00
2023-03-26 07:13:36 +02:00
resetFocus();
2022-01-13 05:24:03 +01:00
return click;
}
}