skiasharp/samples/Basic/macOS/SkiaSharpSample/ViewController.cs
2023-08-17 17:24:04 +02:00

47 lines
965 B
C#

using System;
using AppKit;
using SkiaSharp;
using SkiaSharp.Views.Mac;
namespace SkiaSharpSample
{
public partial class ViewController : NSViewController
{
public ViewController(IntPtr handle)
: base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
skiaView.IgnorePixelScaling = true;
skiaView.PaintSurface += OnPaintSurface;
}
private void OnPaintSurface(object? sender, SKPaintSurfaceEventArgs e)
{
// the the canvas and properties
var canvas = e.Surface.Canvas;
// make sure the canvas is blank
canvas.Clear(SKColors.White);
// draw some text
using var paint = new SKPaint
{
Color = SKColors.Black,
IsAntialias = true,
Style = SKPaintStyle.Fill
};
using var font = new SKFont
{
Size = 24
};
var coord = new SKPoint(e.Info.Width / 2, (e.Info.Height + font.Size) / 2);
canvas.DrawText("SkiaSharp", coord, SKTextAlign.Center, font, paint);
}
}
}