예제 #1
0
        public void CanvasMouseDown(object sender, MouseButtonEventArgs e)
        {
            MousePressed = true;

            if (Corners == null)
            {
                Corners = new List <Corner>();
            }

            if (Walls == null)
            {
                Walls = new List <Wall>();
            }

            var mousePosition = e.MouseDevice.GetPosition(ShapeGen.Can);

            var tempPoint = new Corner(mousePosition.X, mousePosition.Y);

            if (HoveredCorner == null)
            {
                Corners.ForEach(x =>
                {
                    if (x.RepEllipse.IsMouseDirectlyOver)
                    {
                        HoveredCorner = x;
                    }
                });
            }
            if (HoveredCorner == null)
            {
                var cor = new Corner(mousePosition.X, mousePosition.Y)
                {
                    FillBrush       = Brushes.Black,
                    Height          = 10,
                    Width           = 10,
                    StrokeBrush     = Brushes.White,
                    StrokeThickness = 1
                };

                Corners.ForEach(x =>
                {
                    if (cor.DistanceFrom(x) <= SnapTolerance)
                    {
                        cor = x;
                    }
                });

                if (Corners.Count(x => x.X == cor.X && x.Y == cor.Y) == 0)
                {
                    Corners.Add(cor);
                }
                cor.DrawPoint();

                if (AddingWall && LastNode != null)
                {
                    var wall = new Wall(LastNode, cor);
                    Walls.Add(wall);
                    wall.StrokeBrush = Brushes.Black;
                    wall.DrawLine();
                }

                LastNode          = cor;
                LastMousePosition = mousePosition;
                AddingWall        = true;
            }
        }