public static void FillPath(this ICanvas canvas, Action <Path> draw, BaseBrush brush) { var p = new Path(null, brush); draw(p); p.Draw(canvas); }
public Element(Pen pen, BaseBrush brush) { Id = Guid.NewGuid().ToString(); Pen = pen; Brush = brush; Transform = Transform.Identity; }
private void ApplyStyle(string style, ref Pen pen, ref BaseBrush baseBrush) { var stylesDictionary = _stylesParser.ParseStyleValues(style); pen = _stylesParser.GetPen(stylesDictionary); baseBrush = _stylesParser.GetBrush(stylesDictionary, defs, pen); }
private Paint GetBrushPaint(BaseBrush brush, Rect frame) { var paint = new Paint(PaintFlags.AntiAlias); AddBrushPaint(paint, brush, frame); return(paint); }
private static void ReplaceColor( BaseBrush in_Brush, IEnumerable<ColorPair> in_Colors ) { if( (in_Brush == null) || (in_Colors == null) ) return; if( in_Colors.Count( ) == 0 ) return; if( in_Brush is NGraphics.Models.Brushes.GradientBrush ) { GradientBrush typedBrush = in_Brush as GradientBrush; foreach( GradientStop stop in typedBrush.Stops ) { ColorPair pair = in_Colors.FirstOrDefault(x => (stop.Color.Red == x.OldColor.R) && (stop.Color.Green == x.OldColor.G) && (stop.Color.Blue == x.OldColor.B) && (stop.Color.Alpha == x.OldColor.A)); if( pair != null ) stop.Color = new NGraphics.Models.Color(pair.NewColor.R, pair.NewColor.G, pair.NewColor.B, pair.NewColor.A); } } else if( in_Brush is NGraphics.Models.Brushes.SolidBrush ) { SolidBrush typedBrush = in_Brush as SolidBrush; ColorPair pair = in_Colors.FirstOrDefault(x => (typedBrush.Color.Red == x.OldColor.R) && (typedBrush.Color.Green == x.OldColor.G) && (typedBrush.Color.Blue == x.OldColor.B) && (typedBrush.Color.Alpha == x.OldColor.A)); if( pair != null ) typedBrush.Color = new NGraphics.Models.Color(pair.NewColor.R, pair.NewColor.G, pair.NewColor.B, pair.NewColor.A); } }
private static void ReplaceColor(BaseBrush in_Brush, IEnumerable <ColorPair> in_Colors) { if ((in_Brush == null) || (in_Colors == null)) { return; } if (in_Colors.Count( ) == 0) { return; } if (in_Brush is NGraphics.Models.Brushes.GradientBrush) { GradientBrush typedBrush = in_Brush as GradientBrush; foreach (GradientStop stop in typedBrush.Stops) { ColorPair pair = in_Colors.FirstOrDefault(x => (stop.Color.Red == x.OldColor.R) && (stop.Color.Green == x.OldColor.G) && (stop.Color.Blue == x.OldColor.B) && (stop.Color.Alpha == x.OldColor.A)); if (pair != null) { stop.Color = new NGraphics.Models.Color(pair.NewColor.R, pair.NewColor.G, pair.NewColor.B, pair.NewColor.A); } } } else if (in_Brush is NGraphics.Models.Brushes.SolidBrush) { SolidBrush typedBrush = in_Brush as SolidBrush; ColorPair pair = in_Colors.FirstOrDefault(x => (typedBrush.Color.Red == x.OldColor.R) && (typedBrush.Color.Green == x.OldColor.G) && (typedBrush.Color.Blue == x.OldColor.B) && (typedBrush.Color.Alpha == x.OldColor.A)); if (pair != null) { typedBrush.Color = new NGraphics.Models.Color(pair.NewColor.R, pair.NewColor.G, pair.NewColor.B, pair.NewColor.A); } } }
public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) : base(pen, brush) { String = text; Frame = frame; Font = font; Alignment = alignment; }
private void AddElements(IList <IDrawable> list, IEnumerable <XElement> es, Pen inheritPen, BaseBrush inheritBaseBrush) { foreach (var e in es) { AddElement(list, e, inheritPen, inheritBaseBrush); } }
void SetBrush(BaseBrush baseBrush) { var sb = baseBrush as SolidBrush; if (sb != null) { context.SetFillColor((nfloat)sb.Color.Red, (nfloat)sb.Color.Green, (nfloat)sb.Color.Blue, (nfloat)sb.Color.Alpha); } }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush baseBrush = null) { if (baseBrush != null) { graphics.FillEllipse(baseBrush.GetBrush(frame), Conversions.GetRectangleF(frame)); } if (pen != null) { graphics.DrawEllipse(pen.GetPen(), Conversions.GetRectangleF(frame)); } }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush baseBrush = null) { if (pen == null && baseBrush == null) { return; } DrawElement(() => { context.AddEllipseInRect(Conversions.GetCGRect(frame)); return(frame); }, pen, baseBrush); }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush baseBrush = null) { if (baseBrush != null) { graphics.FillRectangle(baseBrush.GetBrush(frame), Conversions.GetRectangleF(frame)); } if (pen != null) { var r = Conversions.GetRectangleF(frame); graphics.DrawRectangle(pen.GetPen(), r.X, r.Y, r.Width, r.Height); } }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null) { if (brush != null) { var paint = GetBrushPaint(brush, frame); graphics.DrawOval(frame.GetRectF(), paint); } if (pen != null) { var paint = GetPenPaint(pen); graphics.DrawOval(frame.GetRectF(), paint); } }
D2D1.Brush GetBrush(Rect frame, BaseBrush brush) { if (brush == null) { return(null); } var sb = brush as SolidBrush; if (sb != null) { return(new D2D1.SolidColorBrush(renderTarget, sb.Color.ToColor4())); } var lgb = brush as LinearGradientBrush; if (lgb != null) { if (lgb.Stops.Count < 2) { return(null); } var props = new D2D1.LinearGradientBrushProperties { StartPoint = lgb.GetAbsoluteStart(frame).ToVector2(), EndPoint = lgb.GetAbsoluteEnd(frame).ToVector2(), }; return(new D2D1.LinearGradientBrush(renderTarget, props, GetStops(lgb.Stops))); } var rgb = brush as RadialGradientBrush; if (rgb != null) { if (rgb.Stops.Count < 2) { return(null); } var rad = rgb.GetAbsoluteRadius(frame); var center = rgb.GetAbsoluteCenter(frame); var focus = rgb.GetAbsoluteFocus(frame); var props = new D2D1.RadialGradientBrushProperties { Center = center.ToVector2(), RadiusX = (float)rad.Width, RadiusY = (float)rad.Height, GradientOriginOffset = (focus - center).ToVector2(), }; return(new D2D1.RadialGradientBrush(renderTarget, props, GetStops(rgb.Stops))); } // TODO: Radial gradient brushes return(new D2D1.SolidColorBrush(renderTarget, Colors.Black.ToColor4())); }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush 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)); } }
void DrawElement(Func <Rect> add, Pen pen = null, BaseBrush 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); } }
protected void NewBrush() { if (brush == null) { var exist = GameObject.Find("Brush"); if (exist != null) { brush = exist.GetComponent <BaseBrush>(); } else { CreateBrush(); } } }
void Awake() { instance = this; showColor = new byte[size * size * 4]; material = GetComponent <MeshRenderer>().material; pencil = new Pencil(); pencil.Init(this, size, size, curve); pen = new Pen(); pen.Init(this, size, size, curve); eraser = new Eraser(); eraser.Init(this, size, size, curve); curBrush = pen; layerMgr = LayerMgr.GetInstance(); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush baseBrush = null) { if (baseBrush == null) { return; } var sdfont = new System.Drawing.Font(font.Family, (float)font.Size, FontStyle.Regular, GraphicsUnit.Pixel); var sz = graphics.MeasureString(text, sdfont); var point = frame.Position; var fr = new Rect(point, new Size(sz.Width, sz.Height)); graphics.DrawString(text, sdfont, baseBrush.GetBrush(fr), Conversions.GetPointF(point - new Point(0, sdfont.Height))); }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush 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); } }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null) { var p = GetBrush(pen); var b = GetBrush(frame, brush); var c = frame.Center; var s = new D2D1.Ellipse(new Vector2((float)c.X, (float)c.Y), (float)(frame.Width / 2.0), (float)(frame.Height / 2.0)); if (b != null) { renderTarget.FillEllipse(s, b); } if (p != null) { renderTarget.DrawEllipse(s, p, (float)pen.Width, GetStrokeStyle(pen)); } }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush 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); }
public static Brush GetBrush(this BaseBrush baseBrush, Rect frame) { var cb = baseBrush as SolidBrush; if (cb != null) { return(new System.Drawing.SolidBrush(cb.Color.GetColor())); } var lgb = baseBrush as LinearGradientBrush; if (lgb != null) { var s = lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * frame.Size; var e = lgb.Absolute ? lgb.End : frame.Position + lgb.End * frame.Size; var b = new System.Drawing.Drawing2D.LinearGradientBrush(GetPointF(s), GetPointF(e), System.Drawing.Color.Black, System.Drawing.Color.Black); var bb = BuildBlend(lgb.Stops); if (bb != null) { b.InterpolationColors = bb; } return(b); } var rgb = baseBrush as RadialGradientBrush; if (rgb != null) { var r = rgb.GetAbsoluteRadius(frame); var c = rgb.GetAbsoluteCenter(frame); var path = new GraphicsPath(); path.AddEllipse(GetRectangleF(new Rect(c - r, 2 * r))); var b = new PathGradientBrush(path); var bb = BuildBlend(rgb.Stops, true); if (bb != null) { b.InterpolationColors = bb; } return(b); } throw new NotImplementedException("Brush " + baseBrush); }
CGPathDrawingMode SetPenAndBrush(Pen pen, BaseBrush baseBrush) { var mode = CGPathDrawingMode.Fill; var sb = baseBrush as SolidBrush; if (sb != null) { if (sb.FillMode == FillMode.EvenOdd) { mode = CGPathDrawingMode.EOFill; } } if (baseBrush != null) { SetBrush(baseBrush); if (pen != null) { mode = CGPathDrawingMode.FillStroke; if (sb != null) { if (sb.FillMode == FillMode.EvenOdd) { mode = CGPathDrawingMode.EOFillStroke; } } } } if (pen != null) { SetPen(pen); if (baseBrush == null) { mode = CGPathDrawingMode.Stroke; } } return(mode); }
void CreateBrush() { var spriteReference = map.currentItemBrush; if (spriteReference != null) { GameObject go = new GameObject("Brush"); go.transform.SetParent(map.transform, false); brush = go.AddComponent <BaseBrush>(); brush.renderer2D = go.AddComponent <SpriteRenderer>(); brush.renderer2D.sortingOrder = 1000; var pixelsToUnits = map.pixelsToUnits; brush.brushSize = new Vector2( spriteReference.sprite.textureRect.width / pixelsToUnits, spriteReference.sprite.textureRect.height / pixelsToUnits ); brush.UpdateBrush(spriteReference); } }
public void SetBrushData(BrushType brushType, int _brushSize, float Concentration) { brushSize = _brushSize; switch (brushType) { case BrushType.pen: curBrush = pen; break; case BrushType.eraser: curBrush = eraser; break; case BrushType.pencil: curBrush = pencil; break; default: break; } curBrush.SetBrushData(brushSize, Concentration); }
public Ellipse(Point position, Size size, Pen pen = null, BaseBrush baseBrush = null) : this(new Rect(position, size), pen, baseBrush) { }
public void DrawPath(IEnumerable <PathOperation> commands, Pen pen = null, BaseBrush brush = null) { Graphic.Children.Add(new Path(commands, pen, brush)); }
public Rectangle(Point position, Size size, Pen pen = null, BaseBrush baseBrush = null) : this(new Rect(position, size), pen, baseBrush) { }
D2D1.Brush GetBrush(Rect frame, BaseBrush brush) { if (brush == null) return null; var sb = brush as SolidBrush; if (sb != null) { return new D2D1.SolidColorBrush (renderTarget, sb.Color.ToColor4 ()); } var lgb = brush as LinearGradientBrush; if (lgb != null) { if (lgb.Stops.Count < 2) return null; var props = new D2D1.LinearGradientBrushProperties { StartPoint = lgb.GetAbsoluteStart (frame).ToVector2 (), EndPoint = lgb.GetAbsoluteEnd (frame).ToVector2 (), }; return new D2D1.LinearGradientBrush (renderTarget, props, GetStops (lgb.Stops)); } var rgb = brush as RadialGradientBrush; if (rgb != null) { if (rgb.Stops.Count < 2) return null; var rad = rgb.GetAbsoluteRadius (frame); var center = rgb.GetAbsoluteCenter (frame); var focus = rgb.GetAbsoluteFocus (frame); var props = new D2D1.RadialGradientBrushProperties { Center = center.ToVector2 (), RadiusX = (float)rad.Width, RadiusY = (float)rad.Height, GradientOriginOffset = (focus - center).ToVector2 (), }; return new D2D1.RadialGradientBrush (renderTarget, props, GetStops (rgb.Stops)); } // TODO: Radial gradient brushes return new D2D1.SolidColorBrush (renderTarget, Colors.Black.ToColor4 ()); }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush 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)); } }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null) { var p = GetBrush (pen); var b = GetBrush (frame, brush); var c = frame.Center; var s = new D2D1.Ellipse (new Vector2 ((float)c.X, (float)c.Y), (float)(frame.Width / 2.0), (float)(frame.Height / 2.0)); if (b != null) { renderTarget.FillEllipse (s, b); } if (p != null) { renderTarget.DrawEllipse (s, p, (float)pen.Width, GetStrokeStyle (pen)); } }
private void AddElement(IList<IDrawable> list, XElement e, Pen inheritPen, BaseBrush inheritBaseBrush) { Element element = null; var styleAttributedDictionary = e.Attributes().ToDictionary(k => k.Name.LocalName, v => v.Value); var pen = _stylesParser.GetPen(styleAttributedDictionary); var baseBrush = _stylesParser.GetBrush(styleAttributedDictionary,defs, pen); var style = ReadString(e.Attribute("style")); if (!string.IsNullOrWhiteSpace(style)) { ApplyStyle(style, ref pen, ref baseBrush); } pen = pen ?? inheritPen; baseBrush = baseBrush ?? inheritBaseBrush; //var id = ReadString (e.Attribute ("id")); // // Elements // switch (e.Name.LocalName) { case "text": { var x = _valuesParser.ReadNumber(e.Attribute("x")); var y = _valuesParser.ReadNumber(e.Attribute("y")); var text = e.Value.Trim(); var font = new Font(); element = new Text(text, new Rect(new Point(x, y), new Size(double.MaxValue, double.MaxValue)), font, TextAlignment.Left, pen, baseBrush); } break; case "rect": { var x = _valuesParser.ReadNumber(e.Attribute("x")); var y = _valuesParser.ReadNumber(e.Attribute("y")); var width = _valuesParser.ReadNumber(e.Attribute("width")); var height = _valuesParser.ReadNumber(e.Attribute("height")); element = new Rectangle(new Point(x, y), new Size(width, height), pen, baseBrush); } break; case "ellipse": { var cx = _valuesParser.ReadNumber(e.Attribute("cx")); var cy = _valuesParser.ReadNumber(e.Attribute("cy")); var rx = _valuesParser.ReadNumber(e.Attribute("rx")); var ry = _valuesParser.ReadNumber(e.Attribute("ry")); element = new Ellipse(new Point(cx - rx, cy - ry), new Size(2*rx, 2*ry), pen, baseBrush); } break; case "circle": { var cx = _valuesParser.ReadNumber(e.Attribute("cx")); var cy = _valuesParser.ReadNumber(e.Attribute("cy")); var rr = _valuesParser.ReadNumber(e.Attribute("r")); element = new Ellipse(new Point(cx - rr, cy - rr), new Size(2*rr, 2*rr), pen, baseBrush); } break; case "path": { var dA = e.Attribute("d"); if (dA != null && !string.IsNullOrWhiteSpace(dA.Value)) { var p = new Path(pen, baseBrush); SvgPathParser.Parse(p, dA.Value); element = p; } } break; case "g": { var g = new Group(); AddElements(g.Children, e.Elements(), pen, baseBrush); element = g; } break; case "use": { var href = ReadString(e.Attributes().FirstOrDefault(x => x.Name.LocalName == "href")); if (!string.IsNullOrWhiteSpace(href)) { XElement useE; if (defs.TryGetValue(href.Trim().Replace("#", ""), out useE)) { var useList = new List<IDrawable>(); AddElement(useList, useE, pen, baseBrush); element = useList.OfType<Element>().FirstOrDefault(); } } } break; case "title": Graphic.Title = ReadString(e); break; case "description": Graphic.Description = ReadString(e); break; case "defs": // Already read in earlier pass break; case "namedview": case "metadata": case "SVGTestCase": case "switch": break; default: throw new NotSupportedException("SVG element \"" + e.Name.LocalName + "\" is not supported"); } if (element != null) { element.Transform = ReadTransform(ReadString(e.Attribute("transform"))); list.Add(element); } }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush 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); } }
public void DrawPath(IEnumerable<PathOperation> commands, Pen pen = null, BaseBrush brush = null) { Graphic.Children.Add(new Path(commands, pen, brush)); }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush brush = null) { Graphic.Children.Add(new Rectangle(frame, pen, brush)); }
private void AddBrushPaint(Paint paint, BaseBrush brush, Rect frame) { paint.SetStyle(Paint.Style.Fill); var sb = brush as SolidBrush; if (sb != null) { paint.SetARGB(sb.Color.A, sb.Color.R, sb.Color.G, sb.Color.B); return; } var lgb = brush as LinearGradientBrush; if (lgb != null) { var n = lgb.Stops.Count; if (n >= 2) { var locs = new float[n]; var comps = new int[n]; for (var i = 0; i < n; i++) { var s = lgb.Stops[i]; locs[i] = (float) s.Offset; comps[i] = s.Color.Argb; } var p1 = lgb.Absolute ? lgb.Start : frame.Position + lgb.Start*frame.Size; var p2 = lgb.Absolute ? lgb.End : frame.Position + lgb.End*frame.Size; var lg = new LinearGradient( (float) p1.X, (float) p1.Y, (float) p2.X, (float) p2.Y, comps, locs, Shader.TileMode.Clamp); paint.SetShader(lg); } return; } var rgb = brush as RadialGradientBrush; if (rgb != null) { var n = rgb.Stops.Count; if (n >= 2) { var locs = new float[n]; var comps = new int[n]; for (var i = 0; i < n; i++) { var s = rgb.Stops[i]; locs[i] = (float) s.Offset; comps[i] = s.Color.Argb; } var p1 = rgb.GetAbsoluteCenter(frame); var r = rgb.GetAbsoluteRadius(frame); var rg = new RadialGradient( (float) p1.X, (float) p1.Y, (float) r.Max, comps, locs, Shader.TileMode.Clamp); paint.SetShader(rg); } return; } throw new NotSupportedException("Brush " + brush); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) { throw new NotImplementedException(); }
public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null) { using (var path = new Path()) { var bb = new BoundingBoxBuilder(); foreach (var op in ops) { var moveTo = op as MoveTo; if (moveTo != null) { var start = moveTo.Start; var end = moveTo.End; path.MoveTo((float) start.X, (float) start.Y); bb.Add(start); bb.Add(end); continue; } var lineTo = op as LineTo; if (lineTo != null) { var start = lineTo.Start; var end = lineTo.End; path.LineTo((float) start.X, (float) start.Y); path.LineTo((float) end.X, (float) end.Y); bb.Add(start); bb.Add(end); 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 curveTo = op as CurveTo; if (curveTo != null) { var end = curveTo.End; var firstControlPoint = curveTo.FirstControlPoint; var secondControlPoint = curveTo.SecondControlPoint; path.CubicTo((float) firstControlPoint.X, (float) firstControlPoint.Y, (float) secondControlPoint.X, (float) secondControlPoint.Y, (float) end.X, (float) end.Y); bb.Add(firstControlPoint); bb.Add(secondControlPoint); bb.Add(end); 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 solidBrush = brush as SolidBrush; if (solidBrush != null) { path.SetFillType(GetPathFillType(((SolidBrush)brush).FillMode)); } var brushPaint = GetBrushPaint(brush, frame); graphics.DrawPath(path, brushPaint); } if (pen != null) { var penPaint = GetPenPaint(pen); graphics.DrawPath(path, penPaint); } } }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush 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); }
public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush baseBrush = null) { using (var path = new GraphicsPath()) { var bb = new BoundingBoxBuilder(); var position = Point.Zero; foreach (var op in ops) { var start = op as StartFigure; if (start != null) { path.StartFigure(); continue; } var moveTo = op as MoveTo; if (moveTo != null) { path.StartFigure(); continue; } var lineTo = op as LineTo; if (lineTo != null) { var p = lineTo.Start; path.AddLine(Conversions.GetPointF(lineTo.Start), Conversions.GetPointF(lineTo.End)); position = p; bb.Add(p); continue; } var arcTo = op as ArcTo; if (arcTo != null) { var p = arcTo.Point; path.AddLine(Conversions.GetPointF(position), Conversions.GetPointF(p)); position = p; bb.Add(p); continue; } var curveTo = op as CurveTo; if (curveTo != null) { path.AddBezier(Conversions.GetPointF(curveTo.Start), Conversions.GetPointF(curveTo.FirstControlPoint), Conversions.GetPointF(curveTo.SecondControlPoint), Conversions.GetPointF(curveTo.End)); bb.Add(curveTo.Start); bb.Add(curveTo.FirstControlPoint); bb.Add(curveTo.SecondControlPoint); bb.Add(curveTo.End); continue; } var closePath = op as ClosePath; if (closePath != null) { path.CloseFigure(); continue; } throw new NotSupportedException("Path Op " + op); } var frame = bb.BoundingBox; if (baseBrush != null) { graphics.FillPath(baseBrush.GetBrush(frame), path); } if (pen != null) { var r = Conversions.GetRectangleF(frame); graphics.DrawPath(pen.GetPen(), path); } } }
private Paint GetBrushPaint(BaseBrush brush, Rect frame) { var paint = new Paint(PaintFlags.AntiAlias); AddBrushPaint(paint, brush, frame); return paint; }
public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush 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.Start), D2D1.FigureBegin.Filled); figureDepth++; bb.Add (mt.Start); } else if (op is LineTo) { var lt = ((LineTo)op); sink.AddLine (lt.Start.ToVector2()); sink.AddLine (lt.End.ToVector2()); bb.Add (lt.Start); bb.Add (lt.End); } 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.FirstControlPoint), Point2 = Conversions.ToVector2 (ct.SecondControlPoint), Point3 = Conversions.ToVector2 (ct.End), }); bb.Add(ct.FirstControlPoint); bb.Add(ct.SecondControlPoint); bb.Add(ct.End); } 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)); } }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush baseBrush = null) { if (baseBrush == null) return; var sdfont = new System.Drawing.Font(font.Family, (float) font.Size, FontStyle.Regular, GraphicsUnit.Pixel); var sz = graphics.MeasureString(text, sdfont); var point = frame.Position; var fr = new Rect(point, new Size(sz.Width, sz.Height)); graphics.DrawString(text, sdfont, baseBrush.GetBrush(fr), Conversions.GetPointF(point - new Point(0, sdfont.Height))); }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) { var layout = new DW.TextLayout (factories.DWFactory, text, GetTextFormat (font), (float)frame.Width, (float)frame.Height); var h = layout.Metrics.Height; //todo : : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. //renderTarget.DrawTextLayout ((frame.TopLeft - h*Point.OneY.Y).ToVector2 (), layout, GetBrush (frame, brush)); }
public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null) { }
public Rectangle(Rect frame, Pen pen = null, BaseBrush baseBrush = null) : base(pen, baseBrush) { this.frame = frame; }
public void DrawRectangle(Rect frame, Pen pen = null, BaseBrush brush = null) { }
public void DrawText(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null) { }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null) { Graphic.Children.Add(new Ellipse(frame, pen, brush)); }
public void DrawEllipse(Rect frame, Pen pen = null, BaseBrush brush = null) { }
public Ellipse(Rect frame, Pen pen = null, BaseBrush baseBrush = null) : base(pen, baseBrush) { this.frame = frame; }
private void AddElements(IList<IDrawable> list, IEnumerable<XElement> es, Pen inheritPen, BaseBrush inheritBaseBrush) { foreach (var e in es) AddElement(list, e, inheritPen, inheritBaseBrush); }