From e6d39113c253d910ea951b535bf0f2c3a7d95fde Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sat, 27 Jul 2024 12:36:17 +0700 Subject: [PATCH] - [Path] Previewing node now set proper preview area. --- scripts/__bbox/__bbox.gml | 14 ++++++++++++++ scripts/node_path/node_path.gml | 7 +++++-- scripts/panel_preview/panel_preview.gml | 20 +++++++++++++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/scripts/__bbox/__bbox.gml b/scripts/__bbox/__bbox.gml index 310c7015e..9fc8fbbf1 100644 --- a/scripts/__bbox/__bbox.gml +++ b/scripts/__bbox/__bbox.gml @@ -102,6 +102,20 @@ function __BBOX() constructor { return self; } + static fromBoundingBox = function(box) { + self.x0 = box.minx; + self.x1 = box.maxx; + self.y0 = box.miny; + self.y1 = box.maxy; + + self.xc = (x0 + x1) / 2; + self.yc = (y0 + y1) / 2; + self.w = x1 - x0; + self.h = y1 - y0; + + return self; + } + static toSquare = function() { var _span = min(w, h) / 2; diff --git a/scripts/node_path/node_path.gml b/scripts/node_path/node_path.gml index 279cd0815..ad5ffa2e6 100644 --- a/scripts/node_path/node_path.gml +++ b/scripts/node_path/node_path.gml @@ -856,8 +856,9 @@ function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { lengthAccs[i] = lengthTotal; } - var minx = boundary.minx - 8, miny = boundary.miny - 8; - var maxx = boundary.maxx + 8, maxy = boundary.maxy + 8; + var pad = min(8, abs(boundary.maxx - boundary.minx) * 0.1, abs(boundary.maxy - boundary.miny) * 0.1); + var minx = boundary.minx - pad, miny = boundary.miny - pad; + var maxx = boundary.maxx + pad, maxy = boundary.maxy + pad; var rngx = maxx - minx, rngy = maxy - miny; var prev_s = 128; var _surf = surface_create(prev_s, prev_s); @@ -1050,4 +1051,6 @@ function Node_Path(_x, _y, _group = noone) : Node(_x, _y, _group) constructor { gpu_set_tex_filter(false); } } #endregion + + static getPreviewBoundingBox = function() { return BBOX().fromBoundingBox(boundary); } } \ No newline at end of file diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 2b5f96231..0156ecef7 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -633,20 +633,30 @@ function Panel_Preview() : PanelContent() constructor { canvas_hover = point_in_rectangle(mx, my, 0, toolbar_height, w, h - toolbar_height); } #endregion - function fullView() { #region + function fullView() { var bbox = noone; var node = getNodePreview(); if(node != noone) bbox = node.getPreviewBoundingBox(); if(bbox == noone) bbox = BBOX().fromWH(0, 0, PROJECT.attributes.surface_dimension[0], PROJECT.attributes.surface_dimension[1]); + var _x = bbox.x0, _y = bbox.y0; + var _w = bbox.w, _h = bbox.h; + + if(_w == 0 || _h == 0) { + _x = 0; + _y = 0; + _w = DEF_SURF_W; + _h = DEF_SURF_H; + } + var tl = tool_side_draw_l * 40; var tr = tool_side_draw_r * 40; - var ss = min((w - 32 - tl - tr) / bbox.w, (h - 32 - toolbar_height * 2) / bbox.h); + var ss = min((w - 32 - tl - tr) / _w, (h - 32 - toolbar_height * 2) / _h); canvas_s = ss; - canvas_x = w / 2 - bbox.w * canvas_s / 2 - bbox.x0 * canvas_s + (tl - tr) / 2; - canvas_y = h / 2 - bbox.h * canvas_s / 2 - bbox.y0 * canvas_s; - } #endregion + canvas_x = w / 2 - _w * canvas_s / 2 - _x * canvas_s + (tl - tr) / 2; + canvas_y = h / 2 - _h * canvas_s / 2 - _y * canvas_s; + } function drawNodeChannel(_x, _y) { #region var _node = getNodePreview();