draw close button using Render2D to make it look good even when zoomed in a lot
This commit is contained in:
@@ -223,7 +223,7 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
if ((Archetype.Flags & NodeFlags.NoCloseButton) == 0 && Surface.CanEdit)
|
||||
{
|
||||
bool highlightClose = _closeButtonRect.Contains(_mousePosition) && !Surface.IsConnecting && !Surface.IsSelecting;
|
||||
Render2D.DrawSprite(style.Cross, _closeButtonRect, highlightClose ? style.Foreground : style.ForegroundGrey);
|
||||
DrawCloseButton(_closeButtonRect, highlightClose ? style.Foreground : style.ForegroundGrey);
|
||||
}
|
||||
|
||||
DrawChildren();
|
||||
@@ -596,7 +596,7 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
|
||||
const float headerHeight = FlaxEditor.Surface.Constants.NodeHeaderHeight;
|
||||
const float closeButtonMargin = FlaxEditor.Surface.Constants.NodeCloseButtonMargin;
|
||||
float closeButtonSize = FlaxEditor.Surface.Constants.NodeCloseButtonSize * 0.65f;
|
||||
float closeButtonSize = FlaxEditor.Surface.Constants.NodeCloseButtonSize * 0.75f;
|
||||
_headerRect = new Rectangle(0, bounds.Y - Y, bounds.Width, headerHeight);
|
||||
_headerTextRect = _headerRect with { X = 5f, Width = Width - closeButtonSize - closeButtonMargin * 4f };
|
||||
_closeButtonRect = new Rectangle(bounds.Width - closeButtonSize - closeButtonMargin, _headerRect.Y + closeButtonMargin, closeButtonSize, closeButtonSize);
|
||||
@@ -744,10 +744,13 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
|
||||
_footerRect = Rectangle.Empty;
|
||||
const float closeButtonMargin = FlaxEditor.Surface.Constants.NodeCloseButtonMargin;
|
||||
float closeButtonSize = FlaxEditor.Surface.Constants.NodeCloseButtonSize * 0.65f;
|
||||
float closeButtonSize = FlaxEditor.Surface.Constants.NodeCloseButtonSize * 0.75f;
|
||||
_closeButtonRect = new Rectangle(Bounds.Width - closeButtonSize - closeButtonMargin, _headerRect.Y + closeButtonMargin, closeButtonSize, closeButtonSize);
|
||||
if (_dragIcon != null)
|
||||
_dragIcon.Bounds = new Rectangle(_closeButtonRect.X - _closeButtonRect.Width, _closeButtonRect.Y, _closeButtonRect.Size);
|
||||
{
|
||||
var dragIconRect = _closeButtonRect.MakeExpanded(5f);
|
||||
_dragIcon.Bounds = new Rectangle(dragIconRect.X - dragIconRect.Width, dragIconRect.Y, dragIconRect.Size);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateTitle()
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
Render2D.DrawRectangle(new Rectangle(1, 0, Width - 2, Height - 1), Colors[idx]);
|
||||
|
||||
// Close button
|
||||
Render2D.DrawSprite(style.Cross, _closeButtonRect, _closeButtonRect.Contains(_mousePosition) ? style.Foreground : style.ForegroundGrey);
|
||||
DrawCloseButton(_closeButtonRect, _closeButtonRect.Contains(_mousePosition) ? style.Foreground : style.ForegroundGrey);
|
||||
|
||||
// Arrange button
|
||||
var dragBarColor = _arrangeButtonRect.Contains(_mousePosition) ? style.Foreground : style.ForegroundGrey;
|
||||
@@ -267,9 +267,9 @@ namespace FlaxEditor.Surface.Archetypes
|
||||
const float closeButtonMargin = FlaxEditor.Surface.Constants.NodeCloseButtonMargin;
|
||||
const float closeButtonSize = FlaxEditor.Surface.Constants.NodeCloseButtonSize;
|
||||
_headerRect = new Rectangle(0, 0, Width, headerSize);
|
||||
_closeButtonRect = new Rectangle(Width - closeButtonSize - closeButtonMargin, closeButtonMargin, closeButtonSize, closeButtonSize);
|
||||
_closeButtonRect = new Rectangle(Width - closeButtonSize * 0.75f - closeButtonMargin, closeButtonMargin + 0.25f, closeButtonSize * 0.75f, closeButtonSize * 0.75f);
|
||||
_footerRect = Rectangle.Empty;
|
||||
_enabled.Location = new Float2(_closeButtonRect.X - _enabled.Width - 2, _closeButtonRect.Y);
|
||||
_enabled.Location = new Float2(_closeButtonRect.X - _enabled.Width - 2, _closeButtonRect.Y - 0.25f);
|
||||
_arrangeButtonRect = new Rectangle(_enabled.X - closeButtonSize - closeButtonMargin, closeButtonMargin, closeButtonSize, closeButtonSize);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace FlaxEditor.Surface
|
||||
/// <summary>
|
||||
/// The node close button size.
|
||||
/// </summary>
|
||||
public const float NodeCloseButtonSize = 16.0f;
|
||||
public const float NodeCloseButtonSize = 10.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The node close button margin from the edges.
|
||||
/// </summary>
|
||||
public const float NodeCloseButtonMargin = 2.0f;
|
||||
public const float NodeCloseButtonMargin = 5.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The node header height.
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace FlaxEditor.Surface
|
||||
const float buttonMargin = Constants.NodeCloseButtonMargin;
|
||||
const float buttonSize = Constants.NodeCloseButtonSize;
|
||||
_headerRect = new Rectangle(0, 0, Width, headerSize);
|
||||
_closeButtonRect = new Rectangle(Width - buttonSize - buttonMargin, buttonMargin, buttonSize, buttonSize);
|
||||
_closeButtonRect = new Rectangle(Width - buttonSize * 0.75f - buttonMargin, buttonMargin, buttonSize * 0.75f, buttonSize * 0.75f);
|
||||
_colorButtonRect = new Rectangle(_closeButtonRect.Left - buttonSize - buttonMargin, buttonMargin, buttonSize, buttonSize);
|
||||
_resizeButtonRect = new Rectangle(_closeButtonRect.Left, Height - buttonSize - buttonMargin, buttonSize, buttonSize);
|
||||
_renameTextBox.Width = Width;
|
||||
@@ -183,7 +183,7 @@ namespace FlaxEditor.Surface
|
||||
if (Surface.CanEdit)
|
||||
{
|
||||
// Close button
|
||||
Render2D.DrawSprite(style.Cross, _closeButtonRect, _closeButtonRect.Contains(_mousePosition) && Surface.CanEdit ? style.Foreground : style.ForegroundGrey);
|
||||
DrawCloseButton(_closeButtonRect, _closeButtonRect.Contains(_mousePosition) && Surface.CanEdit ? style.Foreground : style.ForegroundGrey);
|
||||
|
||||
// Color button
|
||||
Render2D.DrawSprite(style.Settings, _colorButtonRect, _colorButtonRect.Contains(_mousePosition) && Surface.CanEdit ? style.Foreground : style.ForegroundGrey);
|
||||
|
||||
@@ -454,7 +454,7 @@ namespace FlaxEditor.Surface
|
||||
private static readonly List<SurfaceNode> UpdateStack = new List<SurfaceNode>();
|
||||
|
||||
/// <summary>
|
||||
/// Updates dependant/independent boxes types.
|
||||
/// Updates dependent/independent boxes types.
|
||||
/// </summary>
|
||||
public void UpdateBoxesTypes()
|
||||
{
|
||||
@@ -796,6 +796,24 @@ namespace FlaxEditor.Surface
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the close button inside of the <paramref name="rect"/>.
|
||||
/// </summary>
|
||||
/// <param name="rect">The rectangle to draw the close button in.</param>
|
||||
/// <param name="color">The color of the close button.</param>
|
||||
public void DrawCloseButton(Rectangle rect, Color color)
|
||||
{
|
||||
// Disable vertex snapping to reduce artefacts at the line ends
|
||||
var features = Render2D.Features;
|
||||
Render2D.Features = features & ~Render2D.RenderingFeatures.VertexSnapping;
|
||||
|
||||
rect.Expand(-2f); // Don't overshoot the rectangle because of the thickness
|
||||
Render2D.DrawLine(rect.TopLeft, rect.BottomRight, color, 2f);
|
||||
Render2D.DrawLine(rect.BottomLeft, rect.TopRight, color, 2f);
|
||||
|
||||
Render2D.Features = features;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws all the connections between surface objects related to this node.
|
||||
/// </summary>
|
||||
@@ -1113,7 +1131,7 @@ namespace FlaxEditor.Surface
|
||||
if ((Archetype.Flags & NodeFlags.NoCloseButton) == 0 && Surface.CanEdit)
|
||||
{
|
||||
bool highlightClose = _closeButtonRect.Contains(_mousePosition) && !Surface.IsConnecting && !Surface.IsSelecting;
|
||||
Render2D.DrawSprite(style.Cross, _closeButtonRect, highlightClose ? style.Foreground : style.ForegroundGrey);
|
||||
DrawCloseButton(_closeButtonRect, highlightClose ? style.Foreground : style.ForegroundGrey);
|
||||
}
|
||||
|
||||
// Footer
|
||||
|
||||
@@ -245,6 +245,7 @@ namespace FlaxEditor.Surface
|
||||
icon = hasConnections ? style.Icons.BoxClose : style.Icons.BoxOpen;
|
||||
color *= box.ConnectionsHighlightIntensity + 1;
|
||||
|
||||
// Disable vertex snapping to prevent position jitter/ snapping artefacts for the boxes when zooming the surface
|
||||
var features = Render2D.Features;
|
||||
Render2D.Features = features & ~Render2D.RenderingFeatures.VertexSnapping;
|
||||
|
||||
@@ -273,7 +274,7 @@ namespace FlaxEditor.Surface
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function used to create style for the given surface type. Can be overriden to provide some customization via user plugin.
|
||||
/// Function used to create style for the given surface type. Can be overridden to provide some customization via user plugin.
|
||||
/// </summary>
|
||||
public static Func<Editor, SurfaceStyle> CreateStyleHandler = CreateDefault;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user