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);
|
2022-12-10 05:06:01 +01:00
|
|
|
dialog_h = ui(476);
|
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");
|
2022-01-13 05:24:03 +01:00
|
|
|
gradient = noone;
|
2023-02-28 09:43:01 +01:00
|
|
|
interactable = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
key_selecting = noone;
|
|
|
|
key_dragging = noone;
|
|
|
|
key_drag_sx = 0;
|
|
|
|
key_drag_mx = 0;
|
2023-01-25 06:49:00 +01:00
|
|
|
key_drag_dead = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
destroy_on_click_out = true;
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
sl_position = new 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);
|
|
|
|
}, function() { removeKeyOverlap(key_selecting); })
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
setColor = function(color) {
|
2022-01-13 05:24:03 +01:00
|
|
|
if(key_selecting == noone) return;
|
2022-11-18 03:20:31 +01:00
|
|
|
key_selecting.value = 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;
|
|
|
|
if(array_length(grad.keys))
|
|
|
|
key_selecting = grad.keys[0];
|
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
|
|
|
|
presets = ds_list_create();
|
|
|
|
preset_name = ds_list_create();
|
|
|
|
|
|
|
|
function presetCollect() {
|
|
|
|
ds_list_clear(presets);
|
|
|
|
ds_list_clear(preset_name);
|
|
|
|
|
|
|
|
var path = DIRECTORY + "Gradients/"
|
|
|
|
var file = file_find_first(path + "*", 0);
|
|
|
|
while(file != "") {
|
|
|
|
ds_list_add(presets, loadGradient(path + file));
|
|
|
|
ds_list_add(preset_name, filename_name(file));
|
|
|
|
file = file_find_next();
|
|
|
|
}
|
|
|
|
file_find_close();
|
|
|
|
}
|
|
|
|
presetCollect();
|
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
hovering_name = "";
|
2022-11-03 11:44:49 +01:00
|
|
|
sp_preset_w = ui(240 - 32 - 16);
|
|
|
|
sp_presets = new scrollPane(sp_preset_w, dialog_h - ui(62), function(_y, _m) {
|
|
|
|
var ww = sp_preset_w - ui(40);
|
|
|
|
var hh = ui(32);
|
|
|
|
var yy = _y + ui(8);
|
|
|
|
var hg = ui(52);
|
2022-12-19 13:35:30 +01:00
|
|
|
var _hover = sHOVER && sp_presets.hover;
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(presets); i++) {
|
2022-12-10 05:06:01 +01:00
|
|
|
var isHover = point_in_rectangle(_m[0], _m[1], ui(4), yy, ui(4) + sp_preset_w - ui(16), yy + hg);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(4), yy, sp_preset_w - ui(16), hg);
|
2022-12-19 13:35:30 +01:00
|
|
|
if(_hover && isHover)
|
2022-12-10 05:06:01 +01:00
|
|
|
draw_sprite_stretched_ext(THEME.node_active, 1, ui(4), yy, sp_preset_w - ui(16), hg, COLORS._main_accent, 1);
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
|
2023-02-23 07:02:19 +01:00
|
|
|
draw_text(ui(16), yy + ui(8), filename_name_only(preset_name[| i]));
|
2023-03-02 07:59:14 +01:00
|
|
|
presets[| i].draw(ui(16), yy + ui(28), ww, ui(16));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-02 07:59:14 +01:00
|
|
|
if(_hover && isHover) {
|
|
|
|
if(mouse_press(mb_left, interactable && sFOCUS))
|
|
|
|
gradient.keys = presets[| i].keys;
|
|
|
|
|
|
|
|
if(mouse_press(mb_right, interactable && sFOCUS)) {
|
|
|
|
hovering_name = preset_name[| i];
|
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-03-02 07:59:14 +01:00
|
|
|
file_delete( DIRECTORY + "Gradients/" + hovering_name);
|
|
|
|
presetCollect();
|
|
|
|
})
|
2023-05-04 20:00:56 +02:00
|
|
|
],, { name: hovering_name })
|
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;
|
|
|
|
})
|
2022-11-18 03:20:31 +01:00
|
|
|
#endregion
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
#region palette
|
|
|
|
palettes = ds_list_create();
|
|
|
|
palette_name = ds_list_create();
|
2023-07-21 12:40:20 +02:00
|
|
|
palette_selecting = 0;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
function paletteCollect() {
|
|
|
|
ds_list_clear(palettes);
|
|
|
|
ds_list_clear(palette_name);
|
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
ds_list_add(palettes, DEF_PALETTE);
|
|
|
|
ds_list_add(palette_name, "Project");
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
var path = DIRECTORY + "Palettes/"
|
|
|
|
var file = file_find_first(path + "*", 0);
|
|
|
|
while(file != "") {
|
|
|
|
ds_list_add(palettes, loadPalette(path + file));
|
|
|
|
ds_list_add(palette_name, filename_name(file));
|
|
|
|
file = file_find_next();
|
|
|
|
}
|
|
|
|
file_find_close();
|
|
|
|
}
|
|
|
|
paletteCollect();
|
|
|
|
|
|
|
|
sp_palette_w = ui(240 - 32 - 16);
|
|
|
|
sp_palette_size = ui(24);
|
2023-07-21 12:40:20 +02:00
|
|
|
click_block = true;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
sp_palettes = new scrollPane(sp_palette_w, dialog_h - ui(62), function(_y, _m) {
|
|
|
|
var ww = sp_palette_w - ui(40);
|
|
|
|
var hh = ui(32);
|
|
|
|
var _gs = sp_palette_size;
|
|
|
|
var yy = _y + ui(8);
|
|
|
|
var _height, pre_amo;
|
|
|
|
var _hover = sHOVER && sp_palettes.hover;
|
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(palettes); i++) {
|
|
|
|
pre_amo = array_length(palettes[| i]);
|
|
|
|
var col = floor(ww / _gs);
|
|
|
|
var row = ceil(pre_amo / col);
|
|
|
|
|
|
|
|
if(palette_selecting == i)
|
|
|
|
_height = ui(28) + row * _gs + ui(12);
|
|
|
|
else
|
|
|
|
_height = ui(56);
|
|
|
|
|
|
|
|
var isHover = _hover && point_in_rectangle(_m[0], _m[1], ui(4), yy, ui(4) + sp_palette_w - ui(16), yy + _height);
|
|
|
|
|
|
|
|
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(4), yy, sp_palette_w - ui(16), _height);
|
|
|
|
if(isHover)
|
|
|
|
draw_sprite_stretched_ext(THEME.node_active, 1, ui(4), yy, sp_palette_w - ui(16), _height, COLORS._main_accent, 1);
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
var x0 = ui(16) + (i == 0) * ui(8 + 6);
|
|
|
|
var cc = i == palette_selecting? COLORS._main_accent : COLORS._main_text_sub;
|
|
|
|
draw_set_text(f_p2, fa_left, fa_top, cc);
|
|
|
|
draw_text(x0, yy + ui(8), filename_name_only(palette_name[| i]));
|
|
|
|
if(i == 0) {
|
|
|
|
draw_set_color(cc);
|
|
|
|
draw_circle_prec(ui(16) + ui(4), yy + ui(16), ui(4), false);
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
if(palette_selecting == i)
|
|
|
|
drawPaletteGrid(palettes[| i], ui(16), yy + ui(28), ww, _gs);
|
|
|
|
else
|
|
|
|
drawPalette(palettes[| i], ui(16), yy + ui(28), ww, ui(20));
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
if(!click_block && mouse_click(mb_left, interactable && sFOCUS)) {
|
2023-01-17 08:11:55 +01:00
|
|
|
if(palette_selecting == i && _hover && point_in_rectangle(_m[0], _m[1], ui(16), yy + ui(28), ui(16) + ww, yy + ui(28) + _height)) {
|
|
|
|
var m_ax = _m[0] - ui(16);
|
|
|
|
var m_ay = _m[1] - (yy + ui(28));
|
|
|
|
|
|
|
|
var m_gx = floor(m_ax / _gs);
|
|
|
|
var m_gy = floor(m_ay / _gs);
|
|
|
|
|
|
|
|
var _index = m_gy * col + m_gx;
|
|
|
|
if(_index < pre_amo && _index >= 0) {
|
|
|
|
selector.setColor(palettes[| i][_index]);
|
|
|
|
selector.setHSV();
|
|
|
|
}
|
|
|
|
} else if(isHover) {
|
|
|
|
palette_selecting = i;
|
|
|
|
click_block = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
yy += _height + ui(4);
|
|
|
|
hh += _height + ui(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
click_block = false;
|
|
|
|
|
|
|
|
return hh;
|
|
|
|
})
|
|
|
|
#endregion
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
#region action
|
|
|
|
function checkMouse() {}
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|