From c43e93f0923fd10da12b650325b483c0552f9154 Mon Sep 17 00:00:00 2001 From: Tanasart <22589759+Ttanasart-pt@users.noreply.github.com> Date: Sun, 13 Aug 2023 13:10:20 +0200 Subject: [PATCH] export template preview --- PixelComposer.resource_order | 1 + PixelComposer.yyp | 1 + .../draw_text_delimiter.gml | 2 +- .../draw_text_function/draw_text_function.gml | 4 +- scripts/draw_text_path/draw_text_path.gml | 42 + scripts/draw_text_path/draw_text_path.yy | 11 + scripts/luaHighlight/luaHighlight.gml | 4 +- scripts/node_export/node_export.gml | 147 ++- scripts/node_value/node_value.gml | 2 - scripts/panel_graph/panel_graph.gml | 1066 ++++++++--------- scripts/panel_inspector/panel_inspector.gml | 5 +- scripts/panel_preview/panel_preview.gml | 89 +- scripts/textArea/textArea.gml | 8 +- scripts/textBox/textBox.gml | 67 +- 14 files changed, 778 insertions(+), 671 deletions(-) create mode 100644 scripts/draw_text_path/draw_text_path.gml create mode 100644 scripts/draw_text_path/draw_text_path.yy diff --git a/PixelComposer.resource_order b/PixelComposer.resource_order index 5dc4b09de..08b3f5e81 100644 --- a/PixelComposer.resource_order +++ b/PixelComposer.resource_order @@ -204,6 +204,7 @@ {"name":"sh_noise_grid_hex","order":2,"path":"shaders/sh_noise_grid_hex/sh_noise_grid_hex.yy",}, {"name":"node_3d_obj","order":8,"path":"scripts/node_3d_obj/node_3d_obj.yy",}, {"name":"__path","order":1,"path":"scripts/__path/__path.yy",}, + {"name":"draw_text_path","order":25,"path":"scripts/draw_text_path/draw_text_path.yy",}, {"name":"sh_brush_outline","order":7,"path":"shaders/sh_brush_outline/sh_brush_outline.yy",}, {"name":"s_node_grid_tri_noise","order":22,"path":"sprites/s_node_grid_tri_noise/s_node_grid_tri_noise.yy",}, {"name":"o_dialog_menubox","order":1,"path":"objects/o_dialog_menubox/o_dialog_menubox.yy",}, diff --git a/PixelComposer.yyp b/PixelComposer.yyp index 6418e0ea7..8852ece2d 100644 --- a/PixelComposer.yyp +++ b/PixelComposer.yyp @@ -718,6 +718,7 @@ {"id":{"name":"sh_noise_grid_hex","path":"shaders/sh_noise_grid_hex/sh_noise_grid_hex.yy",},}, {"id":{"name":"node_3d_obj","path":"scripts/node_3d_obj/node_3d_obj.yy",},}, {"id":{"name":"__path","path":"scripts/__path/__path.yy",},}, + {"id":{"name":"draw_text_path","path":"scripts/draw_text_path/draw_text_path.yy",},}, {"id":{"name":"sh_brush_outline","path":"shaders/sh_brush_outline/sh_brush_outline.yy",},}, {"id":{"name":"s_node_grid_tri_noise","path":"sprites/s_node_grid_tri_noise/s_node_grid_tri_noise.yy",},}, {"id":{"name":"o_dialog_menubox","path":"objects/o_dialog_menubox/o_dialog_menubox.yy",},}, diff --git a/scripts/draw_text_delimiter/draw_text_delimiter.gml b/scripts/draw_text_delimiter/draw_text_delimiter.gml index f1b1a6ecb..2780753d3 100644 --- a/scripts/draw_text_delimiter/draw_text_delimiter.gml +++ b/scripts/draw_text_delimiter/draw_text_delimiter.gml @@ -12,7 +12,7 @@ function draw_text_delimiter(ch_x, ch_y, _str) { } else draw_set_color(cc); - draw_text(_x, _y, ch); + draw_text_add(_x, _y, ch); _x += string_width(ch); } } \ No newline at end of file diff --git a/scripts/draw_text_function/draw_text_function.gml b/scripts/draw_text_function/draw_text_function.gml index 9f418d0e5..3a0a13aa3 100644 --- a/scripts/draw_text_function/draw_text_function.gml +++ b/scripts/draw_text_function/draw_text_function.gml @@ -120,8 +120,8 @@ function __string_width_ext(text, sep, w) { #macro _string_height_ext string_height_ext #macro string_height_ext __string_height_ext -function __string_height_ext(text, sep, w) { - if(!LOCALE.config.per_character_line_break) +function __string_height_ext(text, sep, w, _break = LOCALE.config.per_character_line_break) { + if(!_break) return _string_height_ext(text, sep, w); var lw = 0; diff --git a/scripts/draw_text_path/draw_text_path.gml b/scripts/draw_text_path/draw_text_path.gml new file mode 100644 index 000000000..77b41c401 --- /dev/null +++ b/scripts/draw_text_path/draw_text_path.gml @@ -0,0 +1,42 @@ +function draw_text_path(_x, _y, _text) { + draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color); + var _x0 = _x, ch = "", len = string_length(_text), i = 1; + var cc = draw_get_color(); + var str = "", _comm = false; + + while(i <= len) { + ch = string_char_at(_text, i); + + if(ch == "%") + _comm = true; + + if(!_comm) { + draw_text_add(_x0, _y, ch); + _x0 += string_width(ch); + } else { + str += ch; + switch(ch) { + case "d" : draw_set_color(COLORS.widget_text_dec_d); break; + case "n" : draw_set_color(COLORS.widget_text_dec_n); break; + case "e" : draw_set_color(COLORS.widget_text_dec_e); break; + case "f" : draw_set_color(COLORS.widget_text_dec_f); break; + case "i" : draw_set_color(COLORS.widget_text_dec_i); break; + } + + switch(ch) { + case "d" : case "n" : case "e" : case "f" : case "i" : + draw_text_add(_x0, _y, str); + _x0 += string_width(str); + _comm = false; + str = ""; + + draw_set_color(cc); + break; + } + } + + i++; + } + + draw_text_add(_x0, _y, str); +} \ No newline at end of file diff --git a/scripts/draw_text_path/draw_text_path.yy b/scripts/draw_text_path/draw_text_path.yy new file mode 100644 index 000000000..477faa098 --- /dev/null +++ b/scripts/draw_text_path/draw_text_path.yy @@ -0,0 +1,11 @@ +{ + "resourceType": "GMScript", + "resourceVersion": "1.0", + "name": "draw_text_path", + "isCompatibility": false, + "isDnD": false, + "parent": { + "name": "draw", + "path": "folders/functions/draw.yy", + }, +} \ No newline at end of file diff --git a/scripts/luaHighlight/luaHighlight.gml b/scripts/luaHighlight/luaHighlight.gml index f875810fb..e284eeb6c 100644 --- a/scripts/luaHighlight/luaHighlight.gml +++ b/scripts/luaHighlight/luaHighlight.gml @@ -58,7 +58,7 @@ function draw_code(_x, _y, str) { if(i < amo - 1) word += "\""; draw_set_color(COLORS.lua_highlight_string); - draw_text(tx, ty, word); + draw_text_add(tx, ty, word); tx += string_width(word); continue; } @@ -81,7 +81,7 @@ function draw_code(_x, _y, str) { draw_set_color(COLORS.lua_highlight_function); } - draw_text(tx, ty, word); + draw_text_add(tx, ty, word); tx += string_width(word); } } diff --git a/scripts/node_export/node_export.gml b/scripts/node_export/node_export.gml index 566b33ef8..d4fe0821c 100644 --- a/scripts/node_export/node_export.gml +++ b/scripts/node_export/node_export.gml @@ -59,6 +59,8 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor inputs[| 2] = nodeValue("Template", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "%d%n") .rejectArray(); + inputs[| 2].editWidget.format = TEXT_AREA_FORMAT.path_template; + inputs[| 2].editWidget.auto_update = true; format_single = ["Single image", "Image sequence", "Animation"]; format_array = ["Multiple images", "Image sequences", "Animation"]; @@ -112,8 +114,86 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor outputs[| 1] = nodeValue("Preview", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone) .setVisible(false); + template_guide = [ + ["%d", "Directory"], + ["%1d", "Goes up 1 level"], + ["%n", "File name"], + ["%f", "Frame"], + ["%i", "Array index"], + ]; + export_template = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { + var _tx = _x + ui(10); + var _ty = _y; + var _tw = _w - ui(8); + + var rawpath = inputs[| 1].getValue(,,, true); + if(is_array(rawpath)) rawpath = array_safe_get(rawpath, 0, ""); + + var _ext = inputs[| 9].getValue(,,, true); + var path = pathString(rawpath); + var pathA = pathString(rawpath,, true); + path = string_replace(path, ".png", array_safe_get(inputs[| 9].display_data, _ext, "")); + + draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text); + var _th = ui(12) + string_height_ext(path, -1, _tw - ui(16), true); + draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _tx, _ty, _tw, _th, COLORS.node_composite_bg_blend, 1); + + var lw = 0; + var lx = _tx + ui(8); + var ly = _ty + ui(6); + + draw_set_alpha(0.9); + for( var i = 0, n = array_length(pathA); i < n; i++ ) { + var _txt = pathA[i]; + + if(is_array(_txt)) { + switch(_txt[0]) { + case "d" : draw_set_color(COLORS.widget_text_dec_d); break; + case "n" : draw_set_color(COLORS.widget_text_dec_n); break; + case "f" : draw_set_color(COLORS.widget_text_dec_f); break; + case "i" : draw_set_color(COLORS.widget_text_dec_i); break; + case "ext" : draw_set_color(COLORS._main_text_sub); break; + } + + _txt = _txt[1]; + } else + draw_set_color(COLORS._main_text); + + for( var j = 1; j <= string_length(_txt); j++ ) { + var ch = string_char_at(_txt, j); + var ww = string_width(ch); + + if(lw + ww > _tw - ui(16)) { + lw = 0; + lx = _tx + ui(8); + ly += string_height("M"); + } + + draw_text(lx, ly, ch); + + lw += ww; + lx += ww; + } + } + draw_set_alpha(1); + + var hh = _th + ui(116); + var _cy = _y + _th + ui(8); + for( var i = 0, n = array_length(template_guide); i < n; i++ ) { + var _yy = _cy + ui(20) * i; + + draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text_sub); + draw_text_add(_x + ui(16 + 16), _yy, template_guide[i][0]); + + draw_set_text(f_p1, fa_right, fa_top, COLORS._main_text_sub); + draw_text_add(_x + _w - ui(4 + 16), _yy, template_guide[i][1]); + } + + return hh; + }); + input_display_list = [ - ["Export", false], 0, 1, 2, 4, + ["Export", false], 0, 1, 2, export_template, ["Format ", false], 3, 9, ["Settings", false], 12, 8, 5, 6, 7, 10, 11, ]; @@ -256,12 +336,18 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor PANEL_MENU.setNotiIcon(THEME.noti_icon_tick); } - static pathString = function(path, suff, index = 0) { + static pathString = function(path, index = 0, _array = false) { + var suff = inputs[| 2].getValue(); var form = inputs[| 3].getValue(); var strt = inputs[| 11].getValue(); - var s = "", i = 1, ch, ch_s; + path = string_replace_all(path, "\\", "/"); + + var s = _array? [] : ""; + var i = 1; + var ch, ch_s; var len = string_length(suff); + while(i <= len) { ch = string_char_at(suff, i); @@ -273,40 +359,51 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor ch_s = string_char_at(suff, i); switch(ch_s) { case "f" : + var _txt = ""; var float_str = string_digits(str); if(float_str != "") { var float_val = string_digits(float_str); var str_val = max(float_val - string_length(string(PROJECT.animator.current_frame + strt)), 0); repeat(str_val) - s += "0"; + _txt += "0"; } - - s += string(PROJECT.animator.current_frame + strt); + + _txt += string(PROJECT.animator.current_frame + strt); + if(_array) array_push(s, [ "f", _txt ]); + else s += _txt; res = true; break; case "i" : - s += string(index); + if(_array) array_push(s, [ "i", string(index) ]); + else s += string(index); res = true; break; case "d" : - var dir = filename_dir(path) + "/"; + var dir = filename_dir(path) + "/"; + var _txt = ""; var float_str = string_digits(str); if(float_str != "") { - var float_val = string_digits(float_str); + var float_val = toNumber(string_digits(float_str)) + 1; var dir_s = ""; - var sep = string_splice(dir, "/"); - for(var j = 0; j < array_length(sep) - float_val; j++) { + var sep = string_splice(dir, "/"); + + for(var j = 0; j < array_length(sep) - float_val; j++) dir_s += sep[j] + "/"; - } - s += dir_s; + _txt += dir_s; } else - s += dir; + _txt += dir; + + if(_array) array_push(s, [ "d", _txt ]); + else s += _txt; res = true; break; case "n" : - var ext = filename_ext(path); - s += string_replace(filename_name(path), ext, ""); + var ext = filename_ext(path); + var _txt = string_replace(filename_name(path), ext, ""); + + if(_array) array_push(s, [ "n", _txt ]); + else s += _txt; res = true; break; default : @@ -316,12 +413,14 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor i++; } until(i > string_length(suff) || res); } else { - s += ch; + if(_array) array_push(s, ch); + else s += ch; i++; } } - s += ".png"; + if(_array) array_push(s, ["ext", ".png"]); + else s += ".png"; return s; } @@ -397,9 +496,9 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor p = directory + "/" + string(i) + "/" + string_lead_zero(PROJECT.animator.current_frame, 5) + ".png"; } else { if(is_array(path) && array_length(path) == array_length(surf)) - p = pathString(path[ safe_mod(i, array_length(path)) ], suff, i); + p = pathString(path[ safe_mod(i, array_length(path)) ], i); else - p = pathString(path, suff, i); + p = pathString(path, i); } p = save_surface(_surf, p); @@ -419,7 +518,7 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor if(form == NODE_EXPORT_FORMAT.gif) p = directory + "/" + string_lead_zero(PROJECT.animator.current_frame, 5) + ".png"; else - p = pathString(p, suff); + p = pathString(p); //print("Exporting " + p); p = save_surface(surf, p); @@ -545,9 +644,9 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor for(var i = 0; i < array_length(surf); i++) { temp_path = directory + "/" + string(i) + "/" + "*.png"; if(is_array(path)) - target_path = pathString(path[ safe_mod(i, array_length(path)) ], suff, i); + target_path = pathString(path[ safe_mod(i, array_length(path)) ], i); else - target_path = pathString(path, suff, i); + target_path = pathString(path, i); if(extd == 0) { target_path = string_replace(target_path, ".png", ".gif"); @@ -558,7 +657,7 @@ function Node_Export(_x, _y, _group = noone) : Node(_x, _y, _group) constructor } } } else { - target_path = pathString(path, suff); + target_path = pathString(path); if(extd == 0) { target_path = string_replace(target_path, ".png", ".gif"); diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index d33f4cf9d..4cdcb07c6 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -76,9 +76,7 @@ enum VALUE_DISPLAY { path_array, //Text - export_format, code, - node_title, text_array, //path diff --git a/scripts/panel_graph/panel_graph.gml b/scripts/panel_graph/panel_graph.gml index 22046d286..679a0be32 100644 --- a/scripts/panel_graph/panel_graph.gml +++ b/scripts/panel_graph/panel_graph.gml @@ -102,7 +102,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { toolbar_height = ui(40); - function toCenterNode() { + function toCenterNode() { #region if(!project.active) return; if(ds_list_empty(nodes_list)) { @@ -135,11 +135,11 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { graph_y = round(graph_y); //print(title + ": Center " + string(graph_x) + ", " + string(graph_y)); - } + } #endregion - static initSize = function() { toCenterNode(); } - initSize(); + function initSize() { toCenterNode(); } initSize(); + #region ++++ toolbars ++++ toolbars = [ [ THEME.icon_preview_export, @@ -186,8 +186,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { gs.anchor = ANCHOR.bottom | ANCHOR.left; } ], - ]; + ]; #endregion + #region ++++ hotkeys ++++ addHotkey("Graph", "Add node", "A", MOD_KEY.none, function() { PANEL_GRAPH.callAddDialog(); }); addHotkey("Graph", "Focus content", "F", MOD_KEY.none, function() { PANEL_GRAPH.fullView(); }); addHotkey("Graph", "Preview focusing node", "P", MOD_KEY.none, function() { PANEL_GRAPH.setCurrentPreview(); }); @@ -199,30 +200,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { addHotkey("Graph", "Add vector3", "3", MOD_KEY.none, function() { nodeBuild("Node_Vector3", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); }); addHotkey("Graph", "Add vector4", "4", MOD_KEY.none, function() { nodeBuild("Node_Vector4", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); }); - function addNodeTransform() { - if(ds_list_empty(nodes_select_list)) { - if(node_focus != noone && !ds_list_empty(node_focus.outputs)) { - var _o = node_focus.outputs[| 0]; - if(_o.type == VALUE_TYPE.surface) { - var tr = nodeBuild("Node_Transform", node_focus.x + node_focus.w + 64, node_focus.y); - tr.inputs[| 0].setFrom(_o); - } - } - } else { - for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { - var node = nodes_select_list[| i]; - if(ds_list_empty(node.outputs)) continue; - - var _o = node.outputs[| 0]; - if(_o.type == VALUE_TYPE.surface) { - var tr = nodeBuild("Node_Transform", node.x + node.w + 64, node.y); - tr.inputs[| 0].setFrom(_o); - } - } - } - } - - addHotkey("Graph", "Transform node", "T", MOD_KEY.ctrl, function() { PANEL_GRAPH.addNodeTransform(); }); + addHotkey("Graph", "Transform node", "T", MOD_KEY.ctrl, function() { PANEL_GRAPH.doTransform(); }); addHotkey("Graph", "Select all", "A", MOD_KEY.ctrl, function() { ds_list_clear(nodes_select_list); @@ -267,14 +245,134 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { if(PREF_MAP[? "alt_picker"]) return; PANEL_GRAPH.graph_zooming_key = true; }); + #endregion - function onFocusBegin() { + #region ++++ node setters ++++ + function setCurrentPreview(_node = node_focus) { #region + if(!_node) return; + + PANEL_PREVIEW.setNodePreview(_node); + } #endregion + + function setCurrentExport(_node = node_focus) { #region + if(DEMO) return; + if(!_node) return; + + var _outp = -1; + var _path = -1; + + for( var i = 0; i < ds_list_size(_node.outputs); i++ ) { + if(_node.outputs[| i].type == VALUE_TYPE.path) + _path = _node.outputs[| i]; + if(_node.outputs[| i].type == VALUE_TYPE.surface && _outp == -1) + _outp = _node.outputs[| i]; + } + + if(_outp == -1) return; + + var _export = nodeBuild("Node_Export", _node.x + _node.w + 64, _node.y); + if(_path != -1) + _export.inputs[| 1].setFrom(_path); + + _export.inputs[| 0].setFrom(_outp); + } #endregion + + function setCurrentCanvas(_node = node_focus) { #region + if(!_node) return; + + var _outp = -1; + var surf = -1; + + for( var i = 0; i < ds_list_size(_node.outputs); i++ ) { + if(_node.outputs[| i].type == VALUE_TYPE.surface) { + _outp = _node.outputs[| i]; + var _val = _node.outputs[| i].getValue(); + if(is_array(_val)) + surf = _val[_node.preview_index]; + else + surf = _val; + break; + } + } + + if(_outp == -1) return; + + var _canvas = nodeBuild("Node_Canvas", _node.x + _node.w + 64, _node.y); + + _canvas.inputs[| 0].setValue([surface_get_width(surf), surface_get_height(surf)]); + _canvas.canvas_surface = surface_clone(surf); + _canvas.apply_surface(); + } #endregion + + function setTriggerPreview() { #region + if(node_focus != noone) + node_focus.previewable = !node_focus.previewable; + + var show = false; + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + if(i == 0) show = !nodes_select_list[| i].previewable; + nodes_select_list[| i].previewable = show; + } + } #endregion + + function setTriggerRender() { #region + if(node_focus != noone) + node_focus.renderActive = !node_focus.renderActive; + + var show = false; + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + if(i == 0) show = !nodes_select_list[| i].renderActive; + nodes_select_list[| i].renderActive = show; + } + } #endregion + + function setCurrentCanvasBlend(_node = node_focus) { #region + if(!_node) return; + + var _outp = -1; + var surf = -1; + + for( var i = 0; i < ds_list_size(_node.outputs); i++ ) { + if(_node.outputs[| i].type == VALUE_TYPE.surface) { + _outp = _node.outputs[| i]; + var _val = _node.outputs[| i].getValue(); + if(is_array(_val)) + surf = _val[_node.preview_index]; + else + surf = _val; + break; + } + } + + if(_outp == -1) return; + + var _canvas = nodeBuild("Node_Canvas", _node.x, _node.y + _node.h + 64); + + _canvas.inputs[| 0].setValue([surface_get_width(surf), surface_get_height(surf)]); + _canvas.inputs[| 5].setValue(true); + + var _blend = new Node_Blend(_node.x + _node.w + 64, _node.y, getCurrentContext()); + _blend.inputs[| 0].setFrom(_outp); + _blend.inputs[| 1].setFrom(_canvas.outputs[| 0]); + } #endregion + #endregion + + function getCurrentContext() { #region + if(ds_list_empty(node_context)) return noone; + return node_context[| ds_list_size(node_context) - 1]; + } #endregion + + function getNodeList(cont = getCurrentContext()) { #region + return cont == noone? project.nodes : cont.getNodeList(); + } #endregion + + function onFocusBegin() { #region PANEL_GRAPH = self; PROJECT = project; PANEL_ANIMATION.updatePropertyList(); - } + } #endregion - function stepBegin() { + function stepBegin() { #region var gr_x = graph_x * graph_s; var gr_y = graph_y * graph_s; var m_x = (mx - gr_x) / graph_s; @@ -284,9 +382,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { mouse_grid_x = round(m_x / project.graphGrid.size) * project.graphGrid.size; mouse_grid_y = round(m_y / project.graphGrid.size) * project.graphGrid.size; - } + } #endregion - function focusNode(_node) { + function focusNode(_node) { #region node_focus = _node; if(_node == noone) return; @@ -298,9 +396,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { graph_x = round(graph_x); graph_y = round(graph_y); - } + } #endregion - function fullView() { + function fullView() { #region if(node_focus == noone) { toCenterNode(); return; @@ -311,9 +409,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { graph_x = round(graph_x); graph_y = round(graph_y); - } + } #endregion - function dragGraph() { + function dragGraph() { #region if(graph_dragging) { if(!MOUSE_WRAPPING) { var dx = mx - graph_drag_mx; @@ -429,9 +527,10 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { graph_draggable = true; graph_x = round(graph_x); graph_y = round(graph_y); - } + } #endregion - function drawGrid() { + function drawGrid() { #region + if(!show_grid) return; var gls = project.graphGrid.size; if(graph_s <= 0.15) gls *= 10; @@ -457,9 +556,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { yy += gr_ls; } draw_set_alpha(1); - } + } #endregion - function drawNodes() { + function drawNodes() { #region if(selection_block-- > 0) return; //print("==== DRAW NODES ===="); @@ -658,7 +757,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { }, THEME.copy, ["Graph", "Copy"])); array_push(menu, -1); - array_push(menu, menuItem(__txtx("panel_graph_add_transform", "Add transform"), addNodeTransform, noone, ["Graph", "Transform node"])); + array_push(menu, menuItem(__txtx("panel_graph_add_transform", "Add transform"), doTransform, noone, ["Graph", "Transform node"])); array_push(menu, menuItem(__txtx("panel_graph_canvas", "Canvas"), function(_dat) { return submenuCall(_dat, [ @@ -958,437 +1057,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { #endregion printIf(log, "Draw selection frame : " + string(current_time - t)); t = current_time; - } + } #endregion - function doDuplicate() { - var nodeArray = []; - if(ds_list_empty(nodes_select_list)) { - if(node_focus == noone) return; - nodeArray = [node_focus]; - } else { - for(var i = 0; i < ds_list_size(nodes_select_list); i++) - nodeArray[i] = nodes_select_list[| i]; - } - - var _map = {}; - var _node = []; - for(var i = 0; i < array_length(nodeArray); i++) - SAVE_NODE(_node, nodeArray[i],,,, getCurrentContext()); - _map.nodes = _node; - - APPENDING = true; - CLONING = true; - var _app = __APPEND_MAP(_map); - APPENDING = false; - CLONING = false; - - if(ds_list_size(_app) == 0) { - ds_list_destroy(_app); - return; - } - - var x0 = 99999999; - var y0 = 99999999; - for(var i = 0; i < ds_list_size(_app); i++) { - var _node = _app[| i]; - - x0 = min(x0, _node.x); - y0 = min(y0, _node.y); - } - - node_dragging = _app[| 0]; - node_drag_mx = x0; node_drag_my = y0; - node_drag_sx = x0; node_drag_sy = y0; - node_drag_ox = x0; node_drag_oy = y0; - - ds_list_destroy(nodes_select_list); - nodes_select_list = _app; - } - - function doInstance() { - if(node_focus == noone) return; - if(!struct_has(node_focus, "nodes")) return; - - if(node_focus.instanceBase == noone) { - node_focus.isInstancer = true; - - CLONING = true; - var _type = instanceof(node_focus); - var _node = nodeBuild(_type, x, y); - CLONING = false; - - _node.setInstance(node_focus); - } - - var _nodeNew = _node.clone(); - - node_dragging = _nodeNew; - node_drag_mx = _nodeNew.x; node_drag_my = _nodeNew.y; - node_drag_sx = _nodeNew.x; node_drag_sy = _nodeNew.y; - node_drag_ox = _nodeNew.x; node_drag_oy = _nodeNew.y; - } - - function doCopy() { - clipboard_set_text(""); - - var nodeArray = []; - if(ds_list_empty(nodes_select_list)) { - if(node_focus == noone) return; - nodeArray = [node_focus]; - } else { - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - var _node = nodes_select_list[| i]; - nodeArray[i] = _node; - } - } - - var _map = {}; - var _node = []; - for(var i = 0; i < array_length(nodeArray); i++) - SAVE_NODE(_node, nodeArray[i],,,, getCurrentContext()); - _map.nodes = _node; - - clipboard_set_text(json_stringify_minify(_map)); - } - - function doPaste() { - var txt = clipboard_get_text(); - var _map = json_try_parse(txt, noone); - - if(_map != noone) { - ds_map_clear(APPEND_MAP); - APPENDING = true; - CLONING = true; - var _app = __APPEND_MAP(_map); - APPENDING = false; - CLONING = false; - - if(_app == noone) - return; - - if(ds_list_size(_app) == 0) { - ds_list_destroy(_app); - return; - } - - var x0 = 99999999; - var y0 = 99999999; - for(var i = 0; i < ds_list_size(_app); i++) { - var _node = _app[| i]; - - x0 = min(x0, _node.x); - y0 = min(y0, _node.y); - } - - node_dragging = _app[| 0]; - node_drag_mx = x0; node_drag_my = y0; - node_drag_sx = x0; node_drag_sy = y0; - node_drag_ox = x0; node_drag_oy = y0; - - ds_list_destroy(nodes_select_list); - nodes_select_list = _app; - return; - } - - if(filename_ext(txt) == ".pxc") - APPEND(txt); - else if(filename_ext(txt) == ".pxcc") - APPEND(txt); - else if(filename_ext(txt) == ".png") { - if(file_exists(txt)) { - Node_create_Image_path(0, 0, txt); - return; - } - - var path = DIRECTORY + "temp/url_pasted_" + string(irandom_range(100000, 999999)) + ".png"; - var img = http_get_file(txt, path); - CLONING = true; - var node = Node_create_Image(0, 0); - CLONING = false; - var args = [node, path]; - - global.FILE_LOAD_ASYNC[? img] = [ function(args) { - args[0].inputs[| 0].setValue(args[1]); - args[0].doUpdate(); - }, args]; - } - } - - function doBlend() { - if(ds_list_empty(nodes_select_list)) return; - if(ds_list_size(nodes_select_list) != 2) return; - - var cx = nodes_select_list[| 0].x; - var cy = 0; - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - var _node = nodes_select_list[| i]; - cx = max(cx, _node.x); - cy += _node.y; - } - cx = cx + 160; - cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; - - var _blend = new Node_Blend(cx, cy, getCurrentContext()); - var index = 0; - for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { - var _node = nodes_select_list[| i]; - if(ds_list_size(_node.outputs) == 0) continue; - if(_node.outputs[| 0].type == VALUE_TYPE.surface) { - _blend.inputs[| index].setFrom(_node.outputs[| 0]); - index++; - } - } - - ds_list_clear(nodes_select_list); - } - - function doCompose() { - if(ds_list_empty(nodes_select_list)) return; - - var cx = nodes_select_list[| 0].x; - var cy = 0; - - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - var _node = nodes_select_list[| i]; - cx = max(cx, _node.x); - cy += _node.y; - } - cx = cx + 160; - cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; - - var _compose = nodeBuild("Node_Composite", cx, cy); - - for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { - var _node = nodes_select_list[| i]; - if(ds_list_size(_node.outputs) == 0) continue; - if(_node.outputs[| 0].type == VALUE_TYPE.surface) { - _compose.addInput(_node.outputs[| 0]); - } - } - - ds_list_clear(nodes_select_list); - } - - function doArray() { - if(ds_list_empty(nodes_select_list)) return; - - var cx = nodes_select_list[| 0].x; - var cy = 0; - - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - var _node = nodes_select_list[| i]; - cx = max(cx, _node.x); - cy += _node.y; - } - cx = cx + 160; - cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; - - var _array = nodeBuild("Node_Array", cx, cy); - - for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { - var _node = nodes_select_list[| i]; - if(ds_list_size(_node.outputs) == 0) continue; - _array.addInput(_node.outputs[| 0]); - } - - ds_list_clear(nodes_select_list); - } - - function doGroup() { - if(ds_list_empty(nodes_select_list) && node_focus != noone) - ds_list_add(nodes_select_list, node_focus); - node_focus = noone; - - if(ds_list_empty(nodes_select_list)) return; - - groupNodes(array_create_from_list(nodes_select_list)); - } - - function doUngroup() { - if(node_focus == noone) return; - if(!variable_struct_exists(node_focus, "nodes")) return; - if(!node_focus.ungroupable) return; - - upgroupNode(node_focus); - } - - function doLoop() { - if(ds_list_empty(nodes_select_list) && node_focus != noone) - ds_list_add(nodes_select_list, node_focus); - - if(ds_list_empty(nodes_select_list)) return; - - var cx = 0; - var cy = 0; - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - var _node = nodes_select_list[| i]; - cx += _node.x; - cy += _node.y; - } - cx = round(cx / ds_list_size(nodes_select_list) / 32) * 32; - cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; - - var _group = new Node_Iterate(cx, cy, getCurrentContext()); - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - _group.add(nodes_select_list[| i]); - } - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - nodes_select_list[| i].checkConnectGroup("loop"); - } - - ds_list_clear(nodes_select_list); - } - - function doFrame() { - var x0 = 999999, y0 = 999999, x1 = -999999, y1 = -999999; - - if(ds_list_empty(nodes_select_list)) { - if(node_focus != noone) { - x0 = node_focus.x; - y0 = node_focus.y; - x1 = node_focus.x + node_focus.w; - y1 = node_focus.y + node_focus.h; - } else - return; - } else { - for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { - var _node = nodes_select_list[| i]; - x0 = min(x0, _node.x); - y0 = min(y0, _node.y); - x1 = max(x1, _node.x + _node.w); - y1 = max(y1, _node.y + _node.h); - } - } - - x0 -= 64; - y0 -= 64; - x1 += 64; - y1 += 64; - - var f = new Node_Frame(x0, y0, getCurrentContext()); - f.inputs[| 0].setValue([x1 - x0, y1 - y0]); - } - - function doDelete(_merge = false) { - if(node_focus != noone && node_focus.manual_deletable) - nodeDelete(node_focus, _merge); - - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - if(nodes_select_list[| i].manual_deletable) - nodeDelete(nodes_select_list[| i], _merge); - } - ds_list_clear(nodes_select_list); - } - - function setCurrentPreview(_node = node_focus) { - if(!_node) return; - - PANEL_PREVIEW.setNodePreview(_node); - } - - function setCurrentExport(_node = node_focus) { - if(DEMO) return; - if(!_node) return; - - var _outp = -1; - var _path = -1; - - for( var i = 0; i < ds_list_size(_node.outputs); i++ ) { - if(_node.outputs[| i].type == VALUE_TYPE.path) - _path = _node.outputs[| i]; - if(_node.outputs[| i].type == VALUE_TYPE.surface && _outp == -1) - _outp = _node.outputs[| i]; - } - - if(_outp == -1) return; - - var _export = nodeBuild("Node_Export", _node.x + _node.w + 64, _node.y); - if(_path != -1) - _export.inputs[| 1].setFrom(_path); - - _export.inputs[| 0].setFrom(_outp); - } - - function setCurrentCanvas(_node = node_focus) { - if(!_node) return; - - var _outp = -1; - var surf = -1; - - for( var i = 0; i < ds_list_size(_node.outputs); i++ ) { - if(_node.outputs[| i].type == VALUE_TYPE.surface) { - _outp = _node.outputs[| i]; - var _val = _node.outputs[| i].getValue(); - if(is_array(_val)) - surf = _val[_node.preview_index]; - else - surf = _val; - break; - } - } - - if(_outp == -1) return; - - var _canvas = nodeBuild("Node_Canvas", _node.x + _node.w + 64, _node.y); - - _canvas.inputs[| 0].setValue([surface_get_width(surf), surface_get_height(surf)]); - _canvas.canvas_surface = surface_clone(surf); - _canvas.apply_surface(); - } - - function setTriggerPreview() { - if(node_focus != noone) - node_focus.previewable = !node_focus.previewable; - - var show = false; - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - if(i == 0) show = !nodes_select_list[| i].previewable; - nodes_select_list[| i].previewable = show; - } - } - - function setTriggerRender() { - if(node_focus != noone) - node_focus.renderActive = !node_focus.renderActive; - - var show = false; - for(var i = 0; i < ds_list_size(nodes_select_list); i++) { - if(i == 0) show = !nodes_select_list[| i].renderActive; - nodes_select_list[| i].renderActive = show; - } - } - - function setCurrentCanvasBlend(_node = node_focus) { - if(!_node) return; - - var _outp = -1; - var surf = -1; - - for( var i = 0; i < ds_list_size(_node.outputs); i++ ) { - if(_node.outputs[| i].type == VALUE_TYPE.surface) { - _outp = _node.outputs[| i]; - var _val = _node.outputs[| i].getValue(); - if(is_array(_val)) - surf = _val[_node.preview_index]; - else - surf = _val; - break; - } - } - - if(_outp == -1) return; - - var _canvas = nodeBuild("Node_Canvas", _node.x, _node.y + _node.h + 64); - - _canvas.inputs[| 0].setValue([surface_get_width(surf), surface_get_height(surf)]); - _canvas.inputs[| 5].setValue(true); - - var _blend = new Node_Blend(_node.x + _node.w + 64, _node.y, getCurrentContext()); - _blend.inputs[| 0].setFrom(_outp); - _blend.inputs[| 1].setFrom(_canvas.outputs[| 0]); - } - - function drawJunctionConnect() { + function drawJunctionConnect() { #region if(value_dragging) { var xx = value_dragging.x; var yy = value_dragging.y; @@ -1498,9 +1169,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { for(var i = 0; i < ds_list_size(nodes_list); i++) nodes_list[| i].drawJunctionNames(gr_x, gr_y, mx, my, graph_s); #endregion - } + } #endregion - function callAddDialog() { + function callAddDialog() { #region with(dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8)) { node_target_x = other.mouse_grid_x; node_target_y = other.mouse_grid_y; @@ -1509,9 +1180,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { resetPosition(); alarm[0] = 1; } - } + } #endregion - function drawContext() { + function drawContext() { #region draw_set_text(f_p0, fa_left, fa_center); var xx = ui(16), tt, tw, th; var bh = toolbar_height - ui(12); @@ -1564,9 +1235,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { xx += tw; xx += ui(32); } - } + } #endregion - function drawToolBar() { + function drawToolBar() { #region toolbar_height = ui(40); var ty = h - toolbar_height; @@ -1593,9 +1264,10 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { draw_set_color(COLORS.panel_toolbar_separator); draw_line_width(tbx + ui(12), tby - toolbar_height / 2 + ui(8), tbx + ui(12), tby + toolbar_height / 2 - ui(8), 2); - } + } #endregion - static drawMinimap = function() { + function drawMinimap() { #region + if(!minimap_show) return; var mx1 = w - ui(8); var my1 = h - toolbar_height - ui(8); var mx0 = mx1 - minimap_w; @@ -1704,9 +1376,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { } } else draw_sprite_ui(THEME.node_resize, 0, mx0 + ui(2), my0 + ui(2), 0.5, 0.5, 180, c_white, 0.3); - } + } #endregion - function drawContextFrame() { + function drawContextFrame() { #region if(!context_framing) return; context_frame_progress = lerp_float(context_frame_progress, 1, 5); if(context_frame_progress == 1) @@ -1730,9 +1402,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { draw_set_alpha(0.5); draw_roundrect_ext(frm_x0, frm_y0, frm_x1, frm_y1, THEME_VALUE.panel_corner_radius, THEME_VALUE.panel_corner_radius, true); draw_set_alpha(1); - } + } #endregion - function addContext(node) { + function addContext(node) { #region title = node.display_name == ""? node.name : node.display_name; var _node = node.getNodeBase(); @@ -1747,9 +1419,9 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { toCenterNode(); PANEL_ANIMATION.updatePropertyList(); - } + } #endregion - function setContextFrame(dirr, node) { + function setContextFrame(dirr, node) { #region context_framing = true; context_frame_direct = dirr; context_frame_progress = 0; @@ -1757,51 +1429,23 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { context_frame_sy = h / 2 - 8; context_frame_ex = context_frame_sx + 16; context_frame_ey = context_frame_sy + 16; - } + } #endregion - function getCurrentContext() { - if(ds_list_empty(node_context)) return noone; - return node_context[| ds_list_size(node_context) - 1]; - } - - function getNodeList(cont = getCurrentContext()) { - return cont == noone? project.nodes : cont.getNodeList(); - } - - function dropFile(path) { - if(node_hovering && node_hovering.on_dragdrop_file != -1) - return node_hovering.on_dragdrop_file(path); - return false; - } - - function drawContent(panel) { + function drawContent(panel) { #region >>>>>>>>>>>>>>>>>>>> MAIN DRAW <<<<<<<<<<<<<<<<<<<< if(!project.active) return; - - dragGraph(); - if(project.path == "") title = "New project"; else title = filename_name_only(project.path); title += project.modified? "*" : ""; - - var bg = COLORS.panel_bg_clear; - var context = instanceof(getCurrentContext()); - switch(context) { - case "Node_Group" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_collection, 0.05); break; - case "Node_Iterate" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_loop, 0.05); break; - case "Node_Iterate_Each" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_loop, 0.05); break; - case "Node_VFX_Group" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_vfx, 0.05); break; - case "Node_Feedback" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_feedback, 0.05); break; - case "Node_Rigid_Group" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_simulation, 0.05); break; - case "Node_Fluid_Group" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_fluid, 0.05); break; - case "Node_Strand_Group" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_strand, 0.05); break; - case "Node_Pixel_Builder" : bg = merge_color(COLORS.panel_bg_clear, COLORS.node_blend_feedback, 0.05); break; - } - draw_clear(bg); - if(show_grid) drawGrid(); + dragGraph(); + + var context = getCurrentContext(); + var bg = context == noone? COLORS.panel_bg_clear : merge_color(COLORS.panel_bg_clear, context.color, 0.05); + draw_clear(bg); + drawGrid(); draw_set_text(f_p0, fa_right, fa_top, COLORS._main_text_sub); - draw_text(w - ui(8), ui(8), "x" + string(graph_s_to)); + draw_text(w - ui(8), ui(8), $"x{graph_s_to}"); drawNodes(); drawJunctionConnect(); @@ -1809,17 +1453,16 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { mouse_on_graph = true; drawToolBar(); - if(minimap_show) - drawMinimap(); + drawMinimap(); if(pFOCUS && node_focus) node_focus.focusStep(); if(UPDATE == RENDER_TYPE.full) draw_text(w - ui(8), ui(28), __txtx("panel_graph_rendering", "Rendering") + "..."); - else if(UPDATE == RENDER_TYPE.full) + else if(UPDATE == RENDER_TYPE.partial) draw_text(w - ui(8), ui(28), __txtx("panel_graph_rendering_partial", "Rendering partial") + "..."); - if(DRAGGING && pHOVER) { + if(DRAGGING && pHOVER) { #region file dropping if(node_hovering && node_hovering.droppable(DRAGGING)) { node_hovering.draw_droppable = true; if(mouse_release(mb_left)) @@ -1829,13 +1472,364 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { if(mouse_release(mb_left)) checkDropItem(); } - } + } #endregion graph_dragging_key = false; graph_zooming_key = false; - } + } #endregion - static checkDropItem = function() { + #region ++++ node manipulation ++++ + function doTransform() { #region + if(ds_list_empty(nodes_select_list)) { + if(node_focus != noone && !ds_list_empty(node_focus.outputs)) { + var _o = node_focus.outputs[| 0]; + if(_o.type == VALUE_TYPE.surface) { + var tr = nodeBuild("Node_Transform", node_focus.x + node_focus.w + 64, node_focus.y); + tr.inputs[| 0].setFrom(_o); + } + } + } else { + for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { + var node = nodes_select_list[| i]; + if(ds_list_empty(node.outputs)) continue; + + var _o = node.outputs[| 0]; + if(_o.type == VALUE_TYPE.surface) { + var tr = nodeBuild("Node_Transform", node.x + node.w + 64, node.y); + tr.inputs[| 0].setFrom(_o); + } + } + } + } #endregion + + function doDuplicate() { #region + var nodeArray = []; + if(ds_list_empty(nodes_select_list)) { + if(node_focus == noone) return; + nodeArray = [node_focus]; + } else { + for(var i = 0; i < ds_list_size(nodes_select_list); i++) + nodeArray[i] = nodes_select_list[| i]; + } + + var _map = {}; + var _node = []; + for(var i = 0; i < array_length(nodeArray); i++) + SAVE_NODE(_node, nodeArray[i],,,, getCurrentContext()); + _map.nodes = _node; + + APPENDING = true; + CLONING = true; + var _app = __APPEND_MAP(_map); + APPENDING = false; + CLONING = false; + + if(ds_list_size(_app) == 0) { + ds_list_destroy(_app); + return; + } + + var x0 = 99999999; + var y0 = 99999999; + for(var i = 0; i < ds_list_size(_app); i++) { + var _node = _app[| i]; + + x0 = min(x0, _node.x); + y0 = min(y0, _node.y); + } + + node_dragging = _app[| 0]; + node_drag_mx = x0; node_drag_my = y0; + node_drag_sx = x0; node_drag_sy = y0; + node_drag_ox = x0; node_drag_oy = y0; + + ds_list_destroy(nodes_select_list); + nodes_select_list = _app; + } #endregion + + function doInstance() { #region + if(node_focus == noone) return; + if(!struct_has(node_focus, "nodes")) return; + + if(node_focus.instanceBase == noone) { + node_focus.isInstancer = true; + + CLONING = true; + var _type = instanceof(node_focus); + var _node = nodeBuild(_type, x, y); + CLONING = false; + + _node.setInstance(node_focus); + } + + var _nodeNew = _node.clone(); + + node_dragging = _nodeNew; + node_drag_mx = _nodeNew.x; node_drag_my = _nodeNew.y; + node_drag_sx = _nodeNew.x; node_drag_sy = _nodeNew.y; + node_drag_ox = _nodeNew.x; node_drag_oy = _nodeNew.y; + } #endregion + + function doCopy() { #region + clipboard_set_text(""); + + var nodeArray = []; + if(ds_list_empty(nodes_select_list)) { + if(node_focus == noone) return; + nodeArray = [node_focus]; + } else { + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + var _node = nodes_select_list[| i]; + nodeArray[i] = _node; + } + } + + var _map = {}; + var _node = []; + for(var i = 0; i < array_length(nodeArray); i++) + SAVE_NODE(_node, nodeArray[i],,,, getCurrentContext()); + _map.nodes = _node; + + clipboard_set_text(json_stringify_minify(_map)); + } #endregion + + function doPaste() { #region + var txt = clipboard_get_text(); + var _map = json_try_parse(txt, noone); + + if(_map != noone) { + ds_map_clear(APPEND_MAP); + APPENDING = true; + CLONING = true; + var _app = __APPEND_MAP(_map); + APPENDING = false; + CLONING = false; + + if(_app == noone) + return; + + if(ds_list_size(_app) == 0) { + ds_list_destroy(_app); + return; + } + + var x0 = 99999999; + var y0 = 99999999; + for(var i = 0; i < ds_list_size(_app); i++) { + var _node = _app[| i]; + + x0 = min(x0, _node.x); + y0 = min(y0, _node.y); + } + + node_dragging = _app[| 0]; + node_drag_mx = x0; node_drag_my = y0; + node_drag_sx = x0; node_drag_sy = y0; + node_drag_ox = x0; node_drag_oy = y0; + + ds_list_destroy(nodes_select_list); + nodes_select_list = _app; + return; + } + + if(filename_ext(txt) == ".pxc") + APPEND(txt); + else if(filename_ext(txt) == ".pxcc") + APPEND(txt); + else if(filename_ext(txt) == ".png") { + if(file_exists(txt)) { + Node_create_Image_path(0, 0, txt); + return; + } + + var path = DIRECTORY + "temp/url_pasted_" + string(irandom_range(100000, 999999)) + ".png"; + var img = http_get_file(txt, path); + CLONING = true; + var node = Node_create_Image(0, 0); + CLONING = false; + var args = [node, path]; + + global.FILE_LOAD_ASYNC[? img] = [ function(args) { + args[0].inputs[| 0].setValue(args[1]); + args[0].doUpdate(); + }, args]; + } + } #endregion + + function doBlend() { #region + if(ds_list_empty(nodes_select_list)) return; + if(ds_list_size(nodes_select_list) != 2) return; + + var cx = nodes_select_list[| 0].x; + var cy = 0; + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + var _node = nodes_select_list[| i]; + cx = max(cx, _node.x); + cy += _node.y; + } + cx = cx + 160; + cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; + + var _blend = new Node_Blend(cx, cy, getCurrentContext()); + var index = 0; + for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { + var _node = nodes_select_list[| i]; + if(ds_list_size(_node.outputs) == 0) continue; + if(_node.outputs[| 0].type == VALUE_TYPE.surface) { + _blend.inputs[| index].setFrom(_node.outputs[| 0]); + index++; + } + } + + ds_list_clear(nodes_select_list); + } #endregion + + function doCompose() { #region + if(ds_list_empty(nodes_select_list)) return; + + var cx = nodes_select_list[| 0].x; + var cy = 0; + + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + var _node = nodes_select_list[| i]; + cx = max(cx, _node.x); + cy += _node.y; + } + cx = cx + 160; + cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; + + var _compose = nodeBuild("Node_Composite", cx, cy); + + for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { + var _node = nodes_select_list[| i]; + if(ds_list_size(_node.outputs) == 0) continue; + if(_node.outputs[| 0].type == VALUE_TYPE.surface) { + _compose.addInput(_node.outputs[| 0]); + } + } + + ds_list_clear(nodes_select_list); + } #endregion + + function doArray() { #region + if(ds_list_empty(nodes_select_list)) return; + + var cx = nodes_select_list[| 0].x; + var cy = 0; + + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + var _node = nodes_select_list[| i]; + cx = max(cx, _node.x); + cy += _node.y; + } + cx = cx + 160; + cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; + + var _array = nodeBuild("Node_Array", cx, cy); + + for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { + var _node = nodes_select_list[| i]; + if(ds_list_size(_node.outputs) == 0) continue; + _array.addInput(_node.outputs[| 0]); + } + + ds_list_clear(nodes_select_list); + } #endregion + + function doGroup() { #region + if(ds_list_empty(nodes_select_list) && node_focus != noone) + ds_list_add(nodes_select_list, node_focus); + node_focus = noone; + + if(ds_list_empty(nodes_select_list)) return; + + groupNodes(array_create_from_list(nodes_select_list)); + } #endregion + + function doUngroup() { #region + if(node_focus == noone) return; + if(!variable_struct_exists(node_focus, "nodes")) return; + if(!node_focus.ungroupable) return; + + upgroupNode(node_focus); + } #endregion + + function doLoop() { #region + if(ds_list_empty(nodes_select_list) && node_focus != noone) + ds_list_add(nodes_select_list, node_focus); + + if(ds_list_empty(nodes_select_list)) return; + + var cx = 0; + var cy = 0; + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + var _node = nodes_select_list[| i]; + cx += _node.x; + cy += _node.y; + } + cx = round(cx / ds_list_size(nodes_select_list) / 32) * 32; + cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32; + + var _group = new Node_Iterate(cx, cy, getCurrentContext()); + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + _group.add(nodes_select_list[| i]); + } + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + nodes_select_list[| i].checkConnectGroup("loop"); + } + + ds_list_clear(nodes_select_list); + } #endregion + + function doFrame() { #region + var x0 = 999999, y0 = 999999, x1 = -999999, y1 = -999999; + + if(ds_list_empty(nodes_select_list)) { + if(node_focus != noone) { + x0 = node_focus.x; + y0 = node_focus.y; + x1 = node_focus.x + node_focus.w; + y1 = node_focus.y + node_focus.h; + } else + return; + } else { + for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) { + var _node = nodes_select_list[| i]; + x0 = min(x0, _node.x); + y0 = min(y0, _node.y); + x1 = max(x1, _node.x + _node.w); + y1 = max(y1, _node.y + _node.h); + } + } + + x0 -= 64; + y0 -= 64; + x1 += 64; + y1 += 64; + + var f = new Node_Frame(x0, y0, getCurrentContext()); + f.inputs[| 0].setValue([x1 - x0, y1 - y0]); + } #endregion + + function doDelete(_merge = false) { #region + if(node_focus != noone && node_focus.manual_deletable) + nodeDelete(node_focus, _merge); + + for(var i = 0; i < ds_list_size(nodes_select_list); i++) { + if(nodes_select_list[| i].manual_deletable) + nodeDelete(nodes_select_list[| i], _merge); + } + ds_list_clear(nodes_select_list); + } #endregion + #endregion + + function dropFile(path) { #region + if(node_hovering && node_hovering.on_dragdrop_file != -1) + return node_hovering.on_dragdrop_file(path); + return false; + } #endregion + + static checkDropItem = function() { #region var node = noone; switch(DRAGGING.type) { @@ -1920,16 +1914,16 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { for( var i = 0; i < ds_list_size(node.outputs); i++ ) if(DRAGGING.from.setFrom(node.outputs[| i])) break; } - } + } #endregion - static bringNodeToFront = function(node) { + static bringNodeToFront = function(node) { #region if(!ds_list_exist(nodes_list, node)) return; ds_list_remove(nodes_list, node); ds_list_add(nodes_list, node); - } + } #endregion - function close() { + function close() { #region var panels = findPanels("Panel_Graph"); for( var i = 0, n = array_length(panels); i < n; i++ ) { if(panels[i] == self) continue; @@ -1946,5 +1940,5 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor { var dia = dialogCall(o_dialog_save); dia.project = project; - } + } #endregion } \ No newline at end of file diff --git a/scripts/panel_inspector/panel_inspector.gml b/scripts/panel_inspector/panel_inspector.gml index 13eb274e7..b546b5eda 100644 --- a/scripts/panel_inspector/panel_inspector.gml +++ b/scripts/panel_inspector/panel_inspector.gml @@ -642,9 +642,10 @@ function Panel_Inspector() : PanelContent() constructor { tb_node_name.font = f_h5; tb_node_name.hide = true; tb_node_name.setFocusHover(pFOCUS, pHOVER); - tb_node_name.align = fa_center; + tb_node_name.align = fa_center; + tb_node_name.format = TEXT_AREA_FORMAT.node_title; var txt = inspecting.display_name == ""? inspecting.name : inspecting.display_name; - tb_node_name.draw(ui(64), ui(14), w - ui(128), ui(32), txt, [mx, my], VALUE_DISPLAY.node_title); + tb_node_name.draw(ui(64), ui(14), w - ui(128), ui(32), txt, [mx, my]); draw_set_text(f_p1, fa_center, fa_center, COLORS._main_text_sub); draw_text_add(w / 2 + ui(8), ui(56), inspecting.name); diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index a338215da..59e72a03a 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -5,7 +5,7 @@ function Panel_Preview() : PanelContent() constructor { last_focus = noone; - static initSize = function() { + function initSize() { canvas_x = w / 2; canvas_y = h / 2; } @@ -73,6 +73,9 @@ function Panel_Preview() : PanelContent() constructor { tileMode = 0; + tb_framerate = new textBox(TEXTBOX_INPUT.number, function(val) { preview_rate = real(val); }); + + #region ++++ toolbars & actions ++++ toolbar_height = ui(40); toolbars = [ [ @@ -149,9 +152,9 @@ function Panel_Preview() : PanelContent() constructor { ], ] + #endregion - tb_framerate = new textBox(TEXTBOX_INPUT.number, function(val) { preview_rate = real(val); }); - + #region ++++ hotkey ++++ addHotkey("Preview", "Focus content", "F", MOD_KEY.none, function() { PANEL_PREVIEW.fullView(); }); addHotkey("Preview", "Save current frame", "S", MOD_KEY.shift, function() { PANEL_PREVIEW.saveCurrentFrame(); }); addHotkey("Preview", "Save all current frame", -1, MOD_KEY.none, function() { PANEL_PREVIEW.saveAllCurrentFrames(); }); @@ -166,28 +169,29 @@ function Panel_Preview() : PanelContent() constructor { if(PREF_MAP[? "alt_picker"]) return; PANEL_PREVIEW.canvas_zooming_key = true; }); + #endregion - function setNodePreview(node) { + function setNodePreview(node) { #region if(resetViewOnDoubleClick) do_fullView = true; preview_node[splitView? splitSelection : 0] = node; - } + } #endregion - function removeNodePreview(node) { + function removeNodePreview(node) { #region if(preview_node[0] == node) preview_node[0] = noone; if(preview_node[1] == node) preview_node[1] = noone; - } + } #endregion - function resetNodePreview() { + function resetNodePreview() { #region preview_node = [ noone, noone ]; - } + } #endregion function getNodePreview() { return preview_node[splitView? splitSelection : 0]; } function getNodePreviewSurface() { return preview_surface[splitView? splitSelection : 0]; } function getNodePreviewSequence() { return preview_sequence[splitView? splitSelection : 0]; } - function getPreviewData() { + function getPreviewData() { #region preview_surface = [ 0, 0 ]; preview_sequence = [ 0, 0 ]; @@ -227,11 +231,11 @@ function Panel_Preview() : PanelContent() constructor { canvas_w = surface_get_width(prevS); canvas_h = surface_get_height(prevS); } - } + } #endregion function onFocusBegin() { PANEL_PREVIEW = self; } - function dragCanvas() { + function dragCanvas() { #region if(canvas_dragging) { if(!MOUSE_WRAPPING) { var dx = mx - canvas_drag_mx; @@ -322,9 +326,9 @@ function Panel_Preview() : PanelContent() constructor { canvas_dragging_key = false; canvas_zooming_key = false; canvas_hover = point_in_rectangle(mx, my, 0, toolbar_height, w, h - toolbar_height); - } + } #endregion - function fullView() { + function fullView() { #region var node = getNodePreview(); if(node == noone) { canvas_s = 1; @@ -345,18 +349,18 @@ function Panel_Preview() : PanelContent() constructor { canvas_s = ss; canvas_x = w / 2 - bbox.w * canvas_s / 2 - bbox.x0 * canvas_s + (tool_side_drawing * 40 / 2); canvas_y = h / 2 - bbox.h * canvas_s / 2 - bbox.y0 * canvas_s; - } + } #endregion - sbChannel = new scrollBox([], function(index) { + sbChannel = new scrollBox([], function(index) { #region var node = getNodePreview(); if(node == noone) return; node.preview_channel = array_safe_get(sbChannelIndex, index); - }); + }); #endregion sbChannelIndex = []; sbChannel.align = fa_left; - function drawNodeChannel(_x, _y) { + function drawNodeChannel(_x, _y) { #region var _node = getNodePreview(); if(_node == noone) return; if(ds_list_size(_node.outputs) < 2) return; @@ -381,16 +385,9 @@ function Panel_Preview() : PanelContent() constructor { sbChannel.draw(_x - ww, _y - hh / 2, ww, hh, currName, [mx, my], x, y); right_menu_y += ui(40); - } + } #endregion - /** - * Function Description - * @param {Struct.Node} node Description - * @param {any*} psx Description - * @param {any*} psy Description - * @param {any*} ss Description - */ - function drawOnionSkin(node, psx, psy, ss) { + function drawOnionSkin(node, psx, psy, ss) { #region var _surf = preview_surface[0]; var _rang = PROJECT.onion_skin.range; @@ -423,9 +420,9 @@ function Panel_Preview() : PanelContent() constructor { } if(_top) draw_surface_ext_safe(_surf, psx, psy, ss, ss); - } + } #endregion - function drawNodePreview() { + function drawNodePreview() { #region var ss = canvas_s; var psx = 0, psy = 0; var psw = 0, psh = 0; @@ -590,9 +587,9 @@ function Panel_Preview() : PanelContent() constructor { draw_set_color(COLORS.panel_preview_surface_outline); draw_rectangle(psx, psy, psx + pswd - 1, psy + pshd - 1, true); } - } + } #endregion - function drawPreviewOverlay() { + function drawPreviewOverlay() { #region right_menu_y = toolbar_height - ui(4); toolbar_draw = false; @@ -705,12 +702,12 @@ function Panel_Preview() : PanelContent() constructor { } draw_sprite_ui_uniform(THEME.sequence_control, 0, bx + ui(20), by + ui(20), 1, COLORS._main_accent, .75); } - } + } #endregion tool_hovering = false; tool_side_drawing = false; - function drawNodeTools(active, _node) { + function drawNodeTools(active, _node) { #region var _mx = mx; var _my = my; var isHover = pHOVER && mouse_on_preview; @@ -823,9 +820,9 @@ function Panel_Preview() : PanelContent() constructor { } } else tool_current = noone; - } + } #endregion - function drawToolBar(_node) { + function drawToolBar(_node) { #region toolbar_height = ui(40); var ty = h - toolbar_height; //draw_sprite_stretched_ext(THEME.toolbar_shadow, 0, 0, ty - 12 + 4, w, 12, c_white, 0.5); @@ -942,9 +939,9 @@ function Panel_Preview() : PanelContent() constructor { draw_set_color(COLORS.panel_toolbar_separator); draw_line_width(tbx + ui(12), tby - toolbar_height / 2 + ui(8), tbx + ui(12), tby + toolbar_height / 2 - ui(8), 2); drawNodeChannel(tbx, tby); - } + } #endregion - function drawSplitView() { + function drawSplitView() { #region if(splitView == 0) return; draw_set_color(COLORS.panel_preview_split_line); @@ -1004,9 +1001,9 @@ function Panel_Preview() : PanelContent() constructor { splitSelection = 1; } } - } + } #endregion - function drawContent(panel) { + function drawContent(panel) { #region >>>>>>>>>>>>>>>>>>>> MAIN DRAW <<<<<<<<<<<<<<<<<<<< mouse_on_preview = pHOVER && point_in_rectangle(mx, my, 0, toolbar_height, w, h - toolbar_height); draw_clear(COLORS.panel_bg_clear); @@ -1056,9 +1053,9 @@ function Panel_Preview() : PanelContent() constructor { drawSplitView(); drawToolBar(tool); - } + } #endregion - function copyCurrentFrame() { + function copyCurrentFrame() { #region var prevS = getNodePreviewSurface(); if(!is_surface(prevS)) return; @@ -1075,9 +1072,9 @@ function Panel_Preview() : PanelContent() constructor { surface_free(s); clipboard_set_bitmap(buffer_get_address(buff), surface_get_width(prevS), surface_get_height(prevS)); - } + } #endregion - function saveCurrentFrame() { + function saveCurrentFrame() { #region var prevS = getNodePreviewSurface(); if(!is_surface(prevS)) return; @@ -1087,9 +1084,9 @@ function Panel_Preview() : PanelContent() constructor { if(filename_ext(path) != ".png") path += ".png"; surface_save_safe(prevS, path); - } + } #endregion - function saveAllCurrentFrames() { + function saveAllCurrentFrames() { #region var path = get_save_filename(".png", "export"); key_release(); if(path == "") return; @@ -1106,5 +1103,5 @@ function Panel_Preview() : PanelContent() constructor { surface_save_safe(prev, _name); ind++; } - } + } #endregion } \ No newline at end of file diff --git a/scripts/textArea/textArea.gml b/scripts/textArea/textArea.gml index 82c316ca5..88f85e653 100644 --- a/scripts/textArea/textArea.gml +++ b/scripts/textArea/textArea.gml @@ -1,7 +1,9 @@ enum TEXT_AREA_FORMAT { _default, code, - delimiter + delimiter, + path_template, + node_title, } function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onModify, _extras) constructor { @@ -514,11 +516,13 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod _str = _input_text_line[i]; if(format == TEXT_AREA_FORMAT._default) - draw_text(ch_x, ch_y, _str); + draw_text_add(ch_x, ch_y, _str); else if(format == TEXT_AREA_FORMAT.code) draw_code(ch_x, ch_y, _str); else if(format == TEXT_AREA_FORMAT.delimiter) draw_text_delimiter(ch_x, ch_y, _str); + else if(format == TEXT_AREA_FORMAT.path_template) + draw_text_path(ch_x, ch_y, _str); ch_y += line_get_height(); } diff --git a/scripts/textBox/textBox.gml b/scripts/textBox/textBox.gml index a64855106..2d6a4a33f 100644 --- a/scripts/textBox/textBox.gml +++ b/scripts/textBox/textBox.gml @@ -9,6 +9,7 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi font = noone; color = COLORS._main_text; boxColor = c_white; + format = TEXT_AREA_FORMAT._default; no_empty = true; auto_update = false; @@ -22,8 +23,8 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi starting_char = 1; _current_text = ""; - _input_text = ""; - _last_text = ""; + _input_text = ""; + _last_text = ""; current_value = ""; cursor = 0; @@ -226,61 +227,19 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi apply(); } - static display_text = function(_x, _y, _text, _w, _format, _m = -1) { + static display_text = function(_x, _y, _text, _w, _m = -1) { _text = string_real(_text); BLEND_OVERRIDE; if(!interactable) draw_set_alpha(0.5); - switch(_format) { - case VALUE_DISPLAY._default : + switch(format) { + case TEXT_AREA_FORMAT._default : draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color); - draw_text(_x + disp_x, _y, _text); + draw_text_add(_x + disp_x, _y, _text); break; - case VALUE_DISPLAY.export_format : + case TEXT_AREA_FORMAT.node_title : draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color); - var _x0 = _x + disp_x, ch = "", len = string_length(_text), i = 1; - var cc = draw_get_color(); - var str = "", _comm = false; - - while(i <= len) { - ch = string_char_at(_text, i); - - if(ch == "%") - _comm = true; - - if(!_comm) { - draw_text(_x0, 0, ch); - _x0 += string_width(ch); - } else { - str += ch; - switch(ch) { - case "d" : draw_set_color(COLORS.widget_text_dec_d); break; - case "n" : draw_set_color(COLORS.widget_text_dec_n); break; - case "e" : draw_set_color(COLORS.widget_text_dec_e); break; - case "f" : draw_set_color(COLORS.widget_text_dec_f); break; - case "i" : draw_set_color(COLORS.widget_text_dec_i); break; - } - - switch(ch) { - case "d" : case "n" : case "e" : case "f" : case "i" : - draw_text(_x0, 0, str); - _x0 += string_width(str); - _comm = false; - str = ""; - - draw_set_color(cc); - break; - } - } - - i++; - } - - draw_text(_x0, _y, str); - break; - case VALUE_DISPLAY.node_title : - draw_set_text(font == noone? f_p0 : font, fa_left, fa_top, color); - draw_text(_x + disp_x, _y, _text); + draw_text_add(_x + disp_x, _y, _text); break; } @@ -318,10 +277,10 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi } static drawParam = function(params) { - return draw(params.x, params.y, params.w, params.h, params.data, params.m,, params.halign, params.valign); + return draw(params.x, params.y, params.w, params.h, params.data, params.m, params.halign, params.valign); } - static draw = function(_x, _y, _w, _h, _text = "", _m = mouse_ui, _format = VALUE_DISPLAY._default, halign = fa_left, valign = fa_top) { + static draw = function(_x, _y, _w, _h, _text = "", _m = mouse_ui, halign = fa_left, valign = fa_top) { x = _x; y = _y; w = _w; @@ -496,7 +455,7 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi surface_set_target(text_surface); DRAW_CLEAR - display_text(tx - tb_surf_x, _h / 2 - th / 2, txt, _w - ui(4), _format, _mx); + display_text(tx - tb_surf_x, _h / 2 - th / 2, txt, _w - ui(4), _mx); surface_reset_target(); draw_surface(text_surface, tb_surf_x, tb_surf_y); @@ -560,7 +519,7 @@ function textBox(_input, _onModify, _extras = noone) : textInput(_input, _onModi //draw_set_color(c_black); //draw_line(0, _h / 2 - th / 2, 9999, _h / 2 - th / 2); - display_text(tx - tb_surf_x, _h / 2 - th / 2, _display_text, _w - ui(4), _format); + display_text(tx - tb_surf_x, _h / 2 - th / 2, _display_text, _w - ui(4)); surface_reset_target(); draw_surface(text_surface, tb_surf_x, tb_surf_y); }