2022-01-13 05:24:03 +01:00
|
|
|
/// @description init
|
|
|
|
event_inherited();
|
|
|
|
|
|
|
|
#region data
|
2023-01-17 08:11:55 +01:00
|
|
|
dialog_w = ui(1068);
|
2024-07-30 13:02:53 +02:00
|
|
|
dialog_h = ui(468);
|
2023-02-28 09:43:01 +01:00
|
|
|
title_height = 52;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-04 18:28:29 +02:00
|
|
|
name = __txtx("gradient_editor_title", "Gradient editor");
|
2024-05-25 10:07:11 +02:00
|
|
|
gradient = noone;
|
|
|
|
interactable = true;
|
|
|
|
drop_target = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
key_selecting = noone;
|
|
|
|
key_dragging = noone;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_deleting = false;
|
|
|
|
key_drag_dead = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
key_drag_sx = 0;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_drag_sy = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
key_drag_mx = 0;
|
2024-07-31 05:45:59 +02:00
|
|
|
key_drag_my = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
destroy_on_click_out = true;
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
sl_position = slider(0, 100, 0.1, function(val) {
|
2023-02-28 09:43:01 +01:00
|
|
|
if(!interactable) return;
|
2022-11-14 03:16:15 +01:00
|
|
|
if(key_selecting == noone) return;
|
|
|
|
setKeyPosition(key_selecting, val / 100);
|
2024-07-30 13:02:53 +02:00
|
|
|
}, function() { removeKeyOverlap(key_selecting); }).setLabel(__txt("Position"));
|
2022-11-14 03:16:15 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
setColor = function(color) {
|
2022-01-13 05:24:03 +01:00
|
|
|
if(key_selecting == noone) return;
|
2024-01-16 09:56:20 +01:00
|
|
|
key_selecting.value = int64(color);
|
2023-02-21 07:38:25 +01:00
|
|
|
|
|
|
|
onApply(gradient);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-02-14 13:44:46 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
function setGradient(grad) {
|
|
|
|
gradient = grad;
|
2024-01-08 08:10:50 +01:00
|
|
|
if(array_empty(grad.keys)) return;
|
|
|
|
|
|
|
|
key_selecting = grad.keys[0];
|
|
|
|
selector.setColor(key_selecting.value, false);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
selector = new colorSelector(setColor);
|
2022-12-22 03:09:55 +01:00
|
|
|
selector.dropper_close = false;
|
2022-11-18 03:20:31 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
previous_gradient = noone;
|
2023-02-14 13:44:46 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
function setDefault(grad) {
|
|
|
|
setGradient(grad);
|
|
|
|
previous_gradient = grad.clone();
|
2023-02-14 13:44:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
b_cancel = button(function() {
|
|
|
|
onApply(previous_gradient);
|
|
|
|
instance_destroy();
|
2023-06-10 13:59:45 +02:00
|
|
|
}).setIcon(THEME.undo, 0, COLORS._main_icon)
|
2023-06-05 18:27:53 +02:00
|
|
|
.setTooltip(__txtx("dialog_revert_and_exit", "Revert and exit"));
|
2023-02-14 13:44:46 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
b_apply = button(function() {
|
2023-02-14 13:44:46 +01:00
|
|
|
onApply(gradient);
|
2023-01-25 06:49:00 +01:00
|
|
|
instance_destroy();
|
|
|
|
}).setIcon(THEME.accept, 0, COLORS._main_icon_dark);
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
function setKeyPosition(key, position) {
|
|
|
|
key.time = position;
|
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
array_remove(gradient.keys, key);
|
|
|
|
gradient.add(key, false);
|
2023-02-21 07:38:25 +01:00
|
|
|
|
|
|
|
onApply(gradient);
|
2022-11-14 03:16:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeKeyOverlap(key) {
|
2023-03-02 07:59:14 +01:00
|
|
|
var keys = gradient.keys;
|
|
|
|
for(var i = 0; i < array_length(keys); i++) {
|
|
|
|
var _key = keys[i];
|
2022-11-14 03:16:15 +01:00
|
|
|
if(_key == key || _key.time != key.time)
|
|
|
|
continue;
|
2023-02-14 13:44:46 +01:00
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
_key.value = key.value;
|
2023-03-02 07:59:14 +01:00
|
|
|
array_remove(keys, key);
|
2022-11-14 03:16:15 +01:00
|
|
|
}
|
2023-02-21 07:38:25 +01:00
|
|
|
|
|
|
|
onApply(gradient);
|
2022-11-14 03:16:15 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region preset
|
2023-03-02 07:59:14 +01:00
|
|
|
hovering_name = "";
|
2024-07-30 13:02:53 +02:00
|
|
|
|
|
|
|
pal_padding = ui(9);
|
|
|
|
sp_preset_w = ui(240) - pal_padding * 2 - ui(8);
|
|
|
|
|
|
|
|
sp_presets = new scrollPane(sp_preset_w, dialog_h - ui(48 + 8) - pal_padding, function(_y, _m) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
var ww = sp_presets.surface_w;
|
|
|
|
var _gs = ui(16);
|
|
|
|
var hh = ui(24);
|
|
|
|
var nh = ui(20);
|
|
|
|
var pd = ui(6);
|
|
|
|
var _ww = ww - pd * 2;
|
|
|
|
var hg = nh + _gs + pd;
|
|
|
|
var yy = _y;
|
|
|
|
|
|
|
|
var _hover = sHOVER && sp_presets.hover;
|
|
|
|
|
2023-10-16 12:54:20 +02:00
|
|
|
for(var i = 0; i < array_length(GRADIENTS); i++) {
|
|
|
|
var _gradient = GRADIENTS[i];
|
2024-07-30 13:02:53 +02:00
|
|
|
var isHover = point_in_rectangle(_m[0], _m[1], 0, yy, ww, yy + hg);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 3, 0, yy, ww, hg);
|
2024-07-28 13:55:57 +02:00
|
|
|
if(_hover && isHover) {
|
|
|
|
sp_presets.hover_content = true;
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.node_active, 1, 0, yy, ww, hg, COLORS._main_accent, 1);
|
2024-07-28 13:55:57 +02:00
|
|
|
}
|
2022-12-10 05:06:01 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_text_add(pd, yy + ui(2), _gradient.name);
|
|
|
|
_gradient.gradient.draw(pd, yy + nh, _ww, _gs);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
if(_hover && isHover) {
|
2023-11-22 10:21:50 +01:00
|
|
|
if(mouse_press(mb_left, interactable && sFOCUS)) {
|
|
|
|
gradient.keys = [];
|
2024-01-08 08:10:50 +01:00
|
|
|
for( var i = 0, n = array_length(_gradient.gradient.keys); i < n; i++ ) {
|
|
|
|
var k = _gradient.gradient.keys[i].clone();
|
|
|
|
gradient.keys[i] = k;
|
|
|
|
|
|
|
|
if(is_real(k.value)) k.value = cola(k.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
onApply(gradient);
|
2023-11-22 10:21:50 +01:00
|
|
|
}
|
2023-03-02 07:59:14 +01:00
|
|
|
|
|
|
|
if(mouse_press(mb_right, interactable && sFOCUS)) {
|
2023-10-16 12:54:20 +02:00
|
|
|
hovering_name = _gradient.path;
|
2023-05-03 21:42:17 +02:00
|
|
|
menuCall("gradient_window_preset_menu",,, [
|
2023-06-05 18:27:53 +02:00
|
|
|
menuItem(__txtx("gradient_editor_delete", "Delete gradient"), function() {
|
2023-10-16 12:54:20 +02:00
|
|
|
file_delete(hovering_name);
|
|
|
|
__initGradient();
|
2023-03-02 07:59:14 +01:00
|
|
|
})
|
2023-10-16 12:54:20 +02:00
|
|
|
]);
|
2023-03-02 07:59:14 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
yy += hg + ui(4);
|
|
|
|
hh += hg + ui(4);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hh;
|
2023-12-29 14:30:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
sp_presets.always_scroll = true;
|
2022-11-18 03:20:31 +01:00
|
|
|
#endregion
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
#region palette
|
2023-10-16 12:54:20 +02:00
|
|
|
palette_selecting = -1;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
sp_palette_w = ui(240) - pal_padding * 2 - ui(8);
|
|
|
|
sp_palette_size = ui(20);
|
|
|
|
click_block = true;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
sp_palettes = new scrollPane(sp_palette_w, dialog_h - ui(48 + 8) - pal_padding, function(_y, _m) {
|
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
|
|
|
|
|
|
|
var ww = sp_palettes.surface_w;
|
2023-01-17 08:11:55 +01:00
|
|
|
var _gs = sp_palette_size;
|
2024-07-30 13:02:53 +02:00
|
|
|
var hh = ui(24);
|
|
|
|
var nh = ui(20);
|
|
|
|
var pd = ui(6);
|
|
|
|
var _ww = ww - pd * 2;
|
|
|
|
var _bh = nh + _gs + pd;
|
|
|
|
var yy = _y;
|
|
|
|
|
|
|
|
var _height, pre_amo, _palRes;
|
2023-01-17 08:11:55 +01:00
|
|
|
var _hover = sHOVER && sp_palettes.hover;
|
2024-07-30 13:02:53 +02:00
|
|
|
var col = max(1, floor(_ww / _gs)), row;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-10-16 12:54:20 +02:00
|
|
|
for(var i = -1; i < array_length(PALETTES); i++) {
|
|
|
|
var pal = i == -1? {
|
2024-07-30 13:02:53 +02:00
|
|
|
name : "project",
|
|
|
|
palette : PROJECT.attributes.palette,
|
|
|
|
path : ""
|
2023-10-16 12:54:20 +02:00
|
|
|
} : PALETTES[i];
|
|
|
|
|
|
|
|
pre_amo = array_length(pal.palette);
|
2024-07-30 13:02:53 +02:00
|
|
|
row = ceil(pre_amo / col);
|
|
|
|
_height = palette_selecting == i? nh + row * _gs + pd : _bh;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
var isHover = _hover && point_in_rectangle(_m[0], _m[1], 0, yy, ww, yy + _height);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 3, 0, yy, ww, _height);
|
2024-07-28 13:55:57 +02:00
|
|
|
if(isHover) {
|
|
|
|
sp_palettes.hover_content = true;
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.node_active, 1, 0, yy, ww, _height, COLORS._main_accent, 1);
|
2024-07-28 13:55:57 +02:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
var cc = i == palette_selecting? COLORS._main_accent : COLORS._main_text_sub;
|
|
|
|
draw_set_text(f_p2, fa_left, fa_top, cc);
|
2024-07-30 13:02:53 +02:00
|
|
|
draw_text_add(pd, yy + ui(2), pal.name);
|
2023-07-25 20:12:40 +02:00
|
|
|
|
2024-07-30 13:02:53 +02:00
|
|
|
if(i == -1) { draw_set_color(cc); draw_circle_prec(ww - ui(10), yy + ui(10), ui(4), false); }
|
|
|
|
|
|
|
|
if(palette_selecting == i)
|
|
|
|
_palRes = drawPaletteGrid(pal.palette, pd, yy + nh, _ww, _gs, { mx : _m[0], my : _m[1] });
|
2023-01-17 08:11:55 +01:00
|
|
|
else
|
2024-07-30 13:02:53 +02:00
|
|
|
drawPalette(pal.palette, pd, yy + nh, _ww, _gs);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
if(!click_block && mouse_click(mb_left, interactable && sFOCUS)) {
|
2024-05-29 04:41:08 +02:00
|
|
|
if(palette_selecting == i && _hover && _palRes.hoverIndex > noone) {
|
|
|
|
var c = _palRes.hoverColor;
|
|
|
|
if(is_real(c)) c = cola(c);
|
|
|
|
|
|
|
|
selector.setColor(c);
|
|
|
|
selector.setHSV();
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
} else if(isHover) {
|
|
|
|
palette_selecting = i;
|
|
|
|
click_block = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-31 05:45:59 +02:00
|
|
|
if(isHover && mouse_press(mb_right, interactable && sFOCUS)) {
|
2024-07-30 13:02:53 +02:00
|
|
|
hovering = pal;
|
|
|
|
|
|
|
|
menuCall("palette_window_preset_menu",,, [
|
2024-07-31 05:45:59 +02:00
|
|
|
menuItem(__txtx("gradient_set_palette", "Convert to Gradient"), function() {
|
|
|
|
var _p = hovering.palette;
|
|
|
|
if(array_length(_p) < 2) return;
|
|
|
|
|
|
|
|
gradient.keys = [];
|
|
|
|
for( var i = 0, n = array_length(_p); i < n; i++ )
|
2024-08-02 14:30:35 +02:00
|
|
|
gradient.keys[i] = new gradientKey(i / (n - 1), cola(_p[i]));
|
2024-07-30 13:02:53 +02:00
|
|
|
}),
|
|
|
|
]);
|
2024-01-16 09:56:20 +01:00
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
yy += _height + ui(4);
|
|
|
|
hh += _height + ui(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
click_block = false;
|
|
|
|
|
|
|
|
return hh;
|
2023-12-29 14:30:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
sp_palettes.always_scroll = true;
|
2023-01-17 08:11:55 +01:00
|
|
|
#endregion
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
#region action
|
|
|
|
function checkMouse() {}
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|