mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2025-02-04 17:25:14 +01:00
[Export Graph] Fix frame not rendering.
This commit is contained in:
parent
648e0ebe3f
commit
31acbf4ee7
4 changed files with 76 additions and 77 deletions
Binary file not shown.
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue