node snap

This commit is contained in:
Tanasart 2024-07-02 18:25:59 +07:00
parent 67644b3b7c
commit 14bf99095b
9 changed files with 58 additions and 22 deletions

View File

@ -54,7 +54,6 @@ if !ready exit;
case "Node_Image_Animated" : Node_create_Image_Animated_path(nx, ny, path_arr); break; case "Node_Image_Animated" : Node_create_Image_Animated_path(nx, ny, path_arr); break;
case "Node_Directory_Search" : Node_create_Directory_path(nx, ny, paths[0]); break; case "Node_Directory_Search" : Node_create_Directory_path(nx, ny, paths[0]); break;
} }
PANEL_GRAPH.fullView();
instance_destroy(); instance_destroy();
} }
} }

View File

@ -138,7 +138,7 @@ function buttonGroup(_data, _onClick) : widget() constructor {
} }
} else { } else {
sb_small.setFocusHover(active, hover); sb_small.setFocusHover(active, hover);
sb_small.draw(_x, _y, _w, _h, data[_selecting], _m, _rx, _ry); sb_small.draw(_x, _y, _w, _h, array_safe_get(data, _selecting, "-"), _m, _rx, _ry);
} }
if(WIDGET_CURRENT == self) if(WIDGET_CURRENT == self)

View File

@ -61,12 +61,18 @@ function canvas_tool_node(canvas, node) : canvas_tool() constructor {
inputJunction = noone; inputJunction = noone;
outputJunction = noone; outputJunction = noone;
setColor = true;
for( var i = 0, n = ds_list_size(nodeObject.inputs); i < n; i++ ) { for( var i = 0, n = ds_list_size(nodeObject.inputs); i < n; i++ ) {
var _in = nodeObject.inputs[| i]; var _in = nodeObject.inputs[| i];
if(_in.type == VALUE_TYPE.surface || _in.name == "Dimension") { if(_in.type == VALUE_TYPE.surface || _in.name == "Dimension")
inputJunction = _in; inputJunction = _in;
break;
if(_in.type == VALUE_TYPE.color && setColor) {
_in.setValue(CURRENT_COLOR);
setColor = false;
} }
} }
for( var i = 0, n = ds_list_size(nodeObject.outputs); i < n; i++ ) { for( var i = 0, n = ds_list_size(nodeObject.outputs); i < n; i++ ) {

View File

@ -38,7 +38,7 @@
LATEST_VERSION = 11700; LATEST_VERSION = 11700;
VERSION = 11760; VERSION = 11760;
SAVE_VERSION = 11700; SAVE_VERSION = 11700;
VERSION_STRING = "1.17.6.004"; VERSION_STRING = "1.17.6.005";
BUILD_NUMBER = 11760; BUILD_NUMBER = 11760;
globalvar HOTKEYS, HOTKEY_CONTEXT; globalvar HOTKEYS, HOTKEY_CONTEXT;

View File

@ -298,7 +298,7 @@ function Node_Collection(_x, _y, _group = noone) : Node(_x, _y, _group) construc
return _nodes; return _nodes;
} #endregion } #endregion
static getInput = function(junc = noone) { #region static getInput = function(_y = 0, junc = noone) { #region
return input_dummy; return input_dummy;
} #endregion } #endregion

View File

@ -449,19 +449,27 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
function onInputResize() { refreshDynamicInput(); triggerRender(); } function onInputResize() { refreshDynamicInput(); triggerRender(); }
static getOutput = function(junc = noone) { #region static getOutput = function(_y, junc = noone) {
var _targ = noone;
var _dy = 9999;
for( var i = 0; i < ds_list_size(outputs); i++ ) { for( var i = 0; i < ds_list_size(outputs); i++ ) {
if(!outputs[| i].visible) continue; if(!outputs[| i].visible) continue;
if(junc != noone && !junc.isConnectable(outputs[| i], true)) continue; if(junc != noone && !junc.isConnectable(outputs[| i], true)) continue;
return outputs[| i]; var _ddy = abs(outputs[| i].y - _y);
if(_ddy < _dy) {
_targ = outputs[| i];
_dy = _ddy;
}
} }
return noone; return _targ;
} #endregion }
static getInput = function(junc = noone, shift = input_fix_len) { #region
if(dummy_input) return dummy_input;
static getInput = function(_y = 0, junc = noone, shift = input_fix_len) {
var _targ = noone;
var _dy = 9999;
for( var i = shift; i < ds_list_size(inputs); i++ ) { for( var i = shift; i < ds_list_size(inputs); i++ ) {
var _inp = inputs[| i]; var _inp = inputs[| i];
@ -469,10 +477,22 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
if(_inp.value_from != noone) continue; if(_inp.value_from != noone) continue;
if(junc != noone && (value_bit(junc.type) & value_bit(_inp.type)) == 0) continue; if(junc != noone && (value_bit(junc.type) & value_bit(_inp.type)) == 0) continue;
return _inp; var _ddy = abs(_inp.y - _y);
if(_ddy < _dy) {
_targ = _inp;
_dy = _ddy;
}
} }
return noone;
} #endregion if(dummy_input) {
var _ddy = abs(dummy_input.y - _y);
if(_ddy < _dy)
_targ = dummy_input;
}
return _targ;
}
/////========== INSPECTOR =========== /////========== INSPECTOR ===========
@ -726,7 +746,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
} if(!APPENDING && !LOADING) run_in(1, method(self, resetDefault)); } if(!APPENDING && !LOADING) run_in(1, method(self, resetDefault));
static addInput = function(junctionFrom, shift = input_fix_len) { #region static addInput = function(junctionFrom, shift = input_fix_len) { #region
var targ = getInput(junctionFrom, shift); var targ = getInput(y, junctionFrom, shift);
if(targ == noone) return; if(targ == noone) return;
targ.setFrom(junctionFrom); targ.setFrom(junctionFrom);
@ -1360,9 +1380,18 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
var yy = y * _s + _y; var yy = y * _s + _y;
var _hov = PANEL_GRAPH.pHOVER && (PANEL_GRAPH.node_hovering == noone || PANEL_GRAPH.node_hovering == self); var _hov = PANEL_GRAPH.pHOVER && (PANEL_GRAPH.node_hovering == noone || PANEL_GRAPH.node_hovering == self);
show_input_name = _hov && point_in_rectangle(_mx, _my, xx - 12 * _s, yy + 20 * _s, xx + 12 * _s, yy + h * _s); show_input_name = _hov && point_in_rectangle(_mx, _my, xx - 12 * _s, yy + 20 * _s, xx + 12 * _s, yy + h * _s);
show_output_name = _hov && point_in_rectangle(_mx, _my, xx + (w - 12) * _s, yy + 20 * _s, xx + (w + 12) * _s, yy + h * _s); show_output_name = _hov && point_in_rectangle(_mx, _my, xx + (w - 12) * _s, yy + 20 * _s, xx + (w + 12) * _s, yy + h * _s);
if(PANEL_GRAPH.value_dragging && PANEL_GRAPH.node_hovering == self) {
if(PANEL_GRAPH.value_dragging.connect_type == JUNCTION_CONNECT.input)
show_output_name = true;
if(PANEL_GRAPH.value_dragging.connect_type == JUNCTION_CONNECT.output)
show_input_name = true;
}
if(show_input_name) { if(show_input_name) {
for(var i = 0, n = array_length(inputDisplayList); i < n; i++) { for(var i = 0, n = array_length(inputDisplayList); i < n; i++) {
var jun = inputDisplayList[i]; var jun = inputDisplayList[i];

View File

@ -206,7 +206,7 @@
var _var = strs[0]; var _var = strs[0];
var splt = string_splice(_var, "["); var splt = string_splice(_var, "[");
var inp = PROJECT.globalNode.getInput(_var); var inp = PROJECT.globalNode.getInputKey(_var);
if(inp == noone) { if(inp == noone) {
noti_warning($"Variable {_var} not found."); noti_warning($"Variable {_var} not found.");
return 0; return 0;

View File

@ -219,7 +219,7 @@ function Node_Global(_x = 0, _y = 0) : __Node_Base(_x, _y) constructor {
return true; return true;
} #endregion } #endregion
static getInput = function(key, def = noone) { #region static getInputKey = function(key, def = noone) { #region
if(!ds_map_exists(value, key)) return def; if(!ds_map_exists(value, key)) return def;
return value[? key]; return value[? key];
} #endregion } #endregion

View File

@ -1666,15 +1666,17 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
if(value_focus && value_focus != value_dragging) if(value_focus && value_focus != value_dragging)
target = value_focus; target = value_focus;
if(key_mod_press(CTRL) && node_hovering != noone) { else if(!key_mod_press(CTRL) && node_hovering != noone) {
if(value_dragging.connect_type == JUNCTION_CONNECT.input) { if(value_dragging.connect_type == JUNCTION_CONNECT.input) {
target = node_hovering.getOutput(value_dragging); target = node_hovering.getOutput(my, value_dragging);
if(target != noone) if(target != noone)
node_hovering.active_draw_index = 1; node_hovering.active_draw_index = 1;
} else { } else {
target = node_hovering.getInput(value_dragging, 0); target = node_hovering.getInput(my, value_dragging, 0);
if(target != noone) if(target != noone)
node_hovering.active_draw_index = 1; node_hovering.active_draw_index = 1;
} }
} }