Improvements for Visject Surface

This commit is contained in:
Wojtek Figat
2021-10-08 15:30:42 +02:00
parent aa3a6e2766
commit 78e093245d
4 changed files with 20 additions and 22 deletions

View File

@@ -156,7 +156,7 @@ namespace FlaxEditor.Surface
/// </summary> /// </summary>
/// <param name="width">The width.</param> /// <param name="width">The width.</param>
/// <param name="height">The height.</param> /// <param name="height">The height.</param>
protected void Resize(float width, float height) public void Resize(float width, float height)
{ {
Size = CalculateNodeSize(width, height); Size = CalculateNodeSize(width, height);
@@ -176,7 +176,7 @@ namespace FlaxEditor.Surface
/// <summary> /// <summary>
/// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions. /// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions.
/// </summary> /// </summary>
protected void ResizeAuto() public void ResizeAuto()
{ {
var width = 0.0f; var width = 0.0f;
var height = 0.0f; var height = 0.0f;

View File

@@ -141,8 +141,11 @@ namespace FlaxEditor.Surface
// Create secondary context menu // Create secondary context menu
var menu = new FlaxEditor.GUI.ContextMenu.ContextMenu(); var menu = new FlaxEditor.GUI.ContextMenu.ContextMenu();
menu.AddButton("Save", _onSave).Enabled = CanEdit; if (_onSave != null)
menu.AddSeparator(); {
menu.AddButton("Save", _onSave).Enabled = CanEdit;
menu.AddSeparator();
}
_cmCopyButton = menu.AddButton("Copy", Copy); _cmCopyButton = menu.AddButton("Copy", Copy);
menu.AddButton("Paste", Paste).Enabled = CanEdit && CanPaste(); menu.AddButton("Paste", Paste).Enabled = CanEdit && CanPaste();
_cmDuplicateButton = menu.AddButton("Duplicate", Duplicate); _cmDuplicateButton = menu.AddButton("Duplicate", Duplicate);
@@ -219,13 +222,9 @@ namespace FlaxEditor.Surface
} }
menu.AddSeparator(); menu.AddSeparator();
_cmFormatNodesConnectionButton = menu.AddButton("Format node(s)", () => _cmFormatNodesConnectionButton = menu.AddButton("Format node(s)", () => { FormatGraph(SelectedNodes); });
{ _cmFormatNodesConnectionButton.Enabled = CanEdit && HasNodesSelection;
FormatGraph(SelectedNodes);
});
_cmFormatNodesConnectionButton.Enabled = HasNodesSelection;
menu.AddSeparator();
_cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () => _cmRemoveNodeConnectionsButton = menu.AddButton("Remove all connections to that node(s)", () =>
{ {
var nodes = ((List<SurfaceNode>)menu.Tag); var nodes = ((List<SurfaceNode>)menu.Tag);

View File

@@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FlaxEngine; using FlaxEngine;
using FlaxEditor.Surface.Elements; using FlaxEditor.Surface.Elements;
using FlaxEditor.Surface.Undo; using FlaxEditor.Surface.Undo;
@@ -36,9 +34,10 @@ namespace FlaxEditor.Surface
/// Uses the Sugiyama method /// Uses the Sugiyama method
/// </summary> /// </summary>
/// <param name="nodes">List of nodes</param> /// <param name="nodes">List of nodes</param>
protected void FormatGraph(List<SurfaceNode> nodes) public void FormatGraph(List<SurfaceNode> nodes)
{ {
if (nodes.Count <= 1 || !CanEdit) return; if (nodes.Count <= 1)
return;
var nodesToVisit = new HashSet<SurfaceNode>(nodes); var nodesToVisit = new HashSet<SurfaceNode>(nodes);
@@ -70,7 +69,6 @@ namespace FlaxEditor.Surface
queue.Enqueue(box.Connections[j].ParentNode); queue.Enqueue(box.Connections[j].ParentNode);
} }
} }
} }
} }
} }
@@ -85,7 +83,8 @@ namespace FlaxEditor.Surface
/// <param name="nodes">List of connected nodes</param> /// <param name="nodes">List of connected nodes</param>
protected void FormatConnectedGraph(List<SurfaceNode> nodes) protected void FormatConnectedGraph(List<SurfaceNode> nodes)
{ {
if (nodes.Count <= 1 || !CanEdit) return; if (nodes.Count <= 1)
return;
var boundingBox = GetNodesBounds(nodes); var boundingBox = GetNodesBounds(nodes);
@@ -93,9 +92,9 @@ namespace FlaxEditor.Surface
// Rightmost nodes with none of our nodes to the right of them // Rightmost nodes with none of our nodes to the right of them
var endNodes = nodes var endNodes = nodes
.Where(n => !n.GetBoxes().Any(b => b.IsOutput && b.Connections.Any(c => nodeData.ContainsKey(c.ParentNode)))) .Where(n => !n.GetBoxes().Any(b => b.IsOutput && b.Connections.Any(c => nodeData.ContainsKey(c.ParentNode))))
.OrderBy(n => n.Top) // Keep their relative order .OrderBy(n => n.Top) // Keep their relative order
.ToList(); .ToList();
// Longest path layering // Longest path layering
int maxLayer = SetLayers(nodeData, endNodes); int maxLayer = SetLayers(nodeData, endNodes);
@@ -219,7 +218,8 @@ namespace FlaxEditor.Surface
void SetOffsets(SurfaceNode node, NodeFormattingData straightParentData) void SetOffsets(SurfaceNode node, NodeFormattingData straightParentData)
{ {
if (!nodeData.TryGetValue(node, out var data)) return; if (!nodeData.TryGetValue(node, out var data))
return;
// If we realize that the current node would collide with an already existing node in this layer // If we realize that the current node would collide with an already existing node in this layer
if (data.Layer >= 0 && offsets[data.Layer] > data.Offset) if (data.Layer >= 0 && offsets[data.Layer] > data.Offset)
@@ -282,6 +282,5 @@ namespace FlaxEditor.Surface
return maxOffset; return maxOffset;
} }
} }
} }

View File

@@ -329,7 +329,7 @@ namespace FlaxEditor.Surface
/// <param name="style">The custom surface style. Use null to create the default style.</param> /// <param name="style">The custom surface style. Use null to create the default style.</param>
/// <param name="groups">The custom surface node types. Pass null to use the default nodes set.</param> /// <param name="groups">The custom surface node types. Pass null to use the default nodes set.</param>
/// <param name="supportsDebugging">True if surface supports debugging features (breakpoints, etc.).</param> /// <param name="supportsDebugging">True if surface supports debugging features (breakpoints, etc.).</param>
public VisjectSurface(IVisjectSurfaceOwner owner, Action onSave, FlaxEditor.Undo undo = null, SurfaceStyle style = null, List<GroupArchetype> groups = null, bool supportsDebugging = false) public VisjectSurface(IVisjectSurfaceOwner owner, Action onSave = null, FlaxEditor.Undo undo = null, SurfaceStyle style = null, List<GroupArchetype> groups = null, bool supportsDebugging = false)
{ {
AnchorPreset = AnchorPresets.StretchAll; AnchorPreset = AnchorPresets.StretchAll;
Offsets = Margin.Zero; Offsets = Margin.Zero;