Merge branch 'DirectionGizmoRotation' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-DirectionGizmoRotation

This commit is contained in:
2026-05-27 14:59:55 +02:00
4 changed files with 54 additions and 9 deletions
+48 -3
View File
@@ -36,8 +36,10 @@ internal class DirectionGizmo : ContainerControl
private List<AxisData> _axisData = new List<AxisData>();
private int _hoveredAxisIndex = -1;
private bool _mouseDown;
private Float2 _mouseDownLocation;
private SpriteHandle _posHandle;
private SpriteHandle _negHandle;
private FontReference _fontReference;
@@ -110,7 +112,6 @@ internal class DirectionGizmo : ContainerControl
var editor = Editor.Instance;
_posHandle = editor.Icons.VisjectBoxClosed32;
_negHandle = editor.Icons.VisjectBoxOpen32;
_fontReference = new FontReference(Style.Current.FontSmall);
@@ -142,7 +143,25 @@ internal class DirectionGizmo : ContainerControl
public override void OnMouseMove(Float2 location)
{
_hoveredAxisIndex = -1;
if (_mouseDown)
{
StartMouseCapture(true);
Cursor = CursorType.Hidden;
const float sensitivity = 0.125f;
Float2 delta = Input.MousePositionDelta;
delta *= Mathf.DegreesToRadians;
delta *= sensitivity;
const float orbitRadius = 500f;
Quaternion newOrientation = _viewport.ViewOrientation * Quaternion.RotationYawPitchRoll(delta.X , delta.Y, 0f);
Vector3 orbitCenter = _viewport.ViewPosition + _viewport.ViewDirection * orbitRadius;
_viewport.ViewportCamera.SetArcBallView(newOrientation, orbitCenter, orbitRadius);
return;
}
// Check which axis is being hovered - check from closest to farthest for proper layering
for (int i = _spritePositions.Count - 1; i >= 0; i--)
{
@@ -156,9 +175,30 @@ internal class DirectionGizmo : ContainerControl
base.OnMouseMove(location);
}
public override bool OnMouseDown(Float2 location, MouseButton button)
{
_mouseDown = true;
_mouseDownLocation = location;
return true;
}
/// <inheritdoc />
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (_mouseDown)
{
_mouseDown = false;
if (_mouseDownLocation != location)
{
_mouseDown = false;
EndMouseCapture();
Root.MousePosition = PointToParent(Root, _mouseDownLocation);
Cursor = CursorType.Default;
return true;
}
}
if (base.OnMouseUp(location, button))
return true;
@@ -269,7 +309,12 @@ internal class DirectionGizmo : ContainerControl
// Rebuild sprite positions list for hover detection
_spritePositions.Clear();
Render2D.DrawSprite(_posHandle, new Rectangle(0, 0, Size), Color.Black.AlphaMultiplied(_backgroundOpacity));
if (IsMouseOver)
{
Rectangle backgroundRect = new Rectangle(0, 0, Size);
Color backgroundColor = Color.DarkGray.AlphaMultiplied(_backgroundOpacity);
Render2D.DrawSprite(_posHandle, backgroundRect, backgroundColor);
}
// Draw in order from farthest to closest
for (int i = 0; i < _axisData.Count; i++)
+1 -1
View File
@@ -187,7 +187,7 @@ namespace FlaxEditor.Options
public float DirectionGizmoScale { get; set; } = 1f;
/// <summary>
/// Gets or sets a value for the opacity of the main viewports <see cref="Gizmo.DirectionGizmo"/> background.
/// Gets or sets a value for the opacity of the main viewports <see cref="Gizmo.DirectionGizmo"/> background. Background will only show when the gizmo is hovered.
/// </summary>
[DefaultValue(0.1f), Limit(0.0f, 1.0f)]
[EditorDisplay("Direction Gizmo"), EditorOrder(502), Tooltip("The background opacity of the of the direction gizmo in the main viewport.")]
@@ -706,7 +706,7 @@ namespace FlaxEditor.Viewport
{
base.OnLeftMouseButtonDown();
if (!IsAltKeyDown)
if (!IsAltKeyDown && !_directionGizmo.IsMouseOver)
_rubberBandSelector.TryStartingRubberBandSelection(_viewMousePos);
}
@@ -714,7 +714,7 @@ namespace FlaxEditor.Viewport
protected override void OnLeftMouseButtonUp()
{
// Skip if was controlling mouse or mouse is not over the area
if (_prevInput.IsControllingMouse || !Bounds.Contains(ref _viewMousePos))
if (_prevInput.IsControllingMouse || !Bounds.Contains(ref _viewMousePos) || _directionGizmo.IsMouseOver)
return;
// Select rubberbanded rect actor nodes or pick with gizmo
+3 -3
View File
@@ -572,12 +572,12 @@ namespace FlaxEngine.GUI
/// <summary>
/// Starts the mouse tracking. Used by the scrollbars, splitters, etc.
/// </summary>
/// <param name="useMouseScreenOffset">If set to <c>true</c> will use mouse screen offset.</param>
/// <param name="screenSpaceMouseWrap">If set to <c>true</c> will wrap when it hits a screen border.</param>
[NoAnimate]
public void StartMouseCapture(bool useMouseScreenOffset = false)
public void StartMouseCapture(bool screenSpaceMouseWrap = false)
{
var parent = Root;
parent?.StartTrackingMouse(this, useMouseScreenOffset);
parent?.StartTrackingMouse(this, screenSpaceMouseWrap);
}
/// <summary>