/// <summary> /// Updated if required the position of the arm dependent on /// the given rects. /// /// Caution: /// - Only the first rect found will be used to update the /// position. /// - It assumes that the width is specified in the ui and /// the height is dynamic. /// </summary> /// <param name="rects">List of rects.</param> private void UpdateArmPosition(IEnumerable <Rect> rects) { // Determine if a re-positing of the arm is required. var rect = rects.FirstOrDefault(); var rectCenter = rect.X + (rect.Width / 2); var isMovementRequired = Math.Abs(rectCenter - previewControlSize.Width) > ARM_RELOCATION_CENTER_THRESHHOLD; // Ensure that a movement is required. if (isMovementRequired == false) { Debug.WriteLine("OK"); return; } // If the face is left of the preview center. if (rectCenter < previewControlSize.Width) { // move to the right. NegativePanCommand.Execute(null); } // If the face is left of the preview center. else if (rectCenter > previewControlSize.Width) { // move to the left. PositivePanCommand.Execute(null); } }
/// <summary> /// Should be called externally to listen on key /// down events. /// /// Caution: /// - It only listens on Gamepad keys. /// </summary> /// <param name="args"></param> public void OnKeyDown(KeyEventArgs args) { // Ensure that controller selection mode is // selected and no cool down is active. if (isKeyDownCooldownActive || selectedMode != HomeBearTiltControlMode.XBOX_CONTROLLER) { return; } // Listen on pressed keys. // Use only GamePad ones and trigger actions. switch (args.VirtualKey) { // Stick upwards. case VirtualKey.GamepadLeftThumbstickUp: PositiveTiltCommand.Execute(null); break; // Stick downwards. case VirtualKey.GamepadLeftThumbstickDown: NegativeTiltCommand.Execute(null); break; // Stick to the left. case VirtualKey.GamepadLeftThumbstickLeft: PositivePanCommand.Execute(null); break; // Stick to the right. case VirtualKey.GamepadLeftThumbstickRight: NegativePanCommand.Execute(null); break; } // Start cool down timer. keyDownCooldownTimer = ThreadPoolTimer.CreateTimer(CooldownTimer_Tick, KEYDOWN_COOLDOWN_SECONDS); }