From fee47a99b3f9a233bfd09a699e7fcb19f813349c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 13:47:31 +0200 Subject: [PATCH] Add additional info text and pivot location preview to anchors editor --- .../Dedicated/UIControlEditor.cs | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index 19b1cf55a..ccecfe569 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -75,14 +75,10 @@ namespace FlaxEditor.CustomEditors.Dedicated borderColor = BorderColorHighlighted; } - if (Input.GetKey(KeyboardKeys.Shift) && SupportsShiftModulation) + if (SupportsShiftModulation && Input.GetKey(KeyboardKeys.Shift)) { backgroundColor = BackgroundColorSelected; } - if (Input.GetKey(KeyboardKeys.Control) && SupportsShiftModulation) - { - borderColor = BackgroundColorSelected; - } // Calculate fill area float fillSize = rect.Width / 3; @@ -159,6 +155,55 @@ namespace FlaxEditor.CustomEditors.Dedicated { Render2D.DrawRectangle(rect, style.BackgroundSelected.AlphaMultiplied(0.8f), 1.1f); } + + // Draw pivot point + if (SupportsShiftModulation && Input.GetKey(KeyboardKeys.Control)) + { + Vector2 pivotPoint; + switch (_presets) + { + case AnchorPresets.Custom: + pivotPoint = Vector2.Minimum; + break; + case AnchorPresets.TopLeft: + pivotPoint = new Vector2(0, 0); + break; + case AnchorPresets.TopCenter: + case AnchorPresets.HorizontalStretchTop: + pivotPoint = new Vector2(rect.Width / 2, 0); + break; + case AnchorPresets.TopRight: + pivotPoint = new Vector2(rect.Width, 0); + break; + case AnchorPresets.MiddleLeft: + case AnchorPresets.VerticalStretchLeft: + pivotPoint = new Vector2(0, rect.Height / 2); + break; + case AnchorPresets.MiddleCenter: + case AnchorPresets.VerticalStretchCenter: + case AnchorPresets.HorizontalStretchMiddle: + case AnchorPresets.StretchAll: + pivotPoint = new Vector2(rect.Width / 2, rect.Height / 2); + break; + case AnchorPresets.MiddleRight: + case AnchorPresets.VerticalStretchRight: + pivotPoint = new Vector2(rect.Width, rect.Height / 2); + break; + case AnchorPresets.BottomLeft: + pivotPoint = new Vector2(0, rect.Height); + break; + case AnchorPresets.BottomCenter: + case AnchorPresets.HorizontalStretchBottom: + pivotPoint = new Vector2(rect.Width / 2, rect.Height); + break; + case AnchorPresets.BottomRight: + pivotPoint = new Vector2(rect.Width, rect.Height); + break; + default: throw new ArgumentOutOfRangeException(); + } + var pivotPointSize = new Vector2(3.0f); + Render2D.DrawRectangle(new Rectangle(pivotPoint - pivotPointSize * 0.5f, pivotPointSize), style.ProgressNormal, 1.1f); + } } } @@ -172,8 +217,9 @@ namespace FlaxEditor.CustomEditors.Dedicated const float ButtonsMarginStretch = 8.0f; const float ButtonsSize = 32.0f; const float TitleHeight = 23.0f; + const float IntoHeight = 23.0f; const float DialogWidth = ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch; - const float DialogHeight = TitleHeight + ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch; + const float DialogHeight = TitleHeight + IntoHeight + ButtonsSize * 4 + ButtonsMargin * 5 + ButtonsMarginStretch; private readonly bool _supportsShiftModulation; @@ -198,9 +244,17 @@ namespace FlaxEditor.CustomEditors.Dedicated Parent = this }; + // Info + var info = new Label(0, title.Bottom, DialogWidth, IntoHeight) + { + Font = new FontReference(style.FontSmall), + Text = "Shift: also set bounds\nControl: also set pivot", + Parent = this + }; + // Buttons var buttonsX = ButtonsMargin; - var buttonsY = title.Bottom + ButtonsMargin; + var buttonsY = info.Bottom + ButtonsMargin; var buttonsSpacingX = ButtonsSize + ButtonsMargin; var buttonsSpacingY = ButtonsSize + ButtonsMargin; //