示例#1
0
        protected override void OnMouseDown(MouseButtonEventArgs args)
        {
            base.OnMouseDown(args);
            if (args.Handled || _division == null)
            {
                return;
            }

            Point cursor = Mouse.GetPosition(OutputBox);

            if (cursor.X < 0 || cursor.X >= OutputBox.Width ||
                cursor.Y < 0 || cursor.Y >= OutputBox.Height)
            {
                return;
            }

            if (AddEdgeToggle.IsChecked == true)
            {
                if (_selectedVertex >= 0)
                {
                    PointD oldVertex = _division.Vertices.GetKey(_selectedVertex);
                    _division.AddEdge(oldVertex, cursor.ToPointD());
                }
            }
            else if (RemoveEdgeToggle.IsChecked == true)
            {
                if (_selectedEdge >= 0)
                {
                    _division.RemoveEdge(_selectedEdge);
                }
            }
            else if (SplitEdgeToggle.IsChecked == true)
            {
                if (_selectedEdge >= 0)
                {
                    _division.SplitEdge(_selectedEdge);
                }
            }
            else if (ConnectVertexToggle.IsChecked == true)
            {
                if (_selectedVertex >= 0)
                {
                    PointD oldVertex = _division.Vertices.GetKey(_selectedVertex);
                    CollectionsUtility.AnyRandom(_division.Vertices.Keys,
                                                 p => (_division.AddEdge(oldVertex, p) != null));
                }
            }
            else if (MoveVertexToggle.IsChecked == true)
            {
                if (_selectedVertex >= 0)
                {
                    PointD newVertex = cursor.ToPointD();
                    _division.MoveVertex(_selectedVertex, newVertex);
                }
            }
            else if (RemoveVertexToggle.IsChecked == true)
            {
                if (_selectedVertex >= 0)
                {
                    _division.RemoveVertex(_selectedVertex);
                }
            }
            else
            {
                return;
            }

            DrawSubdivision(_division);
            SetNearestEdge(null, 0);
            SetSelectedEdge(-1);
            SetSelectedVertex(-1);
        }