private void HandleMouseUp(int x, int y)
        {
            var point = new ClickPoint
            {
                X = x,
                Y = y
            };

            var isMoved = point.Distance(StartPoint) > MinDistance;
            if(isMoved)
            {
                point.SelectedClickMode = (int)ClickMode.Release;
                CreatePoint(point);
                DrawTraectory(StartPoint, x, y, true);
                CurrentTraectoryLine = null;
            }
            else
            {
                StartPoint.SelectedClickMode = (int)ClickMode.PushAndRelease;
                Canvas.Children.Remove(CurrentTraectoryLine);
            }

            StartPoint = null;
        }
Exemplo n.º 2
0
 private void RemovePoint(ClickPoint point)
 {
     Points.Remove(point);
 }
        private void HandleMouseDown(int x, int y)
        {
            StartPoint = new ClickPoint
            {
                X = x,
                Y = y,
                SelectedClickMode = (int)ClickMode.Push
            };

            CreatePoint(StartPoint);
        }
        private void DrawTraectory(ClickPoint from, int toX, int toY, bool adjustTrarget = false)
        {
            if(!Canvas.Children.Contains(CurrentTraectoryLine))
            {
                Canvas.Children.Add(CurrentTraectoryLine);
            }

            var angle = from.Angle(toX, toY);
            var fullSize = CircleSize - BorderSize;

            var xOffset = fullSize / 2 * Math.Sin(angle);
            var yOffset = fullSize / 2 * Math.Cos(angle);

            CurrentTraectoryLine.X1 = from.X + xOffset;
            CurrentTraectoryLine.Y1 = from.Y + yOffset;
            CurrentTraectoryLine.X2 = toX - (adjustTrarget ? xOffset : 0);
            CurrentTraectoryLine.Y2 = toY - (adjustTrarget ? yOffset : 0);
        }
 private void CreatePoint(ClickPoint point)
 {
     Points.Add(point);
     AddCircleAtPosition(Points.Count, point);
 }
        private void AddCircleAtPosition(int index, ClickPoint p)
        {
            var border = new Border
            {
                BorderBrush = StrokeBrush,
                Background = BackgroundBrush,
                Width = CircleSize,
                Height = CircleSize,
                BorderThickness = new Thickness(BorderSize),
                CornerRadius = new CornerRadius(360),
                Opacity = DefaultOpacity,
                Child = new Viewbox
                {
                    Child = new TextBlock
                    {
                        Text = index.ToString(),
                        VerticalAlignment = VerticalAlignment.Center,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Padding = new Thickness(3)
                    }
                }
            };

            Canvas.Children.Add(border);

            Canvas.SetLeft(border, p.X - border.Width / 2);
            Canvas.SetTop(border, p.Y - border.Height / 2);
        }
Exemplo n.º 7
0
 public double Distance(ClickPoint toPoint)
 {
     return Sqrt(Pow(X - toPoint.X, 2) + Pow(Y - toPoint.Y, 2));
 }