Exemple #1
0
        // throws ArgumentException if pointerPoint.pointerId is already in live rendering mode
        public void EnterLiveRendering(Windows.UI.Input.PointerPoint pointerPoint, Windows.UI.Input.Inking.InkDrawingAttributes drawingAttributes)
        {
            uint pointerId = pointerPoint.PointerId;

            // Create and initialize the data structures necessary to render a polyline in XAML.
            var stroke = new Windows.UI.Xaml.Media.PolyLineSegment();

            stroke.Points.Add(pointerPoint.Position);
            var figure = new Windows.UI.Xaml.Media.PathFigure();

            figure.StartPoint = pointerPoint.Position;
            figure.Segments.Add(stroke);
            var geometry = new Windows.UI.Xaml.Media.PathGeometry();

            geometry.Figures.Add(figure);
            var path = new Windows.UI.Xaml.Shapes.Path();

            path.Data = geometry;

            // Set the stroke's graphical properties, which are controlled by the Path object
            path.Stroke             = new Windows.UI.Xaml.Media.SolidColorBrush(drawingAttributes.Color);
            path.StrokeThickness    = drawingAttributes.Size.Width;
            path.StrokeLineJoin     = Windows.UI.Xaml.Media.PenLineJoin.Round;
            path.StrokeStartLineCap = Windows.UI.Xaml.Media.PenLineCap.Round;

            // Update dictionaries
            liveStrokes.Add(pointerId, stroke); // throws ArgumentException if pointerId is already in the dictionary
            livePaths.Add(pointerId, path);     // throws ArgumentException if pointerId is already in the dictionary

            // Add path to render so that it is rendered (on top of all the elements with same ZIndex).
            // We want the live render to be on top of the Bezier render, so we set the ZIndex of the elements of the
            // live render to 2 and that of the elements of the Bezier render to 1.
            render.Children.Add(path);
            Windows.UI.Xaml.Controls.Canvas.SetZIndex(path, 2);
        }
Exemple #2
0
        public static Windows.UI.Xaml.Shapes.Path CreateBezierPath(Windows.UI.Input.Inking.InkStroke stroke)
        {
            // Create Bezier geometries using information provided by the stroke's segments
            var figure   = new Windows.UI.Xaml.Media.PathFigure();
            var segments = stroke.GetRenderingSegments().GetEnumerator();

            segments.MoveNext();
            // First segment is degenerate and corresponds to initial position
            figure.StartPoint = segments.Current.Position;
            // Now loop through all remaining segments
            while (segments.MoveNext())
            {
                var bs = new Windows.UI.Xaml.Media.BezierSegment();
                bs.Point1 = segments.Current.BezierControlPoint1;
                bs.Point2 = segments.Current.BezierControlPoint2;
                bs.Point3 = segments.Current.Position;
                figure.Segments.Add(bs);
            }

            // Create and initialize the data structures necessary to render the figure
            var geometry = new Windows.UI.Xaml.Media.PathGeometry();

            geometry.Figures.Add(figure);
            var path = new Windows.UI.Xaml.Shapes.Path();

            path.Data = geometry;

            // Set the stroke's graphical properties, which are controlled by the Path object
            path.Stroke             = new Windows.UI.Xaml.Media.SolidColorBrush(stroke.DrawingAttributes.Color);
            path.StrokeThickness    = stroke.DrawingAttributes.Size.Width;
            path.StrokeLineJoin     = Windows.UI.Xaml.Media.PenLineJoin.Round;
            path.StrokeStartLineCap = Windows.UI.Xaml.Media.PenLineCap.Round;

            return(path);
        }
        public static Windows.UI.Xaml.Shapes.Path CreateBezierPath(Windows.UI.Input.Inking.InkStroke stroke)
        {
            // Create Bezier geometries using information provided by the stroke's segments
            var figure = new Windows.UI.Xaml.Media.PathFigure();
            var segments = stroke.GetRenderingSegments().GetEnumerator();
            segments.MoveNext();
            // First segment is degenerate and corresponds to initial position
            figure.StartPoint = segments.Current.Position;
            // Now loop through all remaining segments
            while (segments.MoveNext())
            {
                var bs = new Windows.UI.Xaml.Media.BezierSegment();
                bs.Point1 = segments.Current.BezierControlPoint1;
                bs.Point2 = segments.Current.BezierControlPoint2;
                bs.Point3 = segments.Current.Position;
                figure.Segments.Add(bs);
            }

            // Create and initialize the data structures necessary to render the figure
            var geometry = new Windows.UI.Xaml.Media.PathGeometry();
            geometry.Figures.Add(figure);
            var path = new Windows.UI.Xaml.Shapes.Path();
            path.Data = geometry;

            // Set the stroke's graphical properties, which are controlled by the Path object
            path.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(stroke.DrawingAttributes.Color);
            path.StrokeThickness = stroke.DrawingAttributes.Size.Width;
            path.StrokeLineJoin = Windows.UI.Xaml.Media.PenLineJoin.Round;
            path.StrokeStartLineCap = Windows.UI.Xaml.Media.PenLineCap.Round;

            return path;
        }
Exemple #4
0
 static void AddCurve(PathFigure pathFigure, Curve curve)
 {
     foreach (ICurve seg in curve.Segments)
     {
         var ls = seg as LineSegment;
         if (ls != null)
         {
             pathFigure.Segments.Add(new Windows.UI.Xaml.Media.LineSegment {
                 Point = Common.WpfPoint(ls.End)
             });
         }
         else
         {
             var ellipse = seg as Ellipse;
             if (ellipse != null)
             {
                 pathFigure.Segments.Add(new ArcSegment {
                     Point          = Common.WpfPoint(ellipse.End),
                     Size           = new Size(ellipse.AxisA.Length, ellipse.AxisB.Length),
                     RotationAngle  = Point.Angle(new Point(1, 0), ellipse.AxisA),
                     IsLargeArc     = ellipse.ParEnd - ellipse.ParEnd >= Math.PI,
                     SweepDirection = !ellipse.OrientedCounterclockwise()
                         ? SweepDirection.Counterclockwise
                         : SweepDirection.Clockwise
                 });
             }
         }
     }
 }
Exemple #5
0
        Geometry CreateGeometryFromMsaglCurve(ICurve iCurve)
        {
            var pathGeometry = new PathGeometry();
            var pathFigure   = new PathFigure {
                IsClosed   = true,
                IsFilled   = true,
                StartPoint = Common.WpfPoint(iCurve.Start)
            };

            var curve = iCurve as Curve;

            if (curve != null)
            {
                AddCurve(pathFigure, curve);
            }
            else
            {
                var rect = iCurve as RoundedRect;
                if (rect != null)
                {
                    AddCurve(pathFigure, rect.Curve);
                }
                else
                {
                    var ellipse = iCurve as Ellipse;
                    if (ellipse != null)
                    {
                        return(new EllipseGeometry {
                            Center = Common.WpfPoint(ellipse.Center),
                            RadiusX = ellipse.AxisA.Length,
                            RadiusY = ellipse.AxisB.Length
                        });
                    }
                    var poly = iCurve as Polyline;
                    if (poly != null)
                    {
                        var p = poly.StartPoint.Next;
                        do
                        {
                            pathFigure.Segments.Add(new Windows.UI.Xaml.Media.LineSegment {
                                Point = Common.WpfPoint(p.Point)
                            });
                            p = p.NextOnPolyline;
                        } while (p != poly.StartPoint);
                    }
                }
            }


            pathGeometry.Figures.Add(pathFigure);

            return(pathGeometry);
        }
Exemple #6
0
        Geometry CreateCollapseSymbolPath(Point center, double width)
        {
            var pathGeometry = new PathGeometry();
            var pathFigure   = new PathFigure {
                StartPoint = Common.WpfPoint(center + new Point(-width, width))
            };

            pathFigure.Segments.Add(new Windows.UI.Xaml.Media.LineSegment {
                Point = Common.WpfPoint(center)
            });
            pathFigure.Segments.Add(
                new Windows.UI.Xaml.Media.LineSegment {
                Point = Common.WpfPoint(center + new Point(width, width))
            });

            pathGeometry.Figures.Add(pathFigure);
            return(pathGeometry);
        }
        // throws ArgumentException if pointerPoint.pointerId is already in live rendering mode
        public void EnterLiveRendering(Windows.UI.Input.PointerPoint pointerPoint, Windows.UI.Input.Inking.InkDrawingAttributes drawingAttributes)
        {
            uint pointerId = pointerPoint.PointerId;

            // Create and initialize the data structures necessary to render a polyline in XAML.
            var stroke = new Windows.UI.Xaml.Media.PolyLineSegment();
            stroke.Points.Add(pointerPoint.Position);
            var figure = new Windows.UI.Xaml.Media.PathFigure();
            figure.StartPoint = pointerPoint.Position;
            figure.Segments.Add(stroke);
            var geometry = new Windows.UI.Xaml.Media.PathGeometry();
            geometry.Figures.Add(figure);
            var path = new Windows.UI.Xaml.Shapes.Path();
            path.Data = geometry;

            // Set the stroke's graphical properties, which are controlled by the Path object
            path.Stroke = new Windows.UI.Xaml.Media.SolidColorBrush(drawingAttributes.Color);
            path.StrokeThickness = drawingAttributes.Size.Width;
            path.StrokeLineJoin = Windows.UI.Xaml.Media.PenLineJoin.Round;
            path.StrokeStartLineCap = Windows.UI.Xaml.Media.PenLineCap.Round;

            // Update dictionaries
            liveStrokes.Add(pointerId, stroke); // throws ArgumentException if pointerId is already in the dictionary
            livePaths.Add(pointerId, path);     // throws ArgumentException if pointerId is already in the dictionary

            // Add path to render so that it is rendered (on top of all the elements with same ZIndex).
            // We want the live render to be on top of the Bezier render, so we set the ZIndex of the elements of the
            // live render to 2 and that of the elements of the Bezier render to 1.
            render.Children.Add(path);
            Windows.UI.Xaml.Controls.Canvas.SetZIndex(path, 2);
        }