private void OnPaintSurface(object sender, SKPaintGLSurfaceEventArgs e) { game.Update(); var canvas = e.Surface.Canvas; canvas.Clear(SKColors.Black); using var save = new SKAutoCanvasRestore(canvas, true); scale = Math.Min( (float)e.BackendRenderTarget.Width / baseSize.Width, (float)e.BackendRenderTarget.Height / baseSize.Height); var screenRect = (SKRect)e.BackendRenderTarget.Rect; var centeredRect = screenRect.AspectFit(baseSize); offset = centeredRect.Location; canvas.Translate(offset); canvas.Scale(scale); canvas.ClipRect(SKRect.Create(baseSize)); game.Draw(canvas); }
public void Draw(SKCanvas canvas, float angle, float x, float y) { using var save = new SKAutoCanvasRestore(canvas, true); var bird = birdAnimation.Frames[birdAnimation.CurrentFrame]; x -= Width / 2f; y += BobOffset; canvas.RotateDegrees(angle, x + Width / 2f, y + Height / 2f); bird.Draw(canvas, x, y); }
public void Draw(SKCanvas canvas, float angle, float x, float y) { using var save = new SKAutoCanvasRestore(canvas, true); var bird = birdAnimation.Frames[birdAnimation.CurrentFrame]; var bounds = GetBounds(x, y); canvas.Translate(bounds.Left, bounds.Top); canvas.RotateDegrees(angle, Width / 2f, Height / 2f); bird.Draw(canvas, 0, 0); }
/// <inheritdoc/> public void DrawText( ScreenPoint p, string text, OxyColor fill, string fontFamily = null, double fontSize = 10, double fontWeight = 400, double rotation = 0, HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left, VerticalAlignment verticalAlignment = VerticalAlignment.Top, OxySize?maxSize = null) { if (text == null || !fill.IsVisible()) { return; } var paint = this.GetTextPaint(fontFamily, fontSize, fontWeight, out var shaper); paint.Color = fill.ToSKColor(); var x = this.Convert(p.X); var y = this.Convert(p.Y); var lines = StringHelper.SplitLines(text); var lineHeight = paint.GetFontMetrics(out var metrics); var deltaY = verticalAlignment switch { VerticalAlignment.Top => - metrics.Ascent, VerticalAlignment.Middle => - (metrics.Ascent + metrics.Descent + lineHeight * (lines.Length - 1)) / 2, VerticalAlignment.Bottom => - metrics.Descent - lineHeight * (lines.Length - 1), _ => throw new ArgumentOutOfRangeException(nameof(verticalAlignment)) }; using var _ = new SKAutoCanvasRestore(this.SkCanvas); this.SkCanvas.Translate(x, y); this.SkCanvas.RotateDegrees((float)rotation); foreach (var line in lines) { if (this.UseTextShaping) { var width = this.MeasureText(line, shaper, paint); var deltaX = horizontalAlignment switch { HorizontalAlignment.Left => 0, HorizontalAlignment.Center => - width / 2, HorizontalAlignment.Right => - width, _ => throw new ArgumentOutOfRangeException(nameof(horizontalAlignment)) }; this.paint.TextAlign = SKTextAlign.Left; this.SkCanvas.DrawShapedText(shaper, line, deltaX, deltaY, paint); } else { paint.TextAlign = horizontalAlignment switch { HorizontalAlignment.Left => SKTextAlign.Left, HorizontalAlignment.Center => SKTextAlign.Center, HorizontalAlignment.Right => SKTextAlign.Right, _ => throw new ArgumentOutOfRangeException(nameof(horizontalAlignment)) }; this.SkCanvas.DrawText(line, 0, deltaY, paint); } deltaY += lineHeight; } }