Connection visibility

This commit is contained in:
Tanasart 2023-08-31 18:49:57 +02:00
parent 0f8232645b
commit 970513a8b3
12 changed files with 187 additions and 87 deletions

View file

@ -698,7 +698,8 @@ event_inherited();
__txtx("add_node_create_equation", "Create equation") + ": " + eq, -1, search_pane.w - ui(32));
draw_set_text(f_p0, fa_center, fa_top, COLORS._main_text_sub);
draw_text(search_pane.w / 2, search_pane.h / 2 - ui(4), __txtx("add_node_equation_enter", "Press Enter to create equation node."));
draw_text_add(round(search_pane.w / 2), round(search_pane.h / 2 - ui(4)),
__txtx("add_node_equation_enter", "Press Enter to create equation node."));
if(keyboard_check_pressed(vk_enter))
buildNode(ALL_NODES[? "Node_Equation"], eq);

View file

@ -28,7 +28,10 @@ function draw_text_cut(x, y, str, w, scale = 1) {
function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation) {
if(!LOCALE.config.per_character_line_break) {
BLEND_ALPHA_MULP;
draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation);
BLEND_NORMAL;
return string_height_ext(_text, _sep, _w) * sy;
}
@ -71,7 +74,8 @@ function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation)
case fa_middle : yy = _y - hh / 2; break;
case fa_bottom : yy = _y - hh; break;
}
BLEND_ALPHA_MULP;
for( var i = 0, n = array_length(lines); i < n; i++ ) {
var lw = string_width(lines[i]) * sx;
@ -84,6 +88,7 @@ function __draw_text_ext_transformed(_x, _y, _text, _sep, _w, sx, sy, rotation)
draw_text_transformed(xx, yy, lines[i], sx, sy, rotation);
yy += string_height("M") * sy;
}
BLEND_NORMAL;
draw_set_halign(ha);
draw_set_valign(va);

View file

@ -749,7 +749,7 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
}
} #endregion
static drawConnections = function(_x, _y, _s, mx, my, _active, aa = 1, minx = undefined, miny = undefined, maxx = undefined, maxy = undefined) { #region
static drawConnections = function(params = {}) { #region
if(!active) return;
var hovering = noone;
@ -800,7 +800,7 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
else if(i == -2) jun = inspectInput2;
else jun = inputs[| i];
var hov = jun.drawConnections(_x, _y, _s, mx, my, _active, aa, minx, miny, maxx, maxy);
var hov = jun.drawConnections(params);
if(hov) hovering = hov;
}
@ -981,8 +981,6 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
static drawActive = function(_x, _y, _s, ind = 0) { active_draw_index = ind; }
static drawPreview = function(_x, _y, _s) {}
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {}
static drawAnimationTimeline = function(_w, _h, _s) {}
@ -1268,7 +1266,9 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x
} #endregion
static getPreviewValues = function() { #region
if(preview_channel > ds_list_size(outputs)) return noone;
if(preview_channel >= ds_list_size(outputs)) return noone;
if(outputs[| preview_channel].type != VALUE_TYPE.surface) return noone; //I feels like I've wrote this line before. Did I delete it because of a bug? Am I reintroducing old bug?
return outputs[| preview_channel].getValue();
} #endregion

View file

@ -1,4 +1,4 @@
function Node_create_Equation(_x, _y, _group = noone, _param = "") {
function Node_create_Equation(_x, _y, _group = noone, _param = "") { #region
var node = new Node_Equation(_x, _y, _group);
if(_param == "") return node;
@ -26,29 +26,31 @@ function Node_create_Equation(_x, _y, _group = noone, _param = "") {
node.inputs[| 1 + i * 2].setValue(vars[i]);
return node;
}
} #endregion
function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Equation";
color = COLORS.node_blend_number;
previewable = false;
w = 96;
w = 96;
ast = [];
inputs[| 0] = nodeValue("Equation", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "");
static createNewInput = function() {
static createNewInput = function() { #region
var index = ds_list_size(inputs);
inputs[| index + 0] = nodeValue("Argument name", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "" );
inputs[| index + 0] = nodeValue("Argument name", self, JUNCTION_CONNECT.input, VALUE_TYPE.text, "" )
.setDisplay(VALUE_DISPLAY.text_box);
inputs[| index + 1] = nodeValue("Argument value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
.setVisible(true, true);
inputs[| index + 1].editWidget.interactable = false;
}
} #endregion
outputs[| 0] = nodeValue("Result", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0);
argument_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
argument_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
argument_renderer.x = _x;
argument_renderer.y = _y;
argument_renderer.w = _w;
@ -79,12 +81,12 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
argument_renderer.h = hh;
return hh;
});
}); #endregion
argument_renderer.register = function(parent = noone) {
argument_renderer.register = function(parent = noone) { #region
for( var i = input_fix_len; i < ds_list_size(inputs); i++ )
inputs[| i].editWidget.register(parent);
}
} #endregion
input_display_list = [
["Function", false], 0,
@ -96,7 +98,7 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
if(!LOADING && !APPENDING) createNewInput();
static refreshDynamicInput = function() {
static refreshDynamicInput = function() { #region
var _in = ds_list_create();
for( var i = 0; i < input_fix_len; i++ )
@ -127,18 +129,18 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
inputs = _in;
createNewInput();
}
} #endregion
static onValueUpdate = function(index = 0) {
static onValueUpdate = function(index = 0) { #region
if(LOADING || APPENDING) return;
if(safe_mod(index - input_fix_len, data_length) == 0) //Variable name
inputs[| index + 1].name = inputs[| index].getValue();
refreshDynamicInput();
}
} #endregion
static processData = function(_output, _data, _output_index, _array_index = 0) {
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
var eq = _data[0];
var params = {};
@ -149,19 +151,24 @@ function Node_Equation(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
variable_struct_set(params, _pName, _pVal);
}
return evaluateFunction(eq, params);
}
var _tree = array_safe_get(ast, _array_index, noone);
if(_tree == noone || _tree.fx != eq) {
ast[_array_index] = { fx: eq, tree: evaluateFunctionTree(eq) };
_tree = ast[_array_index];
}
if(_tree == noone) return noone;
return _tree.tree.eval(params);
} #endregion
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
var str = inputs[| 0].getValue();
var bbox = drawGetBbox(xx, yy, _s);
var ss = string_scale(str, bbox.w, bbox.h);
draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0);
}
} #endregion
static doApplyDeserialize = function() {
refreshDynamicInput();
}
static doApplyDeserialize = function() { refreshDynamicInput(); }
}

View file

@ -94,6 +94,7 @@ enum VALUE_DISPLAY {
//Text
code,
text_array,
text_box,
//path
path_save,
@ -466,6 +467,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
draw_line_shift_y = 0;
draw_line_thick = 1;
draw_line_shift_hover = false;
draw_line_blend = 1;
drawLineIndex = 1;
draw_line_vb = noone;
@ -945,6 +947,13 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
});
extract_node = "Node_String";
break;
case VALUE_DISPLAY.text_box :
editWidget = new textBox(TEXTBOX_INPUT.text, function(str) {
return setValueDirect(str);
});
extract_node = "Node_String";
break;
case VALUE_DISPLAY.code :
editWidget = new textArea(TEXTBOX_INPUT.text, function(str) {
@ -1709,11 +1718,29 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
}
} #endregion
static drawConnections = function(_x, _y, _s, mx, my, _active, aa = 1, minx = undefined, miny = undefined, maxx = undefined, maxy = undefined) { #region
static drawConnections = function(params = {}) { #region
if(value_from == noone) return noone;
if(!value_from.node.active) return noone;
if(!isVisible()) return noone;
var _x = params.x;
var _y = params.y;
var _s = params.s;
var mx = params.mx;
var my = params.my;
var _active = params.active;
var cur_layer = params.cur_layer;
var max_layer = params.max_layer;
var aa = struct_try_get(params, "aa", 1);
var minx = struct_try_get(params, "minx", undefined);
var miny = struct_try_get(params, "miny", undefined);
var maxx = struct_try_get(params, "maxx", undefined);
var maxy = struct_try_get(params, "maxy", undefined);
var high = struct_try_get(params, "highlight", true);
var bg = struct_try_get(params, "bg", c_black);
var hovering = noone;
var jx = x;
var jy = y;
@ -1728,10 +1755,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
if(jy < miny && fry < miny) return noone;
if(jy > maxy && fry > maxy) return noone;
}
var c0 = value_color(value_from.type);
var c1 = value_color(type);
var shx = draw_line_shift_x * _s;
var shy = draw_line_shift_y * _s;
@ -1792,7 +1816,25 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
var ty = LINE_STYLE.solid;
if(type == VALUE_TYPE.node)
ty = LINE_STYLE.dashed;
var c0, c1;
if(PREF_MAP[? "connection_line_highlight"]) {
var _colr = 1;
var _fade = PREF_MAP[? "connection_line_highlight_fade"];
if(high) _colr = node.active_draw_index == -1? _fade : 1;
if(thicken) _colr = 1;
draw_line_blend = _colr == 1? 1 : lerp_float(draw_line_blend, _colr, 3);
c0 = merge_color(bg, value_color(value_from.type), draw_line_blend);
c1 = merge_color(bg, value_color(type), draw_line_blend);
} else {
c0 = value_color(value_from.type);
c1 = value_color(type);
}
var ss = _s * aa;
jx *= aa;
jy *= aa;

View file

@ -20,6 +20,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
avoid_label : true,
preview_scale : 100,
}
bg_color = c_black;
#endregion
#region ---- position ----
@ -57,7 +59,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
#region ---- nodes ----
node_context = ds_list_create();
node_dragging = noone;
node_drag_mx = 0;
node_drag_my = 0;
@ -684,7 +686,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
}
}
if(mouse_press(mb_right, pFOCUS)) {
if(mouse_press(mb_right, pFOCUS)) { #region
node_hover = node_hovering;
if(node_hover) {
var menu = [];
@ -850,7 +852,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
menuCall("graph_node_selected_menu", o_dialog_add_node.dialog_x - ui(8), o_dialog_add_node.dialog_y + ui(4), menu, fa_right );
setFocus(o_dialog_add_node.id, "Dialog");
}
}
} #endregion
}
printIf(log, "Node selection time: " + string(current_time - t)); t = current_time;
@ -871,8 +873,28 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
var hov = noone;
var hoverable = !bool(node_dragging) && pHOVER;
var _params = {
x : gr_x,
y : gr_y,
s : graph_s,
mx : mx,
my : my,
aa : aa,
bg : bg_color,
minx : -64,
miny : -64,
maxx : w + 64,
maxy : h + 64,
active : hoverable,
max_layer : ds_list_size(nodes_list),
highlight : !ds_list_empty(nodes_select_list) || node_focus != noone,
};
for(var i = 0; i < ds_list_size(nodes_list); i++) {
var _hov = nodes_list[| i].drawConnections(gr_x, gr_y, graph_s, mx, my, hoverable, aa, -64, -64, w + 64, h + 64);
_params.cur_layer = i + 1;
var _hov = nodes_list[| i].drawConnections(_params);
if(_hov != noone && is_struct(_hov)) hov = _hov;
}
printIf(log, "Draw connection: " + string(current_time - t)); t = current_time;
@ -990,7 +1012,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
node_dragging = noone;
#endregion
if(mouse_on_graph && pFOCUS) {
if(mouse_on_graph && pFOCUS) { #region
if(node_focus && node_focus.draggable && value_focus == noone) {
if(mouse_press(mb_left) && !key_mod_press(ALT)) {
node_dragging = node_focus;
@ -1012,7 +1034,7 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
_pin.inputs[| 0].setFrom(junction_hovering.value_from);
junction_hovering.setFrom(_pin.outputs[| 0]);
}
}
} #endregion
#region draw selection frame
if(nodes_select_drag) {
@ -1454,8 +1476,8 @@ function Panel_Graph(project = PROJECT) : PanelContent() constructor {
dragGraph();
var context = getCurrentContext();
var bg = context == noone? COLORS.panel_bg_clear : merge_color(COLORS.panel_bg_clear, context.color, 0.05);
draw_clear(bg);
bg_color = context == noone? COLORS.panel_bg_clear : merge_color(COLORS.panel_bg_clear, context.color, 0.05);
draw_clear(bg_color);
drawGrid();
draw_set_text(f_p0, fa_right, fa_top, COLORS._main_text_sub);

View file

@ -31,7 +31,19 @@ function Panel_Graph_Connection_Setting() : Panel_Linear_Setting() constructor {
}),
__txtx("pref_connection_quality", "Render quality"),
function() { return PREF_MAP[? "connection_line_aa"]; }
]
],
[
new checkBox(function() {
PREF_MAP[? "connection_line_highlight"] = !PREF_MAP[? "connection_line_highlight"];
}),
__txtx("pref_connection_highlight", "Highlight connection"),
function() { return PREF_MAP[? "connection_line_highlight"]; }
],
[
new slider(0, 1, 0.05, function(val) { PREF_MAP[? "connection_line_highlight_fade"] = val; }),
__txtx("pref_connection_highlight_fade", "Fade connection"),
function() { return PREF_MAP[? "connection_line_highlight_fade"] },
],
];
setHeight();

View file

@ -89,8 +89,21 @@ function graph_export_image(allList, nodeList, settings = {}) {
#region draw conneciton
surface_set_target(cs);
DRAW_CLEAR
var _params = {
x : gr_x,
y : gr_y,
s : scale,
mx : mx,
my : my,
aa : aa,
active : true,
max_layer : 1,
cur_layer : 1,
highlight : false,
};
for(var i = 0; i < ds_list_size(nodeList); i++)
nodeList[| i].drawConnections(gr_x, gr_y, scale, mx, my, true, aa);
nodeList[| i].drawConnections(_params);
surface_reset_target();
shader_set(sh_downsample);

View file

@ -293,8 +293,8 @@ function Panel_Preview() : PanelContent() constructor {
function getNodePreviewSequence() { return preview_sequence[splitView? splitSelection : 0]; }
function getPreviewData() { #region
preview_surface = [ 0, 0 ];
preview_sequence = [ 0, 0 ];
preview_surface = [ noone, noone ];
preview_sequence = [ noone, noone ];
for( var i = 0; i < 2; i++ ) {
var node = preview_node[i];
@ -315,7 +315,7 @@ function Panel_Preview() : PanelContent() constructor {
canvas_a = 0;
}
if(preview_sequence[i] != 0) {
if(preview_sequence[i] != noone) {
if(array_length(preview_sequence[i]) == 0) return;
preview_surface[i] = preview_sequence[i][safe_mod(node.preview_index, array_length(preview_sequence[i]))];
}
@ -618,13 +618,8 @@ function Panel_Preview() : PanelContent() constructor {
}
var _node = getNodePreview();
if(_node) {
if(_node)
title = _node.display_name == ""? _node.name : _node.display_name;
var cx = canvas_x + _node.preview_x * canvas_s;
var cy = canvas_y + _node.preview_y * canvas_s;
_node.drawPreview(cx, cy, canvas_s);
}
if(splitView == 0 && tileMode == 0 && is_surface(preview_surface[0])) {
var node = preview_node[0];
@ -997,7 +992,7 @@ function Panel_Preview() : PanelContent() constructor {
#endregion
var pseq = getNodePreviewSequence();
if(pseq == 0) return;
if(pseq == noone) return;
if(!array_equals(pseq, _preview_sequence)) {
_preview_sequence = pseq;

View file

@ -28,6 +28,8 @@
PREF_MAP[? "connection_line_corner"] = 8;
PREF_MAP[? "connection_line_aa"] = 2;
PREF_MAP[? "connection_line_transition"] = true;
PREF_MAP[? "connection_line_highlight"] = false;
PREF_MAP[? "connection_line_highlight_fade"] = 0.75;
PREF_MAP[? "curve_connection_line"] = 1;
PREF_MAP[? "default_surface_side"] = 32;

View file

@ -7,10 +7,9 @@ enum TEXT_AREA_FORMAT {
}
function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onModify, _extras) constructor {
font = f_p0;
hide = false;
line_width = 1000;
color = COLORS._main_text;
font = f_p0;
hide = false;
color = COLORS._main_text;
boxColor = c_white;
auto_update = false;
@ -24,7 +23,8 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
_prev_width = 0;
_stretch_width = false;
min_lines = 0;
min_lines = 0;
line_width = 1000;
cursor = 0;
cursor_tx = 0;
@ -32,7 +32,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
cursor_pos_x_to = 0;
cursor_pos_y = 0;
cursor_pos_y_to = 0;
cursor_line = 0;
cursor_line = 0;
char_run = 0
@ -45,17 +45,17 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
parser_server = noone;
autocomplete_box = instance_create(0, 0, o_dialog_textbox_autocomplete);
autocomplete_box = instance_create(0, 0, o_dialog_textbox_autocomplete);
autocomplete_box.textbox = self;
autocomplete_server = noone;
autocomplete_server = noone;
function_guide_box = instance_create(0, 0, o_dialog_textbox_function_guide);
function_guide_box = instance_create(0, 0, o_dialog_textbox_function_guide);
function_guide_box.textbox = self;
function_guide_server = noone;
function_guide_server = noone;
_cl = -1;
static activate = function() {
static activate = function() { #region
WIDGET_CURRENT = self;
WIDGET_CURRENT_SCROLL = parent;
parentFocus();
@ -70,16 +70,16 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
keyboard_lastkey = -1;
cut_line();
}
} #endregion
static deactivate = function() {
static deactivate = function() { #region
if(WIDGET_CURRENT != self) return;
apply();
WIDGET_CURRENT = noone;
UNDO_HOLDING = false;
}
} #endregion
static onModified = function() {
static onModified = function() { #region
if(format == TEXT_AREA_FORMAT.code && autocomplete_server != noone) {
var crop = string_copy(_input_text, 1, cursor);
var slp = string_splice(crop, [" ", "(", ",", "\n"]);
@ -138,9 +138,9 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
} else
function_guide_box.active = false;
}
}
} #endregion
static onKey = function(key) {
static onKey = function(key) { #region
if(key == vk_left) {
if(key_mod_press(SHIFT)) {
if(cursor_select == -1)
@ -244,21 +244,21 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
cursor = _target;
onModified();
}
}
} #endregion
static apply = function() {
static apply = function() { #region
if(onModify) onModify(_input_text);
UNDO_HOLDING = true;
}
} #endregion
static move_cursor = function(delta) {
static move_cursor = function(delta) { #region
var ll = string_length(_input_text);
cursor = clamp(cursor + delta, 0, ll);
onModified();
}
} #endregion
static cut_line = function() {
static cut_line = function() { #region
_input_text_line = [];
_input_text_line_index = [];
draw_set_font(font);
@ -315,9 +315,9 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
array_push(_input_text_line_index, _iIndex); _iIndex = "";
}
}
}
} #endregion
static editText = function() {
static editText = function() { #region
//print("==========");
//print(_input_text);
//print($"cursor: {cursor}");
@ -480,9 +480,9 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
} else if(keyboard_check_pressed(vk_enter) && !key_mod_press(SHIFT)) {
deactivate();
}
}
} #endregion
static display_text = function(_x, _y, _text, _w, _mx = -1, _my = -1) {
static display_text = function(_x, _y, _text, _w, _mx = -1, _my = -1) { #region
_text = string_real(_text);
if(_w != _prev_width) {
_prev_width = _w;
@ -576,13 +576,13 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
cursor_select = target;
}
}
}
} #endregion
static drawParam = function(params) {
static drawParam = function(params) { #region
return draw(params.x, params.y, params.w, params.h, params.data, params.m);
}
} #endregion
static draw = function(_x, _y, _w, _h, _text, _m) {
static draw = function(_x, _y, _w, _h, _text, _m) { #region
x = _x;
y = _y;
w = _w;
@ -748,5 +748,5 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod
resetFocus();
return hh;
}
} #endregion
}

View file

@ -15,9 +15,10 @@ void main() {
for( float j = 0.; j < down; j++ ) {
vec4 samp = texture2D( gm_BaseTexture, v_vTexcoord * down + vec2(i, j) / dimension );
col += samp;
wei += samp.a;
}
col /= down * down;
col /= wei;
gl_FragColor = col * v_vColour;
}