- [Canvas] Fix apply node not working.

This commit is contained in:
Tanasart 2024-07-02 15:51:52 +07:00
parent 5e2eb0a352
commit caf9ae292c
8 changed files with 62 additions and 18 deletions

View file

@ -137,7 +137,7 @@ event_inherited();
if(!_node) return; if(!_node) return;
if(is_instanceof(context, Node_Canvas)) { if(is_instanceof(context, Node_Canvas) || is_instanceof(context, Node_Canvas_Group)) {
UNDO_HOLDING = true; UNDO_HOLDING = true;
context.nodeTool = new canvas_tool_node(context, _node).init(); context.nodeTool = new canvas_tool_node(context, _node).init();
UNDO_HOLDING = false; UNDO_HOLDING = false;

View file

@ -10,6 +10,7 @@ function buttonGroup(_data, _onClick) : widget() constructor {
tooltips = []; tooltips = [];
current_selecting = 0; current_selecting = 0;
collapsable = true;
for(var i = 0; i < array_length(data); i++) for(var i = 0; i < array_length(data); i++)
buttons[i] = button(-1); buttons[i] = button(-1);
@ -21,7 +22,8 @@ function buttonGroup(_data, _onClick) : widget() constructor {
return self; 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() { static trigger = function() {
if(current_selecting + 1 >= array_length(data)) 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; var ww = (_mx? _tw : _w) / tamo;
if(display_button) { if(display_button) {

View file

@ -81,6 +81,8 @@ function canvas_tool_node(canvas, node) : canvas_tool() constructor {
return noone; return noone;
} }
panelAdd("Panel_Inspector", true, false).content.setInspecting(nodeObject, true, false);
return self; return self;
} }

View file

@ -163,6 +163,34 @@ function canvas_tool_selection(selector = noone) : canvas_tool() constructor {
is_selected = true; 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() { function copySelection() {
var s = surface_encode(selection_surface, false); var s = surface_encode(selection_surface, false);
s.position = selection_position; s.position = selection_position;

View file

@ -32,7 +32,8 @@ function dialogPanelCall(_panel, _x = noone, _y = noone, params = {}) { #region
dia.ystart = _y; dia.ystart = _y;
dia.resetPosition(); dia.resetPosition();
setFocus(dia.id, "Dialog"); if(struct_try_get(params, "focus", true))
setFocus(dia.id, "Dialog");
return dia; return dia;
} #endregion } #endregion

View file

@ -235,7 +235,8 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
tool_attribute.drawLayer = 0; tool_attribute.drawLayer = 0;
tool_attribute.pickColor = c_white; 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; }) 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_attribute.mirror = [ false, false, false ];
tool_mirror_edit = new checkBoxGroup( THEME.canvas_mirror, function(ind, val) { tool_attribute.mirror[ind] = val; }) 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_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; }) 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_fil8 = [ "Fill", tool_fil8_edit, "fillType", tool_attribute ];
tool_attribute.button_apply = [ false, false ]; tool_attribute.button_apply = [ false, false ];
@ -339,7 +341,8 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
}); });
nodeTool = noone; 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 = [ rightTools_general = [
nodeToolPreview, 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 #endregion
if(DRAGGING && hover&& mouse_release(mb_left)) { #region drag n drop if(DRAGGING && hover&& mouse_release(mb_left)) { #region drag n drop

View file

@ -47,13 +47,13 @@
PANEL_FILE = 0; PANEL_FILE = 0;
} #endregion } #endregion
function getPanelFromName(name, create = false) { #region function getPanelFromName(name, create = false, focus = true) { #region
switch(name) { switch(name) {
case "Panel_Menu" : var p = (create || findPanel(name))? new Panel_Menu() : PANEL_MENU; PANEL_MENU = 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; PANEL_INSPECTOR = 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; PANEL_ANIMATION = 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; PANEL_PREVIEW = 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; PANEL_GRAPH = 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_Collection" : return new Panel_Collection();
case "Panel_Workspace" : return new Panel_Workspace(); case "Panel_Workspace" : return new Panel_Workspace();
@ -138,11 +138,11 @@
return val; return val;
} #endregion } #endregion
function panelAdd(panel, create = false) { #region function panelAdd(panel, create = false, focus = true) { #region
var pan = getPanelFromName(panel, create); var pan = getPanelFromName(panel, create, focus);
if(pan == noone) return noone; if(pan == noone) return noone;
return dialogPanelCall(pan); return dialogPanelCall(pan, noone, noone, { focus });
} #endregion } #endregion
function panelObjectInit() { #region function panelObjectInit() { #region

View file

@ -47,6 +47,8 @@ function Panel_Inspector() : PanelContent() constructor {
min_w = ui(160); min_w = ui(160);
locked = false; locked = false;
focusable = true;
inspecting = noone; inspecting = noone;
inspectings = []; inspectings = [];
inspectGroup = false; inspectGroup = false;
@ -214,11 +216,12 @@ function Panel_Inspector() : PanelContent() constructor {
menu_junc_color.spacing = ui(24); menu_junc_color.spacing = ui(24);
#endregion #endregion
function setInspecting(inspecting, _lock = false) { #region function setInspecting(inspecting, _lock = false, _focus = true) { #region
if(locked) return; if(locked) return;
self.inspecting = inspecting; self.inspecting = inspecting;
if(_lock) locked = true; if(_lock) locked = true;
focusable = _focus;
if(inspecting != noone) if(inspecting != noone)
inspecting.onInspect(); inspecting.onInspect();
@ -233,7 +236,7 @@ function Panel_Inspector() : PanelContent() constructor {
return inspecting.active? inspecting : noone; return inspecting.active? inspecting : noone;
} #endregion } #endregion
function onFocusBegin() { PANEL_INSPECTOR = self; } function onFocusBegin() { if(!focusable) return; PANEL_INSPECTOR = self; }
function onResize() { #region function onResize() { #region
initSize(); initSize();