Implement viewport camera rotation toggle for trackpad users
This commit is contained in:
@@ -136,10 +136,19 @@ namespace FlaxEditor.Options
|
||||
|
||||
private bool ProcessModifiers(Control control)
|
||||
{
|
||||
var root = control.Root;
|
||||
bool ctrlPressed = root.GetKey(KeyboardKeys.Control);
|
||||
bool shiftPressed = root.GetKey(KeyboardKeys.Shift);
|
||||
bool altPressed = root.GetKey(KeyboardKeys.Alt);
|
||||
return ProcessModifiers(control.Root.GetKey);
|
||||
}
|
||||
|
||||
private bool ProcessModifiers(Window window)
|
||||
{
|
||||
return ProcessModifiers(window.GetKey);
|
||||
}
|
||||
|
||||
private bool ProcessModifiers(Func<KeyboardKeys, bool> getKeyFunc)
|
||||
{
|
||||
bool ctrlPressed = getKeyFunc(KeyboardKeys.Control);
|
||||
bool shiftPressed = getKeyFunc(KeyboardKeys.Shift);
|
||||
bool altPressed = getKeyFunc(KeyboardKeys.Alt);
|
||||
|
||||
bool mod1 = false;
|
||||
if (Modifier1 == KeyboardKeys.None)
|
||||
@@ -210,6 +219,16 @@ namespace FlaxEditor.Options
|
||||
return ProcessModifiers(control);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes this input binding to check if state matches.
|
||||
/// </summary>
|
||||
/// <param name="window">The input providing window.</param>
|
||||
/// <returns>True if input has been processed, otherwise false.</returns>
|
||||
public bool Process(Window window)
|
||||
{
|
||||
return window.GetKey(Key) && ProcessModifiers(window);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -192,6 +192,10 @@ namespace FlaxEditor.Options
|
||||
[EditorDisplay("Viewport"), EditorOrder(1550)]
|
||||
public InputBinding Down = new InputBinding(KeyboardKeys.Q);
|
||||
|
||||
[DefaultValue(typeof(InputBinding), "None")]
|
||||
[EditorDisplay("Viewport", "Toggle Camera Rotation"), EditorOrder(1560)]
|
||||
public InputBinding CameraToggleRotation = new InputBinding(KeyboardKeys.None);
|
||||
|
||||
[DefaultValue(typeof(InputBinding), "Numpad0")]
|
||||
[EditorDisplay("Viewport"), EditorOrder(1600)]
|
||||
public InputBinding ViewpointFront = new InputBinding(KeyboardKeys.Numpad0);
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
// Input
|
||||
|
||||
private bool _isControllingMouse, _isViewportControllingMouse;
|
||||
private bool _isControllingMouse, _isViewportControllingMouse, _wasVirtualMouseRightDown, _isVirtualMouseRightDown;
|
||||
private int _deltaFilteringStep;
|
||||
private Float2 _startPos;
|
||||
private Float2 _mouseDeltaLast;
|
||||
@@ -685,6 +685,7 @@ namespace FlaxEditor.Viewport
|
||||
InputActions.Add(options => options.ViewpointBack, () => OrientViewport(Quaternion.Euler(EditorViewportCameraViewpointValues.First(vp => vp.Name == "Back").Orientation)));
|
||||
InputActions.Add(options => options.ViewpointRight, () => OrientViewport(Quaternion.Euler(EditorViewportCameraViewpointValues.First(vp => vp.Name == "Right").Orientation)));
|
||||
InputActions.Add(options => options.ViewpointLeft, () => OrientViewport(Quaternion.Euler(EditorViewportCameraViewpointValues.First(vp => vp.Name == "Left").Orientation)));
|
||||
InputActions.Add(options => options.CameraToggleRotation, () => _isVirtualMouseRightDown = !_isVirtualMouseRightDown);
|
||||
|
||||
// Link for task event
|
||||
task.Begin += OnRenderBegin;
|
||||
@@ -1048,6 +1049,15 @@ namespace FlaxEditor.Viewport
|
||||
// Track controlling mouse state change
|
||||
bool wasControllingMouse = _prevInput.IsControllingMouse;
|
||||
_isControllingMouse = _input.IsControllingMouse;
|
||||
|
||||
// Simulate holding mouse right down for trackpad users
|
||||
if (_prevInput.IsMouseRightDown && !_input.IsMouseRightDown)
|
||||
_isVirtualMouseRightDown = false;
|
||||
if (_wasVirtualMouseRightDown)
|
||||
wasControllingMouse = true;
|
||||
if (_isVirtualMouseRightDown)
|
||||
_isControllingMouse = _isVirtualMouseRightDown;
|
||||
|
||||
if (wasControllingMouse != _isControllingMouse)
|
||||
{
|
||||
if (_isControllingMouse)
|
||||
@@ -1061,16 +1071,18 @@ namespace FlaxEditor.Viewport
|
||||
OnLeftMouseButtonDown();
|
||||
else if (_prevInput.IsMouseLeftDown && !_input.IsMouseLeftDown)
|
||||
OnLeftMouseButtonUp();
|
||||
//
|
||||
if (!_prevInput.IsMouseRightDown && _input.IsMouseRightDown)
|
||||
|
||||
if ((!_prevInput.IsMouseRightDown && _input.IsMouseRightDown) || (!_wasVirtualMouseRightDown && _isVirtualMouseRightDown))
|
||||
OnRightMouseButtonDown();
|
||||
else if (_prevInput.IsMouseRightDown && !_input.IsMouseRightDown)
|
||||
else if ((_prevInput.IsMouseRightDown && !_input.IsMouseRightDown) || (_wasVirtualMouseRightDown && !_isVirtualMouseRightDown))
|
||||
OnRightMouseButtonUp();
|
||||
//
|
||||
|
||||
if (!_prevInput.IsMouseMiddleDown && _input.IsMouseMiddleDown)
|
||||
OnMiddleMouseButtonDown();
|
||||
else if (_prevInput.IsMouseMiddleDown && !_input.IsMouseMiddleDown)
|
||||
OnMiddleMouseButtonUp();
|
||||
|
||||
_wasVirtualMouseRightDown = _isVirtualMouseRightDown;
|
||||
}
|
||||
|
||||
// Get clamped delta time (more stable during lags)
|
||||
@@ -1088,7 +1100,7 @@ namespace FlaxEditor.Viewport
|
||||
bool isAltDown = _input.IsAltDown;
|
||||
bool lbDown = _input.IsMouseLeftDown;
|
||||
bool mbDown = _input.IsMouseMiddleDown;
|
||||
bool rbDown = _input.IsMouseRightDown;
|
||||
bool rbDown = _input.IsMouseRightDown || _isVirtualMouseRightDown;
|
||||
bool wheelInUse = Math.Abs(_input.MouseWheelDelta) > Mathf.Epsilon;
|
||||
|
||||
_input.IsPanning = !isAltDown && mbDown && !rbDown;
|
||||
@@ -1098,7 +1110,7 @@ namespace FlaxEditor.Viewport
|
||||
_input.IsOrbiting = isAltDown && lbDown && !mbDown && !rbDown;
|
||||
|
||||
// Control move speed with RMB+Wheel
|
||||
rmbWheel = useMovementSpeed && _input.IsMouseRightDown && wheelInUse;
|
||||
rmbWheel = useMovementSpeed && (_input.IsMouseRightDown || _isVirtualMouseRightDown) && wheelInUse;
|
||||
if (rmbWheel)
|
||||
{
|
||||
float step = 4.0f;
|
||||
@@ -1165,7 +1177,7 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
// Calculate smooth mouse delta not dependant on viewport size
|
||||
var offset = _viewMousePos - _startPos;
|
||||
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown && !_isOrtho && !rmbWheel)
|
||||
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown && !_isOrtho && !rmbWheel && !_isVirtualMouseRightDown)
|
||||
{
|
||||
offset = Float2.Zero;
|
||||
}
|
||||
@@ -1213,7 +1225,7 @@ namespace FlaxEditor.Viewport
|
||||
UpdateView(dt, ref moveDelta, ref mouseDelta, out var centerMouse);
|
||||
|
||||
// Move mouse back to the root position
|
||||
if (centerMouse && (_input.IsMouseRightDown || _input.IsMouseLeftDown || _input.IsMouseMiddleDown))
|
||||
if (centerMouse && (_input.IsMouseRightDown || _input.IsMouseLeftDown || _input.IsMouseMiddleDown || _isVirtualMouseRightDown))
|
||||
{
|
||||
var center = PointToWindow(_startPos);
|
||||
win.MousePosition = center;
|
||||
@@ -1229,7 +1241,7 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_input.IsMouseLeftDown || _input.IsMouseRightDown)
|
||||
if (_input.IsMouseLeftDown || _input.IsMouseRightDown || _isVirtualMouseRightDown)
|
||||
{
|
||||
// Calculate smooth mouse delta not dependant on viewport size
|
||||
var offset = _viewMousePos - _startPos;
|
||||
|
||||
Reference in New Issue
Block a user