From c506e06023060393bac0b69f3db105263d8b61de Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 19 Jun 2024 14:22:25 +0700 Subject: [PATCH] - [Export Graph] Fix general crash. --- .../panel_graph_export_image_dialog.gml | 83 ++++++++++++------- 1 file changed, 55 insertions(+), 28 deletions(-) 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 839526ea5..a4b1e1acc 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,15 +1,25 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { title = __txtx("panel_export_graph", "Export Graph"); padding = ui(8); - w = ui(640); + w = min(WIN_W, ui(800)); h = ui(400); - set_w = ui(240); - surf_s = w - set_w - padding * 2; + + min_w = ui(640); + min_h = ui(320); + + 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; + nodeList = targetPanel.nodes_list; + surface = noone; + bg_surface = noone; + settings = { scale : 1, padding : 64, @@ -77,10 +87,10 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { b_export.text = __txt("Export") + "..."; - sc_settings = new scrollPane(set_w, h - padding * 2, function(_y, _m) { + sc_settings = new scrollPane(set_w, set_h, function(_y, _m) { draw_clear_alpha(COLORS.panel_bg_clear, 0); - var _ww = ui(160); + var _ww = max(set_w * 0.5, ui(160)); var _hh = ui(30); var _ss = ui(28); var ty = _y + _hh / 2; @@ -108,9 +118,12 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { }); function onResize() { - surf_s = w - set_w - padding * 2; + surf_s = min(w - set_wm - padding * 3, h - padding * 2); - sc_settings.resize(set_w, h - padding * 2); + set_w = w - surf_s - padding * 2 - c_space; + set_h = h - padding * 2 - ui(32) - padding; + + sc_settings.resize(set_w, set_h); } function refresh() { @@ -130,40 +143,54 @@ function Panel_Graph_Export_Image(targetPanel) : PanelContent() constructor { var sh = 160; var _sx0 = tx, _sx1 = _sx0 + surf_s; - var _sy0 = ty, _sy1 = _sy0 + surf_s; + var _sy0 = h / 2 - surf_s / 2; + var _sy1 = h / 2 + surf_s / 2; + + var _m = [ mx, my ]; if(is_surface(surface)) { var _sw = surface_get_width_safe(surface); var _sh = surface_get_height_safe(surface); var ss = min(surf_s / _sw, surf_s / _sh); - draw_surface_ext_safe(surface, _sx0 + surf_s / 2 - _sw * ss / 2, - _sy0 + surf_s / 2 - _sh * ss / 2, ss, ss, 0, c_white, 1); + bg_surface = surface_verify(bg_surface, _sw * ss, _sh * ss); + surface_set_target(bg_surface); + draw_sprite_tiled_ext(s_transparent, 0, 0, 0, 1, 1, COLORS.panel_preview_transparent, 1); + surface_reset_target(); + + var _sx = _sx0 + surf_s / 2 - _sw * ss / 2; + var _sy = _sy0 + surf_s / 2 - _sh * ss / 2; + + draw_surface(bg_surface, _sx, _sy); + draw_surface_ext_safe(surface, _sx, _sy, ss, ss, 0, c_white, 1); draw_set_text(f_p2, fa_center, fa_bottom, COLORS._main_text_sub); - draw_text_add(w / 2, ty + sh - ui(2), $"{_sw} x {_sh} px"); + draw_text_add(_sx0 + surf_s / 2, _sy + _sh * ss - ui(2), $"{_sw} x {_sh} px"); + + draw_set_color(COLORS._main_icon); + draw_rectangle(_sx, _sy, _sx + _sw * ss, _sy + _sh * ss, 1); + + var bx = _sx1 - ui(24) - ui(4); + var by = _sy + ui(1) + ui(4); + + if(buttonInstant(THEME.button_hide, bx, by, ui(24), ui(24), _m, pFOCUS, pHOVER) == 2) + refresh(); + draw_sprite_ui(THEME.refresh_16, 0, bx + ui(12), by + ui(12),,,, COLORS._main_icon, 1); + + } else { + draw_set_color(COLORS._main_icon); + draw_rectangle(_sx0, _sy0, _sx1, _sy1, 1); } - draw_set_color(COLORS._main_icon); - draw_rectangle(_sx0, _sy0, _sx1, _sy1, 1); - - var bx = _sx1 - ui(24); - var by = _sy0; - var _m = [ mx, my ]; - - if(buttonInstant(THEME.button_hide, bx, by, ui(24), ui(24), _m, pFOCUS, pHOVER) == 2) - refresh(); - draw_sprite_ui(THEME.refresh_16, 0, bx + ui(12), by + ui(12),,,, COLORS._main_icon, 1); - - var sx = _sx1; - var sy = _sy0; + var sx = w - padding - set_w; + var sy = ty; sc_settings.setFocusHover(pFOCUS, pHOVER); sc_settings.draw(sx, sy, mx - sx, my - sy); draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text); - var _bw = ui(64); - var _bh = ui(24); + var _bw = ui(96); + var _bh = ui(32); bx = w - padding - _bw; by = h - padding - _bh;