- Fixed bug in builder when no content files exist

This commit is contained in:
2024-07-12 23:10:44 +02:00
parent d45f7c3b8c
commit 1096597161
23 changed files with 1096 additions and 32 deletions

View File

@ -3,6 +3,7 @@ namespace Nerfed.Runtime;
public enum ScreenMode
{
Fullscreen,
BorderlessFullscreen,
Windowed
}
FullscreenBorderless,
Windowed,
WindowedBorderless
}

View File

@ -11,6 +11,10 @@ namespace Nerfed.Runtime;
/// </summary>
public class Window
{
public event Action<Window, uint, uint> OnResizedEvent;
public event Action<Window, int, int> OnMovedEvent;
public event Action<Window> OnCloseEvent;
internal IntPtr Handle { get; }
public ScreenMode ScreenMode { get; private set; }
public uint Width { get; private set; }
@ -33,9 +37,7 @@ public class Window
public string Title { get; private set;}
private bool IsDisposed;
private System.Action<uint, uint> SizeChangeCallback = null;
private static readonly Dictionary<uint, Window> windowsById = new Dictionary<uint, Window>();
private static readonly Dictionary<uint, Window> windowsById = new Dictionary<uint, Window>();
public Window(GraphicsDevice graphicsDevice, WindowCreateInfo windowCreateInfo)
{
@ -54,10 +56,14 @@ public class Window
{
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
}
else if (windowCreateInfo.ScreenMode == ScreenMode.BorderlessFullscreen)
else if (windowCreateInfo.ScreenMode == ScreenMode.FullscreenBorderless)
{
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else if(windowCreateInfo.ScreenMode == ScreenMode.WindowedBorderless)
{
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_BORDERLESS;
}
if (windowCreateInfo.SystemResizable)
{
@ -104,27 +110,33 @@ public class Window
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
window.ProcessSizeChangedEvent(ref ev.window);
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED:
window.ProcessMovedChangedEvent(ref ev.window);
break;
case SDL.SDL_WindowEventID.SDL_WINDOWEVENT_CLOSE:
window.ProcessCloseEvent(ref ev.window);
break;
}
}
private void ProcessSizeChangedEvent(ref SDL.SDL_WindowEvent ev)
private void ProcessSizeChangedEvent(ref SDL.SDL_WindowEvent ev)
{
uint newWidth = (uint)ev.data1;
uint newHeight = (uint)ev.data2;
Width = newWidth;
Height = newHeight;
if (SizeChangeCallback != null)
{
SizeChangeCallback(newWidth, newHeight);
}
OnResizedEvent?.Invoke(this, Width, Height);
}
private void ProcessCloseEvent(ref SDL.SDL_WindowEvent ev)
private void ProcessMovedChangedEvent(ref SDL.SDL_WindowEvent ev)
{
OnMovedEvent?.Invoke(this, ev.data1, ev.data2);
}
private void ProcessCloseEvent(ref SDL.SDL_WindowEvent ev)
{
OnCloseEvent?.Invoke(this);
Engine.GraphicsDevice.UnclaimWindow(this);
Dispose();
}
@ -140,7 +152,7 @@ public class Window
{
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
}
else if (screenMode == ScreenMode.BorderlessFullscreen)
else if (screenMode == ScreenMode.FullscreenBorderless)
{
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
}
@ -195,15 +207,7 @@ public class Window
SDL.SDL_ShowWindow(Handle);
}
/// <summary>
/// You can specify a method to run when the window size changes.
/// </summary>
public void RegisterSizeChangeCallback(System.Action<uint, uint> sizeChangeCallback)
{
SizeChangeCallback = sizeChangeCallback;
}
protected virtual void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (!IsDisposed)
{