Skip to content

Commit

Permalink
Making sure the window id has been removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Terria-K committed Jan 10, 2025
1 parent 5fb0801 commit 893da04
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions Riateu/Core/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public WindowMode WindowMode

public static IReadOnlyDictionary<uint, Window> Windows => windows;

public Action<uint, uint> Resized = delegate {};
public event Action<uint, uint> Resized = delegate {};

public Window(WindowSettings settings, SDL.SDL_WindowFlags flags)
private unsafe Window(WindowSettings settings, SDL.SDL_WindowFlags flags)
{
if (settings.WindowMode == WindowMode.Fullscreen)
{
Expand All @@ -63,23 +63,39 @@ public Window(WindowSettings settings, SDL.SDL_WindowFlags flags)

this.windowMode = settings.WindowMode;

var modeID = SDL.SDL_GetPrimaryDisplay();
title = settings.Title;

unsafe {
if (settings.WindowMode == WindowMode.Windowed)
{
Handle = SDL.SDL_CreateWindow(
title,
(int)settings.Width,
(int)settings.Height,
flags
);

Width = settings.Width;
Height = settings.Height;
}
else
{
var modeID = SDL.SDL_GetPrimaryDisplay();
SDL.SDL_DisplayMode *modePtr = (SDL.SDL_DisplayMode*)SDL.SDL_GetCurrentDisplayMode(modeID);

Handle = SDL.SDL_CreateWindow(
title,
settings.WindowMode == WindowMode.Windowed ? (int)settings.Width : modePtr->w,
settings.WindowMode == WindowMode.Windowed ? (int)settings.Height : modePtr->h,
modePtr->w,
modePtr->h,
flags
);
int width = 0;
int height = 0;
SDL.SDL_GetWindowSize(Handle, out width, out height);

Width = (uint)width;
Height = (uint)height;
}
SDL.SDL_GetWindowSize(Handle, out int width, out int height);

Width = (uint)width;
Height = (uint)height;
this.id = SDL.SDL_GetWindowID(Handle);
}

Expand Down Expand Up @@ -175,6 +191,7 @@ protected virtual void Dispose(bool disposing)
{
if (!IsDisposed)
{
windows.Remove(id);
Closed?.Invoke();
SDL.SDL_DestroyWindow(Handle);
IsDisposed = true;
Expand Down

0 comments on commit 893da04

Please sign in to comment.