Exemplo n.º 1
0
        // Handler for the ManipulationDelta event.
        // ManipulationDelta data is loaded into the
        // translations transforms and applied to the
        // upper touch rectangle and lower car images.
        void TouchRectangle_ManipulationDelta(object sender,
                                              ManipulationDeltaRoutedEventArgs e)
        {
            // TO-DO: Need to do more tests with inertia on all platforms.
            if (e.IsInertial != true)
            {
                // Move the upper touch rectangle along the x-axis.
                dragUpperTranslation.X += e.Delta.Translation.X;

                if (dragUpperTranslation.X >= 0 && dragUpperTranslation.X < (MainRoot.ActualWidth * 0.65))
                {
                    //Making sure the SketchCar is not bouncing and rotating wheels under this threshold.
                    CarStoryboard.Stop();

                    // Making sure the scene animation is paused at the same time if it was already started.
                    if (isAnimationStarted)
                    {
                        SceneStoryboard.Pause();
                    }

                    // Move the lower cars along the x-axis and keeping the same upper y-axis.
                    dragLowerTranslation.X = dragUpperTranslation.X;
                    dragLowerTranslation.Y = dragUpperTranslation.Y;
                }
                else if (dragUpperTranslation.X >= (MainRoot.ActualWidth * 0.65))
                {
                    // Keep the upper rectangle at the same position as the lower rectangle.
                    dragUpperTranslation.X = dragLowerTranslation.X;
                    dragUpperTranslation.Y = dragLowerTranslation.Y;

                    //Starting the SketchCar bouncing and rotating wheels animations above the threshold.
                    CarStoryboard.Begin();

                    // Making sure the scene animation begin for the first time or resume if paused.
                    if (isAnimationStarted)
                    {
                        SceneStoryboard.Resume();
                    }
                    else
                    {
                        SceneStoryboard.Begin();
                        isAnimationStarted = true;
                    }
                }
                else
                {
                    // Keep the upper rectangle at the same position as the lower rectangle.
                    dragUpperTranslation.X = dragLowerTranslation.X;
                    dragUpperTranslation.Y = dragLowerTranslation.Y;

                    // Making sure the scene animation is paused at the same time if it was already started.
                    if (isAnimationStarted)
                    {
                        SceneStoryboard.Pause();
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void MainRoot_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // Making sure we are resetting the X axis and the Y axis if the MainRoot is resized (Can be reviewed in the long term).
            dragUpperTranslation.X = 0;
            dragLowerTranslation.X = 0;
            dragLowerTranslation.Y = dragUpperTranslation.Y;

            // Making sure the car animation is stopped.
            CarStoryboard.Stop();

            // Making sure the scene animation is paused if it was already started.
            if (isAnimationStarted)
            {
                SceneStoryboard.Pause();
            }

            // Ajusting the margins on the right side so it will be at the same level as the margins on the left side.
            DragLeftCar.Margin    = new Thickness(MainRoot.ActualWidth * 0.1, 0, 0, 0);
            TouchRectangle.Margin = new Thickness(MainRoot.ActualWidth * 0.1, 0, 0, 0);
            DragRightCar.Margin   = new Thickness(-((MainRoot.ActualWidth / 2) - (MainRoot.ActualWidth * 0.1)), 0, 0, 0);
            FeaturesPanel.Margin  = new Thickness(-((MainRoot.ActualWidth / 2) - (MainRoot.ActualWidth * 0.1)) - 180, 0, 0, 0);
        }
Exemplo n.º 3
0
        private async void HingeAngleSensor_ReadingChanged(HingeAngleSensor sender, HingeAngleSensorReadingChangedEventArgs args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var angleValue = args.Reading.AngleInDegrees;

                AngleValue.Content = "Angle value: " + angleValue.ToString();

                //Making sure we are not moving again the cars if we are keeping the same angle
                if (angleValue != previousAngle)
                {
                    previousAngle = angleValue;

                    // When the dual-screen device is half-opened
                    if (angleValue == 180)
                    {
                        //Making sure the SketchCar is not bouncing and rotating wheels.
                        CarStoryboard.Stop();

                        // Making sure the scene animation is paused at the same time if it was already started.
                        if (isSceneAnimationStarted)
                        {
                            SceneStoryboard.Pause();
                        }

                        // Move the lower cars along the x-axis in the middle of the screen and keeping the same upper y-axis.
                        dragLowerTranslation.X = (MainRoot.ActualWidth / 2) - (MainRoot.ActualWidth *leftSideThresholdRatio) - 100;
                        dragLowerTranslation.Y = dragUpperTranslation.Y;

                        // Keep the upper rectangle at the same position as the lower rectangle.
                        dragUpperTranslation.X = dragLowerTranslation.X;
                    }
                    // When the dual-screen device is fully opened, meaning that both screens are facing aware from each other.
                    else if (angleValue == 360)
                    {
                        // Move the lower cars along the x-axis on the right side of the screen and keeping the same upper y-axis.
                        dragLowerTranslation.X = MainRoot.ActualWidth *rightSideThresholdRatio;
                        dragLowerTranslation.Y = dragUpperTranslation.Y;

                        // Keep the upper rectangle at the same position as the lower rectangle.
                        dragUpperTranslation.X = dragLowerTranslation.X;
                        dragUpperTranslation.Y = dragLowerTranslation.Y;

                        // Making sure the SketchCar bouncing and rotating wheels animations begin for
                        // the first time or correctly being stopped and begin again if already started.
                        if (isCarAnimationStarted)
                        {
                            CarStoryboard.Stop();
                            CarStoryboard.Begin();
                        }
                        else
                        {
                            CarStoryboard.Begin();
                            isCarAnimationStarted = true;
                        }

                        // Making sure the scene animation begin for the first time or resume if paused.
                        if (isSceneAnimationStarted)
                        {
                            SceneStoryboard.Resume();
                        }
                        else
                        {
                            SceneStoryboard.Begin();
                            isSceneAnimationStarted = true;
                        }
                    }
                }
            });
        }