Created
June 27, 2023 13:31
-
-
Save Aurumaker72/514303acf7fc2b82e8755a09f93c1b0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Avalonia; | |
| using Avalonia.Controls; | |
| using Avalonia.Media; | |
| using Avalonia.Platform; | |
| using Avalonia.Rendering.SceneGraph; | |
| using Avalonia.Skia; | |
| using Avalonia.Threading; | |
| using SkiaSharp; | |
| namespace M64RPFW.Views.Avalonia.Controls; | |
| // https://github.com/AvaloniaUI/Avalonia/blob/master/samples/RenderDemo/Pages/CustomSkiaPage.cs | |
| public class SkiaControl : Control | |
| { | |
| public SkiaControl() | |
| { | |
| ClipToBounds = true; | |
| } | |
| private class CustomDrawOp : ICustomDrawOperation | |
| { | |
| public CustomDrawOp(Rect bounds) | |
| { | |
| Bounds = bounds; | |
| } | |
| public void Dispose() | |
| { | |
| // No-op | |
| } | |
| public Rect Bounds { get; } | |
| public bool HitTest(Point p) | |
| { | |
| return false; | |
| } | |
| public bool Equals(ICustomDrawOperation other) | |
| { | |
| return false; | |
| } | |
| public void Render(ImmediateDrawingContext context) | |
| { | |
| var leaseFeature = context.TryGetFeature<ISkiaSharpApiLeaseFeature>(); | |
| using var lease = leaseFeature.Lease(); | |
| var canvas = lease.SkCanvas; | |
| canvas.Save(); | |
| canvas.DrawCircle(100, 100, 50, new SKPaint() { Color = SKColors.Blue}); | |
| canvas.Restore(); | |
| } | |
| } | |
| public override void Render(DrawingContext context) | |
| { | |
| context.Custom(new CustomDrawOp(new Rect(0, 0, Bounds.Width, Bounds.Height))); | |
| Dispatcher.UIThread.InvokeAsync(InvalidateVisual, DispatcherPriority.Background); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment