diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index aba177b7d..743bf3c63 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -641,7 +641,68 @@ namespace FlaxEditor DrawControlWidget(uiControl, ref eu, ref mousePos, ref widgetHandleSize, viewScale, new Float2(0, -1), CursorType.SizeNS); DrawControlWidget(uiControl, ref eb, ref mousePos, ref widgetHandleSize, viewScale, new Float2(0, 1), CursorType.SizeNS); - // TODO: draw anchors + // Draw pivot + var pivotSize = 8.0f; + if (viewScale < 0.7f) + pivotSize *= viewScale; + var pivotX = Mathf.Remap(control.Pivot.X, 0, 1, bounds.Location.X, bounds.Location.X + bounds.Width); + var pivotY = Mathf.Remap(control.Pivot.Y, 0, 1, bounds.Location.Y, bounds.Location.Y + bounds.Height); + var pivotLoc = control.PointToParent(this, new Float2(pivotX, pivotY)); + var pivotRect = new Rectangle(pivotLoc - pivotSize * 0.5f, new Float2(pivotSize)); + var pivotColor = options.UIPivotColor; + Render2D.FillRectangle(pivotRect, pivotColor); + + // Draw anchors + var controlParent = control.Parent; + if (controlParent != null) + { + var parentBounds = controlParent.EditorBounds; + var anchorMin = control.AnchorMin; + var anchorMax = control.AnchorMax; + var newMinX = Mathf.Remap(anchorMin.X, 0, 1, parentBounds.UpperLeft.X, parentBounds.UpperRight.X); + var newMinY = Mathf.Remap(anchorMin.Y, 0, 1, parentBounds.UpperLeft.Y, parentBounds.LowerLeft.Y); + var newMaxX = Mathf.Remap(anchorMax.X, 0, 1, parentBounds.UpperLeft.X, parentBounds.UpperRight.X); + var newMaxY = Mathf.Remap(anchorMax.Y, 0, 1, parentBounds.UpperLeft.Y, parentBounds.LowerLeft.Y); + + var anchorUpperLeft = controlParent.PointToParent(this, new Float2(newMinX, newMinY)); + var anchorUpperRight = controlParent.PointToParent(this, new Float2(newMaxX, newMinY)); + var anchorLowerLeft = controlParent.PointToParent(this, new Float2(newMinX, newMaxY)); + var anchorLowerRight = controlParent.PointToParent(this, new Float2(newMaxX, newMaxY)); + + var anchorRectSize = 8.0f; + if (viewScale < 0.7f) + anchorRectSize *= viewScale; + + // Make anchor rects and rotate if parent is rotated. + var parentRotation = controlParent.Rotation * Mathf.DegreesToRadians; + + var rect1Axis = new Float2(-1, -1); + var rect1 = new Rectangle(anchorUpperLeft + + new Float2(anchorRectSize * rect1Axis.X * Mathf.Cos(parentRotation) - anchorRectSize * rect1Axis.Y * Mathf.Sin(parentRotation), + anchorRectSize * rect1Axis.Y * Mathf.Cos(parentRotation) + anchorRectSize * rect1Axis.X * Mathf.Sin(parentRotation)) - anchorRectSize * 0.5f, new Float2(anchorRectSize)); + var rect2Axis = new Float2(1, -1); + var rect2 = new Rectangle(anchorUpperRight + + new Float2(anchorRectSize * rect2Axis.X * Mathf.Cos(parentRotation) - anchorRectSize * rect2Axis.Y * Mathf.Sin(parentRotation), + anchorRectSize * rect2Axis.Y * Mathf.Cos(parentRotation) + anchorRectSize * rect2Axis.X * Mathf.Sin(parentRotation)) - anchorRectSize * 0.5f, new Float2(anchorRectSize)); + var rect3Axis = new Float2(-1, 1); + var rect3 = new Rectangle(anchorLowerLeft + + new Float2(anchorRectSize * rect3Axis.X * Mathf.Cos(parentRotation) - anchorRectSize * rect3Axis.Y * Mathf.Sin(parentRotation), + anchorRectSize * rect3Axis.Y * Mathf.Cos(parentRotation) + anchorRectSize * rect3Axis.X * Mathf.Sin(parentRotation)) - anchorRectSize * 0.5f, new Float2(anchorRectSize)); + var rect4Axis = new Float2(1, 1); + var rect4 = new Rectangle(anchorLowerRight + + new Float2(anchorRectSize * rect4Axis.X * Mathf.Cos(parentRotation) - anchorRectSize * rect4Axis.Y * Mathf.Sin(parentRotation), + anchorRectSize * rect4Axis.Y * Mathf.Cos(parentRotation) + anchorRectSize * rect4Axis.X * Mathf.Sin(parentRotation)) - anchorRectSize * 0.5f, new Float2(anchorRectSize)); + + var rectColor = options.UIAnchorColor; + Render2D.DrawLine(anchorUpperLeft, anchorUpperRight, rectColor); + Render2D.DrawLine(anchorUpperRight, anchorLowerRight, rectColor); + Render2D.DrawLine(anchorLowerRight, anchorLowerLeft, rectColor); + Render2D.DrawLine(anchorLowerLeft, anchorUpperLeft, rectColor); + Render2D.FillRectangle(rect1, rectColor); + Render2D.FillRectangle(rect2, rectColor); + Render2D.FillRectangle(rect3, rectColor); + Render2D.FillRectangle(rect4, rectColor); + } } } @@ -651,8 +712,7 @@ namespace FlaxEditor var control = uiControl.Control; var rotation = control.Rotation; var rotationInRadians = rotation * Mathf.DegreesToRadians; - var rect = new Rectangle( - (pos + + var rect = new Rectangle((pos + new Float2(resizeAxis.X * Mathf.Cos(rotationInRadians) - resizeAxis.Y * Mathf.Sin(rotationInRadians), resizeAxis.Y * Mathf.Cos(rotationInRadians) + resizeAxis.X * Mathf.Sin(rotationInRadians)) * 10 * scale) - size * 0.5f, size); diff --git a/Source/Editor/Options/VisualOptions.cs b/Source/Editor/Options/VisualOptions.cs index cb5a0a89d..4f014ae16 100644 --- a/Source/Editor/Options/VisualOptions.cs +++ b/Source/Editor/Options/VisualOptions.cs @@ -39,6 +39,20 @@ namespace FlaxEditor.Options [EditorDisplay("UI Gizmo", "UI Control Outline Size"), EditorOrder(103), Tooltip("The size of the selection outline for UI controls.")] public float UISelectionOutlineSize { get; set; } = 2.0f; + /// + /// Gets or sets the pivot color for the UI Gizmo. + /// + [DefaultValue(typeof(Color), "0.0,0.5725,0.8,0.5")] + [EditorDisplay("UI Gizmo", "Pivot Color"), EditorOrder(103), Tooltip("The color of the pivot for the UI Gizmo.")] + public Color UIPivotColor { get; set; } = new Color(0.0f, 0.5725f, 0.8f, 0.5f); + + /// + /// Gets or sets the anchor color for the UI Gizmo. + /// + [DefaultValue(typeof(Color), "0.8392,0.8471,0.8706,0.5")] + [EditorDisplay("UI Gizmo", "Anchor Color"), EditorOrder(103), Tooltip("The color of the anchors for the UI Gizmo.")] + public Color UIAnchorColor { get; set; } = new Color(0.8392f, 0.8471f, 0.8706f, 0.5f); + /// /// Gets or sets the transform gizmo size. ///