public override void DrawLayer(SKCanvas canvas, Matrix3X3 parentMatrix, byte parentAlpha) { LottieLog.BeginSection("CompositionLayer.Draw"); canvas.Save(); RectExt.Set(ref _newClipRect, 0, 0, LayerModel.PreCompWidth, LayerModel.PreCompHeight); parentMatrix.MapRect(ref _newClipRect); for (var i = _layers.Count - 1; i >= 0; i--) { var nonEmptyClip = true; if (!_newClipRect.IsEmpty) { canvas.ClipRect(_newClipRect); //nonEmptyClip = canvas.ClipRect(_newClipRect); //TODO } if (nonEmptyClip) { var layer = _layers[i]; layer.Draw(canvas, parentMatrix, parentAlpha); } } canvas.Restore(); LottieLog.EndSection("CompositionLayer.Draw"); }
/// <summary> /// Draws the LimitLines associated with this axis to the screen. /// </summary> /// <param name="c"></param> public virtual void RenderLimitLines(SKCanvas c) { var limitLines = XAxis.LimitLines; if (limitLines == null || limitLines.Count <= 0) { return; } for (int i = 0; i < limitLines.Count; i++) { LimitLine l = limitLines[i]; if (!l.IsEnabled) { continue; } int clipRestoreCount = c.Save(); c.ClipRect(ViewPortHandler.ContentRect.InsetHorizontally(l.LineWidth)); var position = Trasformer.PointValueToPixel(l.Limit, 0.0f); RenderLimitLineLine(c, l, position); RenderLimitLineLabel(c, l, position, 2.0f + l.YOffset); c.RestoreToCount(clipRestoreCount); } }
public void Render(SKCanvas canvas, SKRect rect) { if (axes == null) { AutoAxis(); } layout.Tighten(rect); axes.SetRect(layout.data); if (layout.display) { layout.RenderDebuggingGuides(canvas); } // update the scale, apply mouse adjustments, then update the scale again PlotSettings.Axes axesAfterMouse = new PlotSettings.Axes(axes); axesAfterMouse.PanPixels(mouse.leftDownDelta); axesAfterMouse.ZoomPixels(mouse.rightDownDelta); axesAfterMouse.SetRect(layout.data); // draw inside a clipping rectangle canvas.Save(); canvas.ClipRect(layout.data); for (int i = 0; i < plottables.Count; i++) { plottables[i].Render(canvas, axesAfterMouse); } canvas.Restore(); axisLabels.Render(layout, canvas); axisScales.Render(layout, axesAfterMouse, canvas); }
public void Render(SKCanvas canvas, SKSize figureSize, Plot onlySubplot = null) { stopwatchRender.Restart(); if (onlySubplot is null) { canvas.Clear(backgroundColor); } var plotsToRender = subplots.Where(p => (onlySubplot is null) || onlySubplot.axes.x == p.axes.x || onlySubplot.axes.y == p.axes.y); foreach (Plot subplot in plotsToRender) { SKRect plotRect = SubplotRect(figureSize, subplot); canvas.Save(); canvas.ClipRect(plotRect); canvas.Clear(backgroundColor); subplot.Render(canvas, plotRect); canvas.Restore(); } stopwatchRender.Stop(); }
/** * <summary>Renders the contents into the specified object.</summary> * <param name="renderContext">Rendering context.</param> * <param name="renderSize">Rendering canvas size.</param> * <param name="renderObject">Rendering object.</param> */ public void Render(SKCanvas renderContext, SKSize renderSize, SKPath renderObject) { if (IsRootLevel() && ClearContext) { renderContext.ClipRect(SKRect.Create(renderSize)); using (var paint = new SKPaint { Color = SKColors.White, Style = SKPaintStyle.Fill }) { renderContext.DrawRect(SKRect.Create(renderSize), paint); } } try { this.renderContext = renderContext; this.canvasSize = renderSize; this.renderObject = renderObject; // Scan this level for rendering! MoveStart(); while (MoveNext()) { ; } } finally { this.renderContext = null; this.canvasSize = contextSize; this.renderObject = null; } }
public void Render(SKSurface surface) { if (surface is null) { throw new ArgumentNullException(nameof(surface)); } SKCanvas canvas = surface.Canvas; canvas.Translate(1, 1); canvas.Clear(SKColors.White); canvas.ClipRect(new SKRect(0, 0, _width + 2, _height + 2), SKClipOperation.Intersect, false); foreach (IBoardRenderer renderer in _boardRenderers) { if (!renderer.Enabled) { continue; } canvas.Save(); renderer.Render(surface, _width, _height); canvas.Restore(); } }
private void BeginClip(SKCanvas c, float x, float y, float width, float height) { var rect = new SKRect(x, y, x + width, y + height); c.Save(); c.ClipRect(Abs(ref rect)); }
/** * <summary>Renders the contents into the specified object.</summary> * <param name="renderContext">Rendering context.</param> * <param name="renderSize">Rendering canvas size.</param> * <param name="renderObject">Rendering object.</param> */ public void Render(SKCanvas renderContext, SKSize renderSize, SKPath renderObject) { if (IsRootLevel() && ClearContext) { renderContext.ClipRect(SKRect.Create(renderSize)); renderContext.DrawRect(SKRect.Create(renderSize), paintWhiteBackground); } try { this.renderContext = renderContext; this.canvasSize = renderSize; this.renderObject = renderObject; // Scan this level for rendering! MoveStart(); while (MoveNext()) { ; } } finally { this.renderContext = null; this.canvasSize = contextSize; this.renderObject = null; } }
private void SideBarCanvas_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); // clear our background SKRect backgroundRect = new SKRect(0, 0, info.Width - buttonSize, info.Height); using (new SKAutoCanvasRestore(canvas)) { canvas.ClipRect(GetPreviousButtonRect(), SKClipOperation.Difference); canvas.DrawRect(backgroundRect, new SKPaint() { Color = SKColors.White }); } // draw our button var nextButtonRect = GetNextButtonRect(); canvas.DrawRect(nextButtonRect, new SKPaint() { Color = SKColors.White }); var previousButtonRect = GetPreviousButtonRect(); var arrowSize = 7 * (float)density; // draw our arrows - next button SKPath nextArrowPath = new SKPath(); nextArrowPath.MoveTo(nextButtonRect.MidX - (arrowSize / 2), nextButtonRect.MidY - (arrowSize / 2)); nextArrowPath.LineTo(nextButtonRect.MidX + (arrowSize / 2), nextButtonRect.MidY); nextArrowPath.LineTo(nextButtonRect.MidX - (arrowSize / 2), nextButtonRect.MidY + (arrowSize / 2)); nextArrowPath.LineTo(nextButtonRect.MidX - (arrowSize / 2), nextButtonRect.MidY - (arrowSize / 2)); nextArrowPath.Close(); canvas.DrawPath(nextArrowPath, new SKPaint() { Color = SKColors.Black }); // draw our arrows - previous button SKPath previousArrowPath = new SKPath(); previousArrowPath.MoveTo(previousButtonRect.MidX + (arrowSize / 2), previousButtonRect.MidY - (arrowSize / 2)); previousArrowPath.LineTo(previousButtonRect.MidX - (arrowSize / 2), previousButtonRect.MidY); previousArrowPath.LineTo(previousButtonRect.MidX + (arrowSize / 2), previousButtonRect.MidY + (arrowSize / 2)); previousArrowPath.LineTo(previousButtonRect.MidX + (arrowSize / 2), previousButtonRect.MidY - (arrowSize / 2)); previousArrowPath.Close(); canvas.DrawPath(previousArrowPath, new SKPaint() { Color = SKColors.White }); DrawPageIndicators(canvas, backgroundRect); }
internal void SetClip(SvgVisualElement svgVisualElement, SKRect sKRectBounds) { var clip = svgVisualElement.Clip; if (!string.IsNullOrEmpty(clip) && clip.StartsWith("rect(")) { clip = clip.Trim(); var offsets = (from o in clip.Substring(5, clip.Length - 6).Split(',') select float.Parse(o.Trim(), NumberStyles.Any, CultureInfo.InvariantCulture)).ToList(); var clipRect = SKRect.Create( sKRectBounds.Left + offsets[3], sKRectBounds.Top + offsets[0], sKRectBounds.Width - (offsets[3] + offsets[1]), sKRectBounds.Height - (offsets[2] + offsets[0])); _skCanvas.ClipRect(clipRect, SKClipOperation.Intersect); } }
public void Draw(SKCanvas canvas) { if (!IsVisible) { return; } int canvasState = int.MaxValue; var renderBounds = RenderBounds; if (IsScaled || IsClippedToBounds) { canvasState = canvas.Save(); } if (IsScaled) { canvas.Translate((float)renderBounds.Center.X, (float)renderBounds.Center.Y); canvas.Scale((float)Scale, (float)Scale); canvas.Translate((float)-renderBounds.Center.X, (float)-renderBounds.Center.Y); } if (IsClippedToBounds) { canvas.ClipRect(renderBounds.ToSKRect()); } if (IsOpaque) { InternalDraw(canvas); } else { using (var surface = GetSKContainer().CreateOpacitySurface()) { if (IsClippedToBounds) { surface.Canvas.ClipRect(renderBounds.ToSKRect()); } InternalDraw(surface.Canvas); using (var paint = new SKPaint()) { paint.Color = new SKColor(255, 255, 255, (byte)(255.0 * Opacity)); canvas.DrawImage(surface.Snapshot(), 0, 0, paint); } } } if (canvasState != int.MaxValue) { canvas.RestoreToCount(canvasState); } }
public static void drawClockPlayground(SKCanvas canvas, Context context, SKColor numbersColor, SKColor darkHandsColor, SKColor lightHandColor, SKColor rimColor, SKColor tickColor, SKColor faceColor) { // Local Colors SKColor color4 = Helpers.ColorFromArgb(255, 255, 255, 255); SKColor color2 = Helpers.ColorFromArgb(255, 56, 95, 117); SKColor color5 = Helpers.ColorFromArgb(255, 22, 216, 217); SKColor color = Helpers.ColorFromArgb(255, 255, 0, 0); SKColor color3 = Helpers.ColorFromArgb(255, 74, 74, 74); // Symbol var symbolRect = new SKRect(90f, 30f, 348f, 288f); canvas.Save(); canvas.ClipRect(symbolRect); canvas.Translate(symbolRect.Left, symbolRect.Top); var symbolTargetRect = new SKRect(0f, 0f, symbolRect.Width, symbolRect.Height); StyleKitName.drawClock(canvas, context, symbolTargetRect, ResizingBehavior.Stretch, color5, color2, color, color2, tickColor, faceColor, 11f, 45f, 39f); canvas.Restore(); // Symbol 2 var symbol2Rect = new SKRect(348f, 33f, 601f, 286f); canvas.Save(); canvas.ClipRect(symbol2Rect); canvas.Translate(symbol2Rect.Left, symbol2Rect.Top); var symbol2TargetRect = new SKRect(0f, 0f, symbol2Rect.Width, symbol2Rect.Height); StyleKitName.drawClock(canvas, context, symbol2TargetRect, ResizingBehavior.Stretch, numbersColor, darkHandsColor, lightHandColor, rimColor, tickColor, faceColor, 7f, 43f, 3f); canvas.Restore(); // Symbol 3 var symbol3Rect = new SKRect(611f, 33f, 871f, 293f); canvas.Save(); canvas.ClipRect(symbol3Rect); canvas.Translate(symbol3Rect.Left, symbol3Rect.Top); var symbol3TargetRect = new SKRect(0f, 0f, symbol3Rect.Width, symbol3Rect.Height); StyleKitName.drawClock(canvas, context, symbol3TargetRect, ResizingBehavior.Stretch, color4, color4, color5, color4, color4, color3, 16f, 6f, 43f); canvas.Restore(); }
/// <summary> /// Clips the current drawing session. /// </summary> /// <param name="bounds">The bounds.</param> /// <param name="cornerRadius">The corner radius.</param> public void ClipRect(Rect bounds, CornerRadius cornerRadius) { if (cornerRadius.TopLeft > 0) { _canvas.ClipRoundRect(new SKRoundRect(bounds.ToSKRect(), cornerRadius.TopLeft.ToFloat(), cornerRadius.TopLeft.ToFloat()), SKClipOperation.Intersect, false); } else { _canvas.ClipRect(bounds.ToSKRect(), SKClipOperation.Intersect, false); } }
public void DrawHole(SKCanvas canvas, SKRect rect, float scale = 1) { if (Roundness <= 0) { canvas.ClipRect(new SKRect(rect.Left, rect.Top, rect.Right, rect.Bottom), SKClipOperation.Difference); } else { canvas.ClipRoundRect( new SKRoundRect(new SKRect(rect.Left, rect.Top, rect.Right, rect.Bottom), Roundness, Roundness), SKClipOperation.Difference); } }
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args) { SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; canvas.Clear(); SKRect rect = new SKRect(50, 50, info.Width - 50, info.Height - 50); canvas.ClipRect(rect); canvas.DrawRect(rect, framePaint); }
public void Render(SKCanvas canvas, SKRect plotRect) { // update plot-level layout with the latest plot dimensions layout.Update(plotRect); if (!axes.x.isValid || !axes.y.isValid) { AutoAxis(); } axes.SetDataRect(layout.dataRect); axes2.SetDataRect(layout.dataRect); // draw the graphics yTicks.Generate(axes.y.low, axes.y.high, layout.dataRect); y2Ticks.Generate(axes2.y.low, axes2.y.high, layout.dataRect); xTicks.Generate(axes.x.low, axes.x.high, layout.dataRect); if (yTicks.biggestTickLabelSize.Width > layout.yScaleWidth) { Debug.WriteLine("increasing Y scale width to prevent overlapping with label Y label"); layout.yScaleWidth = yTicks.biggestTickLabelSize.Width; layout.Update(plotRect); } var fillPaint = new SKPaint(); fillPaint.Color = SKColor.Parse("#FFFFFF"); //fillPaint.Color = Tools.RandomColor(); // useful for assessing when plots are redrawn canvas.DrawRect(layout.dataRect, fillPaint); yTicks.Render(canvas, axes); y2Ticks.Render(canvas, axes2); xTicks.Render(canvas, axes); canvas.Save(); canvas.ClipRect(axes.GetDataRect()); foreach (var primaryPlottable in GetPlottableList(false)) { primaryPlottable.Render(canvas, axes); } foreach (var secondaryPlottable in GetPlottableList(true)) { secondaryPlottable.Render(canvas, axes2); } canvas.Restore(); //RenderLayoutDebug(canvas); RenderLabels(canvas); }
public override void OnDraw(SKCanvas canvas, Attributes ignoreAttributes, Drawable?until) { if (until != null && this == until) { return; } if (MarkerClipRect != null) { canvas.ClipRect(MarkerClipRect.Value, SKClipOperation.Intersect); } MarkerElementDrawable?.Draw(canvas, ignoreAttributes, until); }
private void DrawPlottables(SKCanvas canvas) { canvas.Save(); canvas.ClipRect(axes.GetDataRect()); foreach (var primaryPlottable in GetPlottablesByAxis(false)) { primaryPlottable.Render(canvas, axes); } foreach (var secondaryPlottable in GetPlottablesByAxis(true)) { secondaryPlottable.Render(canvas, axes2); } canvas.Restore(); }
public void DrawMultilineText(AbsoluteRectangle box, Typeface typeface, string text, IBrush brush, float lineHeight = 1.2f) { var paint = typeface.ToSKPaint(brush); canvas.Save(); canvas.ClipRect(box.ToSKRect()); var lines = splitLines(text, paint, box.Width); for (var i = 0; i < lines.Length; i++) { DrawText(new AbsolutePoint(box.Location.X, box.Location.Y + (i + 1) * typeface.Size * lineHeight), typeface, lines[i].text, brush); } canvas.Restore(); }
private void DrawValues(SKRect rect, SKCanvas canvas) { if (BarValues != null && BarValues.Count <= 0) { return; } var delta = rect.Width / (BarValues.Count); _foregroundPaint.StrokeWidth = delta / 1.5f; var xStart = delta / 2f; // draw start and end line if (ShowFirstAndLastLines) { var yTop = rect.Height + 1; var yBottom = rect.Height + _yMargin; var LeftTop = new SKPoint(xStart, yTop); var LeftBottom = new SKPoint(xStart, yBottom); var RightTop = new SKPoint(rect.Right - xStart, yTop); var RightBottom = new SKPoint(rect.Right - xStart, yBottom); canvas.DrawLine(LeftTop, LeftBottom, _backgroundPaint); canvas.DrawLine(RightTop, RightBottom, _backgroundPaint); } canvas.ClipRect(rect); // draw bars for (var i = 0; i < BarValues.Count; i++) { if (BarValues.GetItem(i) is WalkingDayModel data) { var xPos = xStart + i * delta; var normalizedValue = data.MinutesBriskWalking / TotalY; var yTop = rect.Height - (rect.Height * normalizedValue) + (_foregroundPaint.StrokeWidth / 2f); var yBottom = rect.Height + _foregroundPaint.StrokeWidth / 2f; var bottom = new SKPoint(xPos, yBottom); var top = new SKPoint(xPos, yTop); canvas.DrawLine(bottom, top, _foregroundPaint); } } }
public void Render(SKCanvas canvas, int width, int height) { foreach ((int col, int row, Track track) in _gameBoard.GetTracks()) { canvas.Save(); (int x, int y) = _pixelMapper.CoordsToPixels(col, row); canvas.Translate(x, y); canvas.ClipRect(new SKRect(0, 0, _parameters.CellSize, _parameters.CellSize), SKClipOperation.Intersect, false); _trackRenderer.Render(canvas, track, _parameters.CellSize); canvas.Restore(); } }
public void SetClip(RectangleF rect, CombineMode combineMode) { //if (combineMode == CombineMode.Replace && deviceClip != Rectangle.Empty) //{ // var skRect = Convert(deviceClip); // SkiaApi.sk_canvas_clip_rect_with_operation(canvas, ref skRect, SKClipOperation.Replace, false); // skRect = Convert(rect); // SkiaApi.sk_canvas_clip_rect_with_operation(canvas, ref skRect, SKClipOperation.Intersect, false); //} //else //{ // //Console.WriteLine("rect={0} deviceClip={1} mode={2}", rect, deviceClip, combineMode); var skRect = Convert(rect); var skOp = ToSKClipOperation(combineMode); skCanvas.ClipRect(skRect, skOp, antialias: false); //} }
public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache) { var vectorTile = ((DrawableTile)feature.Geometry).Data; vectorTile.Context.Zoom = (float)viewport.Resolution.ToZoomLevel(); var boundingBox = feature.Geometry.BoundingBox; if (viewport.IsRotated) { var priorMatrix = canvas.TotalMatrix; var matrix = CreateRotationMatrix(viewport, boundingBox, priorMatrix); // TODO canvas.SetMatrix(matrix); var destination = new BoundingBox(0.0, 0.0, boundingBox.Width, boundingBox.Height).ToSkia(); canvas.DrawDrawable(vectorTile, destination.Left, destination.Top); } else { var destination = RoundToPixel(WorldToScreen(viewport, feature.Geometry.BoundingBox)).ToSkia(); //var clipRect = vectorTile.Bounds; var scale = Math.Max(destination.Width, destination.Height) / vectorTile.Bounds.Width; vectorTile.Context.Scale = 1f / scale; //canvas.ClipRect(canvas.DeviceClipBounds); canvas.Translate(new SKPoint(destination.Left, destination.Top)); canvas.Scale(scale, scale); canvas.ClipRect(new SKRect(0, 0, vectorTile.Bounds.Width, vectorTile.Bounds.Height)); canvas.DrawDrawable(vectorTile, 0, 0); var frame = SKRect.Inflate(vectorTile.Bounds, (float)-vectorTile.Context.Zoom, (float)-vectorTile.Context.Zoom); canvas.DrawRect(frame, new SKPaint() { Style = SKPaintStyle.Stroke, Color = new SKColor((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256)) }); } return(true); }
public Benchmarks() { skSurface = SKSurface.Create(width: 1024, height: 1024, colorType: SKImageInfo.PlatformColorType, alphaType: SKAlphaType.Premul); skCanvas = skSurface.Canvas; skCanvas.ClipRect(new SKRect(0, 0, 1024, 1024)); skPaintSolidThick = new SKPaint(); skPaintSolidThick.StrokeWidth = STROKE_WIDTH; skPaintSolidThick.IsAntialias = AntiAlias; skPaintSolidThick.Style = SKPaintStyle.Fill; skPaintSolidThin = new SKPaint(); skPaintSolidThin.StrokeWidth = 1; skPaintSolidThin.IsAntialias = AntiAlias; SKPathEffect dashEffect = SKPathEffect.CreateDash(new float[] { 2F, 6F }, 1F); skPaintDashedThick = new SKPaint(); skPaintDashedThick.StrokeWidth = STROKE_WIDTH; skPaintDashedThick.IsAntialias = AntiAlias; skPaintDashedThick.PathEffect = dashEffect; skPaintDashedThin = new SKPaint(); skPaintDashedThin.StrokeWidth = 1; skPaintDashedThin.IsAntialias = AntiAlias; skPaintDashedThin.PathEffect = dashEffect; Bitmap bmp = new Bitmap(1024, 1024); gdiGraphics = Graphics.FromImage(bmp); gdiPenThick = new Pen(Color.Red, STROKE_WIDTH); gdiPenThin = new Pen(Color.Red, 1F); gdiPenDashedThin = new Pen(Color.Red, 1F); gdiPenDashedThin.DashPattern = new float[] { 2F, 6F }; gdiPenDashedThin.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; gdiPenDashedThick = new Pen(Color.Red, STROKE_WIDTH); gdiPenDashedThick.DashPattern = new float[] { 2F, 6F }; gdiPenDashedThick.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom; lineSegments = new LineSegment[1]; lineSegments[0] = new LineSegment(-10F, -10F, 1200F, 1200F); }
public void Render(SKSurface surface) { const int CellSize = 10; int width = _grid.Rows * CellSize; int height = _grid.Columns * CellSize; SKCanvas canvas = surface.Canvas; canvas.Translate(1, 1); canvas.Clear(SKColors.White); canvas.ClipRect(new SKRect(0, 0, width + 10, height + 10), SKClipOperation.Intersect); using var grid = new SKPaint { Color = SKColors.Gray, StrokeWidth = 2, Style = SKPaintStyle.Stroke }; foreach (var cell in _grid.Cells()) { int x1 = CellSize * cell.Column; int y1 = CellSize * cell.Row; int x2 = CellSize * (cell.Column + 1); int y2 = CellSize * (cell.Row + 1); if (cell.North == null) { canvas.DrawLine(x1, y1, x2, y1, grid); } if (cell.West == null) { canvas.DrawLine(x1, y1, x1, y2, grid); } if (!cell.IsLinked(cell.East)) { canvas.DrawLine(x2, y1, x2, y2, grid); } if (!cell.IsLinked(cell.South)) { canvas.DrawLine(x1, y2, x2, y2, grid); } } }
public void Paint(SKCanvas canvas) { using (new SKAutoCanvasRestore(canvas, true)) { var bounds = SKRect.Create((float)Left, (float)Top, (float)Width, (float)Height); if (ClipToBounds) { canvas.ClipRect(bounds, SKClipOperation.Intersect, true); } canvas.Translate((float)Left, (float)Top); OnPaint(canvas); foreach (var child in children) { child.Paint(canvas); } } }
public void RenderGridLines(SKCanvas c) { if (!this.XAxis.IsDrawGridLinesEnabled || !this.XAxis.IsEnabled) { return; } int clipRestoreCount = c.Save(); c.ClipRect(GetGridClippingRect()); if (RenderGridLinesBuffer.Length != Axis.entryCount) { RenderGridLinesBuffer = new SKPoint[XAxis.entryCount]; } var positions = RenderGridLinesBuffer; for (int i = 0; i < positions.Length; i++) { float entry = (float)Axis.entries[i]; positions[i] = new SKPoint(entry, entry); } positions = Trasformer.PointValuesToPixel(positions); SetupGridPaint(); var gridLinePath = RenderGridLinesPath; gridLinePath.Reset(); foreach (SKPoint pos in positions) { DrawGridLine(c, pos, gridLinePath); } c.RestoreToCount(clipRestoreCount); }
void MostlyEmptyQuadrant(SKCanvas canvas, SKPaint paint, SKRect rect) { using (new SKAutoCanvasRestore(canvas)) { canvas.ClipRect(rect, SKClipOperation.Intersect); // Fill in the lines on the upper-left and lower-right paint.Shader = null; paint.Color = SKColors.Silver; canvas.DrawLine(rect.Left - tileSize, rect.Top + tileSize, rect.Left + tileSize, rect.Top - tileSize, paint); canvas.DrawLine(rect.Right - tileSize, rect.Bottom + tileSize, rect.Right + tileSize, rect.Bottom - tileSize, paint); // Fill in the line on the lower-left paint.Shader = SKShader.CreateLinearGradient(new SKPoint(rect.MidX, rect.MidY), new SKPoint(rect.Left - rect.Width / 2, rect.Bottom + rect.Height / 2), shadeGradientColors, shadeGradientOffsets, SKShaderTileMode.Clamp); canvas.DrawLine(rect.Left - tileSize, rect.Bottom - tileSize, rect.Left + tileSize, rect.Bottom + tileSize, paint); // Fill in the line on the upper-right paint.Shader = SKShader.CreateLinearGradient(new SKPoint(rect.Right + rect.Width / 2, rect.Top - rect.Height / 2), new SKPoint(rect.MidX, rect.MidY), shadeGradientColors, shadeGradientOffsets, SKShaderTileMode.Clamp); canvas.DrawLine(rect.Right - tileSize, rect.Top - tileSize, rect.Right + tileSize, rect.Top + tileSize, paint); } }
public static void DrawCheckerboard(SKCanvas canvas, SKRect rect) { var rnd = new Random(); // Draw a checkerboard canvas.Save(); canvas.ClipRect(rect); var checkerboard_color = new SKColor((byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256), 64); DrawCheckerboard(canvas, checkerboard_color, 0x00000000, 12); canvas.Restore(); // Stroke the drawn area SKPaint debugPaint = new SKPaint { StrokeWidth = 8, Style = SKPaintStyle.Stroke, Color = new SKColor(checkerboard_color.Red, checkerboard_color.Green, checkerboard_color.Blue, 255) }; canvas.DrawRect(rect, debugPaint); }
public void RenderGridLines(SKCanvas c) { if (!YAxis.IsEnabled) { return; } if (YAxis.IsDrawGridLinesEnabled) { int clipRestoreCount = c.Save(); c.ClipRect(GetGridClippingRect()); SKPoint[] positions = GetTransformedPositions(); GridPaint.Color = YAxis.GridColor; GridPaint.StrokeWidth = YAxis.GridLineWidth; GridPaint.PathEffect = YAxis.GridDashedLine; SKPath gridLinePath = RenderGridLinesPath; gridLinePath.Reset(); // draw the grid foreach (SKPoint pos in positions) { // draw a path because lines don't support dashing on lower android versions c.DrawPath(LinePath(gridLinePath, pos), GridPaint); gridLinePath.Reset(); } c.RestoreToCount(clipRestoreCount); } if (YAxis.DrawZeroLine) { DrawZeroLine(c); } }