diff --git a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs
index 7e547c326..f044cd6ff 100644
--- a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs
+++ b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs
@@ -484,7 +484,7 @@ namespace FlaxEditor.Surface.Archetypes
var startPos = PointToParent(ref center);
targetState.GetConnectionEndPoint(ref startPos, out var endPos);
var color = style.Foreground;
- StateMachineState.DrawConnection(Surface, ref startPos, ref endPos, ref color);
+ StateMachineState.DrawConnection(ref startPos, ref endPos, ref color);
}
}
@@ -514,7 +514,7 @@ namespace FlaxEditor.Surface.Archetypes
///
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
{
- StateMachineState.DrawConnection(Surface, ref startPos, ref endPos, ref color);
+ StateMachineState.DrawConnection(ref startPos, ref endPos, ref color);
}
///
@@ -680,11 +680,10 @@ namespace FlaxEditor.Surface.Archetypes
///
/// Draws the connection between two state machine nodes.
///
- /// The surface.
/// The start position.
/// The end position.
/// The line color.
- public static void DrawConnection(VisjectSurface surface, ref Float2 startPos, ref Float2 endPos, ref Color color)
+ public static void DrawConnection(ref Float2 startPos, ref Float2 endPos, ref Color color)
{
var sub = endPos - startPos;
var length = sub.Length;
@@ -1293,7 +1292,7 @@ namespace FlaxEditor.Surface.Archetypes
isMouseOver = Float2.DistanceSquared(ref mousePosition, ref point) < 25.0f;
}
var color = isMouseOver ? Color.Wheat : t.LineColor;
- DrawConnection(Surface, ref t.StartPos, ref t.EndPos, ref color);
+ DrawConnection(ref t.StartPos, ref t.EndPos, ref color);
}
}
@@ -1322,7 +1321,7 @@ namespace FlaxEditor.Surface.Archetypes
///
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
{
- DrawConnection(Surface, ref startPos, ref endPos, ref color);
+ DrawConnection(ref startPos, ref endPos, ref color);
}
///
diff --git a/Source/Editor/Surface/Archetypes/Tools.cs b/Source/Editor/Surface/Archetypes/Tools.cs
index 9f6db7ea4..d6c5d8c30 100644
--- a/Source/Editor/Surface/Archetypes/Tools.cs
+++ b/Source/Editor/Surface/Archetypes/Tools.cs
@@ -1237,7 +1237,7 @@ namespace FlaxEditor.Surface.Archetypes
///
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
{
- OutputBox.DrawConnection(ref startPos, ref endPos, ref color, 2);
+ OutputBox.DrawConnection(Surface.Style, ref startPos, ref endPos, ref color, 2);
}
///
diff --git a/Source/Editor/Surface/Elements/Box.cs b/Source/Editor/Surface/Elements/Box.cs
index e771fa71c..8b0caab84 100644
--- a/Source/Editor/Surface/Elements/Box.cs
+++ b/Source/Editor/Surface/Elements/Box.cs
@@ -133,6 +133,11 @@ namespace FlaxEditor.Surface.Elements
}
}
+ ///
+ /// Cached color for .
+ ///
+ public Color CurrentTypeColor => _currentTypeColor;
+
///
/// The collection of the attributes used by the box. Assigned externally. Can be used to control the default value editing for the or to provide more metadata for the surface UI.
///
@@ -544,44 +549,6 @@ namespace FlaxEditor.Surface.Elements
}
}
- ///
- /// Draws the box GUI using .
- ///
- protected void DrawBox()
- {
- var rect = new Rectangle(Float2.Zero, Size);
-
- // Size culling
- const float minBoxSize = 5.0f;
- if (rect.Size.LengthSquared < minBoxSize * minBoxSize)
- return;
-
- // Debugging boxes size
- //Render2D.DrawRectangle(rect, Color.Orange); return;
-
- // Draw icon
- bool hasConnections = HasAnyConnection;
- float alpha = Enabled ? 1.0f : 0.6f;
- Color color = _currentTypeColor * alpha;
- var style = Surface.Style;
- SpriteHandle icon;
- if (_currentType.Type == typeof(void))
- icon = hasConnections ? style.Icons.ArrowClose : style.Icons.ArrowOpen;
- else
- icon = hasConnections ? style.Icons.BoxClose : style.Icons.BoxOpen;
- color *= ConnectionsHighlightIntensity + 1;
- Render2D.DrawSprite(icon, rect, color);
-
- // Draw selection hint
- if (_isSelected)
- {
- float outlineAlpha = Mathf.Sin(Time.TimeSinceStartup * 4.0f) * 0.5f + 0.5f;
- float outlineWidth = Mathf.Lerp(1.5f, 4.0f, outlineAlpha);
- var outlineRect = new Rectangle(rect.X - outlineWidth, rect.Y - outlineWidth, rect.Width + outlineWidth * 2, rect.Height + outlineWidth * 2);
- Render2D.DrawSprite(icon, outlineRect, FlaxEngine.GUI.Style.Current.BorderSelected.RGBMultiplied(1.0f + outlineAlpha * 0.4f));
- }
- }
-
///
public override void OnMouseEnter(Float2 location)
{
@@ -813,7 +780,7 @@ namespace FlaxEditor.Surface.Elements
///
public void DrawConnectingLine(ref Float2 startPos, ref Float2 endPos, ref Color color)
{
- OutputBox.DrawConnection(ref startPos, ref endPos, ref color, 2);
+ OutputBox.DrawConnection(Surface.Style, ref startPos, ref endPos, ref color, 2);
}
///
diff --git a/Source/Editor/Surface/Elements/InputBox.cs b/Source/Editor/Surface/Elements/InputBox.cs
index 4eac03105..2047bcd1a 100644
--- a/Source/Editor/Surface/Elements/InputBox.cs
+++ b/Source/Editor/Surface/Elements/InputBox.cs
@@ -1438,7 +1438,7 @@ namespace FlaxEditor.Surface.Elements
base.Draw();
// Box
- DrawBox();
+ Surface.Style.DrawBox(this);
// Draw text
var style = Style.Current;
diff --git a/Source/Editor/Surface/Elements/OutputBox.cs b/Source/Editor/Surface/Elements/OutputBox.cs
index 67b6e8409..cf527402d 100644
--- a/Source/Editor/Surface/Elements/OutputBox.cs
+++ b/Source/Editor/Surface/Elements/OutputBox.cs
@@ -27,12 +27,19 @@ namespace FlaxEditor.Surface.Elements
///
/// Draws the connection between two boxes.
///
+ /// The Visject surface style.
/// The start location.
/// The end location.
/// The connection color.
/// The connection thickness.
- public static void DrawConnection(ref Float2 start, ref Float2 end, ref Color color, float thickness = 1)
+ public static void DrawConnection(SurfaceStyle style, ref Float2 start, ref Float2 end, ref Color color, float thickness = 1)
{
+ if (style.DrawConnection != null)
+ {
+ style.DrawConnection(start, end, color, thickness);
+ return;
+ }
+
// Calculate control points
var dst = (end - start) * new Float2(0.5f, 0.05f);
var control1 = new Float2(start.X + dst.X, start.Y + dst.Y);
@@ -122,8 +129,9 @@ namespace FlaxEditor.Surface.Elements
///
public void DrawConnections(ref Float2 mousePosition)
{
- float mouseOverDistance = MouseOverConnectionDistance;
// Draw all the connections
+ var style = Surface.Style;
+ var mouseOverDistance = MouseOverConnectionDistance;
var startPos = Parent.PointToParent(Center);
var startHighlight = ConnectionsHighlightIntensity;
for (int i = 0; i < Connections.Count; i++)
@@ -139,7 +147,7 @@ namespace FlaxEditor.Surface.Elements
highlight += 0.5f;
}
- DrawConnection(ref startPos, ref endPos, ref color, highlight);
+ DrawConnection(style, ref startPos, ref endPos, ref color, highlight);
}
}
@@ -151,7 +159,7 @@ namespace FlaxEditor.Surface.Elements
// Draw all the connections
var startPos = Parent.PointToParent(Center);
var endPos = targetBox.Parent.PointToParent(targetBox.Center);
- DrawConnection(ref startPos, ref endPos, ref _currentTypeColor, 2.5f);
+ DrawConnection(Surface.Style, ref startPos, ref endPos, ref _currentTypeColor, 2.5f);
}
///
@@ -163,7 +171,7 @@ namespace FlaxEditor.Surface.Elements
base.Draw();
// Box
- DrawBox();
+ Surface.Style.DrawBox(this);
// Draw text
var style = Style.Current;
diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs
index c24c47fbd..a15f5e42d 100644
--- a/Source/Editor/Surface/SurfaceNode.cs
+++ b/Source/Editor/Surface/SurfaceNode.cs
@@ -165,25 +165,22 @@ namespace FlaxEditor.Surface
{
if (Surface == null)
return;
- Size = CalculateNodeSize(width, height);
- // Update boxes on width change
- //if (!Mathf.NearEqual(prevSize.X, Size.X))
+ for (int i = 0; i < Elements.Count; i++)
{
- for (int i = 0; i < Elements.Count; i++)
+ if (Elements[i] is OutputBox box)
{
- if (Elements[i] is OutputBox box)
- {
- box.Location = box.Archetype.Position + new Float2(width, 0);
- }
+ box.Location = box.Archetype.Position + new Float2(width, 0);
}
}
+
+ Size = CalculateNodeSize(width, height);
}
///
/// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions.
///
- public void ResizeAuto()
+ public virtual void ResizeAuto()
{
if (Surface == null)
return;
diff --git a/Source/Editor/Surface/SurfaceStyle.cs b/Source/Editor/Surface/SurfaceStyle.cs
index 18fa70e4e..2b8e97f62 100644
--- a/Source/Editor/Surface/SurfaceStyle.cs
+++ b/Source/Editor/Surface/SurfaceStyle.cs
@@ -140,6 +140,16 @@ namespace FlaxEditor.Surface
///
public Texture Background;
+ ///
+ /// Boxes drawing callback.
+ ///
+ public Action DrawBox = DefaultDrawBox;
+
+ ///
+ /// Custom box connection drawing callback (null by default).
+ ///
+ public Action DrawConnection = null;
+
///
/// Gets the color for the connection.
///
@@ -204,6 +214,41 @@ namespace FlaxEditor.Surface
color = Colors.Default;
}
+ private static void DefaultDrawBox(Elements.Box box)
+ {
+ var rect = new Rectangle(Float2.Zero, box.Size);
+
+ // Size culling
+ const float minBoxSize = 5.0f;
+ if (rect.Size.LengthSquared < minBoxSize * minBoxSize)
+ return;
+
+ // Debugging boxes size
+ //Render2D.DrawRectangle(rect, Color.Orange); return;
+
+ // Draw icon
+ bool hasConnections = box.HasAnyConnection;
+ float alpha = box.Enabled ? 1.0f : 0.6f;
+ Color color = box.CurrentTypeColor * alpha;
+ var style = box.Surface.Style;
+ SpriteHandle icon;
+ if (box.CurrentType.Type == typeof(void))
+ icon = hasConnections ? style.Icons.ArrowClose : style.Icons.ArrowOpen;
+ else
+ icon = hasConnections ? style.Icons.BoxClose : style.Icons.BoxOpen;
+ color *= box.ConnectionsHighlightIntensity + 1;
+ Render2D.DrawSprite(icon, rect, color);
+
+ // Draw selection hint
+ if (box.IsSelected)
+ {
+ float outlineAlpha = Mathf.Sin(Time.TimeSinceStartup * 4.0f) * 0.5f + 0.5f;
+ float outlineWidth = Mathf.Lerp(1.5f, 4.0f, outlineAlpha);
+ var outlineRect = new Rectangle(rect.X - outlineWidth, rect.Y - outlineWidth, rect.Width + outlineWidth * 2, rect.Height + outlineWidth * 2);
+ Render2D.DrawSprite(icon, outlineRect, FlaxEngine.GUI.Style.Current.BorderSelected.RGBMultiplied(1.0f + outlineAlpha * 0.4f));
+ }
+ }
+
///
/// Function used to create style for the given surface type. Can be overriden to provide some customization via user plugin.
///
diff --git a/Source/Editor/Surface/VisjectSurface.Draw.cs b/Source/Editor/Surface/VisjectSurface.Draw.cs
index 8db64b476..edfa15214 100644
--- a/Source/Editor/Surface/VisjectSurface.Draw.cs
+++ b/Source/Editor/Surface/VisjectSurface.Draw.cs
@@ -176,7 +176,7 @@ namespace FlaxEditor.Surface
var bezierStartPoint = new Float2(upperRight.X + offsetX * 0.75f, (upperRight.Y + bottomRight.Y) * 0.5f);
var bezierEndPoint = inputBracket.Box.ParentNode.PointToParent(_rootControl.Parent, inputBracket.Box.Center);
- Elements.OutputBox.DrawConnection(ref bezierStartPoint, ref bezierEndPoint, ref fadedColor);
+ Elements.OutputBox.DrawConnection(Style, ref bezierStartPoint, ref bezierEndPoint, ref fadedColor);
// Debug Area
//Rectangle drawRect = Rectangle.FromPoints(upperLeft, bottomRight);