Пример #1
0
        private void Window_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {
                //PointerPoint point = e.GetCurrentPoint(LayoutRoot);
                //Debug.WriteLine("Released: " + point.Position.X + ", " + point.Position.Y);

                if (calibrationStickkMoving)
                {
                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (CalibrationReleased != null)
                    {
                        CalibrationReleased(args);
                    }
                }


                if (mainStickkMoving)
                {
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Released != null)
                    {
                        Released(args);
                    }
                }

                newX  = 0;
                newY  = 0;
                angle = 0;
                normalizedDistance = 0;

                MoveJoystick(newX, newY);



                if (calibrationStickkMoving)
                {
                    ReplaceCalibrationStick();
                }

                // Reinit calibration rotation
                rotationTransform.Rotation = 135;



                calibrationStickkMoving = false;
                mainStickkMoving        = false;
                idPointer = 0;
            }
        }
Пример #2
0
        private void Window_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {
                PointerPoint point = e.GetCurrentPoint(mainStickContainer);
                Refresh(point.Position, center);

                Debug.WriteLine("X : {0}, Y : {1}", point.Position.X, point.Position.Y);

                if (mainStickkMoving)
                {
                    MoveJoystick(newX, newY);

                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Moving != null)
                    {
                        Moving(args);
                    }
                }
                else if (calibrationStickkMoving)
                {
                    rotationTransform.Rotation = basicAngle;

                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (Calibrating != null)
                    {
                        Calibrating(args);
                    }

                    //Debug.WriteLine("Angle : {0}", (int)basicAngle);
                }
            }
        }
Пример #3
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (Visibility == System.Windows.Visibility.Collapsed)
                return;

            TouchPointCollection points = e.GetTouchPoints(this);
            
            System.Windows.Point center = new System.Windows.Point(joystick.ActualWidth / 2, joystick.ActualHeight / 2);
            for (int i = 0; i < points.Count; i++)
            {
                TouchPoint point = points[i];

                // If Pointer enter on the main stick
                if (IsEnabled && point.Action == TouchAction.Down && XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, mainStickContainer) && idPointer == -1)
                {
                    #region Pointer enter on MainStick
 
                    // Lock stick type
                    calibrationStickMoving = false;
                    mainStickMoving = true;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);

                    // Update mainStick position
                    MoveJoystick(newX, newY);

                    // Prepare event args
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    // Fire event
                    if (Moving != null)
                        Moving(this, args);

                    #endregion
                }
                // Else if pointer enter on calibrationstick
                else if (IsEnabled && point.Action == TouchAction.Down && (XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationPath) || XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationTxt)) && idPointer == -1)
                {
                    // Lock stick type
                    calibrationStickMoving = true;
                    mainStickMoving = false;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);
                }
                // Else if the pointer moving
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Move)
                {
                    // Updating sticks data
                    Refresh(point.Position, center);

                    // If calibrating
                    if (calibrationStickMoving)
                    {
                        // Update angle
                        rotationTransform.Rotation = basicAngle;

                        // Fire event
                        if (Calibrating != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs { Angle = (int)basicAngle };
                            Calibrating(this, args);
                        }

                    }
                    else if (mainStickMoving)
                    {
                        // Update main stick position
                        MoveJoystick(newX, newY);

                        // Fire event
                        if (Moving != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Moving(this, args);
                        }
                    }
                }
                // On pointer released
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Up)
                {
                    // release the pointer Id
                    idPointer = -1;

                    
                    if (mainStickMoving)
                    {
                        // Fire event
                        if (Released != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Released(this, args);
                        }
                    }

                    if(calibrationStickMoving)
                    {
                        // Fire event
                        if (CalibrationReleased != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs { Angle = (int)basicAngle };
                            CalibrationReleased(this, args);
                        }
                    }

                    // Reinit data
                    newX = 0;
                    newY = 0;
                    angle = 0;
                    normalizedDistance = 0;

                    // Update main stick position
                    MoveJoystick(newX, newY);
                    
                    // Reinit calibration rotation
                    rotationTransform.Rotation = 135;

                    // Reinit flags
                    calibrationStickMoving = false;
                    mainStickMoving = false;
                }
            }
        }
Пример #4
0
        private void Window_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {
                PointerPoint point = e.GetCurrentPoint(mainStickContainer);
                Refresh(point.Position, center);

                Debug.WriteLine("X : {0}, Y : {1}", point.Position.X, point.Position.Y);

                if (mainStickkMoving)
                {
                    

                    MoveJoystick(newX, newY);

                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    if (Moving != null)
                        Moving(args);
                }
                else if(calibrationStickkMoving)
                {
                    rotationTransform.Rotation = basicAngle;

                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (Calibrating != null)
                        Calibrating(args);

                    //Debug.WriteLine("Angle : {0}", (int)basicAngle);
                }

            }
        }
Пример #5
0
        private void Window_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            if (idPointer == e.Pointer.PointerId)
            {

                //PointerPoint point = e.GetCurrentPoint(LayoutRoot);
                //Debug.WriteLine("Released: " + point.Position.X + ", " + point.Position.Y);

                if (calibrationStickkMoving)
                {
                    JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs
                    {
                        Angle = (int)basicAngle
                    };

                    if (CalibrationReleased != null)
                        CalibrationReleased(args);
                }


                if (mainStickkMoving)
                {
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                        {
                            Angle = (int)angle,
                            Speed = (float)normalizedDistance
                        };

                    if (Released != null)
                        Released(args);
                }

                newX = 0;
                newY = 0;
                angle = 0;
                normalizedDistance = 0;

                MoveJoystick(newX, newY);

                

                if(calibrationStickkMoving)
                {
                    ReplaceCalibrationStick();
                }

                // Reinit calibration rotation
                rotationTransform.Rotation = 135;



                calibrationStickkMoving = false;
                mainStickkMoving = false;
                idPointer = 0;
            }
        }
Пример #6
0
        void Touch_FrameReported(object sender, TouchFrameEventArgs e)
        {
            if (Visibility == System.Windows.Visibility.Collapsed)
            {
                return;
            }

            TouchPointCollection points = e.GetTouchPoints(this);

            System.Windows.Point center = new System.Windows.Point(joystick.ActualWidth / 2, joystick.ActualHeight / 2);
            for (int i = 0; i < points.Count; i++)
            {
                TouchPoint point = points[i];

                // If Pointer enter on the main stick
                if (IsEnabled && point.Action == TouchAction.Down && XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, mainStickContainer) && idPointer == -1)
                {
                    #region Pointer enter on MainStick

                    // Lock stick type
                    calibrationStickMoving = false;
                    mainStickMoving        = true;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);

                    // Update mainStick position
                    MoveJoystick(newX, newY);

                    // Prepare event args
                    JoystickMoveEventArgs args = new JoystickMoveEventArgs
                    {
                        Angle = (int)angle,
                        Speed = (float)normalizedDistance
                    };

                    // Fire event
                    if (Moving != null)
                    {
                        Moving(this, args);
                    }

                    #endregion
                }
                // Else if pointer enter on calibrationstick
                else if (IsEnabled && point.Action == TouchAction.Down && (XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationPath) || XamlHelper.IsControlChildOf(point.TouchDevice.DirectlyOver, CalibrationTxt)) && idPointer == -1)
                {
                    // Lock stick type
                    calibrationStickMoving = true;
                    mainStickMoving        = false;

                    // Store TouchDeviceId
                    idPointer = point.TouchDevice.Id;

                    // Updating sticks data
                    Refresh(point.Position, center);
                }
                // Else if the pointer moving
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Move)
                {
                    // Updating sticks data
                    Refresh(point.Position, center);

                    // If calibrating
                    if (calibrationStickMoving)
                    {
                        // Update angle
                        rotationTransform.Rotation = basicAngle;

                        // Fire event
                        if (Calibrating != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs {
                                Angle = (int)basicAngle
                            };
                            Calibrating(this, args);
                        }
                    }
                    else if (mainStickMoving)
                    {
                        // Update main stick position
                        MoveJoystick(newX, newY);

                        // Fire event
                        if (Moving != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Moving(this, args);
                        }
                    }
                }
                // On pointer released
                else if (point.TouchDevice.Id == idPointer && point.Action == TouchAction.Up)
                {
                    // release the pointer Id
                    idPointer = -1;


                    if (mainStickMoving)
                    {
                        // Fire event
                        if (Released != null)
                        {
                            JoystickMoveEventArgs args = new JoystickMoveEventArgs
                            {
                                Angle = (int)angle,
                                Speed = (float)normalizedDistance
                            };

                            Released(this, args);
                        }
                    }

                    if (calibrationStickMoving)
                    {
                        // Fire event
                        if (CalibrationReleased != null)
                        {
                            JoystickCalibrationEventArgs args = new JoystickCalibrationEventArgs {
                                Angle = (int)basicAngle
                            };
                            CalibrationReleased(this, args);
                        }
                    }

                    // Reinit data
                    newX  = 0;
                    newY  = 0;
                    angle = 0;
                    normalizedDistance = 0;

                    // Update main stick position
                    MoveJoystick(newX, newY);

                    // Reinit calibration rotation
                    rotationTransform.Rotation = 135;

                    // Reinit flags
                    calibrationStickMoving = false;
                    mainStickMoving        = false;
                }
            }
        }