undo move

This commit is contained in:
Tanasart 2024-12-02 11:31:44 +07:00
parent 0b5ffeb9d5
commit d61439003b
5 changed files with 92 additions and 15 deletions

View file

@ -1,6 +1,11 @@
function node_halign(nodeList, alignment = fa_center) {
var amo = array_length(nodeList);
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
switch(alignment) {
case fa_left:
var x0 = 999999;
@ -10,6 +15,7 @@ function node_halign(nodeList, alignment = fa_center) {
for( var i = 0; i < amo; i++ )
nodeList[i].x = x0;
break;
case fa_center:
var xc = 0;
for( var i = 0; i < amo; i++ )
@ -19,6 +25,7 @@ function node_halign(nodeList, alignment = fa_center) {
for( var i = 0; i < amo; i++ )
nodeList[i].x = xc - nodeList[i].w / 2;
break;
case fa_right:
var x0 = -999999;
for( var i = 0; i < amo; i++ )
@ -33,6 +40,11 @@ function node_halign(nodeList, alignment = fa_center) {
function node_valign(nodeList, alignment = fa_middle) {
var amo = array_length(nodeList);
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
switch(alignment) {
case fa_top:
var y0 = 999999;
@ -42,6 +54,7 @@ function node_valign(nodeList, alignment = fa_middle) {
for( var i = 0; i < amo; i++ )
nodeList[i].y = y0;
break;
case fa_middle:
var yc = 0;
for( var i = 0; i < amo; i++ )
@ -51,6 +64,7 @@ function node_valign(nodeList, alignment = fa_middle) {
for( var i = 0; i < amo; i++ )
nodeList[i].y = yc - nodeList[i].h / 2;
break;
case fa_bottom:
var y0 = -999999;
for( var i = 0; i < amo; i++ )
@ -66,6 +80,11 @@ function node_hdistribute(nodeList) {
var amo = array_length(nodeList);
var nodes = ds_priority_create();
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
var x0 = 999999;
var x1 = -999999;
for( var i = 0; i < amo; i++ ) {
@ -90,6 +109,11 @@ function node_vdistribute(nodeList) {
var amo = array_length(nodeList);
var nodes = ds_priority_create();
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
var y0 = 999999;
var y1 = -999999;
for( var i = 0; i < amo; i++ ) {
@ -114,6 +138,11 @@ function node_hdistribute_dist(nodeList, anchor = noone, distance = 0) {
var amo = array_length(nodeList);
var nodes = ds_priority_create();
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
var x0 = 999999;
var x1 = -999999;
for( var i = 0; i < amo; i++ ) {
@ -150,6 +179,11 @@ function node_vdistribute_dist(nodeList, anchor = noone, distance = 0) {
var amo = array_length(nodeList);
var nodes = ds_priority_create();
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
var y0 = 999999;
var y1 = -999999;
for( var i = 0; i < amo; i++ ) {
@ -188,6 +222,11 @@ function node_auto_align(nodeList) {
var amo = array_length(nodeList);
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
for( var i = 0; i < amo; i++ ) {
var _n = nodeList[i];
var _x = _n.x;
@ -212,6 +251,14 @@ function node_auto_align(nodeList) {
}
function node_snap_grid(nodeList, spacing = 16) {
var amo = array_length(nodeList);
for( var i = 0; i < amo; i++ ) {
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].x, "x", "node x position" ]);
recordAction(ACTION_TYPE.var_modify, nodeList[i], [ nodeList[i].y, "y", "node y position" ]);
}
for (var i = 0, n = array_length(nodeList); i < n; i++) {
var _node = nodeList[i];

View file

@ -16,16 +16,20 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node_Processor(_x, _y, _
newInput(4, nodeValue_Enum_Scroll("Color Space", self, 1, { data: [ "RGB", "HSV" ], update_hover: false }))
.rejectArray();
newInput(5, nodeValue_Surface("Mask", self));
newOutput(0, nodeValue_Output("Palette", self, VALUE_TYPE.color, [ ]))
.setDisplay(VALUE_DISPLAY.palette);
static getPreviewValues = function() { return getInputData(0); }
input_display_list = [
["Surfaces", true], 0,
["Surfaces", true], 0, 5,
["Palette", false], 3, 4, 1, 2,
]
temp_surface = [ 0 ];
current_palette = [];
current_color = 0;
@ -41,12 +45,9 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node_Processor(_x, _y, _
function sortPalette(pal) {
array_sort(pal, function(c0, c1) {
var r0 = _color_get_red(c0);
var r1 = _color_get_red(c1);
var g0 = _color_get_green(c0);
var g1 = _color_get_green(c1);
var b0 = _color_get_blue(c0);
var b1 = _color_get_blue(c1);
var r0 = _color_get_red(c0), r1 = _color_get_red(c1);
var g0 = _color_get_green(c0), g1 = _color_get_green(c1);
var b0 = _color_get_blue(c0), b1 = _color_get_blue(c1);
var l0 = sqrt( .241 * r0 + .691 * g0 + .068 * b0 );
var l1 = sqrt( .241 * r1 + .691 * g1 + .068 * b1 );
@ -304,8 +305,26 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node_Processor(_x, _y, _
var _size = _data[1];
var _seed = _data[2];
var _algo = _data[3];
var _mask = _data[5];
return extractPalette(_surf, _algo, _size, _seed);
if(!is_surface(_surf)) return;
if(!is_surface(_mask)) return extractPalette(_surf, _algo, _size, _seed);
var _dim = surface_get_dimension(_surf);
temp_surface[0] = surface_verify(temp_surface[0], _dim[0], _dim[1]);
surface_set_target(temp_surface[0]);
DRAW_CLEAR
BLEND_OVERRIDE
draw_surface(_surf, 0, 0);
BLEND_MULTIPLY
draw_surface(_mask, 0, 0);
BLEND_NORMAL
surface_reset_target();
return extractPalette(temp_surface[0], _algo, _size, _seed);
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
@ -314,7 +333,7 @@ function Node_Palette_Extract(_x, _y, _group = noone) : Node_Processor(_x, _y, _
var pal = outputs[0].getValue();
if(array_empty(pal)) return;
if(!is_array(pal[0])) pal = [ pal ];
if(!is_array(array_safe_get(pal, 0))) pal = [ pal ];
var _y = bbox.y0;
var gh = bbox.h / array_length(pal);

View file

@ -61,7 +61,8 @@ function Node_Smoke_Apply_Velocity(_x, _y, _group = noone) : Node_Smoke(_x, _y,
}
}
inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
var hv = inputs[2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny); hover &= !hv;
var hv = inputs[3].drawOverlay(hover, active, _px, _py, _s, _mx, _my, _snx, _sny, 0, 4); hover &= !hv;
}
static update = function(frame = CURRENT_FRAME) {

View file

@ -1793,12 +1793,15 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
if(mouse_on_graph && !node_bg_hovering && mouse_press(mb_left, _focus) && !graph_dragging_key && !graph_zooming_key) {
if(is_instanceof(junction_hovering, NodeValue) && junction_hovering.draw_line_shift_hover) {
nodes_select_mx = mx;
nodes_select_my = my;
nodes_junction_d = junction_hovering;
nodes_junction_dx = junction_hovering.draw_line_shift_x;
nodes_junction_dy = junction_hovering.draw_line_shift_y;
nodes_select_mx = mx;
nodes_select_my = my;
nodes_junction_d = junction_hovering;
nodes_junction_dx = junction_hovering.draw_line_shift_x;
nodes_junction_dy = junction_hovering.draw_line_shift_y;
recordAction(ACTION_TYPE.var_modify, junction_hovering, [ junction_hovering.draw_line_shift_x, "draw_line_shift_x", "junction anchor x position" ]);
recordAction(ACTION_TYPE.var_modify, junction_hovering, [ junction_hovering.draw_line_shift_y, "draw_line_shift_y", "junction anchor y position" ]);
} else if(array_empty(nodes_selecting) && !value_focus && !drag_locking) {
nodes_select_drag = 1;
nodes_select_frame = frame_hovering == noone;
@ -3559,6 +3562,9 @@ function load_file_path(path, _x = undefined, _y = undefined) {
node = new Node_Palette(_x, _y, PANEL_GRAPH.getCurrentContext()).skipDefault();
node.inputs[0].setValue(loadPalette(p));
break;
default :
if(string_starts_with(ext, "pxc")) LOAD_PATH(p);
}
if(!IS_CMD) PANEL_GRAPH.mouse_grid_y += 160;

View file

@ -77,7 +77,11 @@ function path_is_project(path, checkExist = true) {
case "pxc":
case "cpxc":
return true;
default :
return string_starts_with(ext, "pxc");
}
return false;
}