コード例 #1
0
        private void UpdateTouchPosition(float x, float y)
        {
            var height    = this.Height;
            var width     = this.Width;
            var minimal   = Math.Min(height, width);
            var relativeX = 2 * (x - width / 2) / minimal;
            var relativeY = 2 * (y - height / 2) / minimal;

            if (relativeX > 1.0f)
            {
                relativeX = 1.0f;
            }
            if (relativeX < -1.0f)
            {
                relativeX = -1.0f;
            }

            if (relativeY > 1.0f)
            {
                relativeY = 1.0f;
            }
            if (relativeY < -1.0f)
            {
                relativeY = -1.0f;
            }

            // note that we rotate x and y here because we want 0 to be up the screen
            TouchPosition = new CartesianPositionParameters {
                Y = relativeX, X = -relativeY
            };
            Fire(TouchPositionChanged);
        }
コード例 #2
0
 private void SetHightlightPosition(CartesianPositionParameters positionParameters, FrameworkElement highlightImage,
                                    Canvas theParent)
 {
     Canvas.SetTop(highlightImage,
                   (theParent.ActualHeight - positionParameters.Y * theParent.ActualHeight -
                    highlightImage.ActualHeight) / 2);
     Canvas.SetLeft(highlightImage,
                    (theParent.ActualWidth + positionParameters.X * theParent.ActualWidth -
                     highlightImage.ActualWidth) / 2);
 }
コード例 #3
0
        private void DoMove(double x = 0, double y = 0)
        {
            var parameters = new CartesianPositionParameters()
            {
                X = x,
                Y = y
            };

            ViewModel.Movement.RollCommand.Execute(parameters);
        }
コード例 #4
0
        private CartesianPositionParameters GetRelativePositionParameters(object sender, MouseEventArgs e)
        {
            var target             = (FrameworkElement)sender;
            var position           = e.GetPosition(target);
            var relativeX          = 2.0 * (position.X / target.ActualWidth) - 1.0;
            var relativeY          = 1.0 - 2.0 * (position.Y / target.ActualHeight);
            var positionParameters = new CartesianPositionParameters {
                X = relativeX, Y = relativeY
            };

            return(positionParameters);
        }
コード例 #5
0
ファイル: Joystick.xaml.cs プロジェクト: slodge/BallControl
        protected virtual void OnNewCoordinates()
        {
            var parameters = new CartesianPositionParameters()
            {
                X = newX / (ellipseSense.ActualWidth / 2),
                Y = newY / (ellipseSense.ActualWidth / 2),
            };
            var handler = NewCoordinates;

            if (handler != null)
            {
                handler(this, new MvxValueEventArgs <CartesianPositionParameters>(parameters));
            }
        }