/// <inheritdoc/> public override void Draw(object dc, ImageShape image, double dx, double dy, object db, object r) { var _dc = dc as AM.DrawingContext; var rect = CreateRect(image.TopLeft, image.BottomRight, dx, dy); if (image.IsStroked || image.IsFilled) { AM.IBrush brush = ToBrush(image.Style.Fill); AM.Pen pen = ToPen(image.Style, _scaleToPage); DrawRectangleInternal( _dc, brush, pen, image.IsStroked, image.IsFilled, ref rect); } if (_enableImageCache && _biCache.ContainsKey(image.Key)) { try { var bi = _biCache[image.Key]; _dc.DrawImage( bi, 1.0, new A.Rect(0, 0, bi.PixelWidth, bi.PixelHeight), new A.Rect(rect.X, rect.Y, rect.Width, rect.Height)); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } else { if (State.ImageCache == null || string.IsNullOrEmpty(image.Key)) { return; } try { var bytes = State.ImageCache.GetImage(image.Key); if (bytes != null) { using (var ms = new System.IO.MemoryStream(bytes)) { var bi = new AMI.Bitmap(ms); if (_enableImageCache) { _biCache[image.Key] = bi; } _dc.DrawImage( bi, 1.0, new A.Rect(0, 0, bi.PixelWidth, bi.PixelHeight), new A.Rect(rect.X, rect.Y, rect.Width, rect.Height)); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } } }
private void DrawGridInternal(AM.DrawingContext dc, AM.Pen stroke, ref Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked) { double ox = rect.X; double oy = rect.Y; double sx = ox + offsetX; double sy = oy + offsetY; double ex = ox + rect.Width; double ey = oy + rect.Height; for (double x = sx; x < ex; x += cellWidth) { var p0 = new A.Point( _scaleToPage(x), _scaleToPage(oy)); var p1 = new A.Point( _scaleToPage(x), _scaleToPage(ey)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } for (double y = sy; y < ey; y += cellHeight) { var p0 = new A.Point( _scaleToPage(ox), _scaleToPage(y)); var p1 = new A.Point( _scaleToPage(ex), _scaleToPage(y)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } }
/// <inheritdoc/> public override void Draw(object dc, RectangleShape rectangle, double dx, double dy, object db, object r) { var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(rectangle.Style.Fill); AM.Pen pen = ToPen(rectangle.Style, _scaleToPage); var rect = CreateRect(rectangle.TopLeft, rectangle.BottomRight, dx, dy); DrawRectangleInternal( _dc, brush, pen, rectangle.IsStroked, rectangle.IsFilled, ref rect); if (rectangle.IsGrid) { DrawGridInternal( _dc, pen, ref rect, rectangle.OffsetX, rectangle.OffsetY, rectangle.CellWidth, rectangle.CellHeight, true); } }
/// <inheritdoc/> public override void Draw(object dc, QuadraticBezierShape quadraticBezier, double dx, double dy, object db, object r) { if (!quadraticBezier.IsFilled && !quadraticBezier.IsStroked) { return; } var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(quadraticBezier.Style.Fill); AM.Pen pen = ToPen(quadraticBezier.Style, _scaleToPage); var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure( new A.Point(quadraticBezier.Point1.X, quadraticBezier.Point1.Y), quadraticBezier.IsFilled); sgc.QuadraticBezierTo( new A.Point(quadraticBezier.Point2.X, quadraticBezier.Point2.Y), new A.Point(quadraticBezier.Point3.X, quadraticBezier.Point3.Y)); sgc.EndFigure(false); } _dc.DrawGeometry( quadraticBezier.IsFilled ? brush : null, quadraticBezier.IsStroked ? pen : null, sg); }
private AM.Pen ToPen(BaseStyle style, Func <double, float> scale) { var lineCap = default(AM.PenLineCap); var dashStyle = default(AM.DashStyle); switch (style.LineCap) { case LineCap.Flat: lineCap = AM.PenLineCap.Flat; break; case LineCap.Square: lineCap = AM.PenLineCap.Square; break; case LineCap.Round: lineCap = AM.PenLineCap.Round; break; } if (style.Dashes != null) { dashStyle = new AM.DashStyle( ShapeStyle.ConvertDashesToDoubleArray(style.Dashes), style.DashOffset); } var pen = new AM.Pen( ToBrush(style.Stroke), scale(style.Thickness / State.ZoomX), dashStyle, lineCap, lineCap, lineCap); return(pen); }
/// <inheritdoc/> public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { if (!cubicBezier.IsFilled && !cubicBezier.IsStroked) { return; } var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(cubicBezier.Style.Fill); AM.Pen pen = ToPen(cubicBezier.Style, _scaleToPage); var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure( new A.Point(cubicBezier.Point1.X, cubicBezier.Point1.Y), cubicBezier.IsFilled); sgc.CubicBezierTo( new A.Point(cubicBezier.Point2.X, cubicBezier.Point2.Y), new A.Point(cubicBezier.Point3.X, cubicBezier.Point3.Y), new A.Point(cubicBezier.Point4.X, cubicBezier.Point4.Y)); sgc.EndFigure(false); } _dc.DrawGeometry( cubicBezier.IsFilled ? brush : null, cubicBezier.IsStroked ? pen : null, sg); }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { var _dc = dc as AM.DrawingContext; AM.Pen strokeLine = ToPen(line.Style, _scaleToPage); A.Point pt1, pt2; DrawLineArrowsInternal(_dc, line, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( _dc, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(_dc, strokeLine, line.IsStroked, ref pt1, ref pt2); } }
public void DrawLine(Pen pen, Point p1, Point p2) { using (var paint = CreatePaint(pen, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y)))) { Canvas.DrawLine((float)p1.X, (float)p1.Y, (float)p2.X, (float)p2.Y, paint.Paint); } }
private void DrawLineArrowsInternal(AM.DrawingContext dc, LineShape line, double dx, double dy, out A.Point pt1, out A.Point pt2) { AM.IBrush fillStartArrow = ToBrush(line.Style.StartArrowStyle.Fill); AM.Pen strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage); AM.IBrush fillEndArrow = ToBrush(line.Style.EndArrowStyle.Fill); AM.Pen strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage); double _x1 = line.Start.X + dx; double _y1 = line.Start.Y + dy; double _x2 = line.End.X + dx; double _y2 = line.End.Y + dy; line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2); float x1 = _scaleToPage(_x1); float y1 = _scaleToPage(_y1); float x2 = _scaleToPage(_x2); float y2 = _scaleToPage(_y2); var sas = line.Style.StartArrowStyle; var eas = line.Style.EndArrowStyle; double a1 = Math.Atan2(y1 - y2, x1 - x2); double a2 = Math.Atan2(y2 - y1, x2 - x1); // Draw start arrow. pt1 = DrawLineArrowInternal(dc, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(dc, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); }
private static void DrawLineInternal(AM.DrawingContext dc, AM.Pen pen, bool isStroked, ref A.Point p0, ref A.Point p1) { if (isStroked) { dc.DrawLine(pen, p0, p1); } }
public MazeCanvas() : base() { _mazeTileBrush = Avalonia.Media.Brushes.Black; _mazeTilePen = new Avalonia.Media.Pen(_mazeTileBrush); BusyGeneratingMaze2 = new Subject <bool>(); BusyGeneratingMaze2.OnNext(false); GenerateMazeBind = ReactiveCommand.CreateFromTask(GenerateMaze, canExecute: BusyGeneratingMaze2); BusyGeneratingMaze2.OnNext(false); BusyGeneratingMaze = true; }
/// <inheritdoc/> public override void Draw(object dc, EllipseShape ellipse, double dx, double dy, object db, object r) { var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(ellipse.Style.Fill); AM.Pen pen = ToPen(ellipse.Style, _scaleToPage); var rect = CreateRect(ellipse.TopLeft, ellipse.BottomRight, dx, dy); DrawEllipseInternal( _dc, brush, pen, ellipse.IsStroked, ellipse.IsFilled, ref rect); }
public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) { var impl = ((StreamGeometryImpl)geometry.PlatformImpl); var size = geometry.Bounds.Size; using (var fill = brush != null ? CreatePaint(brush, size) : default(PaintWrapper)) using (var stroke = pen?.Brush != null ? CreatePaint(pen, size) : default(PaintWrapper)) { if (fill.Paint != null) { Canvas.DrawPath(impl.EffectivePath, fill.Paint); } if (stroke.Paint != null) { Canvas.DrawPath(impl.EffectivePath, stroke.Paint); } } }
public override void DrawGeometry(Brush brush, Pen pen, Geometry geometry) { Direct2D1StreamGeometry platformGeometry = (Direct2D1StreamGeometry)geometry.PlatformImpl; PathGeometry d2dGeometry = platformGeometry.Direct2DGeometry; if (brush != null) { this.target.FillGeometry(d2dGeometry, brush.ToSharpDX(this.target)); } if (pen != null) { this.target.DrawGeometry( d2dGeometry, pen.Brush.ToSharpDX(this.target), (float)pen.Thickness); } }
public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line) { if (markers == null) { return; } var markersInLine = markers.FindOverlappingSegments(line); foreach (var marker in markersInLine) { if (marker.EndOffset < textView.TextDocument.TextLength) { foreach (var r in VisualLineGeometryBuilder.GetRectsForSegment(textView, marker)) { var startPoint = r.BottomLeft; var endPoint = r.BottomRight; var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1); const double offset = 2.5; var count = Math.Max((int) ((endPoint.X - startPoint.X)/offset) + 1, 4); var geometry = new StreamGeometry(); using (var ctx = geometry.Open()) { ctx.BeginFigure(startPoint, false); foreach (var point in CreatePoints(startPoint, endPoint, offset, count)) { ctx.LineTo(point); } ctx.EndFigure(false); } drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry); break; } } } }
public BasicStyleCache(BasicStyle style) { if (style == null) return; Thickness = style.Thickness; HalfThickness = Thickness / 2.0; if (style.Fill != null) { FillBrush = ToBrush(style.Fill); } if (style.Stroke != null) { StrokeBrush = ToBrush(style.Stroke); StrokePen = new Pen(StrokeBrush, Thickness); } }
/// <inheritdoc/> public override void Draw(object dc, ArcShape arc, double dx, double dy, object db, object r) { if (!arc.IsFilled && !arc.IsStroked) { return; } var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(arc.Style.Fill); AM.Pen pen = ToPen(arc.Style, _scaleToPage); var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { var a = new WpfArc( Point2.FromXY(arc.Point1.X, arc.Point1.Y), Point2.FromXY(arc.Point2.X, arc.Point2.Y), Point2.FromXY(arc.Point3.X, arc.Point3.Y), Point2.FromXY(arc.Point4.X, arc.Point4.Y)); sgc.BeginFigure( new A.Point(a.Start.X + dx, a.Start.Y), arc.IsFilled); sgc.ArcTo( new A.Point(a.End.X + dx, a.End.Y + dy), new A.Size(a.Radius.Width, a.Radius.Height), 0.0, a.IsLargeArc, AM.SweepDirection.Clockwise); sgc.EndFigure(false); } _dc.DrawGeometry( arc.IsFilled ? brush : null, arc.IsStroked ? pen : null, sg); }
private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false); double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); sgc.CubicBezierTo( new A.Point(p1x, p1y), new A.Point(p2x, p2y), new A.Point(pt2.X, pt2.Y)); sgc.EndFigure(false); } _dc.DrawGeometry(null, pen, sg); } }
public override void DrawGeometry(Brush brush, Pen pen, Geometry geometry, Avalonia.Media.Matrix transform) { Direct2D1StreamGeometry platformGeometry = (Direct2D1StreamGeometry)geometry.PlatformImpl; using (TransformedGeometry d2dGeometry = new TransformedGeometry( this.factory, platformGeometry.Direct2DGeometry, transform.ToSharpDX())) { if (brush != null) { this.target.FillGeometry(d2dGeometry, brush.ToSharpDX(this.target)); } if (pen != null) { this.target.DrawGeometry( d2dGeometry, pen.Brush.ToSharpDX(this.target), (float)pen.Thickness); } } }
/// <inheritdoc/> public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r) { if (!arc.IsFilled && !arc.IsStroked) { return; } var _dc = dc as AM.DrawingContext; AM.IBrush brush = ToBrush(arc.Style.Fill); AM.Pen pen = ToPen(arc.Style, _scaleToPage); var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { var a = WpfArc.FromXArc(arc, dx, dy); sgc.BeginFigure( new A.Point(a.Start.X, a.Start.Y), arc.IsFilled); sgc.ArcTo( new A.Point(a.End.X, a.End.Y), new A.Size(a.Radius.Width, a.Radius.Height), 0.0, a.IsLargeArc, AM.SweepDirection.Clockwise); sgc.EndFigure(false); } _dc.DrawGeometry( arc.IsFilled ? brush : null, arc.IsStroked ? pen : null, sg); }
public virtual Rect GetRenderBounds(Pen pen, double tolerance, ToleranceType type) { return this.PlatformImpl.GetRenderBounds(pen, tolerance, type); }
/// <summary> /// Draws a line. /// </summary> /// <param name="pen">The stroke pen.</param> /// <param name="p1">The first point of the line.</param> /// <param name="p2">The second point of the line.</param> public void DrawLine(Pen pen, Point p1, Point p2) => _impl.DrawLine(pen, p1, p2);
private void DrawSpiroPoint(DrawingContext dc, IBrush brush, Pen pen, SpiroControlPoint point) { switch (point.Type) { case SpiroPointType.Corner: dc.FillRectangle(brush, new Rect(point.X - 3.5, point.Y - 3.5, 7, 7)); break; case SpiroPointType.G4: case SpiroPointType.G2: case SpiroPointType.Left: case SpiroPointType.Right: case SpiroPointType.End: case SpiroPointType.OpenContour: case SpiroPointType.EndOpenContour: var tm = Translate(point.X, point.Y); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, EndKnot); tt.Dispose(); break; } }
private PaintWrapper CreatePaint(Pen pen, Size targetSize) { var rv = CreatePaint(pen.Brush, targetSize); var paint = rv.Paint; paint.IsStroke = true; paint.StrokeWidth = (float)pen.Thickness; if (pen.StartLineCap == PenLineCap.Round) paint.StrokeCap = SKStrokeCap.Round; else if (pen.StartLineCap == PenLineCap.Square) paint.StrokeCap = SKStrokeCap.Square; else paint.StrokeCap = SKStrokeCap.Butt; if (pen.LineJoin == PenLineJoin.Miter) paint.StrokeJoin = SKStrokeJoin.Mitter; else if (pen.LineJoin == PenLineJoin.Round) paint.StrokeJoin = SKStrokeJoin.Round; else paint.StrokeJoin = SKStrokeJoin.Bevel; paint.StrokeMiter = (float)pen.MiterLimit; // TODO: Implement Dash Style support // //if (pen.DashStyle?.Dashes != null) //{ // var dashes = pen.DashStyle.Dashes; // if (dashes.Count > NativeBrush.MaxDashCount) // throw new NotSupportedException("Maximum supported dash count is " + NativeBrush.MaxDashCount); // brush.Brush->StrokeDashCount = dashes.Count; // for (int c = 0; c < dashes.Count; c++) // brush.Brush->StrokeDashes[c] = (float)dashes[c]; // brush.Brush->StrokeDashOffset = (float)pen.DashStyle.Offset; //} //if (brush->StrokeDashCount != 0) //{ // paint.setPathEffect(SkDashPathEffect::Create(brush->StrokeDashes, brush->StrokeDashCount, brush->StrokeDashOffset))->unref(); //} return rv; }
private IDisposable SetPen(Pen pen, Size destinationSize) { if (pen.DashStyle != null) { if (pen.DashStyle.Dashes != null && pen.DashStyle.Dashes.Count > 0) { var cray = pen.DashStyle.Dashes.ToArray(); _context.SetDash(cray, pen.DashStyle.Offset); } } _context.LineWidth = pen.Thickness; _context.MiterLimit = pen.MiterLimit; // Line caps and joins are currently broken on Cairo. I've defaulted them to sensible defaults for now. // Cairo does not have StartLineCap, EndLineCap, and DashCap properties, whereas Direct2D does. // TODO: Figure out a solution for this. _context.LineJoin = Cairo.LineJoin.Miter; _context.LineCap = Cairo.LineCap.Butt; if (pen.Brush == null) return Disposable.Empty; return SetBrush(pen.Brush, destinationSize); }
public abstract void DrawLine(Pen pen, Point point0, Point point1);
public abstract void DrawGeometry(Brush brush, Pen pen, Geometry geometry);
/// <summary> /// Draws the outline of a rectangle. /// </summary> /// <param name="pen">The pen.</param> /// <param name="rect">The rectangle bounds.</param> /// <param name="cornerRadius">The corner radius.</param> public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0.0f) => _impl.DrawRectangle(pen, rect, cornerRadius);
/// <summary> /// Draws a line. /// </summary> /// <param name="pen">The stroke pen.</param> /// <param name="p1">The first point of the line.</param> /// <param name="p2">The second point of the line.</param> public void DrawLine(Pen pen, Point p1, Point p2) { if (pen != null) { var size = new Rect(p1, p2).Size; using (var d2dBrush = CreateBrush(pen.Brush, size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget)) { if (d2dBrush.PlatformBrush != null) { _renderTarget.DrawLine( p1.ToSharpDX(), p2.ToSharpDX(), d2dBrush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <summary> /// Draws the outline of a rectangle. /// </summary> /// <param name="pen">The pen.</param> /// <param name="rect">The rectangle bounds.</param> /// <param name="cornerRadius">The corner radius.</param> public void DrawRectangle(Pen pen, Rect rect, float cornerRadius) { using (var brush = CreateBrush(pen.Brush, rect.Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget)) { if (brush.PlatformBrush != null) { if (cornerRadius == 0) { _renderTarget.DrawRectangle( rect.ToDirect2D(), brush.PlatformBrush, (float)pen.Thickness, d2dStroke); } else { _renderTarget.DrawRoundedRectangle( new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius }, brush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
/// <summary> /// Draws a geometry. /// </summary> /// <param name="brush">The fill brush.</param> /// <param name="pen">The stroke pen.</param> /// <param name="geometry">The geometry.</param> public void DrawGeometry(IBrush brush, Pen pen, Avalonia.Media.Geometry geometry) { if (brush != null) { using (var d2dBrush = CreateBrush(brush, geometry.Bounds.Size)) { if (d2dBrush.PlatformBrush != null) { var impl = (GeometryImpl)geometry.PlatformImpl; _renderTarget.FillGeometry(impl.Geometry, d2dBrush.PlatformBrush); } } } if (pen != null) { using (var d2dBrush = CreateBrush(pen.Brush, geometry.GetRenderBounds(pen.Thickness).Size)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget)) { if (d2dBrush.PlatformBrush != null) { var impl = (GeometryImpl)geometry.PlatformImpl; _renderTarget.DrawGeometry(impl.Geometry, d2dBrush.PlatformBrush, (float)pen.Thickness, d2dStroke); } } } }
public abstract void DrawRoundedRectangle(Brush brush, Pen pen, Rect rectangle, double radiusX, double radiusY);
public abstract void DrawRectangle(Brush brush, Pen pen, Rect rectangle);
protected internal override void OnRender(DrawingContext drawingContext) { Rect brushRect = new Rect(new Size(this.ActualWidth, this.ActualHeight)); Rect penRect = brushRect; Pen pen = null; if (this.BorderBrush != null && !this.BorderThickness.IsEmpty) { pen = new Pen(this.BorderBrush, this.BorderThickness.Left); double penOffset = -(pen.Thickness / 2); brushRect.Inflate(-pen.Thickness, -pen.Thickness); penRect.Inflate(penOffset, penOffset); } if (this.CornerRadius.TopLeft > 0 || this.CornerRadius.BottomLeft > 0) { drawingContext.DrawRoundedRectangle( this.Background, pen, brushRect, this.CornerRadius.TopLeft, this.CornerRadius.BottomLeft); } else { if (this.Background != null) { drawingContext.DrawRectangle(this.Background, null, brushRect); } if (pen != null) { drawingContext.DrawRectangle(null, pen, penRect); } } }
/// <summary> /// Draws a geometry. /// </summary> /// <param name="brush">The fill brush.</param> /// <param name="pen">The stroke pen.</param> /// <param name="geometry">The geometry.</param> public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) { var impl = geometry.PlatformImpl as StreamGeometryImpl; var oldMatrix = Transform; Transform = impl.Transform * Transform; if (brush != null) { _context.AppendPath(impl.Path); using (var b = SetBrush(brush, geometry.Bounds.Size)) { _context.FillRule = impl.FillRule == FillRule.EvenOdd ? Cairo.FillRule.EvenOdd : Cairo.FillRule.Winding; if (pen != null) _context.FillPreserve(); else _context.Fill(); } } Transform = oldMatrix; if (pen != null) { _context.AppendPath(impl.Path); using (var p = SetPen(pen, geometry.Bounds.Size)) { _context.Stroke(); } } }
public Rect GetRenderBounds(Pen pen) { return this.GetRenderBounds(pen, StandardFlatteningTolerance, ToleranceType.Absolute); }
public abstract void DrawGeometry(Brush brush, Pen pen, Geometry geometry, Matrix transform);
/// <summary> /// Draws a line. /// </summary> /// <param name="pen">The stroke pen.</param> /// <param name="p1">The first point of the line.</param> /// <param name="p1">The second point of the line.</param> public void DrawLine(Pen pen, Point p1, Point p2) { var size = new Rect(p1, p2).Size; using (var p = SetPen(pen, size)) { _context.MoveTo(p1.ToCairo()); _context.LineTo(p2.ToCairo()); _context.Stroke(); } }
private static A.Point DrawLineArrowInternal(AM.DrawingContext dc, AM.Pen pen, AM.IBrush brush, float x, float y, double angle, ArrowStyle style) { A.Point pt = default(A.Point); var rt = APAZ.MatrixHelper.Rotation(angle, new A.Vector(x, y)); double rx = style.RadiusX; double ry = style.RadiusY; double sx = 2.0 * rx; double sy = 2.0 * ry; switch (style.ArrowType) { default: case ArrowType.None: { pt = new A.Point(x, y); } break; case ArrowType.Rectangle: { pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y)); var rect = new Rect2(x - sx, y - ry, sx, sy); using (var d = dc.PushPreTransform(rt)) { DrawRectangleInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect); } } break; case ArrowType.Ellipse: { pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y)); using (var d = dc.PushPreTransform(rt)) { var rect = new Rect2(x - sx, y - ry, sx, sy); DrawEllipseInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect); } } break; case ArrowType.Arrow: { var pts = new A.Point[] { new A.Point(x, y), new A.Point(x - (float)sx, y + (float)sy), new A.Point(x, y), new A.Point(x - (float)sx, y - (float)sy), new A.Point(x, y) }; pt = APAZ.MatrixHelper.TransformPoint(rt, pts[0]); var p11 = APAZ.MatrixHelper.TransformPoint(rt, pts[1]); var p21 = APAZ.MatrixHelper.TransformPoint(rt, pts[2]); var p12 = APAZ.MatrixHelper.TransformPoint(rt, pts[3]); var p22 = APAZ.MatrixHelper.TransformPoint(rt, pts[4]); DrawLineInternal(dc, pen, style.IsStroked, ref p11, ref p21); DrawLineInternal(dc, pen, style.IsStroked, ref p12, ref p22); } break; } return(pt); }
/// <summary> /// Draws the outline of a rectangle. /// </summary> /// <param name="pen">The pen.</param> /// <param name="rect">The rectangle bounds.</param> public void DrawRectangle(Pen pen, Rect rect, float cornerRadius) { using (var p = SetPen(pen, rect.Size)) { _context.Rectangle(rect.ToCairo ()); _context.Stroke(); } }
private static void DrawRectangleInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isStroked && !isFilled) { return; } var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { dc.FillRectangle(brush, r); } if (isStroked) { dc.DrawRectangle(pen, r); } }
/// <summary> /// Create the actual Avalonia pen instance. /// </summary> public Pen CreatePen() { var pen = new Pen(_brush, _width, _dashStyle); return pen; }
private static void DrawEllipseInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isFilled && !isStroked) { return; } var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height); var g = new AM.EllipseGeometry(r); dc.DrawGeometry( isFilled ? brush : null, isStroked ? pen : null, g); }
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0) { using (var paint = CreatePaint(pen, rect.Size)) { var rc = rect.ToSKRect(); if (cornerRadius == 0) { Canvas.DrawRect(rc, paint.Paint); } else { Canvas.DrawRoundRect(rc, cornerRadius, cornerRadius, paint.Paint); } } }
private PaintWrapper CreatePaint(Pen pen, Size targetSize) { var rv = CreatePaint(pen.Brush, targetSize); var paint = rv.Paint; paint.IsStroke = true; paint.StrokeWidth = (float)pen.Thickness; if (pen.StartLineCap == PenLineCap.Round) paint.StrokeCap = SKStrokeCap.Round; else if (pen.StartLineCap == PenLineCap.Square) paint.StrokeCap = SKStrokeCap.Square; else paint.StrokeCap = SKStrokeCap.Butt; if (pen.LineJoin == PenLineJoin.Miter) paint.StrokeJoin = SKStrokeJoin.Mitter; else if (pen.LineJoin == PenLineJoin.Round) paint.StrokeJoin = SKStrokeJoin.Round; else paint.StrokeJoin = SKStrokeJoin.Bevel; paint.StrokeMiter = (float)pen.MiterLimit; if (pen.DashStyle?.Dashes != null && pen.DashStyle.Dashes.Count > 0) { var pe = SKPathEffect.CreateDash( pen.DashStyle?.Dashes.Select(x => (float)x).ToArray(), (float)pen.DashStyle.Offset); paint.PathEffect = pe; rv.AddDisposable(pe); } return rv; }
/// <summary> /// Draws a geometry. /// </summary> /// <param name="brush">The fill brush.</param> /// <param name="pen">The stroke pen.</param> /// <param name="geometry">The geometry.</param> public void DrawGeometry(IBrush brush, Pen pen, Geometry geometry) => _impl.DrawGeometry(brush, pen, geometry);
private void DrawSpiroKnot(DrawingContext dc, IBrush brush, Pen pen, SpiroKnot knot) { switch (knot.Type) { case SpiroPointType.Corner: dc.FillRectangle(brush, new Rect(knot.X - 3.5, knot.Y - 3.5, 7, 7)); break; case SpiroPointType.G4: FillEllipse(dc, brush, new GuidePoint(knot.X, knot.Y), 3.5, 3.5); break; case SpiroPointType.G2: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var rt = dc.PushPreTransform(rm); dc.FillRectangle(brush, new Rect(knot.X - 1.5, knot.Y - 3.5, 3, 7)); rt.Dispose(); } break; case SpiroPointType.Left: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(brush, null, LeftKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.Right: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(brush, null, RightKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.End: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, EndKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.OpenContour: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, OpenContourKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.EndOpenContour: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, EndOpenContourKnot); tt.Dispose(); rt.Dispose(); } break; } }