2022-01-13 05:24:03 +01:00
|
|
|
/// @description init
|
|
|
|
if !ready exit;
|
|
|
|
|
|
|
|
#region dropper
|
2023-03-02 07:59:14 +01:00
|
|
|
selector.interactable = interactable;
|
2022-11-18 03:20:31 +01:00
|
|
|
if(selector.dropper_active) {
|
|
|
|
selector.drawDropper(self);
|
2022-01-13 05:24:03 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region base UI
|
|
|
|
var presets_x = dialog_x;
|
2022-11-03 11:44:49 +01:00
|
|
|
var presets_w = ui(240);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var content_x = dialog_x + presets_w + ui(16);
|
2023-01-17 08:11:55 +01:00
|
|
|
var content_w = ui(556);
|
|
|
|
|
|
|
|
var palette_x = content_x + content_w + ui(16);
|
2023-07-21 12:40:20 +02:00
|
|
|
var palette_w = ui(240);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-11-13 15:42:14 +01:00
|
|
|
var p = DIALOG_PAD;
|
|
|
|
var p2 = DIALOG_PAD * 2;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-06 06:28:00 +02:00
|
|
|
draw_sprite_stretched(THEME.dialog, 0, presets_x - p, dialog_y - p, presets_w + p2, dialog_h + p2);
|
|
|
|
if(sFOCUS) draw_sprite_stretched_ext(THEME.dialog, 1, presets_x - p, dialog_y - p, presets_w + p2, dialog_h + p2, COLORS._main_accent, 1);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-06 06:28:00 +02:00
|
|
|
draw_sprite_stretched(THEME.dialog, 0, content_x - p, dialog_y - p, content_w + p2, dialog_h + p2);
|
|
|
|
if(sFOCUS) draw_sprite_stretched_ext(THEME.dialog, 1, content_x - p, dialog_y - p, content_w + p2, dialog_h + p2, COLORS._main_accent, 1);
|
2023-11-13 15:42:14 +01:00
|
|
|
|
2024-08-06 06:28:00 +02:00
|
|
|
draw_sprite_stretched(THEME.dialog, 0, palette_x - p, dialog_y - p, presets_w + p2, dialog_h + p2);
|
|
|
|
if(sFOCUS) draw_sprite_stretched_ext(THEME.dialog, 1, palette_x - p, dialog_y - p, presets_w + p2, dialog_h + p2, COLORS._main_accent, 1);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-06-10 13:59:45 +02:00
|
|
|
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
|
2023-06-05 18:27:53 +02:00
|
|
|
draw_text(presets_x + ui(24), dialog_y + ui(16), __txt("Presets"));
|
2023-03-02 07:59:14 +01:00
|
|
|
draw_text(content_x + (!interactable * ui(32)) + ui(24), dialog_y + ui(16), name);
|
|
|
|
if(!interactable)
|
|
|
|
draw_sprite_ui(THEME.lock, 0, content_x + ui(24 + 12), dialog_y + ui(16 + 12),,,, COLORS._main_icon);
|
2023-06-05 18:27:53 +02:00
|
|
|
draw_text(palette_x + ui(24), dialog_y + ui(16), __txt("Palettes"));
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region presets
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 1, presets_x + pal_padding, dialog_y + ui(48), ui(240) - pal_padding * 2, dialog_h - ui(48) - pal_padding);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-21 20:36:53 +02:00
|
|
|
sp_presets.setFocusHover(sFOCUS, sHOVER);
|
2024-07-30 13:02:53 +02:00
|
|
|
sp_presets.draw(presets_x + pal_padding + ui(4), dialog_y + ui(48) + ui(4));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var bx = presets_x + presets_w - ui(44);
|
|
|
|
var by = dialog_y + ui(12);
|
2023-12-29 14:30:54 +01:00
|
|
|
var bs = ui(28);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-12-29 14:30:54 +01:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, mouse_ui, sFOCUS, sHOVER, __txtx("add_preset", "Add to preset"), THEME.add_20) == 2) {
|
2022-11-03 11:44:49 +01:00
|
|
|
var dia = dialogCall(o_dialog_file_name, mouse_mx + ui(8), mouse_my + ui(8));
|
2022-01-13 05:24:03 +01:00
|
|
|
dia.onModify = function (txt) {
|
2022-11-18 03:20:31 +01:00
|
|
|
var gradStr = "";
|
2023-12-29 14:30:54 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
for(var i = 0; i < array_length(gradient.keys); i++) {
|
|
|
|
var gr = gradient.keys[i];
|
2023-12-29 14:30:54 +01:00
|
|
|
gradStr += $"{gr.value},{gr.time}\n";
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-11-18 03:20:31 +01:00
|
|
|
|
2023-12-29 14:30:54 +01:00
|
|
|
file_text_write_all(txt + ".txt", gradStr);
|
2023-10-30 04:18:18 +01:00
|
|
|
__initGradient();
|
2022-01-13 05:24:03 +01:00
|
|
|
};
|
|
|
|
dia.path = DIRECTORY + "Gradients/"
|
|
|
|
}
|
2022-11-03 11:44:49 +01:00
|
|
|
bx -= ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-12-29 14:30:54 +01:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, mouse_ui, sFOCUS, sHOVER, __txt("Refresh"), THEME.refresh_20) == 2)
|
2023-10-30 04:18:18 +01:00
|
|
|
__initGradient();
|
2022-11-03 11:44:49 +01:00
|
|
|
bx -= ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-12-29 14:30:54 +01:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, bs, bs, mouse_ui, sFOCUS, sHOVER, __txtx("graident_editor_open_folder", "Open gradient folder"), THEME.path_open_20) == 2) {
|
2023-05-30 11:09:15 +02:00
|
|
|
var _realpath = DIRECTORY + "Gradients";
|
|
|
|
shellOpenExplorer(_realpath)
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-12-29 14:30:54 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.path_open_20, 1, bx + bs / 2, by + bs / 2, 1, c_white);
|
2022-11-03 11:44:49 +01:00
|
|
|
bx -= ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
#region palette
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 1, palette_x + pal_padding, dialog_y + ui(48), ui(240) - pal_padding * 2, dialog_h - ui(48) - pal_padding);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-06-21 20:36:53 +02:00
|
|
|
sp_palettes.setFocusHover(sFOCUS, sHOVER);
|
2024-07-30 13:02:53 +02:00
|
|
|
sp_palettes.draw(palette_x + pal_padding + ui(4), dialog_y + ui(48) + ui(4));
|
2023-07-21 12:40:20 +02:00
|
|
|
|
|
|
|
var bx = palette_x + palette_w - ui(44);
|
|
|
|
var by = dialog_y + ui(12);
|
|
|
|
|
2023-07-23 20:21:35 +02:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, sFOCUS, sHOVER, __txt("Show on Selector"), THEME.display_palette, NODE_COLOR_SHOW_PALETTE, c_white) == 2)
|
|
|
|
NODE_COLOR_SHOW_PALETTE = !NODE_COLOR_SHOW_PALETTE;
|
2023-07-21 12:40:20 +02:00
|
|
|
bx -= ui(32);
|
2023-01-17 08:11:55 +01:00
|
|
|
#endregion
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
#region gradient
|
|
|
|
|
|
|
|
#region tools
|
2022-11-03 11:44:49 +01:00
|
|
|
var bx = content_x + content_w - ui(50);
|
|
|
|
var by = dialog_y + ui(16);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, interactable && sFOCUS, sHOVER, __txtx("gradient_editor_key_blend", "Key blending"), THEME.grad_blend) == 2) {
|
2024-08-10 11:04:14 +02:00
|
|
|
menuCall("gradient_window_blend_menu", [
|
2024-08-10 07:30:41 +02:00
|
|
|
menuItem(__txtx("gradient_editor_blend_hard", "Solid"), function() { gradient.type = 1; onApply(gradient); }),
|
|
|
|
menuItem(__txtx("gradient_editor_blend_RGB", "RGB"), function() { gradient.type = 0; onApply(gradient); }),
|
|
|
|
menuItem(__txtx("gradient_editor_blend_HSV", "HSV"), function() { gradient.type = 2; onApply(gradient); }),
|
|
|
|
menuItem(__txtx("gradient_editor_blend_OKLAB", "OKLAB"), function() { gradient.type = 3; onApply(gradient); }),
|
2024-08-10 11:04:14 +02:00
|
|
|
], bx + ui(32), by, fa_left, gradient);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-11-03 11:44:49 +01:00
|
|
|
bx -= ui(32);
|
2023-07-30 19:56:53 +02:00
|
|
|
|
|
|
|
if(buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, interactable && sFOCUS, sHOVER, __txtx("gradient_editor_reverse", "Reverse"), THEME.reverse) == 2) {
|
|
|
|
for( var i = 0, n = array_length(gradient.keys); i < n; i++ )
|
|
|
|
gradient.keys[i].time = 1 - gradient.keys[i].time;
|
|
|
|
gradient.keys = array_reverse(gradient.keys);
|
|
|
|
onApply(gradient);
|
|
|
|
}
|
|
|
|
bx -= ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
2024-07-31 05:45:59 +02:00
|
|
|
var gr_x = content_x + ui(22);
|
|
|
|
var gr_y = dialog_y + ui(54);
|
|
|
|
var gr_w = content_w - ui(44);
|
|
|
|
var gr_h = ui(20);
|
2023-01-04 02:30:04 +01:00
|
|
|
draw_sprite_stretched(THEME.textbox, 3, gr_x - ui(6), gr_y - ui(6), gr_w + ui(12), gr_h + ui(12));
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.textbox, 0, gr_x - ui(6), gr_y - ui(6), gr_w + ui(12), gr_h + ui(12));
|
2023-03-02 07:59:14 +01:00
|
|
|
gradient.draw(gr_x, gr_y, gr_w, gr_h);
|
2024-08-06 04:30:00 +02:00
|
|
|
draw_sprite_stretched_add(THEME.ui_panel, 1, gr_x, gr_y, gr_w, gr_h, c_white, 0.25);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var hover = noone;
|
2024-07-31 05:45:59 +02:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
for(var i = 0; i < array_length(gradient.keys); i++) {
|
|
|
|
var _k = gradient.keys[i];
|
2022-11-14 03:16:15 +01:00
|
|
|
var _c = _k.value;
|
2022-01-13 05:24:03 +01:00
|
|
|
var _kx = gr_x + _k.time * gr_w;
|
2024-07-31 05:45:59 +02:00
|
|
|
var _ky = gr_y + gr_h / 2;
|
2022-01-13 05:24:03 +01:00
|
|
|
var _in = _k == key_selecting? 1 : 0;
|
|
|
|
|
2024-07-31 05:45:59 +02:00
|
|
|
var _hov = sHOVER && point_in_rectangle(mouse_mx, mouse_my, _kx - ui(6), gr_y, _kx + ui(6), gr_y + gr_h);
|
|
|
|
_hov |= key_dragging == _k;
|
|
|
|
_k._hover = lerp_float(_k._hover, _hov, 5);
|
|
|
|
|
|
|
|
var _kw = ui(12);
|
|
|
|
var _kh = lerp(ui(24), ui(32), _k._hover);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-31 05:45:59 +02:00
|
|
|
var _kdx = _kx - _kw / 2;
|
|
|
|
var _kdy = _ky - _kh / 2;
|
|
|
|
var _aa = key_dragging == _k && key_deleting? 0.3 : 1;
|
|
|
|
|
|
|
|
draw_sprite_stretched_ext(THEME.prop_gradient, 0, _kdx, _kdy, _kw, _kh, _c, _aa);
|
|
|
|
|
|
|
|
if(key_selecting == _k || key_dragging == _k) {
|
|
|
|
draw_sprite_stretched_ext(THEME.prop_gradient, 1, _kdx, _kdy, _kw, _kh, COLORS._main_accent, _aa);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if(_color_get_light(_c) < 0.75) draw_sprite_stretched_ext(THEME.prop_gradient, 1, _kdx, _kdy, _kw, _kh, c_white, _aa);
|
|
|
|
else draw_sprite_stretched_ext(THEME.prop_gradient, 1, _kdx, _kdy, _kw, _kh, c_black, _aa);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2024-07-31 05:45:59 +02:00
|
|
|
|
|
|
|
if(_hov) hover = _k;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(key_dragging) {
|
2023-01-25 06:49:00 +01:00
|
|
|
if(abs(mouse_mx - key_drag_mx) > 4)
|
|
|
|
key_drag_dead = false;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_deleting = abs(mouse_my - key_drag_my) > ui(32) && array_length(gradient.keys) > 1;
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2024-07-31 05:45:59 +02:00
|
|
|
if(!key_drag_dead && !key_deleting) {
|
|
|
|
var newT = clamp(key_drag_sx + (mouse_mx - key_drag_mx) / gr_w, 0, 1);
|
2023-01-25 06:49:00 +01:00
|
|
|
setKeyPosition(key_dragging, newT);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
2024-07-31 05:45:59 +02:00
|
|
|
if(key_deleting) array_remove(gradient.keys, key_dragging);
|
|
|
|
else removeKeyOverlap(key_dragging);
|
|
|
|
|
|
|
|
key_dragging = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
var _x0 = gr_x - ui(6);
|
|
|
|
var _x1 = gr_x + gr_w + ui(12);
|
|
|
|
var _y0 = gr_y - ui(6);
|
|
|
|
var _y1 = gr_y + gr_h + ui(12);
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(sHOVER && point_in_rectangle(mouse_mx, mouse_my, _x0, _y0, _x1, _y1)) {
|
|
|
|
if(mouse_press(mb_left, sFOCUS)) {
|
2023-01-25 06:49:00 +01:00
|
|
|
widget_clear();
|
2024-07-31 05:45:59 +02:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
if(hover) {
|
|
|
|
key_selecting = hover;
|
2023-02-28 09:43:01 +01:00
|
|
|
if(interactable) {
|
|
|
|
key_dragging = hover;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_drag_dead = true;
|
|
|
|
key_deleting = false;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
key_drag_sx = hover.time;
|
|
|
|
key_drag_mx = mouse_mx;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_drag_my = mouse_my;
|
2023-02-28 09:43:01 +01:00
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
selector.setColor(hover.value);
|
2024-07-31 05:45:59 +02:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
} else if(interactable) {
|
2022-11-18 03:20:31 +01:00
|
|
|
key_selecting = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
var tt = clamp((mouse_mx - gr_x) / gr_w, 0, 1);
|
2023-03-02 07:59:14 +01:00
|
|
|
var cc = gradient.eval(tt);
|
2024-01-08 08:10:50 +01:00
|
|
|
|
2023-02-14 13:44:46 +01:00
|
|
|
var _newkey = new gradientKey(tt, cc);
|
2023-03-02 07:59:14 +01:00
|
|
|
gradient.add(_newkey, true);
|
2024-01-08 08:10:50 +01:00
|
|
|
|
2024-07-31 05:45:59 +02:00
|
|
|
key_selecting = _newkey;
|
|
|
|
key_dragging = _newkey;
|
|
|
|
key_drag_dead = true;
|
|
|
|
key_deleting = false;
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
key_drag_sx = tt;
|
|
|
|
key_drag_mx = mouse_mx;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_drag_my = mouse_my;
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
selector.setColor(key_dragging.value);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-11-18 03:20:31 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
if(mouse_press(mb_right, interactable && sFOCUS) && hover && array_length(gradient.keys) > 1)
|
|
|
|
array_remove(gradient.keys, hover);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-11-14 03:16:15 +01:00
|
|
|
|
|
|
|
var op_x = content_x + ui(20);
|
|
|
|
var op_y = gr_y + gr_h + ui(12);
|
|
|
|
|
2023-02-14 13:44:46 +01:00
|
|
|
var txt = key_selecting? key_selecting.time * 100 : 0;
|
2023-06-21 20:36:53 +02:00
|
|
|
sl_position.setFocusHover(sFOCUS, sHOVER);
|
2023-01-25 06:49:00 +01:00
|
|
|
sl_position.register();
|
2024-07-30 13:02:53 +02:00
|
|
|
sl_position.setFont(f_p2);
|
|
|
|
sl_position.draw(op_x, op_y, ui(content_w - 40), ui(24), txt, mouse_ui);
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
#region selector
|
2022-11-03 11:44:49 +01:00
|
|
|
var col_x = content_x + ui(20);
|
2024-07-30 13:02:53 +02:00
|
|
|
var col_y = dialog_y + ui(128);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
if(palette_selecting > -1)
|
2023-10-16 12:54:20 +02:00
|
|
|
selector.palette = PALETTES[palette_selecting].palette;
|
2022-11-18 03:20:31 +01:00
|
|
|
selector.draw(col_x, col_y, sFOCUS, sHOVER);
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region controls
|
2022-11-03 11:44:49 +01:00
|
|
|
var bx = content_x + content_w - ui(36);
|
|
|
|
var by = dialog_y + dialog_h - ui(36);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
b_apply.register();
|
2023-06-21 20:36:53 +02:00
|
|
|
b_apply.setFocusHover(sFOCUS, sHOVER);
|
2023-01-25 06:49:00 +01:00
|
|
|
b_apply.draw(bx - ui(18), by - ui(18), ui(36), ui(36), mouse_ui, THEME.button_lime);
|
2023-02-14 13:44:46 +01:00
|
|
|
|
|
|
|
bx -= ui(48);
|
|
|
|
b_cancel.register();
|
2023-06-21 20:36:53 +02:00
|
|
|
b_cancel.setFocusHover(sFOCUS, sHOVER);
|
2023-02-14 13:44:46 +01:00
|
|
|
b_cancel.draw(bx - ui(18), by - ui(18), ui(36), ui(36), mouse_ui, THEME.button_hide);
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|