Skip to content

Commit

Permalink
Update CameraControl.cs
Browse files Browse the repository at this point in the history
Small optimization when calculating controller status
  • Loading branch information
victor-david committed Aug 23, 2020
1 parent 617b481 commit e6e0dd9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Camera.App/Core/CameraControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CameraControl : Controls.Control
/* height in xaml is zero, gets animated up when mouse within activation zone */
private const double ControllerHeight = 75.0;
private const double ControllerActivationY = ControllerHeight + 10.0;
private double controllerActivationX;
private bool isControllerEnabled;

private double imageScaledWidth;
Expand Down Expand Up @@ -742,13 +743,21 @@ public double ControllerWidth

private static readonly DependencyPropertyKey ControllerWidthPropertyKey = DependencyProperty.RegisterReadOnly
(
nameof(ControllerWidth), typeof(double), typeof(CameraControl), new PropertyMetadata(0.0)
nameof(ControllerWidth), typeof(double), typeof(CameraControl), new PropertyMetadata(0.0, OnControllerWidthChanged)
);

/// <summary>
/// Identifies the <see cref="ControllerWidth"/> dependency property.
/// </summary>
public static readonly DependencyProperty ControllerWidthProperty = ControllerWidthPropertyKey.DependencyProperty;

private static void OnControllerWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is CameraControl control)
{
control.controllerActivationX = (double)e.NewValue + 10.0;
}
}
#endregion

/************************************************************************/
Expand Down Expand Up @@ -862,14 +871,14 @@ protected override void OnMouseMove(MouseEventArgs e)

Point point = e.GetPosition(this);

if (controllerStatus == ControllerStatus.Hidden && point.Y > ActualHeight - ControllerActivationY && point.X < ControllerWidth + 10.0)
if (controllerStatus == ControllerStatus.Hidden && point.Y > ActualHeight - ControllerActivationY && point.X < controllerActivationX)
{
controllerStatus = ControllerStatus.Showing;
ShowController.Begin();
return;
}

if (controllerStatus == ControllerStatus.Shown && (point.Y < ActualHeight - ControllerActivationY || point.X > ControllerWidth + 10.0))
if (controllerStatus == ControllerStatus.Shown && (point.Y < ActualHeight - ControllerActivationY || point.X > controllerActivationX))
{
controllerStatus = ControllerStatus.Hiding;
HideController.Begin();
Expand Down

0 comments on commit e6e0dd9

Please sign in to comment.