Ejemplo n.º 1
0
        /// <summary>
        /// Draws an ellipse
        /// </summary>
        /// <param name="frame"></param>
        /// <param name="pen"></param>
        /// <param name="brush"></param>
        public void DrawEllipse(Rect frame, Pen pen = null, NGraphics.Brush brush = null)
        {
            var ellipseEl = new Windows.UI.Xaml.Shapes.Ellipse();
            var offset    = pen != null ? pen.Width : 0.0;

            ellipseEl.Width  = frame.Width + offset;
            ellipseEl.Height = frame.Height + offset;

            if (brush != null)
            {
                ellipseEl.Fill = GetBrush(brush);
            }

            if (pen != null)
            {
                ellipseEl.Stroke          = GetStroke(pen);
                ellipseEl.StrokeThickness = pen.Width;
            }

            ellipseEl.RenderTransform = Conversions.GetTransform(CurrentTransform);
            _canvas.Children.Add(ellipseEl);
            Canvas.SetLeft(ellipseEl, frame.X - offset / 2.0);
            Canvas.SetTop(ellipseEl, frame.Y - offset / 2.0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Draws a path
        /// </summary>
        /// <param name="ops"></param>
        /// <param name="pen"></param>
        /// <param name="brush"></param>
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, NGraphics.Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            var pathEl = new Windows.UI.Xaml.Shapes.Path();

            if (brush != null)
            {
                pathEl.Fill = GetBrush(brush);
            }

            if (pen != null)
            {
                pathEl.Stroke          = GetStroke(pen);
                pathEl.StrokeThickness = pen.Width;
            }

            var geo = new StringBuilder();

            foreach (var op in ops)
            {
                var mt = op as MoveTo;
                if (mt != null)
                {
                    geo.AppendFormat(CultureInfo.InvariantCulture, " M {0},{1}", mt.Point.X, mt.Point.Y);
                    continue;
                }

                var lt = op as LineTo;
                if (lt != null)
                {
                    geo.AppendFormat(CultureInfo.InvariantCulture, " L {0},{1}", lt.Point.X, lt.Point.Y);
                    continue;
                }

                var at = op as ArcTo;
                if (at != null)
                {
                    var p = at.Point;
                    var r = at.Radius;

                    geo.AppendFormat(CultureInfo.InvariantCulture, " A {0},{1} 0 {2} {3} {4},{5}",
                                     r.Width, r.Height,
                                     at.LargeArc ? 1 : 0,
                                     at.SweepClockwise ? 1 : 0,
                                     p.X, p.Y);
                    continue;
                }

                var ct = op as CurveTo;
                if (ct != null)
                {
                    var p  = ct.Point;
                    var c1 = ct.Control1;
                    var c2 = ct.Control2;
                    geo.AppendFormat(CultureInfo.InvariantCulture, " C {0},{1} {2},{3} {4},{5}",
                                     c1.X, c1.Y, c2.X, c2.Y, p.X, p.Y);
                    continue;
                }

                var cp = op as ClosePath;
                if (cp != null)
                {
                    geo.Append(" z");
                    continue;
                }
            }

            // Convert path string to geometry
            var b = new Binding {
                Source = geo.ToString()
            };

            BindingOperations.SetBinding(pathEl, Windows.UI.Xaml.Shapes.Path.DataProperty, b);

            pathEl.RenderTransform = Conversions.GetTransform(CurrentTransform);
            _canvas.Children.Add(pathEl);
        }