public void DrawLine(Pen pen, Point p1, Point p2) { using (var brush = CreateBrush(pen, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y)))) MethodTable.Instance.DrawLine(Handle, brush.Brush, (float) p1.X, (float) p1.Y, (float) p2.X, (float) p2.Y); }
public override void Render(IDrawingContext context) { double range = this.Bounds.Width/(MaxValue - MinValue); Pen backgroundPen = new Pen(Brushes.Black, 5); Brush TextBrush = Brushes.Black; double step = 0.5; int countValue = (int) (range / step); double stepX = this.Bounds.Width/countValue; for (int i = 0; i < countValue; i++) { var x = i* stepX; // context.DrawLine(backgroundPen, new Point(x, 0), new Point(x, this.Bounds.Height)); context.DrawText(TextBrush, new Point(x, 2),new FormattedText((i*step).ToString(), "Verdana", 22,FontStyle.Normal, TextAlignment.Center,FontWeight.Normal)); } //context.DrawLine(foreground, new Point(100, 100), new Point(200, 200)); /* var AxisMajorBrush = Brushes.Black; context.DrawRectange(new Pen(AxisMajorBrush,2),new Rect(new Point(10, 0), new Point(10, Height))); var borderBrush = Brushes.AliceBlue; var borderThickness = 3; var cornerRadius = 2; var rect = new Rect(Bounds.Size).Deflate(new Thickness(borderThickness)); context.FillRectange(backgroundPen.Brush, rect, cornerRadius); if (borderBrush != null && borderThickness > 0) { context.DrawRectange(new Pen(borderBrush, borderThickness), 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="p1">The second point of the line.</param> public void DrawLine(Pen pen, Point p1, Point p2) { var size = new Rect(p1, p2).Size; SetPen(pen, size); _context.MoveTo(p1.ToCairo()); _context.LineTo(p2.ToCairo()); _context.Stroke(); }
public void DrawGeometry(Brush brush, Pen pen, Geometry geometry) { var impl = ((StreamGeometryImpl) geometry.PlatformImpl); var size = geometry.Bounds.Size; using(var fill = brush!=null?CreateBrush(brush, size):null) using (var stroke = pen?.Brush != null ? CreateBrush(pen, size) : null) { MethodTable.Instance.DrawGeometry(Handle, impl.EffectivePath, fill != null ? fill.Brush : null, stroke != null ? stroke.Brush : null, impl.FillRule == FillRule.EvenOdd); } }
public void DrawGeometry(Brush brush, Pen pen, Geometry geometry) { var impl = ((StreamGeometryImpl) geometry.PlatformImpl); var oldTransform = Transform; if (!impl.Transform.IsIdentity) Transform = impl.Transform*Transform; var size = geometry.Bounds.Size; using(var fill = brush!=null?CreateBrush(brush, size):null) using (var stroke = pen?.Brush != null ? CreateBrush(pen, size) : null) { MethodTable.Instance.DrawGeometry(Handle, impl.Path.Handle, fill != null ? fill.Brush : null, stroke != null ? stroke.Brush : null); } Transform = oldTransform; }
/// <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)) { _renderTarget.DrawLine( p1.ToSharpDX(), p2.ToSharpDX(), d2dBrush.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(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry) { if (brush != null) { using (var d2dBrush = brush.ToDirect2D(this.renderTarget)) { GeometryImpl impl = (GeometryImpl)geometry.PlatformImpl; this.renderTarget.FillGeometry(impl.Geometry, d2dBrush); } } if (pen != null) { using (var d2dBrush = pen.Brush.ToDirect2D(this.renderTarget)) { GeometryImpl impl = (GeometryImpl)geometry.PlatformImpl; this.renderTarget.DrawGeometry(impl.Geometry, d2dBrush, (float)pen.Thickness); } } }
/// <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(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry) { if (brush != null) { using (SharpDX.Direct2D1.SolidColorBrush d2dBrush = this.Convert(brush)) { GeometryImpl impl = (GeometryImpl)geometry.PlatformImpl; this.renderTarget.FillGeometry(impl.Geometry, d2dBrush); } } if (pen != null) { using (SharpDX.Direct2D1.SolidColorBrush d2dBrush = this.Convert(pen.Brush)) { GeometryImpl impl = (GeometryImpl)geometry.PlatformImpl; this.renderTarget.DrawGeometry(impl.Geometry, d2dBrush, (float)pen.Thickness); } } }
private void SetPen(Pen pen) { this.SetBrush(pen.Brush); this.context.LineWidth = pen.Thickness; }
/// <summary> /// Draws the outline of a rectangle. /// </summary> /// <param name="pen">The pen.</param> /// <param name="rect">The rectangle bounds.</param> public void DrawRectange(Pen pen, Rect rect, float cornerRadius) { this.SetPen(pen); this.context.Rectangle(rect.ToCairo()); this.context.Stroke(); }
NativeBrushContainer CreateBrush(Pen pen, Size targetSize) { var brush = CreateBrush(pen.Brush, targetSize); brush.Brush->Stroke = true; brush.Brush->StrokeThickness = (float)pen.Thickness; brush.Brush->StrokeLineCap = pen.StartLineCap; brush.Brush->StrokeLineJoin = pen.LineJoin; brush.Brush->StrokeMiterLimit = (float)pen.MiterLimit; 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; } return brush; }
public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0) { using (var brush = CreateBrush(pen, rect.Size)) { var rc = SkRect.FromRect(rect); MethodTable.Instance.DrawRectangle(Handle, brush.Brush, ref rc, 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="p1">The second point of the line.</param> public void DrawLine(Pen pen, Perspex.Point p1, Perspex.Point p2) { this.SetBrush(pen.Brush); this.context.LineWidth = pen.Thickness; this.context.MoveTo(p1.ToCairo()); this.context.LineTo(p2.ToCairo()); this.context.Stroke(); }
public override void Render(DrawingContext context) { var geometry = RenderedGeometry; if (geometry != null) { var pen = new Pen(Stroke, StrokeThickness, new DashStyle(StrokeDashArray), StrokeDashCap, StrokeStartLineCap, StrokeEndLineCap); context.DrawGeometry(Fill, pen, geometry); } }
/// <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(Brush brush, Pen pen, Geometry geometry) => _impl.DrawGeometry(brush, pen, geometry);
/// <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, Perspex.Point p1, Perspex.Point p2) { if (pen != null) { using (var d2dBrush = pen.Brush.ToDirect2D(this.renderTarget)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(this.renderTarget)) { this.renderTarget.DrawLine( p1.ToSharpDX(), p2.ToSharpDX(), d2dBrush, (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(Brush 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(); } } }
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); }
/// <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(Perspex.Media.Brush brush, Pen pen, Perspex.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 override void Render(IDrawingContext context) { var geometry = this.RenderedGeometry; if (geometry != null) { var pen = new Pen(this.Stroke, this.StrokeThickness, this.StrokeDashArray); context.DrawGeometry(this.Fill, pen, geometry); } }
/// <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(Perspex.Media.Brush brush, Perspex.Media.Pen pen, Perspex.Media.Geometry geometry) { // TODO: Implement }
/// <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(Brush brush, Pen pen, Geometry geometry) { var impl = geometry.PlatformImpl as StreamGeometryImpl; using (var pop = PushTransform(impl.Transform)) { _context.AppendPath(impl.Path); if (brush != null) { using (var b = SetBrush(brush, geometry.Bounds.Size)) { if (pen != null) _context.FillPreserve(); else _context.Fill(); } } } if (pen != null) { using (var p = SetPen(pen, geometry.Bounds.Size)) { _context.Stroke(); } } }
/// <summary> /// Create the actual Perspex pen instance. /// </summary> public Pen CreatePen() { var pen = new Pen(_brush, _width, _dashStyle); return pen; }
/// <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> /// /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="rect"></param> private static void DrawEllipseInternal( IDrawingContext dc, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isFilled && !isStroked) return; var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height); var g = new EllipseGeometry(r); dc.DrawGeometry( isFilled ? brush : null, isStroked ? pen : null, g); // TODO: g.Dispose(); }
/// <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(); } }
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="p0"></param> /// <param name="p1"></param> private static void DrawLineInternal( IDrawingContext dc, Pen pen, bool isStroked, ref Point p0, ref Point p1) { if (isStroked) { dc.DrawLine(pen, p0, p1); } }
/// <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);
/// <summary> /// /// </summary> /// <param name="dc"></param> /// <param name="brush"></param> /// <param name="pen"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="rect"></param> private static void DrawRectangleInternal( IDrawingContext dc, Brush brush, Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isStroked && !isFilled) return; var r = new Rect(rect.X, rect.Y, rect.Width, rect.Height); if (isFilled) { dc.FillRectangle(brush, r); } if (isStroked) { dc.DrawRectangle(pen, r); } }
/// <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> /// /// </summary> /// <param name="dc"></param> /// <param name="stroke"></param> /// <param name="rect"></param> /// <param name="offsetX"></param> /// <param name="offsetY"></param> /// <param name="cellWidth"></param> /// <param name="cellHeight"></param> /// <param name="isStroked"></param> private void DrawGridInternal( IDrawingContext dc, 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 Point( _scaleToPage(x), _scaleToPage(oy)); var p1 = new Point( _scaleToPage(x), _scaleToPage(ey)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } for (double y = sy; y < ey; y += cellHeight) { var p0 = new Point( _scaleToPage(ox), _scaleToPage(y)); var p1 = new Point( _scaleToPage(ex), _scaleToPage(y)); DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1); } }
/// <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 DrawRectange(Pen pen, Rect rect, float cornerRadius) { using (var brush = pen.Brush.ToDirect2D(this.renderTarget)) using (var d2dStroke = pen.ToDirect2DStrokeStyle(this.renderTarget)) { this.renderTarget.DrawRoundedRectangle( new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius }, brush, (float)pen.Thickness, d2dStroke); } }
/// <summary> /// /// </summary> /// <param name="style"></param> /// <param name="scale"></param> /// <returns></returns> private Pen ToPen(BaseStyle style, Func<double, float> scale) { var lineCap = default(PenLineCap); var dashStyle = default(DashStyle); switch (style.LineCap) { case LineCap.Flat: lineCap = PenLineCap.Flat; break; case LineCap.Square: lineCap = PenLineCap.Square; break; case LineCap.Round: lineCap = PenLineCap.Round; break; } if (style.Dashes != null) { dashStyle = new DashStyle( style.Dashes, style.DashOffset); } var pen = new Pen( ToSolidBrush(style.Stroke), scale(style.Thickness / _state.Zoom), dashStyle, lineCap, lineCap, lineCap); return pen; }