Esempio n. 1
0
        private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            double xChange = e.HorizontalChange;
            double yChange = e.VerticalChange;

            double x = ThumbX + xChange;
            double y = ThumbY + yChange;

            double sin = GetSin(x, y);
            double cos = GetCos(x, y);

            x -= xCenter;
            y -= yCenter;
            double distance = Math.Sqrt(x * x + y * y);

            if (sin > 1 || cos > 1 || sin < -1 || cos < -1)
            {
                Resources["ThumbColor"] = new SolidColorBrush(Colors.Red);
            }

            if (distance < radius / 10)
            {
                CircleThumb.CancelDrag();
                return;
            }

            if (Double.IsNaN(sin))
            {
                sin = 0;
            }

            if (Double.IsNaN(cos))
            {
                cos = 0;
            }

            double newThumbX = xCenter + cos * radius;
            double newThumbY = yCenter + sin * radius;

            double angle = GetAngle(newThumbX, newThumbY);

            UpdateAngle(angle);

            SetThumbPosition(newThumbX, newThumbY);

            RotateTransform rotateTransform = new RotateTransform(angle / Math.PI * 180);

            Stick.RenderTransform = rotateTransform;
        }
Esempio n. 2
0
        private void Thumb_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            double xChange = e.HorizontalChange;
            double yChange = e.VerticalChange;

            double x = ThumbX + xChange;
            double y = ThumbY + yChange;

            double sin = GetSin(x, y);
            double cos = GetCos(x, y);

            x -= xCenter;
            y -= yCenter;
            double distance = Math.Sqrt(x * x + y * y);

            if (sin > 1 || cos > 1 || sin < -1 || cos < -1)
            {
                Resources["ThumbColor"] = new SolidColorBrush(Colors.Red);
            }

            if (distance < radius / 10)
            {
                CircleThumb.CancelDrag();
                return;
            }

            if (Double.IsNaN(sin))
            {
                sin = 0;
            }

            if (Double.IsNaN(cos))
            {
                cos = 0;
            }

            double this_angle_backup = this.angle;

            double newThumbX = xCenter + cos * radius;
            double newThumbY = yCenter + sin * radius;

            double angle = GetAngle(newThumbX, newThumbY);

            UpdateAngle(angle);
            Data.Text = $"{this_angle_backup}\n{this.angle}\n{angle}";

            double currentAngle = this.angle;

            if (this.angle < downAngleLimit)
            {
                if (GetAngle() != downAngleLimit)
                {
                    SetAngle(downAngleLimit);
                }

                return;
            }
            else if (this.angle > upAngleLimit)
            {
                if (GetAngle() != upAngleLimit)
                {
                    SetAngle(upAngleLimit);
                    Destroy();
                }

                return;
            }

            SetThumbPosition(newThumbX, newThumbY);

            Canvas.SetLeft(LockSlider, lockStart + 2 * currentAngle);

            RotateTransform rotateTransform = new RotateTransform(angle / Math.PI * 180);

            Stick.RenderTransform = rotateTransform;
        }