public Element(Pen pen, Brush brush)
 {
     Id = Guid.NewGuid ().ToString ();
     Pen = pen;
     Brush = brush;
     Transform = NGraphics.Transform.Identity;
 }
Esempio n. 2
0
		protected Element (Pen pen, Brush brush)
		{
			Id = "";
			Pen = pen;
			Brush = brush;
			Transform = NGraphics.Transform.Identity;
		}
Esempio n. 3
0
 public static void DrawLine(this ICanvas canvas, Point start, Point end, Pen pen)
 {
     var p = new Path { Pen = pen };
     p.MoveTo (start);
     p.LineTo (end);
     p.Draw (canvas);
 }
Esempio n. 4
0
		public void DrawEllipse (Rect frame, Pen pen = null, Brush brush = null)
		{
			var ch = GetChild (ChildType.Ellipse);
			var s = (Shapes.Rectangle)ch.Shape;
			s.Width = frame.Width;
			s.Height = frame.Height;
			FormatShape (s, pen, brush);
		}
Esempio n. 5
0
		public Text (Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
			: base (pen, brush)
		{
			Frame = frame;
			Font = font;
			Alignment = alignment;
			Spans = new List<TextSpan> ();
		}
Esempio n. 6
0
		public Text (string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
			: base (pen, brush)
		{
			Frame = frame;
			Font = font;
			Alignment = alignment;
			Spans = new List<TextSpan> { new TextSpan (text) };
		}
Esempio n. 7
0
 public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
     : base(pen, brush)
 {
     String = text;
     Frame = frame;
     Font = font;
     Alignment = alignment;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="fromBrush"></param>
 /// <returns></returns>
 private System.Windows.Media.Brush GetStroke(NGraphics.Pen fromPen)
 {
     return(new SolidColorBrush(new System.Windows.Media.Color
     {
         A = fromPen.Color.A,
         R = fromPen.Color.R,
         G = fromPen.Color.G,
         B = fromPen.Color.B
     }));
 }
Esempio n. 9
0
		public override void Draw(ICanvas canvas, Rect rect)
		{
			if(DrawingFunction != null)
			{
				base.Draw(canvas, rect);
				return;
			}

			var borderColro = NGraphics.Color.FromHSL(
				                  BorderColor.Hue,
				                  BorderColor.Saturation,
				                  BorderColor.Luminosity,
				                  BorderColor.A);
			var pen = new Pen(borderColro, BorderWidth);
			var fillColor = NGraphics.Color.FromHSL(
				                BackColor.Hue,
				                BackColor.Saturation,
				                BackColor.Luminosity,
				                BackColor.A);
			var brush = new SolidBrush(fillColor);

			var padding = BorderWidth <= 0 ? 0.0 : BorderWidth;
			var newRect = rect.GetInflated(-padding);
			var curveSize = newRect.Height / 2;

			canvas.DrawPath(new PathOp []{ 
				new MoveTo(newRect.Left+curveSize, newRect.Top),
				new LineTo(newRect.Right-curveSize, newRect.Top),
				new CurveTo(
					new NGraphics.Point(newRect.Right-curveSize, newRect.Top),
					newRect.TopRight,
					new NGraphics.Point(newRect.Right, newRect.Top+curveSize)
				),
				new CurveTo(
					new NGraphics.Point(newRect.Right, newRect.Bottom-curveSize),
					newRect.BottomRight,
					new NGraphics.Point(newRect.Right-curveSize, newRect.Bottom)
				),
				new LineTo(newRect.Left+curveSize, newRect.Bottom),
				new CurveTo(
					new NGraphics.Point(newRect.Left+curveSize, newRect.Bottom),
					newRect.BottomLeft,
					new NGraphics.Point(newRect.Left, newRect.Bottom-curveSize)
				),
				new CurveTo(
					new NGraphics.Point(newRect.Left, newRect.Top+curveSize),
					newRect.TopLeft,
					new NGraphics.Point(newRect.Left+curveSize, newRect.Top)
				),
				new ClosePath()
			}, pen, brush);
		}
Esempio n. 10
0
 public Text(Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
     : base(pen, brush)
 {
     Frame     = frame;
     Font      = font;
     Alignment = alignment;
     Spans     = new List <TextSpan> ();
 }
Esempio n. 11
0
 public Path(IEnumerable<PathOp> operations, Pen pen = null, Brush brush = null)
     : base(pen, brush)
 {
     Operations.AddRange (operations);
 }
 public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null)
 {
 }
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
 }
Esempio n. 14
0
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
        {
            if (brush == null)
                return;

            var paint = GetFontPaint (font, alignment);
            var w = paint.MeasureText (text);
            var fm = paint.GetFontMetrics ();
            var h = fm.Ascent + fm.Descent;
            var point = frame.Position;
            var fr = new Rect (point, new Size (w, h));
            AddBrushPaint (paint, brush, fr);
            graphics.DrawText (text, (float)point.X, (float)point.Y, paint);
        }
Esempio n. 15
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            using (var path = new global::Android.Graphics.Path ()) {

                var bb = new BoundingBoxBuilder ();

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        path.MoveTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        path.LineTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;
                        path.LineTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo ((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null) {
                        path.Close ();
                        continue;
                    }

                    throw new NotSupportedException ("Path Op " + op);
                }

                var frame = bb.BoundingBox;

                if (brush != null) {
                    var paint = GetBrushPaint (brush, frame);
                    graphics.DrawPath (path, paint);
                }
                if (pen != null) {
                    var paint = GetPenPaint (pen);
                    graphics.DrawPath (path, paint);
                }
            }
        }
Esempio n. 16
0
 CGPathDrawingMode SetPenAndBrush(Pen pen, Brush brush)
 {
     var mode = CGPathDrawingMode.Fill;
     if (brush != null) {
         SetBrush (brush);
         if (pen != null)
             mode = CGPathDrawingMode.FillStroke;
     }
     if (pen != null) {
         SetPen (pen);
         if (brush == null)
             mode = CGPathDrawingMode.Stroke;
     }
     return mode;
 }
Esempio n. 17
0
        void DrawElement(Func<Rect> add, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            var lgb = brush as LinearGradientBrush;
            if (lgb != null) {
                var cg = CreateGradient (lgb.Stops);
                context.SaveState ();
                var frame = add ();
                context.Clip ();
                CGGradientDrawingOptions options = CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation;
                var size = frame.Size;
                var start = Conversions.GetCGPoint (lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * size);
                var end = Conversions.GetCGPoint (lgb.Absolute ? lgb.End : frame.Position + lgb.End * size);
                context.DrawLinearGradient (cg, start, end, options);
                context.RestoreState ();
                brush = null;
            }

            var rgb = brush as RadialGradientBrush;
            if (rgb != null) {
                var cg = CreateGradient (rgb.Stops);
                context.SaveState ();
                var frame = add ();
                context.Clip ();
                CGGradientDrawingOptions options = CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation;
                var size = frame.Size;
                var start = Conversions.GetCGPoint (rgb.GetAbsoluteCenter (frame));
                var r = (nfloat)rgb.GetAbsoluteRadius (frame).Max;
                var end = Conversions.GetCGPoint (rgb.GetAbsoluteFocus (frame));
                context.DrawRadialGradient (cg, start, 0, end, r, options);
                context.RestoreState ();
                brush = null;
            }

            if (pen != null || brush != null)
            {
                var mode = SetPenAndBrush (pen, brush);

                add ();
                context.DrawPath (mode);
            }
        }
Esempio n. 18
0
 void SetPen(Pen pen)
 {
     context.SetStrokeColor ((nfloat)pen.Color.Red, (nfloat)pen.Color.Green, (nfloat)pen.Color.Blue, (nfloat)pen.Color.Alpha);
     context.SetLineWidth ((nfloat)pen.Width);
 }
Esempio n. 19
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            var bb = new BoundingBoxBuilder ();
            var s = new D2D1.PathGeometry (factories.D2DFactory);
            var figureDepth = 0;
            using (var sink = s.Open ()) {
                foreach (var op in ops) {
                    if (op is MoveTo) {
                        while (figureDepth > 0) {
                            sink.EndFigure (D2D1.FigureEnd.Open);
                            figureDepth--;
                        }
                        var mt = ((MoveTo)op);
                        sink.BeginFigure (Conversions.ToVector2 (mt.Point), D2D1.FigureBegin.Filled);
                        figureDepth++;
                        bb.Add (mt.Point);
                    }
                    else if (op is LineTo) {
                        var lt = ((LineTo)op);
                        sink.AddLine (Conversions.ToVector2 (lt.Point));
                        bb.Add (lt.Point);
                    }
                    else if (op is ArcTo) {
                        var ar = ((ArcTo)op);
                        // TODO: Direct2D Arcs
                        //sink.AddArc (new D2D1.ArcSegment {
                        //	Size = Conversions.ToSize2F (ar.Radius),
                        //	Point = Conversions.ToVector2 (ar.Point),
                        //	SweepDirection = ar.SweepClockwise ? D2D1.SweepDirection.Clockwise : D2D1.SweepDirection.CounterClockwise,
                        //});
                        sink.AddLine (Conversions.ToVector2 (ar.Point));
                        bb.Add (ar.Point);
                    }
                    else if (op is CurveTo) {
                        var ct = ((CurveTo)op);
                        sink.AddBezier (new D2D1.BezierSegment {
                            Point1 = Conversions.ToVector2 (ct.Control1),
                            Point2 = Conversions.ToVector2 (ct.Control2),
                            Point3 = Conversions.ToVector2 (ct.Point),
                        });
                        bb.Add (ct.Point);
                        bb.Add (ct.Control1);
                        bb.Add (ct.Control2);
                    }
                    else if (op is ClosePath) {
                        sink.EndFigure (D2D1.FigureEnd.Closed);
                        figureDepth--;
                    }
                    else {
                        // TODO: More path operations
                    }
                }
                while (figureDepth > 0) {
                    sink.EndFigure (D2D1.FigureEnd.Open);
                    figureDepth--;
                }
                sink.Close ();
            }

            var p = GetBrush (pen);
            var b = GetBrush (bb.BoundingBox, brush);

            if (b != null) {
                renderTarget.FillGeometry (s, b);
            }
            if (p != null) {
                renderTarget.DrawGeometry (s, p, (float)pen.Width, GetStrokeStyle (pen));
            }
        }
Esempio n. 20
0
 public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null)
 {
     if (brush != null) {
         var paint = GetBrushPaint (brush, frame);
         graphics.DrawOval (Conversions.GetRectF (frame), paint);
     }
     if (pen != null) {
         var paint = GetPenPaint (pen);
         graphics.DrawOval (Conversions.GetRectF (frame), paint);
     }
 }
Esempio n. 21
0
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
     var p = GetBrush (pen);
     var b = GetBrush (frame, brush);
     if (b != null) {
         renderTarget.FillRectangle (frame.ToRectangleF (), b);
     }
     if (p != null) {
         renderTarget.DrawRectangle (frame.ToRectangleF (), p, (float)pen.Width, GetStrokeStyle (pen));
     }
 }
Esempio n. 22
0
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
     if (brush != null) {
         var paint = GetBrushPaint (brush, frame);
         graphics.DrawRect ((float)(frame.X), (float)(frame.Y), (float)(frame.X + frame.Width), (float)(frame.Y + frame.Height), paint);
     }
     if (pen != null) {
         var paint = GetPenPaint (pen);
         graphics.DrawRect ((float)(frame.X), (float)(frame.Y), (float)(frame.X + frame.Width), (float)(frame.Y + frame.Height), paint);
     }
 }
Esempio n. 23
0
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
 {
     var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height);
     var h = layout.Metrics.Height;
     renderTarget.DrawTextLayout ((frame.TopLeft - h*Point.OneY).ToVector2 (), layout, GetBrush (frame, brush));
 }
Esempio n. 24
0
 Paint GetPenPaint(Pen pen)
 {
     var paint = new Paint (PaintFlags.AntiAlias);
     paint.SetStyle (Paint.Style.Stroke);
     paint.SetARGB (pen.Color.A, pen.Color.R, pen.Color.G, pen.Color.B);
     paint.StrokeWidth = (float)pen.Width;
     return paint;
 }
Esempio n. 25
0
 D2D1.Brush GetBrush(Pen pen)
 {
     if (pen == null) return null;
     return new D2D1.SolidColorBrush (renderTarget, pen.Color.ToColor4 ());
 }
 public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
 {
 }
Esempio n. 27
0
 D2D1.StrokeStyle GetStrokeStyle(Pen pen)
 {
     return null;
 }
 public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
 {
 }
Esempio n. 29
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            DrawElement (() => {

                var bb = new BoundingBoxBuilder ();

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        context.MoveTo ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        context.AddLineToPoint ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;
                        var pp = Conversions.GetPoint (context.GetPathCurrentPoint ());
                        Point c1, c2;
                        at.GetCircles (pp, out c1, out c2);

                        var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1;

                        var startAngle = (float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X);
                        var endAngle = (float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X);

                        context.AddArc((nfloat)circleCenter.X, (nfloat)circleCenter.Y, (nfloat)at.Radius.Min, startAngle, endAngle, at.SweepClockwise);

                        bb.Add (p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        context.AddCurveToPoint ((nfloat)c1.X, (nfloat)c1.Y, (nfloat)c2.X, (nfloat)c2.Y, (nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null) {
                        context.ClosePath ();
                        continue;
                    }

                    throw new NotSupportedException ("Path Op " + op);
                }

                return bb.BoundingBox;

            }, pen, brush);
        }
Esempio n. 30
0
        public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            DrawElement (() => {
                context.AddRect (Conversions.GetCGRect (frame));
                return frame;
            }, pen, brush);
        }
Esempio n. 31
0
        public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
        {
            if (string.IsNullOrEmpty (text))
                return;
            if (font == null)
                throw new ArgumentNullException ("font");

            SetBrush (brush);

            //			string fontName = font.Name;
            //			context.SelectFont (font.Name, (nfloat)font.Size, CGTextEncoding.MacRoman);
            //
            //			context.ShowTextAtPoint ((nfloat)frame.X, (nfloat)frame.Y, text);

            var pt = frame.TopLeft;

            using (var atext = new NSMutableAttributedString (text)) {

                atext.AddAttributes (new CTStringAttributes {
                    ForegroundColorFromContext = true,
                    Font = font.GetCTFont (),
                }, new NSRange (0, text.Length));

                using (var l = new CTLine (atext)) {
                    nfloat asc, desc, lead;
                    var width = l.GetTypographicBounds (out asc, out desc, out lead);
                    context.SaveState ();
                    context.TranslateCTM ((nfloat)(pt.X - width / 2), (nfloat)(pt.Y + desc));
                    context.TextPosition = CGPoint.Empty;
                    l.Draw (context);
                    context.RestoreState ();
                }
            }
        }
Esempio n. 32
0
 public Path(Pen pen = null, Brush brush = null)
     : base(pen, brush)
 {
 }
Esempio n. 33
0
 public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, Brush brush = null)
     : base(pen, brush)
 {
     Frame     = frame;
     Font      = font;
     Alignment = alignment;
     Spans     = new List <TextSpan> {
         new TextSpan(text)
         {
             Brush = brush, Pen = pen
         }
     };
 }