Add support for moving object with transform gizmo when mouse moves outside the viewport during usage
This commit is contained in:
@@ -22,6 +22,11 @@ namespace FlaxEditor.Gizmo
|
||||
/// </summary>
|
||||
public bool IsActive => Owner.Gizmos.Active == this;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this gizmo is using mouse currently (eg. user moving objects).
|
||||
/// </summary>
|
||||
public virtual bool IsControllingMouse => false;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GizmoBase"/> class.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FlaxEngine;
|
||||
|
||||
@@ -65,6 +66,16 @@ namespace FlaxEditor.Gizmo
|
||||
/// </summary>
|
||||
public Transform LastDelta { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when transforming selection started.
|
||||
/// </summary>
|
||||
public event Action TransformingStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when transforming selection ended.
|
||||
/// </summary>
|
||||
public event Action TransformingEnded;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TransformGizmoBase" /> class.
|
||||
/// </summary>
|
||||
@@ -118,10 +129,10 @@ namespace FlaxEditor.Gizmo
|
||||
return;
|
||||
|
||||
// End action
|
||||
OnEndTransforming();
|
||||
_startTransforms.Clear();
|
||||
_isTransforming = false;
|
||||
_isDuplicating = false;
|
||||
OnEndTransforming();
|
||||
_startTransforms.Clear();
|
||||
}
|
||||
|
||||
private void UpdateGizmoPosition()
|
||||
@@ -366,6 +377,9 @@ namespace FlaxEditor.Gizmo
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsControllingMouse => _isTransforming;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float dt)
|
||||
{
|
||||
@@ -531,6 +545,7 @@ namespace FlaxEditor.Gizmo
|
||||
/// </summary>
|
||||
protected virtual void OnStartTransforming()
|
||||
{
|
||||
TransformingStarted?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -548,6 +563,7 @@ namespace FlaxEditor.Gizmo
|
||||
/// </summary>
|
||||
protected virtual void OnEndTransforming()
|
||||
{
|
||||
TransformingEnded?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -169,6 +169,9 @@ namespace FlaxEditor.Tools.Foliage
|
||||
PaintEnded?.Invoke();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsControllingMouse => IsPainting;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float dt)
|
||||
{
|
||||
|
||||
@@ -135,6 +135,9 @@ namespace FlaxEditor.Tools.Terrain
|
||||
PaintEnded?.Invoke();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsControllingMouse => IsPainting;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float dt)
|
||||
{
|
||||
|
||||
@@ -135,6 +135,9 @@ namespace FlaxEditor.Tools.Terrain
|
||||
PaintEnded?.Invoke();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsControllingMouse => IsPainting;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float dt)
|
||||
{
|
||||
|
||||
@@ -540,6 +540,9 @@ namespace FlaxEditor.Tools
|
||||
_paintUpdateCount = 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool IsControllingMouse => IsPainting;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float dt)
|
||||
{
|
||||
|
||||
@@ -73,6 +73,9 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public Undo Undo { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void AddUpdateCallbacks(RootControl root)
|
||||
{
|
||||
|
||||
@@ -136,7 +136,7 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
// Input
|
||||
|
||||
private bool _isControllingMouse;
|
||||
private bool _isControllingMouse, _isViewportControllingMouse;
|
||||
private int _deltaFilteringStep;
|
||||
private Vector2 _startPos;
|
||||
private Vector2 _mouseDeltaLast;
|
||||
@@ -653,6 +653,11 @@ namespace FlaxEditor.Viewport
|
||||
task.Begin += OnRenderBegin;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this viewport is using mouse currently (eg. user moving objects).
|
||||
/// </summary>
|
||||
protected virtual bool IsControllingMouse => false;
|
||||
|
||||
/// <summary>
|
||||
/// Orients the viewport.
|
||||
/// </summary>
|
||||
@@ -972,7 +977,16 @@ namespace FlaxEditor.Viewport
|
||||
// Update input
|
||||
{
|
||||
// Get input buttons and keys (skip if viewport has no focus or mouse is over a child control)
|
||||
bool useMouse = Mathf.IsInRange(_viewMousePos.X, 0, Width) && Mathf.IsInRange(_viewMousePos.Y, 0, Height);
|
||||
var isViewportControllingMouse = IsControllingMouse;
|
||||
if (isViewportControllingMouse != _isViewportControllingMouse)
|
||||
{
|
||||
_isViewportControllingMouse = isViewportControllingMouse;
|
||||
if (isViewportControllingMouse)
|
||||
StartMouseCapture();
|
||||
else
|
||||
EndMouseCapture();
|
||||
}
|
||||
bool useMouse = IsControllingMouse || (Mathf.IsInRange(_viewMousePos.X, 0, Width) && Mathf.IsInRange(_viewMousePos.Y, 0, Height));
|
||||
_prevInput = _input;
|
||||
var hit = GetChildAt(_viewMousePos, c => c.Visible && !(c is CanvasRootControl));
|
||||
if (ContainsFocus && hit == null)
|
||||
|
||||
@@ -356,6 +356,9 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public Undo Undo { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsControllingMouse => Gizmos.Active?.IsControllingMouse ?? false;
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void AddUpdateCallbacks(RootControl root)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user