From caf9ae292c5239ab6775407aba0fc9ee00497048 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Tue, 2 Jul 2024 15:51:52 +0700 Subject: [PATCH] - [Canvas] Fix apply node not working. --- objects/o_dialog_add_node/Create_0.gml | 2 +- scripts/buttonGroup/buttonGroup.gml | 6 ++-- scripts/canvas_tool_node/canvas_tool_node.gml | 2 ++ .../canvas_tool_selection.gml | 28 +++++++++++++++++++ .../dialog_management/dialog_management.gml | 3 +- scripts/node_canvas/node_canvas.gml | 14 ++++++++-- scripts/panel_function/panel_function.gml | 18 ++++++------ scripts/panel_inspector/panel_inspector.gml | 7 +++-- 8 files changed, 62 insertions(+), 18 deletions(-) diff --git a/objects/o_dialog_add_node/Create_0.gml b/objects/o_dialog_add_node/Create_0.gml index d39213238..cc8cb7a56 100644 --- a/objects/o_dialog_add_node/Create_0.gml +++ b/objects/o_dialog_add_node/Create_0.gml @@ -137,7 +137,7 @@ event_inherited(); if(!_node) return; - if(is_instanceof(context, Node_Canvas)) { + if(is_instanceof(context, Node_Canvas) || is_instanceof(context, Node_Canvas_Group)) { UNDO_HOLDING = true; context.nodeTool = new canvas_tool_node(context, _node).init(); UNDO_HOLDING = false; diff --git a/scripts/buttonGroup/buttonGroup.gml b/scripts/buttonGroup/buttonGroup.gml index 2796a9af4..8d2cfa616 100644 --- a/scripts/buttonGroup/buttonGroup.gml +++ b/scripts/buttonGroup/buttonGroup.gml @@ -10,6 +10,7 @@ function buttonGroup(_data, _onClick) : widget() constructor { tooltips = []; current_selecting = 0; + collapsable = true; for(var i = 0; i < array_length(data); i++) buttons[i] = button(-1); @@ -21,7 +22,8 @@ function buttonGroup(_data, _onClick) : widget() constructor { return self; } - static setTooltips = function(tt) { tooltips = tt; return self; } + static setTooltips = function(tt) { tooltips = tt; return self; } + static setCollape = function(cc) { collapsable = cc; return self; } static trigger = function() { if(current_selecting + 1 >= array_length(data)) @@ -86,7 +88,7 @@ function buttonGroup(_data, _onClick) : widget() constructor { } } - display_button = total_width < _w; + display_button = !collapsable || total_width < _w; var ww = (_mx? _tw : _w) / tamo; if(display_button) { diff --git a/scripts/canvas_tool_node/canvas_tool_node.gml b/scripts/canvas_tool_node/canvas_tool_node.gml index f51f855cb..96b1094be 100644 --- a/scripts/canvas_tool_node/canvas_tool_node.gml +++ b/scripts/canvas_tool_node/canvas_tool_node.gml @@ -81,6 +81,8 @@ function canvas_tool_node(canvas, node) : canvas_tool() constructor { return noone; } + panelAdd("Panel_Inspector", true, false).content.setInspecting(nodeObject, true, false); + return self; } diff --git a/scripts/canvas_tool_selection/canvas_tool_selection.gml b/scripts/canvas_tool_selection/canvas_tool_selection.gml index 2f6f9793e..f6ce14c08 100644 --- a/scripts/canvas_tool_selection/canvas_tool_selection.gml +++ b/scripts/canvas_tool_selection/canvas_tool_selection.gml @@ -163,6 +163,34 @@ function canvas_tool_selection(selector = noone) : canvas_tool() constructor { is_selected = true; } + function selectAll() { + var sel_w = surface_get_width(_canvas_surface); + var sel_h = surface_get_height(_canvas_surface); + + selection_surface = surface_verify(selection_surface, sel_w, sel_h); + selection_mask = surface_verify(selection_mask, sel_w, sel_h); + + surface_set_target(selection_surface); + DRAW_CLEAR + draw_surface_safe(_canvas_surface, 0, 0); + surface_reset_target(); + + surface_set_target(selection_mask); + draw_clear(c_white); + surface_reset_target(); + + node.storeAction(); + surface_set_target(_canvas_surface); + DRAW_CLEAR + surface_reset_target(); + + node.surface_store_buffer(); + + selection_position = [ 0, 0 ]; + selection_size = [ sel_w, sel_h ]; + is_selected = true; + } + function copySelection() { var s = surface_encode(selection_surface, false); s.position = selection_position; diff --git a/scripts/dialog_management/dialog_management.gml b/scripts/dialog_management/dialog_management.gml index ae5ce9e2e..e2106f49a 100644 --- a/scripts/dialog_management/dialog_management.gml +++ b/scripts/dialog_management/dialog_management.gml @@ -32,7 +32,8 @@ function dialogPanelCall(_panel, _x = noone, _y = noone, params = {}) { #region dia.ystart = _y; dia.resetPosition(); - setFocus(dia.id, "Dialog"); + if(struct_try_get(params, "focus", true)) + setFocus(dia.id, "Dialog"); return dia; } #endregion diff --git a/scripts/node_canvas/node_canvas.gml b/scripts/node_canvas/node_canvas.gml index 944b7f110..d1dbc547f 100644 --- a/scripts/node_canvas/node_canvas.gml +++ b/scripts/node_canvas/node_canvas.gml @@ -235,7 +235,8 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor tool_attribute.drawLayer = 0; tool_attribute.pickColor = c_white; tool_drawLayer_edit = new buttonGroup( [ THEME.canvas_draw_layer, THEME.canvas_draw_layer, THEME.canvas_draw_layer ], function(val) { tool_attribute.drawLayer = val; }) - .setTooltips( [ "Draw on top", "Draw behind", "Draw inside" ] ); + .setTooltips( [ "Draw on top", "Draw behind", "Draw inside" ] ) + .setCollape(false); tool_attribute.mirror = [ false, false, false ]; tool_mirror_edit = new checkBoxGroup( THEME.canvas_mirror, function(ind, val) { tool_attribute.mirror[ind] = val; }) @@ -262,7 +263,8 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor tool_attribute.fillType = 0; tool_fil8_edit = new buttonGroup( [ THEME.canvas_fill_type, THEME.canvas_fill_type, THEME.canvas_fill_type ], function(val) { tool_attribute.fillType = val; }) - .setTooltips( [ "Edge", "Edge + Corner", "Entire image" ] ); + .setTooltips( [ "Edge", "Edge + Corner", "Entire image" ] ) + .setCollape(false); tool_fil8 = [ "Fill", tool_fil8_edit, "fillType", tool_attribute ]; tool_attribute.button_apply = [ false, false ]; @@ -339,7 +341,8 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor }); nodeTool = noone; - nodeToolPreview = new NodeTool( "Apply Node", THEME.canvas_tools_node, self ).setToolFn( __action_add_node ); + nodeToolPreview = new NodeTool( "Apply Node", THEME.canvas_tools_node, self ).setToolFn( __action_add_node ) + .setContext(self); rightTools_general = [ nodeToolPreview, @@ -919,6 +922,11 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor } } } + + if(key_press(ord("A"), MOD_KEY.ctrl)) { + if(tool_selection.is_selected) tool_selection.apply(); + tool_selection.selectAll(); + } #endregion if(DRAGGING && hover&& mouse_release(mb_left)) { #region drag n drop diff --git a/scripts/panel_function/panel_function.gml b/scripts/panel_function/panel_function.gml index ffb022d88..4a163d281 100644 --- a/scripts/panel_function/panel_function.gml +++ b/scripts/panel_function/panel_function.gml @@ -47,13 +47,13 @@ PANEL_FILE = 0; } #endregion - function getPanelFromName(name, create = false) { #region + function getPanelFromName(name, create = false, focus = true) { #region switch(name) { - case "Panel_Menu" : var p = (create || findPanel(name))? new Panel_Menu() : PANEL_MENU; PANEL_MENU = p; return p; - case "Panel_Inspector" : var p = (create || findPanel(name))? new Panel_Inspector() : PANEL_INSPECTOR; PANEL_INSPECTOR = p; return p; - case "Panel_Animation" : var p = (create || findPanel(name))? new Panel_Animation() : PANEL_ANIMATION; PANEL_ANIMATION = p; return p; - case "Panel_Preview" : var p = (create || findPanel(name))? new Panel_Preview() : PANEL_PREVIEW; PANEL_PREVIEW = p; return p; - case "Panel_Graph" : var p = (create || findPanel(name))? new Panel_Graph() : PANEL_GRAPH; PANEL_GRAPH = p; return p; + case "Panel_Menu" : var p = (create || findPanel(name))? new Panel_Menu() : PANEL_MENU; if(focus) { PANEL_MENU = p; } return p; + case "Panel_Inspector" : var p = (create || findPanel(name))? new Panel_Inspector() : PANEL_INSPECTOR; if(focus) { PANEL_INSPECTOR = p; } return p; + case "Panel_Animation" : var p = (create || findPanel(name))? new Panel_Animation() : PANEL_ANIMATION; if(focus) { PANEL_ANIMATION = p; } return p; + case "Panel_Preview" : var p = (create || findPanel(name))? new Panel_Preview() : PANEL_PREVIEW; if(focus) { PANEL_PREVIEW = p; } return p; + case "Panel_Graph" : var p = (create || findPanel(name))? new Panel_Graph() : PANEL_GRAPH; if(focus) { PANEL_GRAPH = p; } return p; case "Panel_Collection" : return new Panel_Collection(); case "Panel_Workspace" : return new Panel_Workspace(); @@ -138,11 +138,11 @@ return val; } #endregion - function panelAdd(panel, create = false) { #region - var pan = getPanelFromName(panel, create); + function panelAdd(panel, create = false, focus = true) { #region + var pan = getPanelFromName(panel, create, focus); if(pan == noone) return noone; - return dialogPanelCall(pan); + return dialogPanelCall(pan, noone, noone, { focus }); } #endregion function panelObjectInit() { #region diff --git a/scripts/panel_inspector/panel_inspector.gml b/scripts/panel_inspector/panel_inspector.gml index 6b4134a80..07f4660d9 100644 --- a/scripts/panel_inspector/panel_inspector.gml +++ b/scripts/panel_inspector/panel_inspector.gml @@ -47,6 +47,8 @@ function Panel_Inspector() : PanelContent() constructor { min_w = ui(160); locked = false; + focusable = true; + inspecting = noone; inspectings = []; inspectGroup = false; @@ -214,11 +216,12 @@ function Panel_Inspector() : PanelContent() constructor { menu_junc_color.spacing = ui(24); #endregion - function setInspecting(inspecting, _lock = false) { #region + function setInspecting(inspecting, _lock = false, _focus = true) { #region if(locked) return; self.inspecting = inspecting; if(_lock) locked = true; + focusable = _focus; if(inspecting != noone) inspecting.onInspect(); @@ -233,7 +236,7 @@ function Panel_Inspector() : PanelContent() constructor { return inspecting.active? inspecting : noone; } #endregion - function onFocusBegin() { PANEL_INSPECTOR = self; } + function onFocusBegin() { if(!focusable) return; PANEL_INSPECTOR = self; } function onResize() { #region initSize();