Pixel-Composer/scripts/buttonGradient/buttonGradient.gml

101 lines
2.9 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function buttonGradient(_onApply, dialog = noone) : widget() constructor {
2024-01-22 10:26:25 +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;
2024-01-22 10:26:25 +01:00
side_button = noone;
2023-01-17 08:11:55 +01:00
function apply(value) { #region
2023-02-28 09:43:01 +01:00
if(!interactable) return;
onApply(value);
} #endregion
2023-02-28 09:43:01 +01:00
static trigger = function() { #region
2023-01-17 08:11:55 +01:00
var dialog = dialogCall(o_dialog_gradient, WIN_W / 2, WIN_H / 2);
2023-07-11 14:18:23 +02:00
dialog.setDefault(current_gradient.clone());
2023-02-28 09:43:01 +01:00
dialog.onApply = apply;
dialog.interactable = interactable;
if(parentDialog)
parentDialog.addChildren(dialog);
} #endregion
2023-01-17 08:11:55 +01:00
static drawParam = function(params) { return draw(params.x, params.y, params.w, params.h, params.data, params.m); }
2023-07-30 19:56:53 +02:00
static draw = function(_x, _y, _w, _h, _gradient, _m) { #region
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
2023-08-24 11:59:05 +02:00
2024-03-28 14:18:02 +01:00
var _bs = min(_h, ui(32));
hovering = hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + _h);
if(_w - _bs > ui(100) && side_button && instanceof(side_button) == "buttonClass") {
2024-01-22 10:26:25 +01:00
side_button.setFocusHover(active, hover);
2024-03-28 14:18:02 +01:00
side_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
_w -= _bs + ui(8);
2024-01-22 10:26:25 +01:00
}
2023-12-29 14:30:54 +01:00
var _gw = _w - ui(8);
var _gh = _h - ui(8);
2023-05-28 20:00:51 +02:00
2023-01-17 08:11:55 +01:00
current_gradient = _gradient;
2023-08-24 11:59:05 +02:00
if(is_array(_gradient)) {
if(array_length(_gradient) == 0) return 0;
h = ui(8) + array_length(_gradient) * _gh;
2023-08-24 11:59:05 +02:00
current_gradient = _gradient[0];
} else {
h = _h;
}
if(!is_instanceof(current_gradient, gradientObject))
return 0;
2022-01-13 05:24:03 +01:00
var click = false;
2023-08-24 11:59:05 +02:00
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + h);
2023-03-26 07:13:36 +02:00
if(ihover && hoverRect) {
2024-03-31 05:36:11 +02:00
draw_sprite_stretched(THEME.button_def, 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)) {
2024-03-31 05:36:11 +02:00
draw_sprite_stretched(THEME.button_def, 2, _x, _y, _w, h);
draw_sprite_stretched_ext(THEME.button_def, 3, _x, _y, _w, h, COLORS._main_accent, 1);
2023-04-08 20:06:27 +02:00
}
2022-01-13 05:24:03 +01:00
} else {
2024-03-31 05:36:11 +02:00
draw_sprite_stretched(THEME.button_def, 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-08-24 11:59:05 +02:00
if(!is_array(_gradient)) _gradient = [ _gradient ];
for( var i = 0, n = array_length(_gradient); i < n; i++ ) {
var _grad = _gradient[i];
2023-12-29 14:30:54 +01:00
var _gx = _x + ui(4);
var _gy = _y + ui(4) + i * _gh;
2023-08-24 11:59:05 +02:00
if(is_instanceof(_grad, gradientObject))
_grad.draw(_gx, _gy, _gw, _gh);
}
2022-01-13 05:24:03 +01:00
2023-01-17 08:11:55 +01:00
if(WIDGET_CURRENT == self)
2023-08-24 11:59:05 +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) {
2023-08-24 11:59:05 +02:00
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, _x, _y, _w, h, COLORS._main_value_positive, 1);
2023-03-26 07:13:36 +02:00
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();
2023-07-30 19:56:53 +02:00
return h;
} #endregion
2024-03-31 11:10:14 +02:00
static clone = function() { #region
var cln = new buttonGradient(onApply, parentDialog);
return cln;
} #endregion
2022-01-13 05:24:03 +01:00
}