From 26d0b9a42c743e110bd361f2b10d29dde86db491 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 31 Dec 2024 14:06:17 -0600 Subject: [PATCH] Fix rotation of UI size handles. --- Source/Editor/Gizmo/UIEditorGizmo.cs | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index 3fa574e1b..a7da826bd 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -1,5 +1,6 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. +using System; using System.Collections.Generic; using System.Linq; using FlaxEditor.Gizmo; @@ -647,7 +648,34 @@ namespace FlaxEditor private void DrawControlWidget(UIControl uiControl, ref Float2 pos, ref Float2 mousePos, ref Float2 size, float scale, Float2 resizeAxis, CursorType cursor) { var style = Style.Current; - var rect = new Rectangle((pos + resizeAxis * 10 * scale) - size * 0.5f, size); + var control = uiControl.Control; + var rect = new Rectangle( + (pos + + new Float2(resizeAxis.X * Mathf.Cos(Mathf.DegreesToRadians * control.Rotation) - resizeAxis.Y * Mathf.Sin(Mathf.DegreesToRadians * control.Rotation), + resizeAxis.Y * Mathf.Cos(Mathf.DegreesToRadians * control.Rotation) + resizeAxis.X * Mathf.Sin(Mathf.DegreesToRadians * control.Rotation)) * 10 * scale) - size * 0.5f, + size); + + // Find more correct cursor at different angles + var unwindRotation = Mathf.UnwindDegrees(control.Rotation); + if (unwindRotation is (>= 45 and < 135) or (> -135 and <= -45) ) + { + switch (cursor) + { + case CursorType.SizeNESW: + cursor = CursorType.SizeNWSE; + break; + case CursorType.SizeNS: + cursor = CursorType.SizeWE; + break; + case CursorType.SizeNWSE: + cursor = CursorType.SizeNESW; + break; + case CursorType.SizeWE: + cursor = CursorType.SizeNS; + break; + default: break; + } + } if (rect.Contains(ref mousePos)) { Render2D.FillRectangle(rect, style.Foreground);