From 26d0b9a42c743e110bd361f2b10d29dde86db491 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 31 Dec 2024 14:06:17 -0600 Subject: [PATCH 1/2] 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); From 867f7d01439ea764664021f00454f6ae547aa621 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 31 Dec 2024 14:12:23 -0600 Subject: [PATCH 2/2] Add local variables to simplify math. --- Source/Editor/Gizmo/UIEditorGizmo.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index a7da826bd..aba177b7d 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -649,14 +649,16 @@ namespace FlaxEditor { var style = Style.Current; var control = uiControl.Control; + var rotation = control.Rotation; + var rotationInRadians = rotation * Mathf.DegreesToRadians; 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, + 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); // Find more correct cursor at different angles - var unwindRotation = Mathf.UnwindDegrees(control.Rotation); + var unwindRotation = Mathf.UnwindDegrees(rotation); if (unwindRotation is (>= 45 and < 135) or (> -135 and <= -45) ) { switch (cursor)