Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
DirectSvg.cs
1using System.Drawing;
7using SkiaSharp;
8
10
14public sealed class DirectSvg : DirectDrawingMovableBase
15{
16 private readonly SvgResource _svgResource;
17 private readonly SKPaint _paint = new()
18 {
19 IsAntialias = true,
20 FilterQuality = SKFilterQuality.Medium,
21 BlendMode = SKBlendMode.SrcOver
22 };
23
24 private SKBitmap? _cachedBitmap;
25 private int _cachedWidth;
26 private int _cachedHeight;
27
28 private DirectSvg(SvgResource svgResource,
29 RenderSurfaceHostBase renderSurfaceHost,
31 SceneLayer? sceneLayer,
32 View? view,
33 Rectangle? screenBounds,
34 Rectangle? worldBounds,
35 string? nickname = null)
36 : base(renderSurfaceHost, mode, sceneLayer, view, screenBounds, worldBounds, nickname)
37 {
38 _svgResource = svgResource ?? throw new ArgumentNullException(nameof(svgResource));
39 }
40
49 public DirectSvg(SvgResource svgResource,
50 RenderSurfaceHostBase renderSurfaceHost,
51 SceneLayer sceneLayer,
52 Rectangle worldBounds,
53 string? nickname = null)
54 : this(svgResource, renderSurfaceHost, DirectDrawingMode.SceneLayer, sceneLayer, null, null, worldBounds, nickname)
55 { }
56
65 public DirectSvg(SvgResource svgResource,
66 RenderSurfaceHostBase renderSurfaceHost,
67 View view,
68 Rectangle screenBounds,
69 string? nickname = null)
70 : this(svgResource, renderSurfaceHost, DirectDrawingMode.View, null, view, screenBounds, null, nickname)
71 { }
72
78 public DirectSvg SetFilterQuality(SKFilterQuality quality)
79 {
80 _paint.FilterQuality = quality;
81 ForceRefresh();
82 return this;
83 }
84
86 protected override void OnDraw(BackbufferBase backbuffer, RectangleF destRectScreen)
87 {
88 int width = Math.Max(1, (int)MathF.Round(destRectScreen.Width));
89 int height = Math.Max(1, (int)MathF.Round(destRectScreen.Height));
90
91 if (_cachedBitmap is null || _cachedWidth != width || _cachedHeight != height)
92 {
93 _cachedBitmap = _svgResource.Rasterize(width, height);
94 _cachedWidth = width;
95 _cachedHeight = height;
96 }
97
98 backbuffer.Canvas.DrawBitmap(_cachedBitmap, destRectScreen.ToPixelAlignedRect().ToSKRect(), _paint);
99 }
100
102 protected override void Dispose(bool disposing)
103 {
104 if (disposing)
105 {
106 // Bitmap lifetime is owned by SvgResource's per-size cache.
107 _cachedBitmap = null;
108 _paint.Dispose();
109 }
110
111 base.Dispose(disposing);
112 }
113}
View? View
Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode...
SceneLayer? SceneLayer
Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode...
DirectDrawingMovableBase(RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? name=null)
Initializes a new instance of the DirectDrawingMovableBase class with integrated movement capabilitie...
DirectSvg SetFilterQuality(SKFilterQuality quality)
Sets the filter quality used when drawing the cached SVG bitmap.
Definition DirectSvg.cs:78
DirectSvg(SvgResource svgResource, RenderSurfaceHostBase renderSurfaceHost, SceneLayer sceneLayer, Rectangle worldBounds, string? nickname=null)
Initializes a new world-space DirectSvg.
Definition DirectSvg.cs:49
override void OnDraw(BackbufferBase backbuffer, RectangleF destRectScreen)
Definition DirectSvg.cs:86
override void Dispose(bool disposing)
Releases resources used by this DirectDrawingBase instance.When disposing is true,...
Definition DirectSvg.cs:102
DirectSvg(SvgResource svgResource, RenderSurfaceHostBase renderSurfaceHost, View view, Rectangle screenBounds, string? nickname=null)
Initializes a new screen-space DirectSvg.
Definition DirectSvg.cs:65
Represents a loaded SVG asset that can be rasterized into cached bitmaps at requested sizes.
Represents a base class for managing a graphical backbuffer, and is the in-memory surface where rende...
SKCanvas Canvas
Gets the SkiaSharp canvas used for drawing operations on this backbuffer.
Represents a base class for hosting a render surface, providing functionality for managing rendering ...
DirectDrawingMode
Specifies where direct drawing operations are applied within the rendering pipeline.