2023-07-06 19:49:16 +02:00
|
|
|
/// @desc Panel for displaying node graph
|
|
|
|
/// @param {Struct.Project}
|
|
|
|
function Panel_Graph(project = PROJECT) : PanelContent() constructor {
|
2023-06-04 18:28:29 +02:00
|
|
|
title = __txt("Graph");
|
2022-01-13 05:24:03 +01:00
|
|
|
context_str = "Graph";
|
2023-03-21 03:01:53 +01:00
|
|
|
icon = THEME.panel_graph;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-06 19:49:16 +02:00
|
|
|
static setProject = function(project) {
|
|
|
|
self.project = project;
|
|
|
|
nodes_list = project.nodes;
|
|
|
|
}
|
|
|
|
setProject(project);
|
|
|
|
|
2023-08-16 20:16:31 +02:00
|
|
|
#region ---- display ----
|
|
|
|
display_parameter = {
|
|
|
|
show_grid : true,
|
|
|
|
show_dimension : true,
|
|
|
|
show_compute : true,
|
|
|
|
|
2023-08-19 12:42:50 +02:00
|
|
|
avoid_label : true,
|
2023-08-16 20:16:31 +02:00
|
|
|
preview_scale : 100,
|
2023-10-12 07:07:24 +02:00
|
|
|
highlight : false,
|
2023-08-16 20:16:31 +02:00
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
|
|
|
|
bg_color = c_black;
|
2023-08-16 20:16:31 +02:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ---- position ----
|
|
|
|
scale = [ 0.01, 0.02, 0.05, 0.10, 0.15, 0.20, 0.25, 0.33, 0.5, 0.65, 0.8, 1, 1.2, 1.35, 1.5, 2.0];
|
|
|
|
graph_s = 1;
|
|
|
|
graph_s_to = graph_s;
|
|
|
|
|
|
|
|
graph_dragging_key = false;
|
|
|
|
graph_zooming_key = false;
|
|
|
|
|
|
|
|
graph_draggable= true;
|
|
|
|
graph_dragging = false;
|
|
|
|
graph_drag_mx = 0;
|
|
|
|
graph_drag_my = 0;
|
|
|
|
graph_drag_sx = 0;
|
|
|
|
graph_drag_sy = 0;
|
|
|
|
|
|
|
|
graph_zooming = false;
|
|
|
|
graph_zoom_mx = 0;
|
|
|
|
graph_zoom_my = 0;
|
|
|
|
graph_zoom_m = 0;
|
|
|
|
graph_zoom_s = 0;
|
|
|
|
|
2023-10-31 05:30:42 +01:00
|
|
|
drag_key = PREFERENCES.pan_mouse_key;
|
2023-08-16 20:16:31 +02:00
|
|
|
drag_locking = false;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ---- mouse ----
|
|
|
|
mouse_graph_x = 0;
|
|
|
|
mouse_graph_y = 0;
|
|
|
|
mouse_grid_x = 0;
|
|
|
|
mouse_grid_y = 0;
|
|
|
|
mouse_on_graph = false;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ---- nodes ----
|
|
|
|
node_context = ds_list_create();
|
2023-08-31 18:49:57 +02:00
|
|
|
|
2023-08-16 20:16:31 +02:00
|
|
|
node_dragging = noone;
|
|
|
|
node_drag_mx = 0;
|
|
|
|
node_drag_my = 0;
|
|
|
|
node_drag_sx = 0;
|
|
|
|
node_drag_sy = 0;
|
|
|
|
node_drag_ox = 0;
|
|
|
|
node_drag_oy = 0;
|
|
|
|
|
|
|
|
selection_block = 0;
|
|
|
|
nodes_select_list = ds_list_create();
|
|
|
|
nodes_select_drag = false;
|
|
|
|
nodes_select_mx = 0;
|
|
|
|
nodes_select_my = 0;
|
|
|
|
|
|
|
|
nodes_junction_d = noone;
|
|
|
|
nodes_junction_dx = 0;
|
|
|
|
nodes_junction_dy = 0;
|
|
|
|
|
|
|
|
node_hovering = noone;
|
|
|
|
node_hover = noone;
|
|
|
|
node_focus = noone;
|
|
|
|
|
|
|
|
junction_hovering = noone;
|
|
|
|
add_node_draw_junc = false;
|
|
|
|
add_node_draw_x_fix = 0;
|
|
|
|
add_node_draw_y_fix = 0;
|
|
|
|
add_node_draw_x = 0;
|
|
|
|
add_node_draw_y = 0;
|
|
|
|
|
|
|
|
connection_aa = 2;
|
2023-10-18 14:58:55 +02:00
|
|
|
connection_surface = surface_create(1, 1);
|
|
|
|
connection_surface_aa = surface_create(1, 1);
|
2023-10-24 11:23:20 +02:00
|
|
|
|
|
|
|
connection_draw_mouse = noone;
|
|
|
|
connection_draw_target = noone;
|
|
|
|
|
2023-08-16 20:16:31 +02:00
|
|
|
value_focus = noone;
|
|
|
|
value_dragging = noone;
|
|
|
|
value_draggings = [];
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ---- minimap ----
|
|
|
|
minimap_show = false;
|
|
|
|
minimap_w = ui(160);
|
|
|
|
minimap_h = ui(160);
|
|
|
|
minimap_surface = -1;
|
|
|
|
|
|
|
|
minimap_panning = false;
|
|
|
|
minimap_dragging = false;
|
|
|
|
minimap_drag_sx = 0;
|
|
|
|
minimap_drag_sy = 0;
|
|
|
|
minimap_drag_mx = 0;
|
|
|
|
minimap_drag_my = 0;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ---- context frame ----
|
|
|
|
context_framing = false;
|
|
|
|
context_frame_progress = 0;
|
|
|
|
context_frame_direct = 0;
|
|
|
|
context_frame_sx = 0; context_frame_ex = 0;
|
|
|
|
context_frame_sy = 0; context_frame_ey = 0;
|
|
|
|
#endregion
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2023-03-24 05:55:34 +01:00
|
|
|
toolbar_height = ui(40);
|
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function toCenterNode() { #region
|
2023-08-01 11:16:23 +02:00
|
|
|
if(!project.active) return;
|
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
if(ds_list_empty(nodes_list)) {
|
|
|
|
graph_x = round(w / 2 / graph_s);
|
|
|
|
graph_y = round(h / 2 / graph_s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var minx = 99999;
|
|
|
|
var maxx = -99999;
|
|
|
|
var miny = 99999;
|
|
|
|
var maxy = -99999;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = nodes_list[| i];
|
2023-08-01 11:16:23 +02:00
|
|
|
if(!is_struct(_node) || !is_instanceof(_node, Node) || !_node.active)
|
|
|
|
continue;
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
minx = min(_node.x - 32, minx);
|
|
|
|
maxx = max(_node.x + _node.w + 32, maxx);
|
2023-03-21 03:01:53 +01:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
miny = min(_node.y - 32, miny);
|
|
|
|
maxy = max(_node.y + _node.h + 32, maxy);
|
2023-03-21 03:01:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
graph_x = w / 2 / graph_s - (minx + maxx) / 2;
|
|
|
|
graph_y = (h - toolbar_height) / 2 / graph_s - (miny + maxy) / 2;
|
|
|
|
|
|
|
|
graph_x = round(graph_x);
|
|
|
|
graph_y = round(graph_y);
|
|
|
|
|
|
|
|
//print(title + ": Center " + string(graph_x) + ", " + string(graph_y));
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-03-21 03:01:53 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function initSize() { toCenterNode(); } initSize();
|
2023-03-21 03:01:53 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
#region ++++ toolbars ++++
|
2022-09-21 06:09:40 +02:00
|
|
|
toolbars = [
|
2023-05-29 13:06:05 +02:00
|
|
|
[
|
|
|
|
THEME.icon_preview_export,
|
|
|
|
function() { return 0; },
|
2023-06-04 18:28:29 +02:00
|
|
|
function() { return __txtx("panel_graph_export_image", "Export graph as image"); },
|
2023-05-29 13:06:05 +02:00
|
|
|
function() { dialogPanelCall(new Panel_Graph_Export_Image(self)); }
|
|
|
|
],
|
2022-09-21 06:09:40 +02:00
|
|
|
[
|
2022-11-18 03:20:31 +01:00
|
|
|
THEME.icon_center_canvas,
|
2022-09-21 06:09:40 +02:00
|
|
|
function() { return 0; },
|
2023-06-04 18:28:29 +02:00
|
|
|
function() { return __txtx("panel_graph_center_to_nodes", "Center to nodes"); },
|
2022-09-21 06:09:40 +02:00
|
|
|
function() { toCenterNode(); }
|
|
|
|
],
|
|
|
|
[
|
2022-11-18 03:20:31 +01:00
|
|
|
THEME.icon_minimap,
|
2022-09-21 06:09:40 +02:00
|
|
|
function() { return minimap_show; },
|
2023-06-04 18:28:29 +02:00
|
|
|
function() { return minimap_show? __txtx("panel_graph_minimap_enabled", "Minimap enabled") : __txtx("panel_graph_minimap_disabled", "Minimap disabled"); },
|
2022-09-21 06:09:40 +02:00
|
|
|
function() { minimap_show = !minimap_show; }
|
|
|
|
],
|
|
|
|
[
|
2022-11-18 03:20:31 +01:00
|
|
|
THEME.icon_curve_connection,
|
2023-10-31 05:30:42 +01:00
|
|
|
function() { return PREFERENCES.curve_connection_line; },
|
2023-06-04 18:28:29 +02:00
|
|
|
function() { return __txtx("panel_graph_connection_line", "Connection render settings"); },
|
2023-03-05 07:16:44 +01:00
|
|
|
function(param) {
|
2023-08-29 14:33:44 +02:00
|
|
|
dialogPanelCall(new Panel_Graph_Connection_Setting(), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left });
|
2023-03-05 07:16:44 +01:00
|
|
|
}
|
2022-09-21 06:09:40 +02:00
|
|
|
],
|
|
|
|
[
|
2022-11-18 03:20:31 +01:00
|
|
|
THEME.icon_grid_setting,
|
2022-09-21 06:09:40 +02:00
|
|
|
function() { return 0; },
|
2023-06-04 18:28:29 +02:00
|
|
|
function() { return __txtx("grid_title", "Grid settings"); },
|
2022-09-21 06:09:40 +02:00
|
|
|
function(param) {
|
2023-08-29 14:33:44 +02:00
|
|
|
dialogPanelCall(new Panel_Graph_Grid_Setting(), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left });
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
|
|
|
],
|
2023-01-25 06:49:00 +01:00
|
|
|
[
|
|
|
|
THEME.icon_visibility,
|
|
|
|
function() { return 0; },
|
2023-06-04 18:28:29 +02:00
|
|
|
function() { return __txtx("graph_visibility_title", "Visibility settings"); },
|
2023-01-25 06:49:00 +01:00
|
|
|
function(param) {
|
2023-08-29 14:33:44 +02:00
|
|
|
dialogPanelCall(new Panel_Graph_View_Setting(display_parameter), param.x, param.y, { anchor: ANCHOR.bottom | ANCHOR.left });
|
2023-01-25 06:49:00 +01:00
|
|
|
}
|
|
|
|
],
|
2023-08-13 13:10:20 +02:00
|
|
|
]; #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
#region ++++ hotkeys ++++
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Add node", "A", MOD_KEY.none, function() { PANEL_GRAPH.callAddDialog(); });
|
|
|
|
addHotkey("Graph", "Focus content", "F", MOD_KEY.none, function() { PANEL_GRAPH.fullView(); });
|
|
|
|
addHotkey("Graph", "Preview focusing node", "P", MOD_KEY.none, function() { PANEL_GRAPH.setCurrentPreview(); });
|
2023-06-13 14:42:06 +02:00
|
|
|
addHotkey("Graph", "Preview window", "P", MOD_KEY.ctrl, function() { create_preview_window(PANEL_GRAPH.node_focus); });
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Import image", "I", MOD_KEY.none, function() { nodeBuild("Node_Image", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); });
|
|
|
|
addHotkey("Graph", "Import image array", "I", MOD_KEY.shift, function() { nodeBuild("Node_Image_Sequence", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); });
|
|
|
|
addHotkey("Graph", "Add number", "1", MOD_KEY.none, function() { nodeBuild("Node_Number", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); });
|
|
|
|
addHotkey("Graph", "Add vector2", "2", MOD_KEY.none, function() { nodeBuild("Node_Vector2", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); });
|
|
|
|
addHotkey("Graph", "Add vector3", "3", MOD_KEY.none, function() { nodeBuild("Node_Vector3", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); });
|
|
|
|
addHotkey("Graph", "Add vector4", "4", MOD_KEY.none, function() { nodeBuild("Node_Vector4", PANEL_GRAPH.mouse_grid_x, PANEL_GRAPH.mouse_grid_y); });
|
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
addHotkey("Graph", "Transform node", "T", MOD_KEY.ctrl, function() { PANEL_GRAPH.doTransform(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
addHotkey("Graph", "Select all", "A", MOD_KEY.ctrl, function() {
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
|
|
|
ds_list_add(nodes_select_list, nodes_list[| i]);
|
|
|
|
}
|
|
|
|
});
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2023-08-16 20:16:31 +02:00
|
|
|
addHotkey("Graph", "Toggle grid", "G", MOD_KEY.none, function() { display_parameter.show_grid = !display_parameter.show_grid; });
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Toggle preview", "H", MOD_KEY.none, function() { PANEL_GRAPH.setTriggerPreview(); });
|
|
|
|
addHotkey("Graph", "Toggle render", "R", MOD_KEY.none, function() { PANEL_GRAPH.setTriggerRender(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 02:51:14 +01:00
|
|
|
if(!DEMO)
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Export", "E", MOD_KEY.ctrl, function() { PANEL_GRAPH.setCurrentExport(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Blend", "B", MOD_KEY.ctrl, function() { PANEL_GRAPH.doBlend(); });
|
|
|
|
addHotkey("Graph", "Compose", "B", MOD_KEY.ctrl | MOD_KEY.shift, function() { PANEL_GRAPH.doCompose(); });
|
|
|
|
addHotkey("Graph", "Array", "A", MOD_KEY.ctrl | MOD_KEY.shift, function() { PANEL_GRAPH.doArray(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Group", "G", MOD_KEY.ctrl, function() { PANEL_GRAPH.doGroup(); });
|
|
|
|
addHotkey("Graph", "Ungroup", "G", MOD_KEY.ctrl | MOD_KEY.shift, function() { PANEL_GRAPH.doUngroup(); });
|
2022-01-23 04:08:16 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Loop", "L", MOD_KEY.ctrl, function() { PANEL_GRAPH.doLoop(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Canvas", "C", MOD_KEY.ctrl | MOD_KEY.shift, function() { PANEL_GRAPH.setCurrentCanvas(); });
|
|
|
|
addHotkey("Graph", "Canvas blend", "C", MOD_KEY.ctrl | MOD_KEY.alt, function() { PANEL_GRAPH.setCurrentCanvasBlend(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Frame", "F", MOD_KEY.ctrl, function() { PANEL_GRAPH.doFrame(); });
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Delete (break)", vk_delete, MOD_KEY.shift, function() { PANEL_GRAPH.doDelete(false); });
|
|
|
|
addHotkey("Graph", "Delete (merge)", vk_delete, MOD_KEY.none, function() { PANEL_GRAPH.doDelete(true); });
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
addHotkey("Graph", "Duplicate", "D", MOD_KEY.ctrl, function() { PANEL_GRAPH.doDuplicate(); });
|
|
|
|
addHotkey("Graph", "Copy", "C", MOD_KEY.ctrl, function() { PANEL_GRAPH.doCopy(); });
|
|
|
|
addHotkey("Graph", "Paste", "V", MOD_KEY.ctrl, function() { PANEL_GRAPH.doPaste(); });
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
addHotkey("Graph", "Pan", "", MOD_KEY.alt, function() {
|
2023-10-31 05:30:42 +01:00
|
|
|
if(PREFERENCES.alt_picker) return;
|
2023-07-30 13:56:22 +02:00
|
|
|
PANEL_GRAPH.graph_dragging_key = true;
|
|
|
|
});
|
|
|
|
addHotkey("Graph", "Zoom", "", MOD_KEY.alt | MOD_KEY.ctrl, function() {
|
2023-10-31 05:30:42 +01:00
|
|
|
if(PREFERENCES.alt_picker) return;
|
2023-07-30 13:56:22 +02:00
|
|
|
PANEL_GRAPH.graph_zooming_key = true;
|
|
|
|
});
|
2023-08-13 13:10:20 +02:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ++++ node setters ++++
|
|
|
|
function setCurrentPreview(_node = node_focus) { #region
|
|
|
|
if(!_node) return;
|
|
|
|
|
|
|
|
PANEL_PREVIEW.setNodePreview(_node);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function setCurrentExport(_node = node_focus) { #region
|
|
|
|
if(DEMO) return;
|
|
|
|
if(!_node) return;
|
|
|
|
|
|
|
|
var _outp = -1;
|
|
|
|
var _path = -1;
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(_node.outputs); i++ ) {
|
|
|
|
if(_node.outputs[| i].type == VALUE_TYPE.path)
|
|
|
|
_path = _node.outputs[| i];
|
|
|
|
if(_node.outputs[| i].type == VALUE_TYPE.surface && _outp == -1)
|
|
|
|
_outp = _node.outputs[| i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_outp == -1) return;
|
|
|
|
|
|
|
|
var _export = nodeBuild("Node_Export", _node.x + _node.w + 64, _node.y);
|
|
|
|
if(_path != -1)
|
|
|
|
_export.inputs[| 1].setFrom(_path);
|
|
|
|
|
|
|
|
_export.inputs[| 0].setFrom(_outp);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function setCurrentCanvas(_node = node_focus) { #region
|
|
|
|
if(!_node) return;
|
|
|
|
|
|
|
|
var _outp = -1;
|
|
|
|
var surf = -1;
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(_node.outputs); i++ ) {
|
|
|
|
if(_node.outputs[| i].type == VALUE_TYPE.surface) {
|
|
|
|
_outp = _node.outputs[| i];
|
|
|
|
var _val = _node.outputs[| i].getValue();
|
|
|
|
if(is_array(_val))
|
|
|
|
surf = _val[_node.preview_index];
|
|
|
|
else
|
|
|
|
surf = _val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_outp == -1) return;
|
|
|
|
|
|
|
|
var _canvas = nodeBuild("Node_Canvas", _node.x + _node.w + 64, _node.y);
|
|
|
|
|
2023-09-08 21:37:36 +02:00
|
|
|
_canvas.inputs[| 0].setValue([surface_get_width_safe(surf), surface_get_height_safe(surf)]);
|
2023-08-13 13:10:20 +02:00
|
|
|
_canvas.canvas_surface = surface_clone(surf);
|
|
|
|
_canvas.apply_surface();
|
|
|
|
} #endregion
|
2023-04-21 19:08:10 +02:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function setTriggerPreview() { #region
|
|
|
|
if(node_focus != noone)
|
|
|
|
node_focus.previewable = !node_focus.previewable;
|
|
|
|
|
|
|
|
var show = false;
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
if(i == 0) show = !nodes_select_list[| i].previewable;
|
|
|
|
nodes_select_list[| i].previewable = show;
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function setTriggerRender() { #region
|
|
|
|
if(node_focus != noone)
|
|
|
|
node_focus.renderActive = !node_focus.renderActive;
|
|
|
|
|
|
|
|
var show = false;
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
if(i == 0) show = !nodes_select_list[| i].renderActive;
|
|
|
|
nodes_select_list[| i].renderActive = show;
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function setCurrentCanvasBlend(_node = node_focus) { #region
|
|
|
|
if(!_node) return;
|
|
|
|
|
|
|
|
var _outp = -1;
|
|
|
|
var surf = -1;
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(_node.outputs); i++ ) {
|
|
|
|
if(_node.outputs[| i].type == VALUE_TYPE.surface) {
|
|
|
|
_outp = _node.outputs[| i];
|
|
|
|
var _val = _node.outputs[| i].getValue();
|
|
|
|
if(is_array(_val))
|
|
|
|
surf = _val[_node.preview_index];
|
|
|
|
else
|
|
|
|
surf = _val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_outp == -1) return;
|
|
|
|
|
|
|
|
var _canvas = nodeBuild("Node_Canvas", _node.x, _node.y + _node.h + 64);
|
|
|
|
|
2023-09-08 21:37:36 +02:00
|
|
|
_canvas.inputs[| 0].setValue([surface_get_width_safe(surf), surface_get_height_safe(surf)]);
|
2023-08-13 13:10:20 +02:00
|
|
|
_canvas.inputs[| 5].setValue(true);
|
|
|
|
|
|
|
|
var _blend = new Node_Blend(_node.x + _node.w + 64, _node.y, getCurrentContext());
|
|
|
|
_blend.inputs[| 0].setFrom(_outp);
|
|
|
|
_blend.inputs[| 1].setFrom(_canvas.outputs[| 0]);
|
|
|
|
} #endregion
|
|
|
|
#endregion
|
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
#region ++++ context menu ++++
|
|
|
|
menu_sent_to_preview = menuItem(__txtx("panel_graph_send_to_preview", "Send to preview"), function() { setCurrentPreview(node_hover); });
|
|
|
|
menu_send_to_window = menuItem(__txtx("panel_graph_preview_window", "Send to preview window"), function() { create_preview_window(node_hover); }, noone, ["Graph", "Preview window"]);
|
|
|
|
menu_sent_to_inspector = menuItem(__txtx("panel_graph_inspector_panel", "Send to new inspector"), function() {
|
|
|
|
var pan = panelAdd("Panel_Inspector", true);
|
|
|
|
pan.destroy_on_click_out = false;
|
|
|
|
pan.content.setInspecting(node_hover);
|
|
|
|
pan.content.locked = true;
|
|
|
|
});
|
|
|
|
menu_send_export = menuItem(__txtx("panel_graph_send_to_export", "Send to export"), function() { setCurrentExport(node_hover); }, noone, ["Graph", "Export"]);
|
|
|
|
menu_toggle_preview = menuItem(__txtx("panel_graph_toggle_preview", "Toggle node preview"), function() { setTriggerPreview(); }, noone, ["Graph", "Toggle preview"]);
|
|
|
|
menu_toggle_render = menuItem(__txtx("panel_graph_toggle_render", "Toggle node render"), function() { setTriggerRender(); }, noone, ["Graph", "Toggle render"]);
|
|
|
|
menu_open_group = menuItem(__txtx("panel_graph_enter_group", "Open group"), function() { PANEL_GRAPH.addContext(node_hover); }, THEME.group);
|
|
|
|
menu_open_group_tab = menuItem(__txtx("panel_graph_enter_group_new_tab", "Open group in new tab"), function() {
|
|
|
|
var graph = new Panel_Graph(project);
|
|
|
|
panel.setContent(graph, true);
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(node_context); i++ )
|
|
|
|
graph.addContext(node_context[| i]);
|
|
|
|
graph.addContext(node_hover);
|
|
|
|
|
|
|
|
setFocus(panel);
|
|
|
|
}, THEME.group);
|
|
|
|
menu_group_ungroup = menuItem(__txt("Ungroup"), function() { doUngroup(); }, THEME.group, ["Graph", "Ungroup"]);
|
|
|
|
menu_group_tool = menuItem(__txt("Set as group tool"), function() { node_hover.setTool(!node_hover.isTool); });
|
|
|
|
|
|
|
|
menu_node_delete_merge = menuItem(__txtx("panel_graph_delete_and_merge_connection", "Delete and merge connection"), function() { doDelete(true); }, THEME.cross, ["Graph", "Delete (merge)"]);
|
|
|
|
menu_node_delete_cut = menuItem(__txtx("panel_graph_delete_and_cut_connection", "Delete and cut connection"), function() { doDelete(false); }, THEME.cross, ["Graph", "Delete (break)"]);
|
|
|
|
menu_node_duplicate = menuItem(__txt("Duplicate"), function() { doDuplicate(); }, THEME.duplicate, ["Graph", "Duplicate"]);
|
|
|
|
menu_node_copy = menuItem(__txt("Copy"), function() { doCopy(); }, THEME.copy, ["Graph", "Copy"]);
|
|
|
|
|
|
|
|
menu_node_transform = menuItem(__txtx("panel_graph_add_transform", "Add transform"), function() { doTransform(); }, noone, ["Graph", "Transform node"]);
|
|
|
|
menu_node_canvas = menuItem(__txtx("panel_graph_canvas", "Canvas"),
|
|
|
|
function(_dat) {
|
|
|
|
return submenuCall(_dat, [
|
|
|
|
menuItem(__txtx("panel_graph_copy_to_canvas", "Copy to canvas"), function() { setCurrentCanvas(node_hover); }, noone, ["Graph", "Canvas"]),
|
|
|
|
menuItem(__txtx("panel_graph_overlay_canvas", "Overlay canvas"), function() { setCurrentCanvasBlend(node_hover); }, noone, ["Graph", "Canvas blend"])
|
|
|
|
]);
|
|
|
|
}).setIsShelf();
|
|
|
|
|
|
|
|
menu_nodes_align = menuItem(__txtx("panel_graph_align_nodes", "Align nodes"), function(_dat) {
|
|
|
|
return submenuCall(_dat, [
|
|
|
|
menuItemGroup(__txtx("horizontal", "Horizontal"), [
|
|
|
|
[ [THEME.inspector_surface_halign, 0], function() { node_halign(nodes_select_list, fa_left); } ],
|
|
|
|
[ [THEME.inspector_surface_halign, 1], function() { node_halign(nodes_select_list, fa_center); } ],
|
|
|
|
[ [THEME.inspector_surface_halign, 2], function() { node_halign(nodes_select_list, fa_right); } ],
|
|
|
|
]),
|
|
|
|
menuItemGroup(__txtx("vertical", "Vertical"), [
|
|
|
|
[ [THEME.inspector_surface_valign, 0], function() { node_valign(nodes_select_list, fa_top); } ],
|
|
|
|
[ [THEME.inspector_surface_valign, 1], function() { node_valign(nodes_select_list, fa_middle); } ],
|
|
|
|
[ [THEME.inspector_surface_valign, 2], function() { node_valign(nodes_select_list, fa_bottom); } ],
|
|
|
|
]),
|
|
|
|
menuItemGroup(__txtx("distribute", "Distribute"), [
|
|
|
|
[ [THEME.obj_distribute_h, 0], function() { node_hdistribute(nodes_select_list); } ],
|
|
|
|
[ [THEME.obj_distribute_v, 0], function() { node_vdistribute(nodes_select_list); } ],
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
}).setIsShelf();
|
|
|
|
menu_nodes_blend = menuItem(__txtx("panel_graph_blend_nodes", "Blend nodes"), function() { doBlend(); }, noone, ["Graph", "Blend"]);
|
|
|
|
menu_nodes_compose = menuItem(__txtx("panel_graph_compose_nodes", "Compose nodes"), function() { doCompose(); }, noone, ["Graph", "Compose"]);
|
|
|
|
menu_nodes_array = menuItem(__txtx("panel_graph_array_from_nodes", "Array from nodes"), function() { doArray(); }, noone, ["Graph", "Array"]);
|
|
|
|
menu_nodes_group = menuItem(__txtx("panel_graph_group_nodes", "Group nodes"), function() { doGroup(); }, THEME.group, ["Graph", "Group"]);
|
|
|
|
menu_nodes_frame = menuItem(__txtx("panel_graph_frame_nodes", "Frame nodes"), function() { doFrame(); }, noone, ["Graph", "Frame"]);
|
|
|
|
|
2023-10-18 14:58:55 +02:00
|
|
|
menu_node_copy_prop = menuItem(__txtx("panel_graph_copy_prop", "Copy all properties"), function() { doCopyProp(); });
|
|
|
|
menu_node_paste_prop = menuItem(__txtx("panel_graph_paste_prop", "Paste all properties"), function() { doPasteProp(); });
|
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
#region node color
|
|
|
|
function setSelectingNodeColor(color) {
|
|
|
|
if(node_hover == noone) return;
|
2023-10-24 11:23:20 +02:00
|
|
|
node_hover.attributes.color = color;
|
2023-10-15 15:04:42 +02:00
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++)
|
2023-10-24 11:23:20 +02:00
|
|
|
nodes_select_list[| i].attributes.color = color;
|
2023-10-15 15:04:42 +02:00
|
|
|
}
|
|
|
|
|
2023-10-18 14:58:55 +02:00
|
|
|
var _clrs = COLORS.labels;
|
2023-10-15 15:04:42 +02:00
|
|
|
var _item = array_create(array_length(_clrs));
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(_clrs); i < n; i++ ) {
|
|
|
|
_item[i] = [
|
|
|
|
[ THEME.timeline_color, i > 0, _clrs[i] ],
|
|
|
|
function(_data) {
|
|
|
|
setSelectingNodeColor(_data.color);
|
|
|
|
}, "", { color: i == 0? -1 : _clrs[i] }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push(_item, [
|
|
|
|
[ THEME.timeline_color, 2 ],
|
|
|
|
function(_data) {
|
|
|
|
var dialog = dialogCall(o_dialog_color_selector);
|
|
|
|
dialog.selector.onApply = setSelectingNodeColor;
|
|
|
|
dialog.onApply = setSelectingNodeColor;
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
menu_node_color = menuItemGroup(__txt("Node Color"), _item);
|
|
|
|
menu_node_color.spacing = ui(24);
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region junction color
|
|
|
|
__junction_hovering = noone;
|
|
|
|
|
|
|
|
function setSelectingJuncColor(color) {
|
|
|
|
if(__junction_hovering == noone) return;
|
|
|
|
__junction_hovering.color = color;
|
|
|
|
|
|
|
|
if(__junction_hovering.value_from != noone)
|
|
|
|
__junction_hovering.value_from.color = color;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
|
|
|
|
for( var j = 0, m = ds_list_size(_node.inputs); j < m; j++ ) {
|
|
|
|
var _input = _node.inputs[| j];
|
2023-10-27 13:55:31 +02:00
|
|
|
if(_input.isLeaf()) continue;
|
2023-10-15 15:04:42 +02:00
|
|
|
if(!ds_exists(_input.value_from.node, nodes_select_list)) continue;
|
|
|
|
|
|
|
|
_input.color = color;
|
|
|
|
_input.value_from.color = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-18 14:58:55 +02:00
|
|
|
var _clrs = COLORS.labels;
|
2023-10-15 15:04:42 +02:00
|
|
|
var _item = array_create(array_length(_clrs));
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(_clrs); i < n; i++ ) {
|
|
|
|
_item[i] = [
|
|
|
|
[ THEME.timeline_color, i > 0, _clrs[i] ],
|
|
|
|
function(_data) {
|
|
|
|
setSelectingJuncColor(_data.color);
|
|
|
|
}, "", { color: i == 0? -1 : _clrs[i] }
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push(_item, [
|
|
|
|
[ THEME.timeline_color, 2 ],
|
|
|
|
function(_data) {
|
|
|
|
var dialog = dialogCall(o_dialog_color_selector);
|
|
|
|
dialog.selector.onApply = setSelectingJuncColor;
|
|
|
|
dialog.onApply = setSelectingJuncColor;
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
menu_junc_color = menuItemGroup(__txt("Connection Color"), _item);
|
|
|
|
menu_junc_color.spacing = ui(24);
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function getCurrentContext() { #region
|
|
|
|
if(ds_list_empty(node_context)) return noone;
|
|
|
|
return node_context[| ds_list_size(node_context) - 1];
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function getNodeList(cont = getCurrentContext()) { #region
|
|
|
|
return cont == noone? project.nodes : cont.getNodeList();
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function onFocusBegin() { #region
|
2023-03-21 03:01:53 +01:00
|
|
|
PANEL_GRAPH = self;
|
2023-07-06 19:49:16 +02:00
|
|
|
PROJECT = project;
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-03-13 10:45:56 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function stepBegin() { #region
|
2022-12-16 09:18:09 +01:00
|
|
|
var gr_x = graph_x * graph_s;
|
|
|
|
var gr_y = graph_y * graph_s;
|
2022-01-13 05:24:03 +01:00
|
|
|
var m_x = (mx - gr_x) / graph_s;
|
|
|
|
var m_y = (my - gr_y) / graph_s;
|
|
|
|
mouse_graph_x = m_x;
|
|
|
|
mouse_graph_y = m_y;
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
mouse_grid_x = round(m_x / project.graphGrid.size) * project.graphGrid.size;
|
|
|
|
mouse_grid_y = round(m_y / project.graphGrid.size) * project.graphGrid.size;
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function focusNode(_node) { #region
|
2023-01-25 06:49:00 +01:00
|
|
|
node_focus = _node;
|
|
|
|
if(_node == noone) return;
|
|
|
|
|
|
|
|
var cx = node_focus.x + node_focus.w / 2;
|
|
|
|
var cy = node_focus.y + node_focus.h / 2;
|
|
|
|
|
|
|
|
graph_x = w / 2 / graph_s - cx;
|
|
|
|
graph_y = (h - toolbar_height) / 2 / graph_s - cy;
|
|
|
|
|
|
|
|
graph_x = round(graph_x);
|
|
|
|
graph_y = round(graph_y);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function fullView() { #region
|
2023-03-21 03:01:53 +01:00
|
|
|
if(node_focus == noone) {
|
|
|
|
toCenterNode();
|
2022-09-21 06:09:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-21 03:01:53 +01:00
|
|
|
graph_x = -(node_focus.x + node_focus.w / 2) + w / 2 / graph_s;
|
|
|
|
graph_y = -(node_focus.y + node_focus.h / 2) + h / 2 / graph_s;
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
graph_x = round(graph_x);
|
|
|
|
graph_y = round(graph_y);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function dragGraph() { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
if(graph_dragging) {
|
2022-12-23 04:45:52 +01:00
|
|
|
if(!MOUSE_WRAPPING) {
|
|
|
|
var dx = mx - graph_drag_mx;
|
|
|
|
var dy = my - graph_drag_my;
|
|
|
|
|
|
|
|
graph_x += dx / graph_s;
|
|
|
|
graph_y += dy / graph_s;
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
graph_drag_mx = mx;
|
|
|
|
graph_drag_my = my;
|
2022-12-23 04:45:52 +01:00
|
|
|
setMouseWrap();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(drag_key))
|
2022-01-13 05:24:03 +01:00
|
|
|
graph_dragging = false;
|
|
|
|
}
|
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
if(graph_zooming) {
|
|
|
|
if(!MOUSE_WRAPPING) {
|
|
|
|
var dy = -(my - graph_zoom_m) / 200;
|
|
|
|
|
|
|
|
var _s = graph_s;
|
|
|
|
|
|
|
|
graph_s_to = clamp(graph_s_to * (1 + dy), scale[0], scale[array_length(scale) - 1]);
|
|
|
|
graph_s = graph_s_to;
|
|
|
|
|
|
|
|
if(_s != graph_s) {
|
|
|
|
var mb_x = (graph_zoom_mx - graph_x * _s) / _s;
|
|
|
|
var ma_x = (graph_zoom_mx - graph_x * graph_s) / graph_s;
|
|
|
|
var md_x = ma_x - mb_x;
|
|
|
|
graph_x += md_x;
|
|
|
|
|
|
|
|
var mb_y = (graph_zoom_my - graph_y * _s) / _s;
|
|
|
|
var ma_y = (graph_zoom_my - graph_y * graph_s) / graph_s;
|
|
|
|
var md_y = ma_y - mb_y;
|
|
|
|
graph_y += md_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
graph_zoom_m = my;
|
|
|
|
setMouseWrap();
|
|
|
|
|
|
|
|
if(mouse_release(drag_key))
|
|
|
|
graph_zooming = false;
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
if(mouse_on_graph && pFOCUS && graph_draggable) {
|
2022-01-19 03:05:13 +01:00
|
|
|
var _doDragging = false;
|
2023-07-30 13:56:22 +02:00
|
|
|
var _doZooming = false;
|
|
|
|
|
2023-10-31 05:30:42 +01:00
|
|
|
if(mouse_press(PREFERENCES.pan_mouse_key)) {
|
2022-01-19 03:05:13 +01:00
|
|
|
_doDragging = true;
|
2023-10-31 05:30:42 +01:00
|
|
|
drag_key = PREFERENCES.pan_mouse_key;
|
2023-04-21 19:08:10 +02:00
|
|
|
} else if(mouse_press(mb_left) && graph_dragging_key) {
|
2022-01-19 03:05:13 +01:00
|
|
|
_doDragging = true;
|
|
|
|
drag_key = mb_left;
|
2023-07-30 13:56:22 +02:00
|
|
|
} else if(mouse_press(mb_left) && graph_zooming_key) {
|
|
|
|
_doZooming = true;
|
|
|
|
drag_key = mb_left;
|
2022-01-19 03:05:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(_doDragging) {
|
2022-01-13 05:24:03 +01:00
|
|
|
graph_dragging = true;
|
|
|
|
graph_drag_mx = mx;
|
|
|
|
graph_drag_my = my;
|
|
|
|
graph_drag_sx = graph_x;
|
|
|
|
graph_drag_sy = graph_y;
|
|
|
|
}
|
2023-07-30 13:56:22 +02:00
|
|
|
|
|
|
|
if(_doZooming) {
|
|
|
|
graph_zooming = true;
|
|
|
|
graph_zoom_mx = mx;
|
|
|
|
graph_zoom_my = my;
|
|
|
|
graph_zoom_m = my;
|
|
|
|
graph_zoom_s = graph_s;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
if(mouse_on_graph && pHOVER && graph_draggable) {
|
2022-01-13 05:24:03 +01:00
|
|
|
var _s = graph_s;
|
2023-07-30 13:56:22 +02:00
|
|
|
if(mouse_wheel_down()) { //zoom out
|
|
|
|
for( var i = 1, n = array_length(scale); i < n; i++ ) {
|
|
|
|
if(scale[i - 1] < graph_s_to && graph_s_to <= scale[i]) {
|
|
|
|
graph_s_to = scale[i - 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-07-30 13:56:22 +02:00
|
|
|
if(mouse_wheel_up()) { // zoom in
|
|
|
|
for( var i = 1, n = array_length(scale); i < n; i++ ) {
|
|
|
|
if(scale[i - 1] <= graph_s_to && graph_s_to < scale[i]) {
|
|
|
|
graph_s_to = scale[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-07-30 13:56:22 +02:00
|
|
|
|
2023-10-31 05:30:42 +01:00
|
|
|
graph_s = lerp_float(graph_s, graph_s_to, PREFERENCES.graph_zoom_smoooth);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(_s != graph_s) {
|
|
|
|
var mb_x = (mx - graph_x * _s) / _s;
|
|
|
|
var ma_x = (mx - graph_x * graph_s) / graph_s;
|
|
|
|
var md_x = ma_x - mb_x;
|
|
|
|
graph_x += md_x;
|
|
|
|
|
|
|
|
var mb_y = (my - graph_y * _s) / _s;
|
|
|
|
var ma_y = (my - graph_y * graph_s) / graph_s;
|
|
|
|
var md_y = ma_y - mb_y;
|
|
|
|
graph_y += md_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
graph_draggable = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
graph_x = round(graph_x);
|
|
|
|
graph_y = round(graph_y);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawGrid() { #region
|
2023-08-16 20:16:31 +02:00
|
|
|
if(!display_parameter.show_grid) return;
|
2023-08-01 19:21:51 +02:00
|
|
|
var gls = project.graphGrid.size;
|
2023-10-18 14:58:55 +02:00
|
|
|
while(gls * graph_s < 8) gls *= 5;
|
2023-04-11 20:29:20 +02:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
var gr_x = graph_x * graph_s;
|
|
|
|
var gr_y = graph_y * graph_s;
|
2023-04-11 20:29:20 +02:00
|
|
|
var gr_ls = gls * graph_s;
|
2022-01-13 05:24:03 +01:00
|
|
|
var xx = -gr_ls, xs = safe_mod(gr_x, gr_ls);
|
|
|
|
var yy = -gr_ls, ys = safe_mod(gr_y, gr_ls);
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
draw_set_color(project.graphGrid.color);
|
2023-10-18 14:58:55 +02:00
|
|
|
var aa = 0.5;
|
|
|
|
if(graph_s < 0.25)
|
|
|
|
aa = 0.3;
|
|
|
|
var oa = project.graphGrid.opacity;
|
|
|
|
var ori = project.graphGrid.show_origin;
|
|
|
|
var hig = project.graphGrid.highlight;
|
|
|
|
|
|
|
|
while(xx < w + gr_ls) {
|
|
|
|
draw_set_alpha( oa * aa * (1 + (round((xx + xs - gr_x) / gr_ls) % hig == 0) * 2) );
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_line(xx + xs, 0, xx + xs, h);
|
2023-10-18 14:58:55 +02:00
|
|
|
|
|
|
|
if(ori && xx + xs - gr_x == 0) draw_line_width(xx + xs, 0, xx + xs, h, 3);
|
2022-01-13 05:24:03 +01:00
|
|
|
xx += gr_ls;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(yy < h + gr_ls) {
|
2023-10-18 14:58:55 +02:00
|
|
|
draw_set_alpha( oa * aa * (1 + (round((yy + ys - gr_y) / gr_ls) % hig == 0) * 2) );
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_line(0, yy + ys, w, yy + ys);
|
2023-10-18 14:58:55 +02:00
|
|
|
|
|
|
|
if(ori && yy + ys - gr_y == 0) draw_line_width(0, yy + ys, w, yy + ys, 3);
|
2022-01-13 05:24:03 +01:00
|
|
|
yy += gr_ls;
|
|
|
|
}
|
|
|
|
draw_set_alpha(1);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawNodes() { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
if(selection_block-- > 0) return;
|
2023-02-14 02:51:14 +01:00
|
|
|
//print("==== DRAW NODES ====");
|
2023-10-31 05:30:42 +01:00
|
|
|
display_parameter.highlight = (!ds_list_empty(nodes_select_list) || node_focus != noone) * PREFERENCES.connection_line_highlight;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var gr_x = graph_x * graph_s;
|
|
|
|
var gr_y = graph_y * graph_s;
|
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
var log = false;
|
|
|
|
var t = current_time;
|
2023-07-06 19:49:16 +02:00
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
|
|
|
nodes_list[| i].cullCheck(gr_x, gr_y, graph_s, -32, -32, w + 32, h + 64);
|
|
|
|
nodes_list[| i].preDraw(gr_x, gr_y, graph_s, gr_x, gr_y);
|
|
|
|
}
|
|
|
|
printIf(log, "Predraw time: " + string(current_time - t)); t = current_time;
|
2022-01-16 14:28:57 +01:00
|
|
|
|
2022-01-26 06:57:34 +01:00
|
|
|
#region draw frame
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
|
|
|
if(instanceof(nodes_list[| i]) != "Node_Frame") continue;
|
2023-08-16 20:16:31 +02:00
|
|
|
nodes_list[| i].drawNode(gr_x, gr_y, mx, my, graph_s, display_parameter);
|
2022-01-26 06:57:34 +01:00
|
|
|
}
|
|
|
|
#endregion
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Frame draw time: " + string(current_time - t)); t = current_time;
|
2022-01-26 06:57:34 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
#region hover
|
|
|
|
node_hovering = noone;
|
2022-12-12 09:08:03 +01:00
|
|
|
if(pHOVER)
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = nodes_list[| i];
|
2023-10-12 07:07:24 +02:00
|
|
|
_node.branch_drawing = false;
|
2023-07-25 20:12:40 +02:00
|
|
|
if(_node.pointIn(gr_x, gr_y, mx, my, graph_s))
|
|
|
|
node_hovering = _node;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-03-13 10:45:56 +01:00
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
if(node_hovering != noone)
|
|
|
|
_HOVERING_ELEMENT = node_hovering;
|
|
|
|
|
2023-07-15 20:01:29 +02:00
|
|
|
if(node_hovering != noone && pFOCUS && struct_has(node_hovering, "onDoubleClick") && DOUBLE_CLICK) {
|
|
|
|
node_hovering.onDoubleClick(self);
|
2023-03-13 10:45:56 +01:00
|
|
|
DOUBLE_CLICK = false;
|
|
|
|
node_hovering = noone;
|
|
|
|
}
|
2023-06-13 21:24:05 +02:00
|
|
|
|
|
|
|
if(node_hovering) node_hovering.onDrawHover(gr_x, gr_y, mx, my, graph_s);
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Hover time: " + string(current_time - t)); t = current_time;
|
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
#region selection
|
|
|
|
if(mouse_on_graph && pHOVER) {
|
2023-10-15 15:04:42 +02:00
|
|
|
#region select
|
|
|
|
if(NODE_DROPPER_TARGET != noone && node_hovering) {
|
|
|
|
node_hovering.draw_droppable = true;
|
|
|
|
if(mouse_press(mb_left, NODE_DROPPER_TARGET_CAN)) {
|
|
|
|
NODE_DROPPER_TARGET.expression += node_hovering.internalName;
|
|
|
|
NODE_DROPPER_TARGET.expressionUpdate();
|
|
|
|
}
|
|
|
|
} else if(mouse_press(mb_left, pFOCUS)) {
|
|
|
|
if(key_mod_press(SHIFT)) {
|
|
|
|
if(ds_list_empty(nodes_select_list) && node_focus)
|
|
|
|
ds_list_add(nodes_select_list, node_focus);
|
|
|
|
if(node_focus != node_hovering)
|
|
|
|
ds_list_add(nodes_select_list, node_hovering);
|
|
|
|
} else {
|
|
|
|
var _prevFocus = node_focus;
|
|
|
|
if(node_hovering != noone || value_focus == noone)
|
|
|
|
node_focus = node_hovering;
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(node_focus) {
|
|
|
|
if(instanceof(node_focus) == "Node_Frame") {
|
|
|
|
var fx0 = (node_focus.x + graph_x) * graph_s;
|
|
|
|
var fy0 = (node_focus.y + graph_y) * graph_s;
|
|
|
|
var fx1 = fx0 + node_focus.w * graph_s;
|
|
|
|
var fy1 = fy0 + node_focus.h * graph_s;
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
ds_list_clear(nodes_select_list);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(!key_mod_press(CTRL))
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) { //select content
|
|
|
|
var _node = nodes_list[| i];
|
|
|
|
if(instanceof(_node) == "Node_Frame") continue;
|
|
|
|
var _x = (_node.x + graph_x) * graph_s;
|
|
|
|
var _y = (_node.y + graph_y) * graph_s;
|
|
|
|
var _w = _node.w * graph_s;
|
|
|
|
var _h = _node.h * graph_s;
|
2022-11-03 11:44:49 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(rectangle_inside_rectangle(fx0, fy0, fx1, fy1, _x, _y, _x + _w, _y + _h))
|
|
|
|
ds_list_add(nodes_select_list, _node);
|
|
|
|
}
|
|
|
|
ds_list_add(nodes_select_list, node_focus);
|
|
|
|
} else if(DOUBLE_CLICK) {
|
|
|
|
PANEL_PREVIEW.setNodePreview(node_focus);
|
2023-10-31 13:33:36 +01:00
|
|
|
if(PREFERENCES.inspector_focus_on_double_click) {
|
|
|
|
if(PANEL_INSPECTOR.panel && struct_has(PANEL_INSPECTOR.panel, "switchContent"))
|
|
|
|
PANEL_INSPECTOR.panel.switchContent(PANEL_INSPECTOR);
|
|
|
|
}
|
2023-10-15 15:04:42 +02:00
|
|
|
} else {
|
|
|
|
if(_prevFocus != node_focus)
|
|
|
|
bringNodeToFront(node_focus);
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
var hover_selected = false;
|
|
|
|
for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) {
|
|
|
|
if(nodes_select_list[| i] == node_focus) {
|
|
|
|
hover_selected = true;
|
|
|
|
break;
|
|
|
|
}
|
2023-10-12 07:07:24 +02:00
|
|
|
}
|
2023-10-15 15:04:42 +02:00
|
|
|
if(!hover_selected)
|
|
|
|
ds_list_clear(nodes_select_list);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-10-15 15:04:42 +02:00
|
|
|
} else {
|
|
|
|
if(value_focus == noone)
|
2023-10-12 07:07:24 +02:00
|
|
|
ds_list_clear(nodes_select_list);
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(DOUBLE_CLICK && !PANEL_INSPECTOR.locked)
|
|
|
|
PANEL_INSPECTOR.inspecting = noone;
|
|
|
|
}
|
2023-10-12 07:07:24 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-10-15 15:04:42 +02:00
|
|
|
#endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
if(mouse_press(mb_right, pFOCUS)) { #region
|
|
|
|
node_hover = node_hovering;
|
2023-10-15 15:04:42 +02:00
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
if(node_hover) {
|
|
|
|
var menu = [];
|
2023-10-15 15:04:42 +02:00
|
|
|
array_push(menu, menu_node_color, -1, menu_sent_to_preview, menu_send_to_window, menu_sent_to_inspector);
|
|
|
|
if(!DEMO)
|
|
|
|
array_push(menu, menu_send_export);
|
|
|
|
array_push(menu, -1, menu_toggle_preview, menu_toggle_render);
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(is_instanceof(node_hover, Node_Collection))
|
|
|
|
array_push(menu, -1, menu_open_group, menu_open_group_tab, menu_group_ungroup);
|
2023-03-21 03:01:53 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(node_hover.group != noone)
|
|
|
|
array_push(menu, menu_group_tool);
|
2023-10-12 07:07:24 +02:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
array_push(menu, -1, menu_node_delete_merge, menu_node_delete_cut, menu_node_duplicate, menu_node_copy);
|
2023-10-18 14:58:55 +02:00
|
|
|
if(ds_list_empty(nodes_select_list)) array_push(menu, menu_node_copy_prop, menu_node_paste_prop);
|
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
array_push(menu, -1, menu_node_transform, menu_node_canvas);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
if(ds_list_size(nodes_select_list) >= 2)
|
|
|
|
array_push(menu, -1, menu_nodes_align, menu_nodes_blend, menu_nodes_compose, menu_nodes_array, menu_nodes_group, menu_nodes_frame);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
menuCall("graph_node_selected_multiple_menu",,, menu );
|
|
|
|
} else {
|
|
|
|
var menu = [];
|
2023-10-15 15:04:42 +02:00
|
|
|
|
|
|
|
__junction_hovering = junction_hovering;
|
|
|
|
if(junction_hovering != noone)
|
|
|
|
array_push(menu, menu_junc_color, -1);
|
|
|
|
|
|
|
|
array_push(menu, menuItem(__txt("Copy"), function() { doCopy(); }, THEME.copy, ["Graph", "Copy"]).setActive(node_focus != noone || ds_list_size(nodes_select_list)));
|
|
|
|
array_push(menu, menuItem(__txt("Paste"), function() { doPaste(); }, THEME.paste, ["Graph", "Paste"]).setActive(clipboard_get_text() != ""));
|
2023-02-28 09:43:01 +01:00
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
callAddDialog();
|
|
|
|
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
|
|
|
|
}
|
|
|
|
#endregion
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Node selection time: " + string(current_time - t)); t = current_time;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
#region draw active
|
|
|
|
if(node_focus) node_focus.drawActive(gr_x, gr_y, graph_s);
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
if(!_node) continue;
|
|
|
|
_node.drawActive(gr_x, gr_y, graph_s);
|
|
|
|
}
|
|
|
|
#endregion
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Draw active: " + string(current_time - t)); t = current_time;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-31 05:30:42 +01:00
|
|
|
var aa = min(8192 / w, 8192 / h, PREFERENCES.connection_line_aa);
|
2023-10-18 14:58:55 +02:00
|
|
|
connection_surface = surface_verify(connection_surface, w * aa, h * aa);
|
|
|
|
connection_surface_aa = surface_verify(connection_surface_aa, w, h);
|
2023-03-05 07:16:44 +01:00
|
|
|
surface_set_target(connection_surface);
|
2023-03-19 09:17:39 +01:00
|
|
|
DRAW_CLEAR
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2022-01-25 04:05:30 +01:00
|
|
|
var hov = noone;
|
2023-01-04 02:30:04 +01:00
|
|
|
var hoverable = !bool(node_dragging) && pHOVER;
|
2023-08-31 18:49:57 +02:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
2023-10-31 13:33:36 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
2023-08-31 18:49:57 +02:00
|
|
|
_params.cur_layer = i + 1;
|
|
|
|
|
|
|
|
var _hov = nodes_list[| i].drawConnections(_params);
|
2023-05-03 21:42:17 +02:00
|
|
|
if(_hov != noone && is_struct(_hov)) hov = _hov;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-10-24 11:23:20 +02:00
|
|
|
|
|
|
|
if(value_dragging && connection_draw_mouse != noone) {
|
|
|
|
var _cmx = connection_draw_mouse[0];
|
|
|
|
var _cmy = connection_draw_mouse[1];
|
|
|
|
var _cmt = connection_draw_target;
|
|
|
|
|
|
|
|
if(array_empty(value_draggings))
|
|
|
|
value_dragging.drawConnectionMouse(_params, _cmx, _cmy, _cmt);
|
|
|
|
else {
|
|
|
|
var _stIndex = array_find(value_draggings, value_dragging);
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(value_draggings); i < n; i++ ) {
|
|
|
|
var _dmx = _cmx;
|
|
|
|
var _dmy = value_draggings[i].connect_type == JUNCTION_CONNECT.output? _cmy + (i - _stIndex) * 24 * graph_s : _cmy;
|
|
|
|
|
|
|
|
value_draggings[i].drawConnectionMouse(_params, _dmx, _dmy, _cmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Draw connection: " + string(current_time - t)); t = current_time;
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
surface_reset_target();
|
2023-10-18 14:58:55 +02:00
|
|
|
|
|
|
|
surface_set_shader(connection_surface_aa, sh_downsample);
|
|
|
|
shader_set_f("down", aa);
|
|
|
|
shader_set_dim("dimension", connection_surface);
|
|
|
|
draw_surface(connection_surface, 0, 0);
|
|
|
|
surface_reset_shader();
|
|
|
|
|
2023-10-24 11:23:20 +02:00
|
|
|
BLEND_ALPHA_MULP
|
|
|
|
draw_surface(connection_surface_aa, 0, 0);
|
2023-10-18 14:58:55 +02:00
|
|
|
BLEND_NORMAL
|
2022-12-19 13:35:30 +01:00
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
junction_hovering = (node_hovering == noone && !is_struct(node_hovering))? hov : noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
value_focus = noone;
|
|
|
|
|
|
|
|
#region draw node
|
2023-06-17 14:30:49 +02:00
|
|
|
var t = current_time;
|
2023-03-02 07:59:14 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++)
|
|
|
|
nodes_list[| i].onDrawNodeBehind(gr_x, gr_y, mx, my, graph_s);
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = nodes_list[| i];
|
|
|
|
if(instanceof(_node) == "Node_Frame") continue;
|
2023-08-16 20:16:31 +02:00
|
|
|
var val = _node.drawNode(gr_x, gr_y, mx, my, graph_s, display_parameter);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
if(val) {
|
|
|
|
if(key_mod_press(SHIFT))
|
|
|
|
TOOLTIP = [ val.getValue(), val.type ];
|
2023-10-16 13:54:31 +02:00
|
|
|
value_focus = val;
|
2023-01-25 06:49:00 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-09-27 06:37:28 +02:00
|
|
|
|
2023-03-12 02:28:21 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++)
|
2022-01-13 05:24:03 +01:00
|
|
|
nodes_list[| i].drawBadge(gr_x, gr_y, graph_s);
|
2023-06-17 14:30:49 +02:00
|
|
|
|
|
|
|
printIf(log, "Draw node: " + string(current_time - t)); t = current_time;
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region dragging
|
2023-02-14 13:44:46 +01:00
|
|
|
if(mouse_press(mb_left))
|
2022-12-13 09:20:36 +01:00
|
|
|
node_dragging = noone;
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-10-12 07:07:24 +02:00
|
|
|
if(node_dragging && !key_mod_press(ALT)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
node_focus = node_dragging;
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
if(ds_list_size(nodes_select_list) == 0) { // move single node
|
2022-01-13 05:24:03 +01:00
|
|
|
var nx = node_drag_sx + (mouse_graph_x - node_drag_mx);
|
|
|
|
var ny = node_drag_sy + (mouse_graph_y - node_drag_my);
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
if(!key_mod_press(CTRL) && project.graphGrid.snap) {
|
|
|
|
nx = round(nx / project.graphGrid.size) * project.graphGrid.size;
|
|
|
|
ny = round(ny / project.graphGrid.size) * project.graphGrid.size;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
node_dragging.move(nx, ny, graph_s);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 02:51:14 +01:00
|
|
|
if(mouse_release(mb_left) && (nx != node_drag_sx || ny != node_drag_sy)) {
|
|
|
|
recordAction(ACTION_TYPE.var_modify, node_dragging, [ node_drag_sx, "x", "node x position" ]);
|
|
|
|
recordAction(ACTION_TYPE.var_modify, node_dragging, [ node_drag_sy, "y", "node y position" ]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-02-28 09:43:01 +01:00
|
|
|
} else { // move multiple nodes
|
2022-01-13 05:24:03 +01:00
|
|
|
var nx = node_drag_sx + (mouse_graph_x - node_drag_mx);
|
|
|
|
var ny = node_drag_sy + (mouse_graph_y - node_drag_my);
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
if(!key_mod_press(CTRL) && project.graphGrid.snap) {
|
|
|
|
nx = round(nx / project.graphGrid.size) * project.graphGrid.size;
|
|
|
|
ny = round(ny / project.graphGrid.size) * project.graphGrid.size;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(node_drag_ox == -1 || node_drag_oy == -1) {
|
|
|
|
node_drag_ox = nx;
|
|
|
|
node_drag_oy = ny;
|
|
|
|
} else if(nx != node_drag_ox || ny != node_drag_oy) {
|
|
|
|
var dx = nx - node_drag_ox;
|
|
|
|
var dy = ny - node_drag_oy;
|
2022-12-12 09:08:03 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
2022-12-12 09:08:03 +01:00
|
|
|
var _nx = _node.x + dx;
|
|
|
|
var _ny = _node.y + dy;
|
|
|
|
|
2023-08-01 19:21:51 +02:00
|
|
|
if(!key_mod_press(CTRL) && project.graphGrid.snap) {
|
|
|
|
_nx = round(_nx / project.graphGrid.size) * project.graphGrid.size;
|
|
|
|
_ny = round(_ny / project.graphGrid.size) * project.graphGrid.size;
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
|
|
|
|
2023-10-15 15:04:42 +02:00
|
|
|
_node.move(_nx, _ny, graph_s);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
node_drag_ox = nx;
|
|
|
|
node_drag_oy = ny;
|
|
|
|
}
|
2023-02-14 02:51:14 +01:00
|
|
|
|
|
|
|
if(mouse_release(mb_left) && (nx != node_drag_sx || ny != node_drag_sy)) {
|
|
|
|
var shfx = node_drag_sx - nx;
|
|
|
|
var shfy = node_drag_sy - ny;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _n = nodes_select_list[| i];
|
2023-03-19 09:17:39 +01:00
|
|
|
if(_n == noone) continue;
|
2023-02-14 02:51:14 +01:00
|
|
|
recordAction(ACTION_TYPE.var_modify, _n, [ _n.x + shfx, "x", "node x position" ]);
|
|
|
|
recordAction(ACTION_TYPE.var_modify, _n, [ _n.y + shfy, "y", "node y position" ]);
|
|
|
|
}
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Drag node time : " + string(current_time - t)); t = current_time;
|
2023-02-14 02:51:14 +01:00
|
|
|
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
node_dragging = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
#endregion
|
|
|
|
|
2023-08-31 18:49:57 +02:00
|
|
|
if(mouse_on_graph && pFOCUS) { #region
|
2023-03-05 07:16:44 +01:00
|
|
|
if(node_focus && node_focus.draggable && value_focus == noone) {
|
2023-01-25 06:49:00 +01:00
|
|
|
if(mouse_press(mb_left) && !key_mod_press(ALT)) {
|
2022-01-26 06:57:34 +01:00
|
|
|
node_dragging = node_focus;
|
|
|
|
node_drag_mx = mouse_graph_x;
|
|
|
|
node_drag_my = mouse_graph_y;
|
|
|
|
node_drag_sx = node_focus.x;
|
|
|
|
node_drag_sy = node_focus.y;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-01-26 06:57:34 +01:00
|
|
|
node_drag_ox = -1;
|
|
|
|
node_drag_oy = -1;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2022-01-26 06:57:34 +01:00
|
|
|
if(DOUBLE_CLICK && junction_hovering != noone) {
|
2023-08-01 19:21:51 +02:00
|
|
|
var _mx = round(mouse_graph_x / project.graphGrid.size) * project.graphGrid.size;
|
|
|
|
var _my = round(mouse_graph_y / project.graphGrid.size) * project.graphGrid.size;
|
2022-01-26 06:57:34 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
var _pin = nodeBuild("Node_Pin", _mx, _my);
|
2022-01-26 06:57:34 +01:00
|
|
|
_pin.inputs[| 0].setFrom(junction_hovering.value_from);
|
|
|
|
junction_hovering.setFrom(_pin.outputs[| 0]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-08-31 18:49:57 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
#region draw selection frame
|
|
|
|
if(nodes_select_drag) {
|
|
|
|
if(point_distance(nodes_select_mx, nodes_select_my, mx, my) > 16) {
|
2023-06-10 13:59:45 +02:00
|
|
|
draw_sprite_stretched_points(THEME.ui_selection, 0, nodes_select_mx, nodes_select_my, mx, my);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
|
|
|
var _node = nodes_list[| i];
|
|
|
|
if(instanceof(_node) == "Node_Frame") continue;
|
|
|
|
var _x = (_node.x + graph_x) * graph_s;
|
|
|
|
var _y = (_node.y + graph_y) * graph_s;
|
|
|
|
var _w = _node.w * graph_s;
|
|
|
|
var _h = _node.h * graph_s;
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
var _sel = rectangle_in_rectangle(_x, _y, _x + _w, _y + _h, nodes_select_mx, nodes_select_my, mx, my);
|
|
|
|
|
|
|
|
if(!ds_list_exist(nodes_select_list, _node) && _sel)
|
2022-01-13 05:24:03 +01:00
|
|
|
ds_list_add(nodes_select_list, _node);
|
2023-01-25 06:49:00 +01:00
|
|
|
if(ds_list_exist(nodes_select_list, _node) && !_sel)
|
|
|
|
ds_list_remove(nodes_select_list, _node);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left))
|
2022-01-13 05:24:03 +01:00
|
|
|
nodes_select_drag = false;
|
|
|
|
}
|
2023-03-02 07:59:14 +01:00
|
|
|
|
|
|
|
if(nodes_junction_d != noone) {
|
|
|
|
var shx = nodes_junction_dx + (mx - nodes_select_mx) / graph_s;
|
|
|
|
var shy = nodes_junction_dy + (my - nodes_select_my) / graph_s;
|
|
|
|
|
|
|
|
shx = value_snap(shx, key_mod_press(CTRL)? 1 : 4);
|
|
|
|
shy = value_snap(shy, key_mod_press(CTRL)? 1 : 4);
|
|
|
|
|
|
|
|
nodes_junction_d.draw_line_shift_x = shx;
|
|
|
|
nodes_junction_d.draw_line_shift_y = shy;
|
|
|
|
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
nodes_junction_d = noone;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-07-30 13:56:22 +02:00
|
|
|
if(mouse_on_graph && mouse_press(mb_left, pFOCUS) && !graph_dragging_key && !graph_zooming_key) {
|
2023-03-02 07:59:14 +01:00
|
|
|
if(junction_hovering && 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;
|
|
|
|
} else if(!node_focus && !value_focus && !drag_locking) {
|
2022-01-13 05:24:03 +01:00
|
|
|
nodes_select_drag = true;
|
|
|
|
nodes_select_mx = mx;
|
|
|
|
nodes_select_my = my;
|
|
|
|
}
|
2022-11-01 03:06:03 +01:00
|
|
|
drag_locking = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
#endregion
|
2023-02-14 02:51:14 +01:00
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
printIf(log, "Draw selection frame : " + string(current_time - t)); t = current_time;
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-02-19 13:49:20 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawJunctionConnect() { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
if(value_dragging) {
|
2023-08-13 09:51:36 +02:00
|
|
|
var xx = value_dragging.x;
|
|
|
|
var yy = value_dragging.y;
|
|
|
|
var _mx = mx;
|
|
|
|
var _my = my;
|
2023-01-25 06:49:00 +01:00
|
|
|
var target = noone;
|
|
|
|
|
|
|
|
if(value_focus && value_focus != value_dragging && value_focus.connect_type != value_dragging.connect_type)
|
|
|
|
target = value_focus;
|
2023-10-16 13:54:31 +02:00
|
|
|
|
2023-02-14 02:51:14 +01:00
|
|
|
if(key_mod_press(CTRL) && node_hovering != noone) {
|
|
|
|
if(value_dragging.connect_type == JUNCTION_CONNECT.input) {
|
|
|
|
target = node_hovering.getOutput(value_dragging);
|
|
|
|
if(target != noone)
|
|
|
|
node_hovering.active_draw_index = 1;
|
|
|
|
} else {
|
|
|
|
target = node_hovering.getInput(value_dragging);
|
|
|
|
if(target != noone)
|
|
|
|
node_hovering.active_draw_index = 1;
|
|
|
|
}
|
2023-01-25 06:49:00 +01:00
|
|
|
}
|
|
|
|
|
2023-08-13 09:51:36 +02:00
|
|
|
var _mmx = target != noone? target.x : _mx;
|
|
|
|
var _mmy = target != noone? target.y : _my;
|
|
|
|
|
2023-10-24 11:23:20 +02:00
|
|
|
connection_draw_mouse = [ _mmx, _mmy ];
|
|
|
|
connection_draw_target = target;
|
2023-08-13 09:51:36 +02:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
value_dragging.drawJunction(graph_s, value_dragging.x, value_dragging.y);
|
2023-10-27 13:55:31 +02:00
|
|
|
if(target) target.drawJunction(graph_s, target.x, target.y);
|
2023-01-25 06:49:00 +01:00
|
|
|
|
2023-08-13 09:51:36 +02:00
|
|
|
if(mouse_release(mb_left)) { // CONNECT junction
|
|
|
|
if(target != noone) {
|
2023-10-27 13:55:31 +02:00
|
|
|
var _addInput = false;
|
|
|
|
if(target.isLeaf() && target.connect_type == JUNCTION_CONNECT.input && target.node.auto_input)
|
|
|
|
_addInput = true;
|
|
|
|
|
2023-10-16 13:54:31 +02:00
|
|
|
if(value_dragging.connect_type == JUNCTION_CONNECT.input) {
|
|
|
|
if(array_empty(value_draggings))
|
|
|
|
value_dragging.setFrom(target);
|
|
|
|
else {
|
|
|
|
for( var i = 0, n = array_length(value_draggings); i < n; i++ )
|
|
|
|
value_draggings[i].setFrom(target);
|
|
|
|
}
|
2023-10-27 13:55:31 +02:00
|
|
|
} else if(_addInput && !array_empty(value_draggings)) {
|
|
|
|
for( var i = 0, n = array_length(value_draggings); i < n; i++ )
|
|
|
|
target.node.addInput(value_draggings[i]);
|
|
|
|
} else
|
2023-08-13 09:51:36 +02:00
|
|
|
target.setFrom(value_dragging);
|
2022-01-13 05:24:03 +01:00
|
|
|
} else {
|
|
|
|
if(value_dragging.connect_type == JUNCTION_CONNECT.input)
|
|
|
|
value_dragging.removeFrom();
|
2022-12-10 05:06:01 +01:00
|
|
|
value_dragging.node.triggerRender();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(value_focus != value_dragging) {
|
|
|
|
with(dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8)) {
|
|
|
|
node_target_x = other.mouse_grid_x;
|
|
|
|
node_target_y = other.mouse_grid_y;
|
|
|
|
node_called = other.value_dragging;
|
|
|
|
|
|
|
|
alarm[0] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
value_dragging = noone;
|
2023-10-24 11:23:20 +02:00
|
|
|
connection_draw_mouse = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-08-13 09:00:58 +02:00
|
|
|
} else if(!value_dragging && value_focus && mouse_press(mb_left, pFOCUS) && !key_mod_press(ALT)) {
|
|
|
|
value_dragging = value_focus;
|
|
|
|
value_draggings = [];
|
|
|
|
|
2023-08-13 09:51:36 +02:00
|
|
|
if(value_dragging.connect_type == JUNCTION_CONNECT.output) {
|
2023-10-16 13:54:31 +02:00
|
|
|
if(key_mod_press(CTRL)) {
|
|
|
|
var _to = value_dragging.getJunctionTo();
|
2023-08-13 09:51:36 +02:00
|
|
|
|
2023-10-16 13:54:31 +02:00
|
|
|
if(array_length(_to)) {
|
|
|
|
value_dragging = _to[0];
|
|
|
|
value_draggings = array_create(array_length(_to));
|
|
|
|
|
|
|
|
for( var i = 0, n = array_length(_to); i < n; i++ ) {
|
|
|
|
value_draggings[i] = _to[i];
|
|
|
|
_to[i].removeFrom();
|
|
|
|
}
|
2023-08-13 09:51:36 +02:00
|
|
|
}
|
2023-10-16 13:54:31 +02:00
|
|
|
} else {
|
|
|
|
var _jlist = ds_priority_create();
|
|
|
|
|
|
|
|
for( var i = 0, n = ds_list_size(nodes_select_list); i < n; i++ ) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
|
|
|
|
for( var j = 0, m = ds_list_size(_node.outputs); j < m; j++ ) {
|
|
|
|
var _junction = _node.outputs[| j];
|
|
|
|
if(!_junction.visible) continue;
|
|
|
|
if(value_bit(_junction.type) & value_bit(value_dragging.type) == 0) continue;
|
|
|
|
|
|
|
|
ds_priority_add(_jlist, _junction, _junction.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!ds_priority_empty(_jlist))
|
|
|
|
array_push(value_draggings, ds_priority_delete_min(_jlist));
|
|
|
|
|
|
|
|
ds_priority_destroy(_jlist);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(key_mod_press(CTRL) && value_dragging.value_from) {
|
|
|
|
var fr = value_dragging.value_from;
|
|
|
|
value_dragging.removeFrom();
|
|
|
|
value_dragging = fr;
|
2023-08-13 09:51:36 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-13 09:00:58 +02:00
|
|
|
}
|
2023-03-12 02:28:21 +01:00
|
|
|
|
|
|
|
#region draw junction name
|
|
|
|
var gr_x = graph_x * graph_s;
|
|
|
|
var gr_y = graph_y * graph_s;
|
2023-08-13 09:00:58 +02:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++)
|
2023-03-12 02:28:21 +01:00
|
|
|
nodes_list[| i].drawJunctionNames(gr_x, gr_y, mx, my, graph_s);
|
|
|
|
#endregion
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function callAddDialog() { #region
|
2022-01-13 05:24:03 +01:00
|
|
|
with(dialogCall(o_dialog_add_node, mouse_mx + 8, mouse_my + 8)) {
|
|
|
|
node_target_x = other.mouse_grid_x;
|
|
|
|
node_target_y = other.mouse_grid_y;
|
2022-01-25 04:05:30 +01:00
|
|
|
junction_hovering = other.junction_hovering;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
resetPosition();
|
2022-01-13 05:24:03 +01:00
|
|
|
alarm[0] = 1;
|
2023-01-25 06:49:00 +01:00
|
|
|
}
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawContext() { #region
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p0, fa_left, fa_center);
|
2022-11-03 11:44:49 +01:00
|
|
|
var xx = ui(16), tt, tw, th;
|
2022-11-14 03:16:15 +01:00
|
|
|
var bh = toolbar_height - ui(12);
|
2022-09-21 06:09:40 +02:00
|
|
|
var tbh = h - toolbar_height / 2;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
for(var i = -1; i < ds_list_size(node_context); i++) {
|
|
|
|
if(i == -1) {
|
2023-06-04 18:28:29 +02:00
|
|
|
tt = __txt("Global");
|
2022-01-13 05:24:03 +01:00
|
|
|
} else {
|
|
|
|
var _cnt = node_context[| i];
|
2023-02-28 09:43:01 +01:00
|
|
|
tt = _cnt.display_name == ""? _cnt.name : _cnt.display_name;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tw = string_width(tt);
|
|
|
|
th = string_height(tt);
|
|
|
|
|
|
|
|
if(i < ds_list_size(node_context) - 1) {
|
2022-11-18 03:20:31 +01:00
|
|
|
if(buttonInstant(THEME.button_hide_fill, xx - ui(6), tbh - bh / 2, tw + ui(12), bh, [mx, my], pFOCUS, pHOVER) == 2) {
|
2022-09-21 06:09:40 +02:00
|
|
|
node_hover = noone;
|
|
|
|
node_focus = noone;
|
2023-07-17 19:58:33 +02:00
|
|
|
PANEL_PREVIEW.resetNodePreview();
|
2022-12-16 09:18:09 +01:00
|
|
|
setContextFrame(true, node_context[| i + 1]);
|
2022-11-03 11:44:49 +01:00
|
|
|
|
2023-09-19 14:21:55 +02:00
|
|
|
if(i == -1)
|
|
|
|
resetContext();
|
|
|
|
else {
|
2022-01-13 05:24:03 +01:00
|
|
|
for(var j = ds_list_size(node_context) - 1; j > i; j--)
|
|
|
|
ds_list_delete(node_context, j);
|
2023-02-28 09:43:01 +01:00
|
|
|
nodes_list = node_context[| i].getNodeList();
|
2022-09-21 06:09:40 +02:00
|
|
|
toCenterNode();
|
2023-03-21 03:01:53 +01:00
|
|
|
|
|
|
|
var node = getCurrentContext();
|
|
|
|
title = node.display_name == ""? node.name : node.display_name;
|
2022-01-13 05:24:03 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.arrow, 0, xx + tw + ui(16), tbh, 1, COLORS._main_icon);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2022-11-03 11:44:49 +01:00
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
draw_set_color(COLORS._main_text);
|
|
|
|
draw_set_alpha(i < ds_list_size(node_context) - 1? 0.33 : 1);
|
2022-11-01 03:06:03 +01:00
|
|
|
draw_text(xx, tbh - 2, tt);
|
2022-01-13 05:24:03 +01:00
|
|
|
draw_set_alpha(1);
|
|
|
|
xx += tw;
|
2022-11-03 11:44:49 +01:00
|
|
|
xx += ui(32);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawToolBar() { #region
|
2022-11-03 11:44:49 +01:00
|
|
|
toolbar_height = ui(40);
|
2022-09-21 06:09:40 +02:00
|
|
|
var ty = h - toolbar_height;
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(pHOVER && point_in_rectangle(mx, my, 0, ty, w, h))
|
2022-09-21 06:09:40 +02:00
|
|
|
mouse_on_graph = false;
|
|
|
|
|
2023-06-10 13:59:45 +02:00
|
|
|
draw_sprite_stretched(THEME.toolbar, 0, 0, ty, w, h);
|
2022-09-21 06:09:40 +02:00
|
|
|
drawContext();
|
|
|
|
|
|
|
|
var tbx = w - toolbar_height / 2;
|
|
|
|
var tby = ty + toolbar_height / 2;
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(toolbars); i < n; i++ ) {
|
2022-09-21 06:09:40 +02:00
|
|
|
var tb = toolbars[i];
|
|
|
|
var tbSpr = tb[0];
|
|
|
|
var tbInd = tb[1]();
|
|
|
|
var tbTooltip = tb[2]();
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
var b = buttonInstant(THEME.button_hide, tbx - ui(14), tby - ui(14), ui(28), ui(28), [mx, my], pFOCUS, pHOVER, tbTooltip, tbSpr, tbInd);
|
2022-11-03 11:44:49 +01:00
|
|
|
if(b == 2) tb[3]( { x: x + tbx - ui(14), y: y + tby - ui(14) } );
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
tbx -= ui(32);
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.panel_toolbar_separator);
|
2022-11-03 11:44:49 +01:00
|
|
|
draw_line_width(tbx + ui(12), tby - toolbar_height / 2 + ui(8), tbx + ui(12), tby + toolbar_height / 2 - ui(8), 2);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawMinimap() { #region
|
|
|
|
if(!minimap_show) return;
|
2022-11-03 11:44:49 +01:00
|
|
|
var mx1 = w - ui(8);
|
|
|
|
var my1 = h - toolbar_height - ui(8);
|
2022-09-21 06:09:40 +02:00
|
|
|
var mx0 = mx1 - minimap_w;
|
|
|
|
var my0 = my1 - minimap_h;
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
minimap_w = min(minimap_w, w - ui(16));
|
|
|
|
minimap_h = min(minimap_h, h - ui(16) - toolbar_height);
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
var mini_hover = false;
|
|
|
|
if(pHOVER && point_in_rectangle(mx, my, mx0, my0, mx1, my1)) {
|
2022-09-21 06:09:40 +02:00
|
|
|
mouse_on_graph = false;
|
2022-12-22 03:09:55 +01:00
|
|
|
mini_hover = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var hover = mini_hover && !point_in_rectangle(mx, my, mx0, my0, mx0 + ui(16), my0 + ui(16)) && !minimap_dragging;
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-09-08 21:37:36 +02:00
|
|
|
if(!is_surface(minimap_surface) || surface_get_width_safe(minimap_surface) != minimap_w || surface_get_height_safe(minimap_surface) != minimap_h) {
|
2022-11-03 11:44:49 +01:00
|
|
|
minimap_surface = surface_create_valid(minimap_w, minimap_h);
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
surface_set_target(minimap_surface);
|
2022-12-27 04:00:50 +01:00
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear_inner, 0.75);
|
2022-09-21 06:09:40 +02:00
|
|
|
if(!ds_list_empty(nodes_list)) {
|
|
|
|
var minx = 99999;
|
|
|
|
var maxx = -99999;
|
|
|
|
var miny = 99999;
|
|
|
|
var maxy = -99999;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = nodes_list[| i];
|
|
|
|
minx = min(_node.x - 32, minx);
|
|
|
|
maxx = max(_node.x + _node.w + 32, maxx);
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
miny = min(_node.y - 32, miny);
|
|
|
|
maxy = max(_node.y + _node.h + 32, maxy);
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var cx = (minx + maxx) / 2;
|
|
|
|
var cy = (miny + maxy) / 2;
|
|
|
|
var spw = maxx - minx;
|
|
|
|
var sph = maxy - miny;
|
|
|
|
var ss = min(minimap_w / spw, minimap_h / sph);
|
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
draw_set_alpha(0.4);
|
2022-09-21 06:09:40 +02:00
|
|
|
for(var i = 0; i < ds_list_size(nodes_list); i++) {
|
2023-07-25 20:12:40 +02:00
|
|
|
var _node = nodes_list[| i];
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
var nx = minimap_w / 2 + (_node.x - cx) * ss;
|
|
|
|
var ny = minimap_h / 2 + (_node.y - cy) * ss;
|
|
|
|
var nw = _node.w * ss;
|
|
|
|
var nh = _node.h * ss;
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-10-18 14:58:55 +02:00
|
|
|
draw_set_color(_node.getColor());
|
2023-04-08 20:06:27 +02:00
|
|
|
draw_roundrect_ext(nx, ny, nx + nw, ny + nh, THEME_VALUE.minimap_corner_radius, THEME_VALUE.minimap_corner_radius, false);
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
2022-12-22 03:09:55 +01:00
|
|
|
draw_set_alpha(1);
|
2022-09-21 06:09:40 +02:00
|
|
|
|
|
|
|
var gx = minimap_w / 2 - (graph_x + cx) * ss;
|
|
|
|
var gy = minimap_h / 2 - (graph_y + cy) * ss;
|
|
|
|
var gw = w / graph_s * ss;
|
|
|
|
var gh = h / graph_s * ss;
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.panel_graph_minimap_focus);
|
2022-09-21 06:09:40 +02:00
|
|
|
draw_rectangle(gx, gy, gx + gw, gy + gh, 1);
|
|
|
|
|
|
|
|
if(minimap_panning) {
|
|
|
|
graph_x = -((mx - mx0 - gw / 2) - minimap_w / 2) / ss - cx;
|
|
|
|
graph_y = -((my - my0 - gh / 2) - minimap_h / 2) / ss - cy;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
graph_x = round(graph_x);
|
|
|
|
graph_y = round(graph_y);
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left))
|
2022-09-21 06:09:40 +02:00
|
|
|
minimap_panning = false;
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_click(mb_left, hover))
|
2022-09-21 06:09:40 +02:00
|
|
|
minimap_panning = true;
|
|
|
|
}
|
2023-10-18 14:58:55 +02:00
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
surface_reset_target();
|
|
|
|
|
2023-09-09 13:52:16 +02:00
|
|
|
draw_surface_ext_safe(minimap_surface, mx0, my0, 1, 1, 0, c_white, 0.5 + 0.35 * hover);
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.panel_graph_minimap_outline);
|
2022-09-21 06:09:40 +02:00
|
|
|
draw_rectangle(mx0, my0, mx1 - 1, my1 - 1, true);
|
|
|
|
|
|
|
|
if(minimap_dragging) {
|
|
|
|
mouse_on_graph = false;
|
|
|
|
var sw = minimap_drag_sx + minimap_drag_mx - mx;
|
|
|
|
var sh = minimap_drag_sy + minimap_drag_my - my;
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
minimap_w = max(ui(64), sw);
|
|
|
|
minimap_h = max(ui(64), sh);
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left))
|
2022-09-21 06:09:40 +02:00
|
|
|
minimap_dragging = false;
|
|
|
|
}
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(pHOVER && point_in_rectangle(mx, my, mx0, my0, mx0 + ui(16), my0 + ui(16))) {
|
2023-07-30 19:56:53 +02:00
|
|
|
draw_sprite_ui(THEME.node_resize, 0, mx0 + ui(2), my0 + ui(2), 0.5, 0.5, 180, c_white, 0.75);
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_press(mb_left, pFOCUS)) {
|
2022-09-21 06:09:40 +02:00
|
|
|
minimap_dragging = true;
|
|
|
|
minimap_drag_sx = minimap_w;
|
|
|
|
minimap_drag_sy = minimap_h;
|
|
|
|
minimap_drag_mx = mx;
|
|
|
|
minimap_drag_my = my;
|
|
|
|
}
|
|
|
|
} else
|
2023-07-30 19:56:53 +02:00
|
|
|
draw_sprite_ui(THEME.node_resize, 0, mx0 + ui(2), my0 + ui(2), 0.5, 0.5, 180, c_white, 0.3);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-09-21 06:09:40 +02:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawContextFrame() { #region
|
2022-12-16 09:18:09 +01:00
|
|
|
if(!context_framing) return;
|
|
|
|
context_frame_progress = lerp_float(context_frame_progress, 1, 5);
|
|
|
|
if(context_frame_progress == 1)
|
|
|
|
context_framing = false;
|
|
|
|
|
|
|
|
var _fr_x0 = 0, _fr_y0 = 0;
|
|
|
|
var _fr_x1 = w, _fr_y1 = h;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
var _to_x0 = context_frame_sx;
|
|
|
|
var _to_y0 = context_frame_sy;
|
|
|
|
var _to_x1 = context_frame_ex;
|
|
|
|
var _to_y1 = context_frame_ey;
|
2022-12-16 09:18:09 +01:00
|
|
|
|
|
|
|
var prog = context_frame_direct? context_frame_progress : 1 - context_frame_progress;
|
|
|
|
var frm_x0 = lerp(_fr_x0, _to_x0, prog);
|
|
|
|
var frm_y0 = lerp(_fr_y0, _to_y0, prog);
|
|
|
|
var frm_x1 = lerp(_fr_x1, _to_x1, prog);
|
|
|
|
var frm_y1 = lerp(_fr_y1, _to_y1, prog);
|
|
|
|
|
|
|
|
draw_set_color(COLORS._main_accent);
|
|
|
|
draw_set_alpha(0.5);
|
2023-04-08 20:06:27 +02:00
|
|
|
draw_roundrect_ext(frm_x0, frm_y0, frm_x1, frm_y1, THEME_VALUE.panel_corner_radius, THEME_VALUE.panel_corner_radius, true);
|
2022-12-16 09:18:09 +01:00
|
|
|
draw_set_alpha(1);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-12-16 09:18:09 +01:00
|
|
|
|
2023-09-19 14:21:55 +02:00
|
|
|
function resetContext() { #region
|
|
|
|
ds_list_clear(node_context);
|
|
|
|
title = __txt("Graph");
|
|
|
|
nodes_list = project.nodes;
|
|
|
|
toCenterNode();
|
|
|
|
} #endregion
|
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function addContext(node) { #region
|
2023-03-21 03:01:53 +01:00
|
|
|
title = node.display_name == ""? node.name : node.display_name;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
var _node = node.getNodeBase();
|
|
|
|
setContextFrame(false, _node);
|
|
|
|
|
|
|
|
nodes_list = _node.nodes;
|
|
|
|
ds_list_add(node_context, _node);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
node_dragging = noone;
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
selection_block = 1;
|
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
toCenterNode();
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-12-16 09:18:09 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function setContextFrame(dirr, node) { #region
|
2022-12-16 09:18:09 +01:00
|
|
|
context_framing = true;
|
|
|
|
context_frame_direct = dirr;
|
|
|
|
context_frame_progress = 0;
|
2023-02-28 09:43:01 +01:00
|
|
|
context_frame_sx = w / 2 - 8;
|
|
|
|
context_frame_sy = h / 2 - 8;
|
|
|
|
context_frame_ex = context_frame_sx + 16;
|
|
|
|
context_frame_ey = context_frame_sy + 16;
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function drawContent(panel) { #region >>>>>>>>>>>>>>>>>>>> MAIN DRAW <<<<<<<<<<<<<<<<<<<<
|
2023-07-23 21:15:45 +02:00
|
|
|
if(!project.active) return;
|
2023-07-06 19:49:16 +02:00
|
|
|
if(project.path == "") title = "New project";
|
|
|
|
else title = filename_name_only(project.path);
|
|
|
|
title += project.modified? "*" : "";
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
dragGraph();
|
|
|
|
|
|
|
|
var context = getCurrentContext();
|
2023-08-31 18:49:57 +02:00
|
|
|
bg_color = context == noone? COLORS.panel_bg_clear : merge_color(COLORS.panel_bg_clear, context.color, 0.05);
|
|
|
|
draw_clear(bg_color);
|
2023-08-13 13:10:20 +02:00
|
|
|
drawGrid();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p0, fa_right, fa_top, COLORS._main_text_sub);
|
2023-08-13 13:10:20 +02:00
|
|
|
draw_text(w - ui(8), ui(8), $"x{graph_s_to}");
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
drawNodes();
|
|
|
|
drawJunctionConnect();
|
2022-12-16 09:18:09 +01:00
|
|
|
drawContextFrame();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-09-21 06:09:40 +02:00
|
|
|
mouse_on_graph = true;
|
|
|
|
drawToolBar();
|
2023-08-13 13:10:20 +02:00
|
|
|
drawMinimap();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-02-14 02:51:14 +01:00
|
|
|
if(pFOCUS && node_focus) node_focus.focusStep();
|
2022-12-10 05:06:01 +01:00
|
|
|
|
|
|
|
if(UPDATE == RENDER_TYPE.full)
|
2023-06-04 18:28:29 +02:00
|
|
|
draw_text(w - ui(8), ui(28), __txtx("panel_graph_rendering", "Rendering") + "...");
|
2023-08-13 13:10:20 +02:00
|
|
|
else if(UPDATE == RENDER_TYPE.partial)
|
2023-06-04 18:28:29 +02:00
|
|
|
draw_text(w - ui(8), ui(28), __txtx("panel_graph_rendering_partial", "Rendering partial") + "...");
|
2023-03-25 12:27:04 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
if(DRAGGING && pHOVER) { #region file dropping
|
2023-03-26 07:13:36 +02:00
|
|
|
if(node_hovering && node_hovering.droppable(DRAGGING)) {
|
|
|
|
node_hovering.draw_droppable = true;
|
2023-03-25 12:27:04 +01:00
|
|
|
if(mouse_release(mb_left))
|
2023-03-26 07:13:36 +02:00
|
|
|
node_hovering.onDrop(DRAGGING);
|
2023-03-25 12:27:04 +01:00
|
|
|
} else {
|
|
|
|
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, 2, 2, w - 4, h - 4, COLORS._main_value_positive, 1);
|
|
|
|
if(mouse_release(mb_left))
|
|
|
|
checkDropItem();
|
|
|
|
}
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-04-21 19:08:10 +02:00
|
|
|
|
|
|
|
graph_dragging_key = false;
|
2023-07-30 13:56:22 +02:00
|
|
|
graph_zooming_key = false;
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
|
|
|
|
|
|
|
#region ++++ node manipulation ++++
|
|
|
|
function doTransform() { #region
|
|
|
|
if(ds_list_empty(nodes_select_list)) {
|
|
|
|
if(node_focus != noone && !ds_list_empty(node_focus.outputs)) {
|
|
|
|
var _o = node_focus.outputs[| 0];
|
2023-09-16 20:26:35 +02:00
|
|
|
if(_o.type == VALUE_TYPE.surface || _o.type == VALUE_TYPE.dynaSurface) {
|
2023-08-13 13:10:20 +02:00
|
|
|
var tr = nodeBuild("Node_Transform", node_focus.x + node_focus.w + 64, node_focus.y);
|
|
|
|
tr.inputs[| 0].setFrom(_o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) {
|
|
|
|
var node = nodes_select_list[| i];
|
|
|
|
if(ds_list_empty(node.outputs)) continue;
|
|
|
|
|
|
|
|
var _o = node.outputs[| 0];
|
2023-09-16 20:26:35 +02:00
|
|
|
if(_o.type == VALUE_TYPE.surface || _o.type == VALUE_TYPE.dynaSurface) {
|
2023-08-13 13:10:20 +02:00
|
|
|
var tr = nodeBuild("Node_Transform", node.x + node.w + 64, node.y);
|
|
|
|
tr.inputs[| 0].setFrom(_o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doDuplicate() { #region
|
|
|
|
var nodeArray = [];
|
|
|
|
if(ds_list_empty(nodes_select_list)) {
|
|
|
|
if(node_focus == noone) return;
|
|
|
|
nodeArray = [node_focus];
|
|
|
|
} else {
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++)
|
|
|
|
nodeArray[i] = nodes_select_list[| i];
|
|
|
|
}
|
|
|
|
|
|
|
|
var _map = {};
|
|
|
|
var _node = [];
|
|
|
|
for(var i = 0; i < array_length(nodeArray); i++)
|
|
|
|
SAVE_NODE(_node, nodeArray[i],,,, getCurrentContext());
|
|
|
|
_map.nodes = _node;
|
|
|
|
|
|
|
|
APPENDING = true;
|
|
|
|
CLONING = true;
|
|
|
|
var _app = __APPEND_MAP(_map);
|
|
|
|
APPENDING = false;
|
|
|
|
CLONING = false;
|
|
|
|
|
|
|
|
if(ds_list_size(_app) == 0) {
|
|
|
|
ds_list_destroy(_app);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var x0 = 99999999;
|
|
|
|
var y0 = 99999999;
|
|
|
|
for(var i = 0; i < ds_list_size(_app); i++) {
|
|
|
|
var _node = _app[| i];
|
|
|
|
|
|
|
|
x0 = min(x0, _node.x);
|
|
|
|
y0 = min(y0, _node.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
node_dragging = _app[| 0];
|
|
|
|
node_drag_mx = x0; node_drag_my = y0;
|
|
|
|
node_drag_sx = x0; node_drag_sy = y0;
|
|
|
|
node_drag_ox = x0; node_drag_oy = y0;
|
|
|
|
|
|
|
|
ds_list_destroy(nodes_select_list);
|
|
|
|
nodes_select_list = _app;
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doInstance() { #region
|
|
|
|
if(node_focus == noone) return;
|
|
|
|
if(!struct_has(node_focus, "nodes")) return;
|
|
|
|
|
|
|
|
if(node_focus.instanceBase == noone) {
|
|
|
|
node_focus.isInstancer = true;
|
|
|
|
|
|
|
|
CLONING = true;
|
|
|
|
var _type = instanceof(node_focus);
|
|
|
|
var _node = nodeBuild(_type, x, y);
|
|
|
|
CLONING = false;
|
|
|
|
|
|
|
|
_node.setInstance(node_focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
var _nodeNew = _node.clone();
|
|
|
|
|
|
|
|
node_dragging = _nodeNew;
|
|
|
|
node_drag_mx = _nodeNew.x; node_drag_my = _nodeNew.y;
|
|
|
|
node_drag_sx = _nodeNew.x; node_drag_sy = _nodeNew.y;
|
|
|
|
node_drag_ox = _nodeNew.x; node_drag_oy = _nodeNew.y;
|
|
|
|
} #endregion
|
2023-03-25 12:27:04 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function doCopy() { #region
|
|
|
|
clipboard_set_text("");
|
|
|
|
|
|
|
|
var nodeArray = [];
|
|
|
|
if(ds_list_empty(nodes_select_list)) {
|
|
|
|
if(node_focus == noone) return;
|
|
|
|
nodeArray = [node_focus];
|
|
|
|
} else {
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
nodeArray[i] = _node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _map = {};
|
|
|
|
var _node = [];
|
|
|
|
for(var i = 0; i < array_length(nodeArray); i++)
|
|
|
|
SAVE_NODE(_node, nodeArray[i],,,, getCurrentContext());
|
|
|
|
_map.nodes = _node;
|
|
|
|
|
|
|
|
clipboard_set_text(json_stringify_minify(_map));
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doPaste() { #region
|
|
|
|
var txt = clipboard_get_text();
|
|
|
|
var _map = json_try_parse(txt, noone);
|
2023-10-07 09:09:18 +02:00
|
|
|
|
|
|
|
if(txt == "") return;
|
|
|
|
|
|
|
|
if(is_struct(_map)) {
|
2023-08-13 13:10:20 +02:00
|
|
|
ds_map_clear(APPEND_MAP);
|
|
|
|
APPENDING = true;
|
|
|
|
CLONING = true;
|
|
|
|
var _app = __APPEND_MAP(_map);
|
|
|
|
APPENDING = false;
|
|
|
|
CLONING = false;
|
2023-10-20 12:32:43 +02:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
if(_app == noone)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(ds_list_size(_app) == 0) {
|
|
|
|
ds_list_destroy(_app);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var x0 = 99999999;
|
|
|
|
var y0 = 99999999;
|
|
|
|
for(var i = 0; i < ds_list_size(_app); i++) {
|
|
|
|
var _node = _app[| i];
|
|
|
|
|
|
|
|
x0 = min(x0, _node.x);
|
|
|
|
y0 = min(y0, _node.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
node_dragging = _app[| 0];
|
|
|
|
node_drag_mx = x0; node_drag_my = y0;
|
|
|
|
node_drag_sx = x0; node_drag_sy = y0;
|
|
|
|
node_drag_ox = x0; node_drag_oy = y0;
|
|
|
|
|
|
|
|
ds_list_destroy(nodes_select_list);
|
|
|
|
nodes_select_list = _app;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(filename_ext(txt) == ".pxc")
|
|
|
|
APPEND(txt);
|
|
|
|
else if(filename_ext(txt) == ".pxcc")
|
|
|
|
APPEND(txt);
|
|
|
|
else if(filename_ext(txt) == ".png") {
|
|
|
|
if(file_exists(txt)) {
|
|
|
|
Node_create_Image_path(0, 0, txt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var path = DIRECTORY + "temp/url_pasted_" + string(irandom_range(100000, 999999)) + ".png";
|
|
|
|
var img = http_get_file(txt, path);
|
|
|
|
CLONING = true;
|
|
|
|
var node = Node_create_Image(0, 0);
|
|
|
|
CLONING = false;
|
|
|
|
var args = [node, path];
|
|
|
|
|
|
|
|
global.FILE_LOAD_ASYNC[? img] = [ function(args) {
|
|
|
|
args[0].inputs[| 0].setValue(args[1]);
|
|
|
|
args[0].doUpdate();
|
|
|
|
}, args];
|
|
|
|
}
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doBlend() { #region
|
|
|
|
if(ds_list_empty(nodes_select_list)) return;
|
|
|
|
if(ds_list_size(nodes_select_list) != 2) return;
|
|
|
|
|
|
|
|
var cx = nodes_select_list[| 0].x;
|
|
|
|
var cy = 0;
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
cx = max(cx, _node.x);
|
|
|
|
cy += _node.y;
|
|
|
|
}
|
|
|
|
cx = cx + 160;
|
|
|
|
cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32;
|
|
|
|
|
|
|
|
var _blend = new Node_Blend(cx, cy, getCurrentContext());
|
|
|
|
var index = 0;
|
|
|
|
for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
if(ds_list_size(_node.outputs) == 0) continue;
|
|
|
|
if(_node.outputs[| 0].type == VALUE_TYPE.surface) {
|
|
|
|
_blend.inputs[| index].setFrom(_node.outputs[| 0]);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doCompose() { #region
|
|
|
|
if(ds_list_empty(nodes_select_list)) return;
|
|
|
|
|
|
|
|
var cx = nodes_select_list[| 0].x;
|
|
|
|
var cy = 0;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
cx = max(cx, _node.x);
|
|
|
|
cy += _node.y;
|
|
|
|
}
|
|
|
|
cx = cx + 160;
|
|
|
|
cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32;
|
|
|
|
|
|
|
|
var _compose = nodeBuild("Node_Composite", cx, cy);
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
if(ds_list_size(_node.outputs) == 0) continue;
|
|
|
|
if(_node.outputs[| 0].type == VALUE_TYPE.surface) {
|
|
|
|
_compose.addInput(_node.outputs[| 0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doArray() { #region
|
|
|
|
if(ds_list_empty(nodes_select_list)) return;
|
|
|
|
|
|
|
|
var cx = nodes_select_list[| 0].x;
|
|
|
|
var cy = 0;
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
cx = max(cx, _node.x);
|
|
|
|
cy += _node.y;
|
|
|
|
}
|
|
|
|
cx = cx + 160;
|
|
|
|
cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32;
|
|
|
|
|
|
|
|
var _array = nodeBuild("Node_Array", cx, cy);
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
if(ds_list_size(_node.outputs) == 0) continue;
|
|
|
|
_array.addInput(_node.outputs[| 0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doGroup() { #region
|
|
|
|
if(ds_list_empty(nodes_select_list) && node_focus != noone)
|
|
|
|
ds_list_add(nodes_select_list, node_focus);
|
|
|
|
node_focus = noone;
|
|
|
|
|
|
|
|
if(ds_list_empty(nodes_select_list)) return;
|
|
|
|
|
|
|
|
groupNodes(array_create_from_list(nodes_select_list));
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doUngroup() { #region
|
|
|
|
if(node_focus == noone) return;
|
|
|
|
if(!variable_struct_exists(node_focus, "nodes")) return;
|
|
|
|
if(!node_focus.ungroupable) return;
|
|
|
|
|
|
|
|
upgroupNode(node_focus);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doLoop() { #region
|
|
|
|
if(ds_list_empty(nodes_select_list) && node_focus != noone)
|
|
|
|
ds_list_add(nodes_select_list, node_focus);
|
|
|
|
|
|
|
|
if(ds_list_empty(nodes_select_list)) return;
|
|
|
|
|
|
|
|
var cx = 0;
|
|
|
|
var cy = 0;
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
cx += _node.x;
|
|
|
|
cy += _node.y;
|
|
|
|
}
|
|
|
|
cx = round(cx / ds_list_size(nodes_select_list) / 32) * 32;
|
|
|
|
cy = round(cy / ds_list_size(nodes_select_list) / 32) * 32;
|
|
|
|
|
|
|
|
var _group = new Node_Iterate(cx, cy, getCurrentContext());
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
_group.add(nodes_select_list[| i]);
|
|
|
|
}
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
nodes_select_list[| i].checkConnectGroup("loop");
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doFrame() { #region
|
|
|
|
var x0 = 999999, y0 = 999999, x1 = -999999, y1 = -999999;
|
|
|
|
|
|
|
|
if(ds_list_empty(nodes_select_list)) {
|
|
|
|
if(node_focus != noone) {
|
|
|
|
x0 = node_focus.x;
|
|
|
|
y0 = node_focus.y;
|
|
|
|
x1 = node_focus.x + node_focus.w;
|
|
|
|
y1 = node_focus.y + node_focus.h;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
for( var i = 0; i < ds_list_size(nodes_select_list); i++ ) {
|
|
|
|
var _node = nodes_select_list[| i];
|
|
|
|
x0 = min(x0, _node.x);
|
|
|
|
y0 = min(y0, _node.y);
|
|
|
|
x1 = max(x1, _node.x + _node.w);
|
|
|
|
y1 = max(y1, _node.y + _node.h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x0 -= 64;
|
|
|
|
y0 -= 64;
|
|
|
|
x1 += 64;
|
|
|
|
y1 += 64;
|
|
|
|
|
|
|
|
var f = new Node_Frame(x0, y0, getCurrentContext());
|
|
|
|
f.inputs[| 0].setValue([x1 - x0, y1 - y0]);
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doDelete(_merge = false) { #region
|
|
|
|
if(node_focus != noone && node_focus.manual_deletable)
|
|
|
|
nodeDelete(node_focus, _merge);
|
|
|
|
|
|
|
|
for(var i = 0; i < ds_list_size(nodes_select_list); i++) {
|
|
|
|
if(nodes_select_list[| i].manual_deletable)
|
|
|
|
nodeDelete(nodes_select_list[| i], _merge);
|
|
|
|
}
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
} #endregion
|
2023-10-18 14:58:55 +02:00
|
|
|
|
|
|
|
node_prop_clipboard = noone;
|
|
|
|
function doCopyProp() { #region
|
|
|
|
if(node_hover == noone) return;
|
|
|
|
node_prop_clipboard = node_hover;
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
function doPasteProp() { #region
|
|
|
|
if(node_hover == noone) return;
|
|
|
|
if(node_prop_clipboard == noone) return;
|
|
|
|
if(!node_prop_clipboard.active) return;
|
|
|
|
|
|
|
|
if(instanceof(node_prop_clipboard) != instanceof(node_hover)) return;
|
|
|
|
|
|
|
|
var _vals = [];
|
|
|
|
for( var i = 0, n = ds_list_size(node_prop_clipboard.inputs); i < n; i++ ) {
|
|
|
|
var _inp = node_prop_clipboard.inputs[| i];
|
|
|
|
_vals[i] = _inp.serialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
for( var i = 0, n = ds_list_size(node_hover.inputs); i < n; i++ ) {
|
|
|
|
var _inp = node_hover.inputs[| i];
|
|
|
|
if(_inp.value_from != noone) continue;
|
|
|
|
|
|
|
|
_inp.applyDeserialize(_vals[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
node_hover.clearInputCache();
|
|
|
|
RENDER_PARTIAL
|
|
|
|
} #endregion
|
2023-08-13 13:10:20 +02:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
function dropFile(path) { #region
|
2023-09-28 13:15:29 +02:00
|
|
|
if(node_hovering && is_callable(node_hovering.on_drop_file))
|
|
|
|
return node_hovering.on_drop_file(path);
|
2023-08-13 13:10:20 +02:00
|
|
|
return false;
|
|
|
|
} #endregion
|
|
|
|
|
|
|
|
static checkDropItem = function() { #region
|
2023-03-26 07:13:36 +02:00
|
|
|
var node = noone;
|
|
|
|
|
2023-03-25 12:27:04 +01:00
|
|
|
switch(DRAGGING.type) {
|
|
|
|
case "Color":
|
2023-03-26 07:13:36 +02:00
|
|
|
node = nodeBuild("Node_Color", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
2023-03-25 12:27:04 +01:00
|
|
|
node.inputs[| 0].setValue(DRAGGING.data);
|
|
|
|
break;
|
|
|
|
case "Palette":
|
2023-03-26 07:13:36 +02:00
|
|
|
node = nodeBuild("Node_Palette", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
|
|
|
node.inputs[| 0].setValue(DRAGGING.data);
|
|
|
|
break;
|
|
|
|
case "Gradient":
|
|
|
|
node = nodeBuild("Node_Gradient_Out", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
|
|
|
node.inputs[| 0].setValue(DRAGGING.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "Number":
|
|
|
|
if(is_array(DRAGGING.data) && array_length(DRAGGING.data) <= 4) {
|
|
|
|
switch(array_length(DRAGGING.data)) {
|
|
|
|
case 2 : node = nodeBuild("Node_Vector2", mouse_grid_x, mouse_grid_y, getCurrentContext()); break;
|
|
|
|
case 3 : node = nodeBuild("Node_Vector3", mouse_grid_x, mouse_grid_y, getCurrentContext()); break;
|
|
|
|
case 4 : node = nodeBuild("Node_Vector4", mouse_grid_x, mouse_grid_y, getCurrentContext()); break;
|
|
|
|
}
|
|
|
|
|
2023-07-25 20:12:40 +02:00
|
|
|
for( var i = 0, n = array_length(DRAGGING.data); i < n; i++ )
|
2023-03-26 07:13:36 +02:00
|
|
|
node.inputs[| i].setValue(DRAGGING.data[i]);
|
|
|
|
} else {
|
|
|
|
node = nodeBuild("Node_Number", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
|
|
|
node.inputs[| 0].setValue(DRAGGING.data);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "Bool":
|
|
|
|
node = nodeBuild("Node_Boolean", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
|
|
|
node.inputs[| 0].setValue(DRAGGING.data);
|
|
|
|
break;
|
|
|
|
case "Text":
|
|
|
|
node = nodeBuild("Node_String", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
2023-03-25 12:27:04 +01:00
|
|
|
node.inputs[| 0].setValue(DRAGGING.data);
|
|
|
|
break;
|
2023-03-26 07:13:36 +02:00
|
|
|
case "Path":
|
|
|
|
node = nodeBuild("Node_Path", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
|
|
|
break;
|
|
|
|
case "Struct":
|
|
|
|
node = nodeBuild("Node_Struct", mouse_grid_x, mouse_grid_y, getCurrentContext());
|
|
|
|
break;
|
|
|
|
|
2023-03-25 12:53:29 +01:00
|
|
|
case "Asset":
|
|
|
|
var app = Node_create_Image_path(mouse_grid_x, mouse_grid_y, DRAGGING.data.path);
|
|
|
|
break;
|
|
|
|
case "Collection":
|
|
|
|
var path = DRAGGING.data.path;
|
|
|
|
ds_list_clear(nodes_select_list);
|
|
|
|
|
|
|
|
var app = APPEND(DRAGGING.data.path, getCurrentContext());
|
|
|
|
|
|
|
|
if(!is_struct(app) && ds_exists(app, ds_type_list)) {
|
|
|
|
var cx = 0;
|
|
|
|
var cy = 0;
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(app); i++ ) {
|
|
|
|
cx += app[| i].x;
|
|
|
|
cy += app[| i].y;
|
|
|
|
}
|
|
|
|
|
|
|
|
cx /= ds_list_size(app);
|
|
|
|
cy /= ds_list_size(app);
|
|
|
|
|
|
|
|
for( var i = 0; i < ds_list_size(app); i++ ) {
|
|
|
|
app[| i].x = app[| i].x - cx + mouse_grid_x;
|
|
|
|
app[| i].y = app[| i].y - cy + mouse_grid_y;
|
|
|
|
}
|
|
|
|
|
|
|
|
ds_list_destroy(app);
|
|
|
|
} else {
|
|
|
|
app.x = mouse_grid_x;
|
|
|
|
app.y = mouse_grid_y;
|
|
|
|
}
|
|
|
|
break;
|
2023-03-25 12:27:04 +01:00
|
|
|
}
|
2023-03-26 07:13:36 +02:00
|
|
|
|
2023-10-27 13:55:31 +02:00
|
|
|
if(!key_mod_press(SHIFT) && node && struct_has(DRAGGING, "from") && DRAGGING.from.isLeaf()) {
|
2023-07-15 20:01:29 +02:00
|
|
|
for( var i = 0; i < ds_list_size(node.outputs); i++ )
|
|
|
|
if(DRAGGING.from.setFrom(node.outputs[| i])) break;
|
|
|
|
}
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
static bringNodeToFront = function(node) { #region
|
2023-03-05 07:16:44 +01:00
|
|
|
if(!ds_list_exist(nodes_list, node)) return;
|
|
|
|
|
|
|
|
ds_list_remove(nodes_list, node);
|
|
|
|
ds_list_add(nodes_list, node);
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2023-07-06 19:49:16 +02:00
|
|
|
|
2023-08-13 13:10:20 +02:00
|
|
|
function close() { #region
|
2023-08-01 11:16:23 +02:00
|
|
|
var panels = findPanels("Panel_Graph");
|
|
|
|
for( var i = 0, n = array_length(panels); i < n; i++ ) {
|
|
|
|
if(panels[i] == self) continue;
|
|
|
|
if(panels[i].project == project) {
|
|
|
|
panel.remove(self);
|
|
|
|
return;
|
|
|
|
}
|
2023-07-23 21:15:45 +02:00
|
|
|
}
|
|
|
|
|
2023-07-06 19:49:16 +02:00
|
|
|
if(!project.modified || project.readonly) {
|
|
|
|
closeProject(project);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var dia = dialogCall(o_dialog_save);
|
|
|
|
dia.project = project;
|
2023-08-13 13:10:20 +02:00
|
|
|
} #endregion
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|