Exemple #1
0
        /// <summary>
        /// Creates a polygon line segment.
        /// </summary>
        /// <param name="polygon">Polygon to create the line segment for</param>
        /// <param name="previousPoint">Previous polygon point</param>
        /// <param name="nextPoint">Next polygon point</param>
        private void CreatePolygonLineSegment(PolygonViewModel polygon, PolygonPointViewModel previousPoint, PolygonPointViewModel nextPoint)
        {
            PolygonLineSegment segment = new PolygonLineSegment();

            segment.Line.Visibility      = Visibility.Visible;
            segment.Line.Opacity         = 0.0;
            segment.Line.StrokeThickness = 4;
            segment.Line.Stroke          = Brushes.DodgerBlue;
            segment.Line.X1    = previousPoint.X;
            segment.Line.Y1    = previousPoint.Y;
            segment.Line.X2    = nextPoint.X;
            segment.Line.Y2    = nextPoint.Y;
            segment.StartPoint = previousPoint;
            segment.EndPoint   = nextPoint;

            canvas.Children.Add(segment.Line);
            polygon.LineSegments.Add(segment);
        }
Exemple #2
0
        /// <summary>
        /// Updates the resize adorner based on the specified polygon points.
        /// </summary>
        /// <param name="points">Polygon points to include in the resize adorner</param>
        private void UpdateResizeAdorner(ObservableCollection <PolygonPointViewModel> points)
        {
            // Get the bounds of the selected points
            Rect bounds = VM.GetSelectedContentBounds(points);

            // Get the adorner layer from the canvas
            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas);

            // If the resize adorner is NOT null then...
            if (adornerLayer != null)
            {
                // Remove the resizing adorner
                RemoveResizeAdorner();

                // If the selected shape is an ellipse and
                if (VM.SelectedEllipse != null)
                {
                    // If the ellipse has a resize adorner associated with it then...
                    if (VM.SelectedEllipse.ResizeAdorner != null)
                    {
                        // Retrieve the resize adorner from the ellipse view model
                        _resizingAdorner = VM.SelectedEllipse.ResizeAdorner;
                    }
                    else
                    {
                        // Create a collection of point view models
                        ObservableCollection <PolygonPointViewModel> copyPoints =
                            new ObservableCollection <PolygonPointViewModel>();

                        // Create a reverse transform for the ellipse
                        RotateTransform reverseRotateTransform = new RotateTransform(-VM.SelectedEllipse.Angle,
                                                                                     VM.SelectedEllipse.CenterPoint.X, VM.SelectedEllipse.CenterPoint.Y);

                        // Loop over the points on the rectangle that surrounds the ellipse
                        foreach (PolygonPointViewModel pt in points)
                        {
                            // Clone the ellipse (rectangle) point
                            PolygonPointViewModel clonedPoint =
                                new PolygonPointViewModel(pt.PolygonPoint.Clone(), null);

                            // Transform the point
                            Point transformedPoint = reverseRotateTransform.Transform(pt.GetPoint());

                            // Update the cloned point
                            clonedPoint.X = transformedPoint.X;
                            clonedPoint.Y = transformedPoint.Y;

                            // Add the point to the collection
                            copyPoints.Add(clonedPoint);
                        }

                        // Determine the bounds of the resize adorner based on the transformed points
                        bounds = VM.GetSelectedContentBounds(copyPoints);

                        // Create the resizing adorner for the ellipse with the specified angle
                        _resizingAdorner = new ResizeAdorner(VM.SelectedEllipse.Angle, this, canvas, VM, bounds);

                        // Store off the resize adorner with the ellipse
                        VM.SelectedEllipse.ResizeAdorner = _resizingAdorner;
                    }
                }
                else
                {
                    // Create the resizing adorner
                    _resizingAdorner = new ResizeAdorner(0.0, this, canvas, VM, bounds);
                }

                // Add the resizing adorner to the canvas
                adornerLayer.Add(_resizingAdorner);
            }
        }