From 31acbf4ee700daf82f5845ebc251e40a9936ba4f Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sun, 26 Jan 2025 09:07:45 +0700 Subject: [PATCH] [Export Graph] Fix frame not rendering. --- datafiles/data/Nodes/Internal.zip | Bin 9099746 -> 9099746 bytes scripts/node_frame/node_frame.gml | 41 ++++++------ .../panel_graph_export_image.gml | 61 +++++++++--------- .../panel_graph_export_image_dialog.gml | 51 +++++++-------- 4 files changed, 76 insertions(+), 77 deletions(-) diff --git a/datafiles/data/Nodes/Internal.zip b/datafiles/data/Nodes/Internal.zip index 50738bbf7859ef2a355388a2ca911e45ff04cff2..be8346260f3650d5148e182872126549f4b6759c 100644 GIT binary patch delta 1362 zcmZ9~TWphM7zc259c3LIgQ2o^GK<0nJHaN0oy+!#8xuB;Z8v386g;5rAPjVqga3W? zdlQLX=xf$R!Zik#U{WtMJCt2$23K7mZjH&jGg(aV$_u0aK7OB0oBWdh^SsadzF+%w z@z!yZy1{3yT^*nmPj zi2yd@DLjo$*o-0+V+*#T1f?iLIV!LX+fj)sJcAwBiCx%@YSf?>b*M)J8WF@EG@J1s?60U`etrG5rj8X}Igp4u?S30@lyTh$+eIRUjq}3HR zDkOXywuiXir|*T0Txs)?A_>6=+vO2swNq`8a5`cXOYkn3KAlP;M^8lTvw5#i7yO1S z{p){P*_O)Eg`M^kAKdrZ@Q6ouEbr*p`Vo(}qbU8GBN znLdnry3o>>G0tD<=q#!wd^(Gr=@9>67T>s~H8h73J)T6aREeZL`DYR}(y5z6eL6%r zNF(u~IrBlLEcMNs+a>Tt2Xyc6rd!{cH$Bq&ao*hKtW`RlfDU@2naf^b`r%~rl^Eau z)dh2Z9VH<-hUeq_s=J z{Yk4qLjIIhBjMPTRVU%XjOEwkQ`SbQ=BBJ#33=028xsVCR-&$2h~0a$w9T>neoRP&#CVNQf7~; zJrdeSRg;8*7;m{bsy0c*ui@7ZMpcos7L?E(v!`W!B4)2wjB&4POcl!ztLA?WiGMPt H4%Pn!EExu- delta 1362 zcmZ9~TWphM7zc259o;$#<0PY7Y6=)_&yjk`6d77d7t-vzxM0B zo8PgWFZ?KQu!hxOQijo5_E*n+JnLpdr?i7ISEHG>EFXfuC#ecp@d+B?UINw+o@JcI2|#HBzUJxpH3w)OAkftvw5#i=l_dr z{m*l)97|>Ef);y<5AOT=Lcd2hP4DPfUcblNRG;CR|5Eys{=$6xV!7+57W-1UA$2U8 z9rd&t^akyqH)$u;(Jrc|w`eytP$MZNn^5uK-xsgEwuCv=f6(Wmqo zU5W}wLm=7~$scX_)CxI_IpgaFF-TK!_(<7}vC(X6a+IpuG&_QoBbJ{CRKb&m7665>7 zHf3fxdjj7KEB6bNcc;t^vd$3D2L_c#2UF9w=yoIOj`pNXipG0VpBMcl|Bb7|))onW z3|reIEE=)OCF~!uDkWSTv;6wTh_zIzi4m(p!n{$d`q_HtsJ+hpoF26bWR2(h^@C9> zU#gi2tIP?0-I1^sONE5BRl-ohs*xa97TmFql&a0CaL0bqF(=FzvmePAdvZ{mJHGuv zevgV?<=30KRf$wbyVZ_#h+pqk6)tH#IIHTN$vO$qUbRa?vRCbPX8iH$bL!`SlsN-x zyM)F8RU;uk##^orsO3`eYxwoU0afU%1tqk_>}gpairMR>gWT&HR7Enxs`lw2@h=Be GbJb%4#wXkW diff --git a/scripts/node_frame/node_frame.gml b/scripts/node_frame/node_frame.gml index 6cbc73380..2931ae378 100644 --- a/scripts/node_frame/node_frame.gml +++ b/scripts/node_frame/node_frame.gml @@ -33,7 +33,6 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { draw_x1 = 0; draw_y1 = 0; - newInput(0, nodeValue_Vec2("Size", self, [ 240, 160 ] )) .rejectArray(); @@ -82,12 +81,7 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { static drawNode = function() { return noone; } static drawBadge = function() { return noone; } - static drawNodeBase = function(xx, yy, _s, _panel) { - var px0 = 3; - var py0 = 3; - var px1 = -3 + _panel.w; - var py1 = -0 + _panel.h - _panel.toolbar_height; - + static drawNodeBase = function(xx, yy, _s, _panel = noone) { var _yy = yy - name_height; var x0 = xx; @@ -95,10 +89,22 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { var x1 = xx + w * _s; var y1 = _yy + name_height + h * _s; - draw_x0 = max(x0, px0); - draw_x1 = min(x1, px1); - draw_y0 = max(y0, py0); - draw_y1 = min(y1, py1); + draw_x0 = x0; + draw_y0 = y0; + draw_x1 = x1; + draw_y1 = y1; + + if(_panel != noone) { + px0 = 3; + py0 = 3; + px1 = -3 + _panel.w; + py1 = -0 + _panel.h - _panel.toolbar_height; + + draw_x0 = max(x0, px0); + draw_y0 = max(y0, py0); + draw_x1 = min(x1, px1); + draw_y1 = min(y1, py1); + } var _h = max(draw_y1 - draw_y0, name_height); @@ -110,8 +116,7 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { draw_sprite_stretched_ext(bg_spr, 0, x0, y0, x1 - x0, y1 - y0, color, alpha); } - static drawNodeFG = function(_x, _y, _mx, _my, _s, _dparam, _panel) { - + static drawNodeFG = function(_x, _y, _mx, _my, _s, _dparam, _panel = noone) { if(draw_x1 - draw_x0 < 4) return; var _w = draw_x1 - draw_x0; @@ -132,8 +137,6 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { draw_set_text(f_p2, fa_center, fa_bottom, COLORS._main_text); draw_text_cut((draw_x0 + draw_x1) / 2, draw_y0 + name_height + 1, txt, _w - 4); - // draw_text_ext_add((draw_x0 + draw_x1) / 2, draw_y0 + name_height + 1, txt, -1, _w - 4); - // name_height = max(18, string_height_ext(txt, -1, _w - 4)); if(point_in_rectangle(_mx, _my, draw_x0, draw_y0, draw_x0 + _w, draw_y0 + name_height)) { if(PANEL_GRAPH.pFOCUS && DOUBLE_CLICK) @@ -151,7 +154,7 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { drawBadge(_x, _y, _s); } - static drawNodeBG = function(_x, _y, _mx, _my, _s, _dparam, _panel) { + static drawNodeBG = function(_x, _y, _mx, _my, _s, _dparam, _panel = noone) { if(size_dragging) { w = size_dragging_w + (mouse_mx - size_dragging_mx) / _s; @@ -177,14 +180,14 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { var x0 = x1 - 16; var y0 = y1 - 16; var ics = 0.5; - var shf = 8 + 8 * ics; + var shf = 8 * ics; if(w * _s < 32 || h * _s < 32) return point_in_rectangle(_mx, _my, xx, yy, x1, y1); - if(point_in_rectangle(_mx, _my, xx, yy, x1, y1) || size_dragging) + if(_panel != noone && point_in_rectangle(_mx, _my, xx, yy, x1, y1) || size_dragging) draw_sprite_ext_add(THEME.node_resize, 0, x1 - shf, y1 - shf, ics, ics, 0, c_white, 0.15); - if(!name_hover && point_in_rectangle(_mx, _my, x0, y0, x1, y1)) { + if(_panel != noone && !name_hover && point_in_rectangle(_mx, _my, x0, y0, x1, y1)) { draw_sprite_ext_add(THEME.node_resize, 0, x1 - shf, y1 - shf, ics, ics, 0, c_white, 0.30); PANEL_GRAPH.drag_locking = true; diff --git a/scripts/panel_graph_export_image/panel_graph_export_image.gml b/scripts/panel_graph_export_image/panel_graph_export_image.gml index b88b3477f..123195cb4 100644 --- a/scripts/panel_graph_export_image/panel_graph_export_image.gml +++ b/scripts/panel_graph_export_image/panel_graph_export_image.gml @@ -2,19 +2,19 @@ function graph_export_image(allList, nodeList, settings = {}) { var amo = array_length(nodeList); if(amo < 1) return; - var scale = struct_try_get(settings, "scale", 1); - var padding = struct_try_get(settings, "padding", 0); + var scale = settings[$ "scale"] ?? 1; + var padding = settings[$ "padding"] ?? 0; - var bgEnable = struct_try_get(settings, "bgEnable", false); - var bgColor = struct_try_get(settings, "bgColor", c_black); + var bgEnable = settings[$ "bgEnable"] ?? false; + var bgColor = settings[$ "bgColor"] ?? c_black; - var gridEnable = struct_try_get(settings, "gridEnable", false); - var gridColor = struct_try_get(settings, "gridColor", c_white); - var gridAlpha = struct_try_get(settings, "gridAlpha", 0); + var gridEnable = settings[$ "gridEnable"] ?? false; + var gridColor = settings[$ "gridColor"] ?? c_white; + var gridAlpha = settings[$ "gridAlpha"] ?? 0; - var borderPad = struct_try_get(settings, "borderPad", 0); - var borderColor = struct_try_get(settings, "borderColor", c_white); - var borderAlpha = struct_try_get(settings, "borderAlpha", 0.5); + var borderPad = settings[$ "borderPad"] ?? 0; + var borderColor = settings[$ "borderColor"] ?? c_white; + var borderAlpha = settings[$ "borderAlpha"] ?? 0.5; var bbox_x0 = nodeList[0].x * scale; var bbox_y0 = nodeList[0].y * scale; @@ -41,8 +41,7 @@ function graph_export_image(allList, nodeList, settings = {}) { var bbox_w = min(_lim_s, bbox_x1 - bbox_x0); var bbox_h = min(_lim_s, bbox_y1 - bbox_y0); - if(bbox_w == _lim_s || bbox_h == _lim_s) - noti_warning("Maximum surface size reached. Reduce scale to prevent cropping."); + if(bbox_w == _lim_s || bbox_h == _lim_s) noti_warning("Maximum surface size reached. Reduce scale to prevent cropping."); var s = surface_create(bbox_w, bbox_h); var cs = surface_create(bbox_w, bbox_h); @@ -80,15 +79,11 @@ function graph_export_image(allList, nodeList, settings = {}) { draw_set_alpha(1); } - for(var i = 0; i < array_length(allList); i++) + for( var i = 0, n = array_length(allList); i < n; i++ ) allList[i].preDraw(gr_x, gr_y, scale); - #region draw frame - for(var i = 0; i < array_length(nodeList); i++) { - if(instanceof(nodeList[i]) != "Node_Frame") continue; - nodeList[i].drawNode(true, gr_x, gr_y, mx, my, scale); - } - #endregion + for( var i = 0, n = array_length(nodeList); i < n; i++ ) + nodeList[i].drawNodeBG(gr_x, gr_y, mx, my, scale); #region draw conneciton surface_set_target(cs); @@ -98,28 +93,28 @@ function graph_export_image(allList, nodeList, settings = {}) { param.setPos(gr_x, gr_y, scale, mx, my); param.setProp(1, false); param.setDraw(1, c_black); - + param.show_dimension = true; param.show_compute = true; param.avoid_label = true; param.preview_scale = 100; - for(var i = 0; i < array_length(nodeList); i++) + for( var i = 0, n = array_length(nodeList); i < n; i++ ) nodeList[i].drawConnections(param, true); surface_reset_target(); - + draw_surface_safe(cs); #endregion #region draw node - for(var i = 0; i < array_length(nodeList); i++) + for( var i = 0, n = array_length(nodeList); i < n; i++ ) nodeList[i].onDrawNodeBehind(gr_x, gr_y, mx, my, scale); - for(var i = 0; i < array_length(nodeList); i++) { - var _node = nodeList[i]; - if(instanceof(_node) == "Node_Frame") continue; - var val = _node.drawNode(true, gr_x, gr_y, mx, my, scale, param); - } + for( var i = 0, n = array_length(nodeList); i < n; i++ ) + nodeList[i].drawNode(true, gr_x, gr_y, mx, my, scale, param); + + for( var i = 0, n = array_length(nodeList); i < n; i++ ) + nodeList[i].drawNodeFG(gr_x, gr_y, mx, my, scale, param); #endregion surface_reset_target(); @@ -128,11 +123,12 @@ function graph_export_image(allList, nodeList, settings = {}) { if(borderPad == 0) { surface_set_target(_sg); + DRAW_CLEAR + if(bgEnable) { draw_clear(bgColor); gpu_set_colorwriteenable(1, 1, 1, 0); - } else - draw_clear_alpha(0, 0); + } BLEND_OVERRIDE draw_surface_safe(s); @@ -143,11 +139,12 @@ function graph_export_image(allList, nodeList, settings = {}) { } else { surface_set_target(_sg); + DRAW_CLEAR + if(bgEnable) { draw_clear(bgColor); gpu_set_colorwriteenable(1, 1, 1, 0); - } else - draw_clear_alpha(0, 0); + } BLEND_OVERRIDE draw_surface(s, borderPad, borderPad); diff --git a/scripts/panel_graph_export_image_dialog/panel_graph_export_image_dialog.gml b/scripts/panel_graph_export_image_dialog/panel_graph_export_image_dialog.gml index cca5d026b..cd867c0fb 100644 --- a/scripts/panel_graph_export_image_dialog/panel_graph_export_image_dialog.gml +++ b/scripts/panel_graph_export_image_dialog/panel_graph_export_image_dialog.gml @@ -1,38 +1,38 @@ -function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { +function Panel_Graph_Export_Image(_panel) : PanelContent() constructor { title = __txtx("panel_export_graph", "Export Graph"); padding = ui(8); + w = min(WIN_W, ui(800)); h = ui(400); min_w = ui(640); min_h = ui(320); - set_wm = ui(320); - surf_s = min(w - set_wm - padding * 3, h - padding * 2); + set_wm = ui(320); + surf_s = min(w - set_wm - padding * 3, h - padding * 2); c_space = ui(24); set_w = w - surf_s - padding * 2 - c_space; set_h = h - padding * 2 - ui(32) - padding; - self.targetPanel = targetPanel; - - nodeList = targetPanel.nodes_list; - surface = noone; - bg_surface = noone; + targetPanel = _panel; + nodeList = targetPanel.nodes_list; + surface = noone; + bg_surface = noone; settings = { scale : 1, padding : 64, bgEnable : false, - bgColor : COLORS.panel_bg_clear, + bgColor : cola(COLORS.panel_bg_clear), gridEnable : false, - gridColor : targetPanel.project.graphGrid.color, + gridColor : cola(targetPanel.project.graphGrid.color), gridAlpha : targetPanel.project.graphGrid.opacity, borderPad : 0, - borderColor : c_white, + borderColor : cola(c_white), borderAlpha : 0.05, }; @@ -40,7 +40,7 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { nodes_select = [ "All nodes", "Selected" ]; widgets = []; - widgets[0] = [ "Nodes", new scrollBox(nodes_select, + widgets[0] = [ "Nodes", new scrollBox(nodes_select, function(val) /*=>*/ { sel = val; nodeList = val? targetPanel.nodes_selecting : targetPanel.nodes_list; @@ -60,7 +60,7 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { widgets[9] = [ "Border Color", new buttonColor( function(val) /*=>*/ { settings.borderColor = val; refresh(); }), function() /*=>*/ {return settings.borderColor} ]; widgets[10] = [ "Border Opacity", new textBox(TEXTBOX_INPUT.number, function(val) /*=>*/ { settings.borderAlpha = val; refresh(); }), function() /*=>*/ {return settings.borderAlpha} ]; - b_export = button(function() { + b_export = button(function() /*=>*/ { if(!is_surface(surface)) return; var path = get_save_filename_pxc("image|*.png;*.jpg", "Screenshot"); @@ -74,28 +74,28 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { b_export.text = __txt("Export") + "..."; sc_settings = new scrollPane(set_w, set_h, function(_y, _m) { - draw_clear_alpha(COLORS.panel_bg_clear, 0); + draw_clear_alpha(COLORS.panel_bg_clear, 1); var _ww = max(set_w * 0.5, ui(160)); var _hh = ui(30); var _ss = ui(28); - var ty = _y + _hh / 2; - var _tx = sc_settings.surface_w; + var _ty = _y + _hh / 2; + var _tx = sc_settings.surface_w - ui(8); var wh = ui(36); for( var i = 0, n = array_length(widgets); i < n; i++ ) { draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text); - draw_text_add(0, ty + wh * i, __txt(widgets[i][0], "graph_export_")); + draw_text_add(ui(8), _ty + wh * i, __txt(widgets[i][0], "graph_export_")); var _wid = widgets[i][1]; var _dat = widgets[i][2](); _wid.setFocusHover(pFOCUS, pHOVER); switch(instanceof(widgets[i][1])) { - case "textBox" : _wid.draw(_tx - _ww, ty + wh * i - _hh / 2, _ww, _hh, _dat, _m); break; - case "checkBox" : _wid.draw(_tx - _ww / 2 - _ss / 2, ty + wh * i - _ss / 2, _dat, _m); break; - case "buttonColor" : _wid.draw(_tx - _ww, ty + wh * i - _hh / 2, _ww, _hh, _dat, _m); break; - case "scrollBox" : _wid.draw(_tx - _ww, ty + wh * i - _hh / 2, _ww, _hh, _dat, _m, sc_settings.x + x, sc_settings.y + y); break; + case "textBox" : _wid.draw(_tx - _ww, _ty + wh * i - _hh / 2, _ww, _hh, _dat, _m); break; + case "checkBox" : _wid.draw(_tx - _ww / 2 - _ss / 2, _ty + wh * i - _ss / 2, _dat, _m); break; + case "buttonColor" : _wid.draw(_tx - _ww, _ty + wh * i - _hh / 2, _ww, _hh, _dat, _m); break; + case "scrollBox" : _wid.draw(_tx - _ww, _ty + wh * i - _hh / 2, _ww, _hh, _dat, _m, sc_settings.x + x, sc_settings.y + y); break; } if(_wid.inBBOX(_m)) sc_settings.hover_content = true; @@ -115,17 +115,16 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { } function refresh() { - if(is_surface(surface)) - surface_free(surface); + surface_free_safe(surface); surface = noone; - - if(nodeList == noone) - return; + if(nodeList == noone) return; surface = graph_export_image(targetPanel.nodes_list, nodeList, settings); } refresh(); function drawContent(panel) { + draw_clear(COLORS.panel_bg_clear); + var tx = padding; var ty = padding; var sh = 160;