[Export Graph] Fix frame not rendering.

This commit is contained in:
Tanasart 2025-01-26 09:07:45 +07:00
parent 648e0ebe3f
commit 31acbf4ee7
4 changed files with 76 additions and 77 deletions

Binary file not shown.

View file

@ -33,7 +33,6 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
draw_x1 = 0; draw_x1 = 0;
draw_y1 = 0; draw_y1 = 0;
newInput(0, nodeValue_Vec2("Size", self, [ 240, 160 ] )) newInput(0, nodeValue_Vec2("Size", self, [ 240, 160 ] ))
.rejectArray(); .rejectArray();
@ -82,12 +81,7 @@ function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
static drawNode = function() { return noone; } static drawNode = function() { return noone; }
static drawBadge = function() { return noone; } static drawBadge = function() { return noone; }
static drawNodeBase = function(xx, yy, _s, _panel) { static drawNodeBase = function(xx, yy, _s, _panel = noone) {
var px0 = 3;
var py0 = 3;
var px1 = -3 + _panel.w;
var py1 = -0 + _panel.h - _panel.toolbar_height;
var _yy = yy - name_height; var _yy = yy - name_height;
var x0 = xx; 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 x1 = xx + w * _s;
var y1 = _yy + name_height + h * _s; var y1 = _yy + name_height + h * _s;
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_x0 = max(x0, px0);
draw_x1 = min(x1, px1);
draw_y0 = max(y0, py0); draw_y0 = max(y0, py0);
draw_x1 = min(x1, px1);
draw_y1 = min(y1, py1); draw_y1 = min(y1, py1);
}
var _h = max(draw_y1 - draw_y0, name_height); 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); 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; if(draw_x1 - draw_x0 < 4) return;
var _w = draw_x1 - draw_x0; 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_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_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(point_in_rectangle(_mx, _my, draw_x0, draw_y0, draw_x0 + _w, draw_y0 + name_height)) {
if(PANEL_GRAPH.pFOCUS && DOUBLE_CLICK) 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); 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) { if(size_dragging) {
w = size_dragging_w + (mouse_mx - size_dragging_mx) / _s; 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 x0 = x1 - 16;
var y0 = y1 - 16; var y0 = y1 - 16;
var ics = 0.5; 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(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); 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); draw_sprite_ext_add(THEME.node_resize, 0, x1 - shf, y1 - shf, ics, ics, 0, c_white, 0.30);
PANEL_GRAPH.drag_locking = true; PANEL_GRAPH.drag_locking = true;

View file

@ -2,19 +2,19 @@ function graph_export_image(allList, nodeList, settings = {}) {
var amo = array_length(nodeList); var amo = array_length(nodeList);
if(amo < 1) return; if(amo < 1) return;
var scale = struct_try_get(settings, "scale", 1); var scale = settings[$ "scale"] ?? 1;
var padding = struct_try_get(settings, "padding", 0); var padding = settings[$ "padding"] ?? 0;
var bgEnable = struct_try_get(settings, "bgEnable", false); var bgEnable = settings[$ "bgEnable"] ?? false;
var bgColor = struct_try_get(settings, "bgColor", c_black); var bgColor = settings[$ "bgColor"] ?? c_black;
var gridEnable = struct_try_get(settings, "gridEnable", false); var gridEnable = settings[$ "gridEnable"] ?? false;
var gridColor = struct_try_get(settings, "gridColor", c_white); var gridColor = settings[$ "gridColor"] ?? c_white;
var gridAlpha = struct_try_get(settings, "gridAlpha", 0); var gridAlpha = settings[$ "gridAlpha"] ?? 0;
var borderPad = struct_try_get(settings, "borderPad", 0); var borderPad = settings[$ "borderPad"] ?? 0;
var borderColor = struct_try_get(settings, "borderColor", c_white); var borderColor = settings[$ "borderColor"] ?? c_white;
var borderAlpha = struct_try_get(settings, "borderAlpha", 0.5); var borderAlpha = settings[$ "borderAlpha"] ?? 0.5;
var bbox_x0 = nodeList[0].x * scale; var bbox_x0 = nodeList[0].x * scale;
var bbox_y0 = nodeList[0].y * 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_w = min(_lim_s, bbox_x1 - bbox_x0);
var bbox_h = min(_lim_s, bbox_y1 - bbox_y0); var bbox_h = min(_lim_s, bbox_y1 - bbox_y0);
if(bbox_w == _lim_s || bbox_h == _lim_s) if(bbox_w == _lim_s || bbox_h == _lim_s) noti_warning("Maximum surface size reached. Reduce scale to prevent cropping.");
noti_warning("Maximum surface size reached. Reduce scale to prevent cropping.");
var s = surface_create(bbox_w, bbox_h); var s = surface_create(bbox_w, bbox_h);
var cs = 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); 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); allList[i].preDraw(gr_x, gr_y, scale);
#region draw frame for( var i = 0, n = array_length(nodeList); i < n; i++ )
for(var i = 0; i < array_length(nodeList); i++) { nodeList[i].drawNodeBG(gr_x, gr_y, mx, my, scale);
if(instanceof(nodeList[i]) != "Node_Frame") continue;
nodeList[i].drawNode(true, gr_x, gr_y, mx, my, scale);
}
#endregion
#region draw conneciton #region draw conneciton
surface_set_target(cs); surface_set_target(cs);
@ -104,7 +99,7 @@ function graph_export_image(allList, nodeList, settings = {}) {
param.avoid_label = true; param.avoid_label = true;
param.preview_scale = 100; 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); nodeList[i].drawConnections(param, true);
surface_reset_target(); surface_reset_target();
@ -112,14 +107,14 @@ function graph_export_image(allList, nodeList, settings = {}) {
#endregion #endregion
#region draw node #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); nodeList[i].onDrawNodeBehind(gr_x, gr_y, mx, my, scale);
for(var i = 0; i < array_length(nodeList); i++) { for( var i = 0, n = array_length(nodeList); i < n; i++ )
var _node = nodeList[i]; nodeList[i].drawNode(true, gr_x, gr_y, mx, my, scale, param);
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].drawNodeFG(gr_x, gr_y, mx, my, scale, param);
#endregion #endregion
surface_reset_target(); surface_reset_target();
@ -128,11 +123,12 @@ function graph_export_image(allList, nodeList, settings = {}) {
if(borderPad == 0) { if(borderPad == 0) {
surface_set_target(_sg); surface_set_target(_sg);
DRAW_CLEAR
if(bgEnable) { if(bgEnable) {
draw_clear(bgColor); draw_clear(bgColor);
gpu_set_colorwriteenable(1, 1, 1, 0); gpu_set_colorwriteenable(1, 1, 1, 0);
} else }
draw_clear_alpha(0, 0);
BLEND_OVERRIDE BLEND_OVERRIDE
draw_surface_safe(s); draw_surface_safe(s);
@ -143,11 +139,12 @@ function graph_export_image(allList, nodeList, settings = {}) {
} else { } else {
surface_set_target(_sg); surface_set_target(_sg);
DRAW_CLEAR
if(bgEnable) { if(bgEnable) {
draw_clear(bgColor); draw_clear(bgColor);
gpu_set_colorwriteenable(1, 1, 1, 0); gpu_set_colorwriteenable(1, 1, 1, 0);
} else }
draw_clear_alpha(0, 0);
BLEND_OVERRIDE BLEND_OVERRIDE
draw_surface(s, borderPad, borderPad); draw_surface(s, borderPad, borderPad);

View file

@ -1,6 +1,7 @@
function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { function Panel_Graph_Export_Image(_panel) : PanelContent() constructor {
title = __txtx("panel_export_graph", "Export Graph"); title = __txtx("panel_export_graph", "Export Graph");
padding = ui(8); padding = ui(8);
w = min(WIN_W, ui(800)); w = min(WIN_W, ui(800));
h = ui(400); h = ui(400);
@ -14,8 +15,7 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor {
set_w = w - surf_s - padding * 2 - c_space; set_w = w - surf_s - padding * 2 - c_space;
set_h = h - padding * 2 - ui(32) - padding; set_h = h - padding * 2 - ui(32) - padding;
self.targetPanel = targetPanel; targetPanel = _panel;
nodeList = targetPanel.nodes_list; nodeList = targetPanel.nodes_list;
surface = noone; surface = noone;
bg_surface = noone; bg_surface = noone;
@ -25,14 +25,14 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor {
padding : 64, padding : 64,
bgEnable : false, bgEnable : false,
bgColor : COLORS.panel_bg_clear, bgColor : cola(COLORS.panel_bg_clear),
gridEnable : false, gridEnable : false,
gridColor : targetPanel.project.graphGrid.color, gridColor : cola(targetPanel.project.graphGrid.color),
gridAlpha : targetPanel.project.graphGrid.opacity, gridAlpha : targetPanel.project.graphGrid.opacity,
borderPad : 0, borderPad : 0,
borderColor : c_white, borderColor : cola(c_white),
borderAlpha : 0.05, borderAlpha : 0.05,
}; };
@ -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[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} ]; 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; if(!is_surface(surface)) return;
var path = get_save_filename_pxc("image|*.png;*.jpg", "Screenshot"); 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") + "..."; b_export.text = __txt("Export") + "...";
sc_settings = new scrollPane(set_w, set_h, function(_y, _m) { 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 _ww = max(set_w * 0.5, ui(160));
var _hh = ui(30); var _hh = ui(30);
var _ss = ui(28); var _ss = ui(28);
var ty = _y + _hh / 2; var _ty = _y + _hh / 2;
var _tx = sc_settings.surface_w; var _tx = sc_settings.surface_w - ui(8);
var wh = ui(36); var wh = ui(36);
for( var i = 0, n = array_length(widgets); i < n; i++ ) { for( var i = 0, n = array_length(widgets); i < n; i++ ) {
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text); 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 _wid = widgets[i][1];
var _dat = widgets[i][2](); var _dat = widgets[i][2]();
_wid.setFocusHover(pFOCUS, pHOVER); _wid.setFocusHover(pFOCUS, pHOVER);
switch(instanceof(widgets[i][1])) { switch(instanceof(widgets[i][1])) {
case "textBox" : _wid.draw(_tx - _ww, ty + wh * i - _hh / 2, _ww, _hh, _dat, _m); 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 "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 "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 "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; if(_wid.inBBOX(_m)) sc_settings.hover_content = true;
@ -115,17 +115,16 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor {
} }
function refresh() { function refresh() {
if(is_surface(surface)) surface_free_safe(surface);
surface_free(surface);
surface = noone; surface = noone;
if(nodeList == noone) return;
if(nodeList == noone)
return;
surface = graph_export_image(targetPanel.nodes_list, nodeList, settings); surface = graph_export_image(targetPanel.nodes_list, nodeList, settings);
} refresh(); } refresh();
function drawContent(panel) { function drawContent(panel) {
draw_clear(COLORS.panel_bg_clear);
var tx = padding; var tx = padding;
var ty = padding; var ty = padding;
var sh = 160; var sh = 160;