KumiScript/renderer/sdl/SDLWindow.cs

49 lines
No EOL
1.3 KiB
C#

using SDL2;
namespace KumiScript.Renderer
{
public class SDLWindow : IDisposable
{
internal readonly nint Id;
ushort _width;
ushort _height;
string _title;
SDLRenderer? _renderer;
public SDLWindow(ushort horizontalResolution, ushort verticalResolution, string windowTitle)
{
_width = horizontalResolution;
_height = verticalResolution;
_title = windowTitle;
nint window = SDL.SDL_CreateWindow(windowTitle, SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED,
horizontalResolution, verticalResolution, 0);
if (window == 0)
throw new Exception("Failed to create window!");
Id = window;
}
public int UpdateSurface()
{
return SDL.SDL_UpdateWindowSurface(Id);
}
public SDLRenderer GetRenderer()
{
if (_renderer is null)
_renderer = new SDLRenderer(this);
return _renderer;
}
public void SetResizable(bool r)
{
SDL.SDL_SetWindowResizable(Id, r ? SDL.SDL_bool.SDL_TRUE : SDL.SDL_bool.SDL_FALSE);
}
public void Dispose()
{
SDL.SDL_DestroyWindow(Id);
}
}
}