mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-10 12:34:06 +01:00
- [Image Array Editor] Improve UI, add file drop support.
This commit is contained in:
parent
4cc55b3dc3
commit
ad1cdce126
@ -1259,6 +1259,7 @@
|
||||
{"name":"panel_graph_grid_settings","order":7,"path":"scripts/panel_graph_grid_settings/panel_graph_grid_settings.yy",},
|
||||
{"name":"panel_graph_view_settings","order":8,"path":"scripts/panel_graph_view_settings/panel_graph_view_settings.yy",},
|
||||
{"name":"panel_history","order":5,"path":"scripts/panel_history/panel_history.yy",},
|
||||
{"name":"panel_image_array_editor","order":1,"path":"scripts/panel_image_array_editor/panel_image_array_editor.yy",},
|
||||
{"name":"panel_keyframe_driver","order":2,"path":"scripts/panel_keyframe_driver/panel_keyframe_driver.yy",},
|
||||
{"name":"panel_menu","order":6,"path":"scripts/panel_menu/panel_menu.yy",},
|
||||
{"name":"panel_node_align","order":3,"path":"scripts/panel_node_align/panel_node_align.yy",},
|
||||
|
@ -1875,6 +1875,7 @@
|
||||
{"id":{"name":"panel_graph_view_settings","path":"scripts/panel_graph_view_settings/panel_graph_view_settings.yy",},},
|
||||
{"id":{"name":"panel_graph","path":"scripts/panel_graph/panel_graph.yy",},},
|
||||
{"id":{"name":"panel_history","path":"scripts/panel_history/panel_history.yy",},},
|
||||
{"id":{"name":"panel_image_array_editor","path":"scripts/panel_image_array_editor/panel_image_array_editor.yy",},},
|
||||
{"id":{"name":"panel_inspector","path":"scripts/panel_inspector/panel_inspector.yy",},},
|
||||
{"id":{"name":"panel_keyframe_driver","path":"scripts/panel_keyframe_driver/panel_keyframe_driver.yy",},},
|
||||
{"id":{"name":"panel_menu","path":"scripts/panel_menu/panel_menu.yy",},},
|
||||
|
@ -17,7 +17,7 @@ event_inherited();
|
||||
|
||||
function onResize() {
|
||||
sp_content.resize(dialog_w - ui(padding + padding), dialog_h - ui(title_height + padding));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region content
|
||||
|
@ -59,24 +59,20 @@ event_inherited();
|
||||
}
|
||||
|
||||
draw_set_font(font);
|
||||
var ww = string_width(_menuItem.name) + ui(64);
|
||||
var ww = string_width(_menuItem.name) + ui(64);
|
||||
var _key = _menuItem.hotkey != noone? find_hotkey(_menuItem.hotkey[0], _menuItem.hotkey[1]) : noone;
|
||||
|
||||
draw_set_font(font);
|
||||
var _kw = _key? string_width(key_get_name(_key.key, _key.modi)) + ui(16) : 0;
|
||||
|
||||
if(instanceof(_menuItem) == "MenuItemGroup") {
|
||||
var amo = array_length(_menuItem.group);
|
||||
ww = max(ww, ui(16) + amo * (_menuItem.spacing + ui(4)));
|
||||
ww = max(ww + _kw * 2, ui(16) + amo * (_menuItem.spacing + ui(4)));
|
||||
dialog_h += hght;
|
||||
}
|
||||
|
||||
if(instanceof(_menuItem) == "MenuItem") {
|
||||
if(_menuItem.hotkey != noone) {
|
||||
var _key = find_hotkey(_menuItem.hotkey[0], _menuItem.hotkey[1]);
|
||||
if(_key) {
|
||||
draw_set_font(font);
|
||||
var ss = key_get_name(_key.key, _key.modi);
|
||||
ww += string_width(ss) + ui(16);
|
||||
}
|
||||
}
|
||||
|
||||
ww += _kw;
|
||||
if(_menuItem.spr != noone || _menuItem.toggle != noone) show_icon = true;
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ if !ready exit;
|
||||
|
||||
#region base UI
|
||||
var p = ui(8);
|
||||
var m_in = point_in_rectangle(mouse_mx, mouse_my, dialog_x + p, dialog_y + p, dialog_x + dialog_w - p, dialog_y + dialog_h - p);
|
||||
var m_ot = point_in_rectangle(mouse_mx, mouse_my, dialog_x, dialog_y, dialog_x + dialog_w, dialog_y + dialog_h);
|
||||
var m_in = point_in_rectangle(mouse_mxs, mouse_mys, dialog_x + p, dialog_y + p, dialog_x + dialog_w - p, dialog_y + dialog_h - p);
|
||||
var m_ot = point_in_rectangle(mouse_mxs, mouse_mys, dialog_x, dialog_y, dialog_x + dialog_w, dialog_y + dialog_h);
|
||||
|
||||
DIALOG_DRAW_BG
|
||||
#endregion
|
||||
|
@ -1,11 +1,11 @@
|
||||
function file_exists_empty(path) { INLINE return path != "" && file_exists(path); }
|
||||
|
||||
function file_copy_override(src, dest) { #region
|
||||
function file_copy_override(src, dest) {
|
||||
if(file_exists_empty(dest)) file_delete(dest);
|
||||
file_copy(src, dest);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function filepath_resolve(path) { #region
|
||||
function filepath_resolve(path) {
|
||||
INLINE
|
||||
var _path = path;
|
||||
|
||||
@ -13,16 +13,18 @@ function filepath_resolve(path) { #region
|
||||
_path = string_replace_all(_path, "%APP%/", APP_LOCATION);
|
||||
|
||||
return _path;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function get_open_filenames_compat(ext, sel, caption = "Open") { #region
|
||||
function get_open_filenames_compat(ext, sel, caption = "Open") {
|
||||
INLINE
|
||||
|
||||
if(OS == os_windows) return get_open_filenames_ext(ext, sel, PREFERENCES.dialog_path, caption);
|
||||
return get_open_filename_pxc(ext, sel, caption);
|
||||
} #endregion
|
||||
var pat = OS == os_windows? get_open_filenames_ext(ext, sel, PREFERENCES.dialog_path, caption) : get_open_filename_pxc(ext, sel, caption);
|
||||
key_release();
|
||||
|
||||
function file_get_modify_s(path) { #region
|
||||
return pat;
|
||||
}
|
||||
|
||||
function file_get_modify_s(path) {
|
||||
INLINE
|
||||
|
||||
if(!file_exists_empty(path)) return 0;
|
||||
@ -35,7 +37,7 @@ function file_get_modify_s(path) { #region
|
||||
var _s = file_datetime_modified_second(path);
|
||||
|
||||
return ((((_y * 12 + _m) * 31 + _d) * 24 + _h) * 60 + _n) * 60 + _s;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function get_save_filename_pxc(filter, name, caption = "Save as") {
|
||||
INLINE
|
||||
|
@ -92,6 +92,10 @@
|
||||
|
||||
#macro mouse_mx (PEN_USE? PEN_X : device_mouse_x_to_gui(0))
|
||||
#macro mouse_my (PEN_USE? PEN_Y : device_mouse_y_to_gui(0))
|
||||
|
||||
#macro mouse_mxs (FILE_IS_DROPPING? FILE_DROPPING_X : mouse_mx)
|
||||
#macro mouse_mys (FILE_IS_DROPPING? FILE_DROPPING_Y : mouse_my)
|
||||
|
||||
#macro mouse_raw_x (device_mouse_raw_x(0) + window_get_x())
|
||||
#macro mouse_raw_y (device_mouse_raw_y(0) + window_get_y())
|
||||
#macro mouse_ui [device_mouse_x_to_gui(0), device_mouse_y_to_gui(0)]
|
||||
|
@ -396,8 +396,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
|
||||
dragging = -1;
|
||||
}
|
||||
} else {
|
||||
var _mx = FILE_IS_DROPPING? FILE_DROPPING_X : mouse_mx;
|
||||
var _my = FILE_IS_DROPPING? FILE_DROPPING_Y : mouse_my;
|
||||
var _mx = mouse_mxs;
|
||||
var _my = mouse_mys;
|
||||
|
||||
if(con && point_in_rectangle(_mx, _my, x + ui(2), y + ui(2), x + w - ui(4), y + h - ui(4))) {
|
||||
HOVER = self;
|
||||
@ -663,8 +663,8 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
|
||||
|
||||
if(tab) drawTab();
|
||||
|
||||
var _mx = FILE_IS_DROPPING? FILE_DROPPING_X : mouse_mx;
|
||||
var _my = FILE_IS_DROPPING? FILE_DROPPING_Y : mouse_my;
|
||||
var _mx = mouse_mxs;
|
||||
var _my = mouse_mys;
|
||||
|
||||
var p = ui(6);
|
||||
var m_in = point_in_rectangle(_mx, _my, tx + p, ty + p, tx + tw - p, ty + th - p);
|
||||
|
@ -2463,8 +2463,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
|
||||
var _gy = my / graph_s - graph_y;
|
||||
var _node_hover = noone;
|
||||
|
||||
var _mx = (FILE_IS_DROPPING? FILE_DROPPING_X : mouse_mx) - x;
|
||||
var _my = (FILE_IS_DROPPING? FILE_DROPPING_Y : mouse_my) - y;
|
||||
var _mx = mouse_mxs - x;
|
||||
var _my = mouse_mys - y;
|
||||
|
||||
for(var i = 0; i < array_length(nodes_list); i++) {
|
||||
var _n = nodes_list[i];
|
||||
|
207
scripts/panel_image_array_editor/panel_image_array_editor.gml
Normal file
207
scripts/panel_image_array_editor/panel_image_array_editor.gml
Normal file
@ -0,0 +1,207 @@
|
||||
function Panel_Image_Array_Editor(_junction) : PanelContent() constructor {
|
||||
title = __txt("Array Editor");
|
||||
padding = 8;
|
||||
target = _junction;
|
||||
data = target.getValue();
|
||||
|
||||
w = ui(400);
|
||||
h = ui(640);
|
||||
|
||||
menuOn = -1;
|
||||
dragging = -1;
|
||||
drag_spr = -1;
|
||||
sortAsc = true;
|
||||
|
||||
tb_editing = -1;
|
||||
tb_edit = new textBox(TEXTBOX_INPUT.text, function(str) /*=>*/ {
|
||||
if(tb_editing == -1) return;
|
||||
if(!target) return;
|
||||
|
||||
data[@ tb_editing] = str;
|
||||
target.node.triggerRender();
|
||||
});
|
||||
|
||||
tb_edit.font = f_p3;
|
||||
tb_edit.onDeactivate = function() { tb_editing = -1; }
|
||||
|
||||
function apply() { target.setValue(data); target.node.triggerRender(); }
|
||||
|
||||
function rearrange(oldindex, newindex) {
|
||||
if(oldindex == newindex) return;
|
||||
|
||||
var val = data[oldindex];
|
||||
array_delete(data, oldindex, 1);
|
||||
array_insert(data, newindex, val);
|
||||
|
||||
apply();
|
||||
}
|
||||
|
||||
function sortByName() {
|
||||
if(!target) return 0;
|
||||
|
||||
array_sort(data, bool(sortAsc));
|
||||
sortAsc = !sortAsc;
|
||||
|
||||
apply();
|
||||
}
|
||||
|
||||
function onResize() { sp_content.resize(w - ui(padding + padding), h - ui(padding + padding)); }
|
||||
|
||||
sp_content = new scrollPane(w - ui(padding + padding), h - ui(padding + padding), function(_y, _m) {
|
||||
if(!target) return 0;
|
||||
|
||||
draw_clear_alpha(CDEF.main_mdblack, 1);
|
||||
|
||||
var _h = ui(8);
|
||||
|
||||
var itw = ui(320);
|
||||
var ith = ui(64);
|
||||
var its = ui(64);
|
||||
var pad = ui(16);
|
||||
|
||||
var len = array_length(data);
|
||||
var col = max(1, floor((sp_content.surface_w - pad) / (itw + pad)));
|
||||
var row = ceil(len / col);
|
||||
|
||||
itw = (sp_content.surface_w - pad) / col - pad;
|
||||
|
||||
var yy = _y;
|
||||
var drag = -1;
|
||||
var inb_hover = -1;
|
||||
|
||||
for( var i = 0; i < row; i++ ) {
|
||||
var ch = ith;
|
||||
for( var j = 0; j < col; j++ ) {
|
||||
var index = i * col + j;
|
||||
if(index >= len) break;
|
||||
|
||||
var path = data[index];
|
||||
var xx = (itw + pad) * j;
|
||||
|
||||
draw_sprite_stretched(THEME.ui_panel_bg, 0, xx, yy, its, its);
|
||||
draw_sprite_stretched_add(THEME.ui_panel, 1, xx, yy, its, its, c_white, 0.2);
|
||||
|
||||
if(sp_content.hover && point_in_rectangle(_m[0], _m[1], xx, yy, xx + its, yy + its)) {
|
||||
sp_content.hover_content = true;
|
||||
inb_hover = index;
|
||||
|
||||
if(dragging == -1 || dragging == index)
|
||||
draw_sprite_stretched_ext(THEME.ui_panel, 1, xx, yy, its, its, COLORS._main_accent, 1);
|
||||
|
||||
if(mouse_press(mb_left, sp_content.active))
|
||||
dragging = index;
|
||||
}
|
||||
|
||||
var spr = struct_try_get(SPRITE_PATH_MAP, path, noone);
|
||||
if(spr == noone || !sprite_exists(spr))
|
||||
spr = s_texture_default;
|
||||
|
||||
var spr_w = sprite_get_width(spr);
|
||||
var spr_h = sprite_get_height(spr);
|
||||
var spr_s = min((its - ui(16)) / spr_w, (its - ui(16)) / spr_h);
|
||||
var spr_x = xx + its / 2 - spr_w * spr_s / 2;
|
||||
var spr_y = yy + its / 2 - spr_h * spr_s / 2;
|
||||
|
||||
var aa = dragging == -1? 1 : (dragging == index? 1 : 0.5);
|
||||
draw_sprite_ext(spr, 0, spr_x, spr_y, spr_s, spr_s, 0, c_white, aa);
|
||||
|
||||
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
|
||||
var name = filename_name_only(path);
|
||||
var txt_h = string_height_ext(name, -1, itw);
|
||||
var _txtx = xx + its + ui(16);
|
||||
var _txty = yy + ui(4);
|
||||
|
||||
draw_text_ext_add(_txtx, _txty, name, -1, itw);
|
||||
|
||||
var _txth = line_get_height(f_p3, 4);
|
||||
var _txty = yy + its - _txth;
|
||||
draw_set_text(f_p3, fa_left, fa_top, COLORS._main_text_sub);
|
||||
draw_text_add(_txtx, _txty, path);
|
||||
|
||||
var _pthx = _txtx - ui(8);
|
||||
var _pthy = _txty - ui(2);
|
||||
var _pthw = itw - its - ui(16) + ui(8);
|
||||
var _pthh = _txth;
|
||||
|
||||
if(tb_editing == i) {
|
||||
tb_edit.setFocusHover(sp_content.active, sp_content.hover);
|
||||
tb_edit.draw(_pthx, _pthy, _pthw, _pthh, path, _m);
|
||||
}
|
||||
|
||||
if(sp_content.hover && point_in_rectangle(_m[0], _m[1], _pthx, _pthy, _pthx + _pthw, _pthy + _pthh)) {
|
||||
draw_sprite_stretched_add(THEME.ui_panel, 1, _pthx, _pthy, _pthw, _pthh, COLORS._main_icon, 0.2);
|
||||
|
||||
if(mouse_press(mb_left, sp_content.active)) {
|
||||
tb_editing = i;
|
||||
tb_edit.activate(path);
|
||||
}
|
||||
}
|
||||
|
||||
ch = max(ch, ith + ui(8));
|
||||
}
|
||||
|
||||
yy += ch;
|
||||
_h += ch;
|
||||
}
|
||||
|
||||
if(dragging != -1) {
|
||||
if(inb_hover != -1) {
|
||||
rearrange(dragging, inb_hover);
|
||||
dragging = inb_hover;
|
||||
}
|
||||
|
||||
if(mouse_release(mb_left))
|
||||
dragging = -1;
|
||||
}
|
||||
|
||||
if(mouse_press(mb_right, sp_content.active)) {
|
||||
menuOn = inb_hover;
|
||||
|
||||
if(inb_hover == -1) {
|
||||
menuCall("image_array_edit_menu_empty", [
|
||||
menuItem(__txt("Add") + "...", function() /*=>*/ {
|
||||
var path = get_open_filenames_compat("image|*.png;*.jpg", "");
|
||||
if(path == "") return;
|
||||
|
||||
var paths = string_splice(path, "\n");
|
||||
array_append(data, paths);
|
||||
apply();
|
||||
}, THEME.add),
|
||||
menuItem(__txt("Sort"), function() /*=>*/ { sortByName(); }, THEME.text)
|
||||
]);
|
||||
} else {
|
||||
menuCall("image_array_edit_menu", [
|
||||
menuItem(__txt("Remove"), function() /*=>*/ { array_delete(data, menuOn, 1); apply(); }, THEME.cross)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return _h;
|
||||
});
|
||||
|
||||
function drawContent(panel) {
|
||||
draw_clear_alpha(COLORS.panel_bg_clear, 0);
|
||||
|
||||
var px = ui(padding);
|
||||
var py = ui(padding);
|
||||
var pw = w - ui(padding + padding);
|
||||
var ph = h - ui(padding + padding);
|
||||
|
||||
var msx = mx - px;
|
||||
var msy = my - py;
|
||||
|
||||
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
|
||||
|
||||
sp_content.setFocusHover(pFOCUS, pHOVER);
|
||||
sp_content.draw(px, py, msx, msy);
|
||||
|
||||
if(pHOVER) {
|
||||
if(FILE_IS_DROPPING) draw_sprite_stretched_ext(THEME.ui_panel_selection, 0, 8, 8, w - 16, h - 16, COLORS._main_value_positive, 1);
|
||||
|
||||
if(FILE_DROPPED && !array_empty(FILE_DROPPING)) {
|
||||
array_append(data, FILE_DROPPING);
|
||||
apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
13
scripts/panel_image_array_editor/panel_image_array_editor.yy
Normal file
13
scripts/panel_image_array_editor/panel_image_array_editor.yy
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"$GMScript":"",
|
||||
"%Name":"panel_image_array_editor",
|
||||
"isCompatibility":false,
|
||||
"isDnD":false,
|
||||
"name":"panel_image_array_editor",
|
||||
"parent":{
|
||||
"name":"nodes",
|
||||
"path":"folders/panels/nodes.yy",
|
||||
},
|
||||
"resourceType":"GMScript",
|
||||
"resourceVersion":"2.0",
|
||||
}
|
@ -13,8 +13,7 @@ function pathArrayBox(_target, _data, _onClick) : widget() constructor {
|
||||
}, THEME.button_path_icon);
|
||||
|
||||
static trigger = function() {
|
||||
with(dialogCall(o_dialog_image_array_edit, WIN_W / 2, WIN_H / 2))
|
||||
target = other.target;
|
||||
dialogPanelCall(new Panel_Image_Array_Editor(target));
|
||||
}
|
||||
|
||||
static drawParam = function(params) {
|
||||
|
Loading…
Reference in New Issue
Block a user