Add Multiple window support
This commit is contained in:
parent
500f631772
commit
afa0e4fd51
1 changed files with 38 additions and 28 deletions
|
|
@ -5,34 +5,41 @@ namespace Raylib_cs;
|
||||||
|
|
||||||
public sealed class Window : IDisposable
|
public sealed class Window : IDisposable
|
||||||
{
|
{
|
||||||
private static Window _instance;
|
public event OnInit Init;
|
||||||
|
public event OnUpdate Update;
|
||||||
|
public event OnDraw Draw;
|
||||||
|
public event OnClose Close;
|
||||||
|
|
||||||
private Window(ConfigFlags flags, int width, int height, string title)
|
private int _width;
|
||||||
{
|
private int _height;
|
||||||
Raylib.SetConfigFlags(flags);
|
private string _title;
|
||||||
Raylib.InitWindow(width, height, title);
|
|
||||||
_instance = this;
|
public Window(int width, int height, string title) {
|
||||||
|
this._width = width;
|
||||||
|
this._height = height;
|
||||||
|
this._title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void Run() {
|
||||||
/// Gets an instance of the Window or creates a new one if it doesn't exist.
|
Raylib.InitWindow(_width, _height, _title);
|
||||||
/// </summary>
|
Init?.Invoke();
|
||||||
/// <param name="flags">The configuration flags for the window.</param>
|
|
||||||
/// <param name="width">The width of the window.</param>
|
while (!ShouldClose()) {
|
||||||
/// <param name="height">The height of the window.</param>
|
Update?.Invoke();
|
||||||
/// <param name="title">The title of the window.</param>
|
|
||||||
/// <returns>An instance of the Window.</returns>
|
Raylib.BeginDrawing();
|
||||||
public static Window Instance(ConfigFlags flags, int width, int height, string title)
|
Raylib.ClearBackground(Color.SKYBLUE);
|
||||||
{
|
Draw?.Invoke();
|
||||||
return _instance ?? new Window(flags, width, height, title);
|
Raylib.EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
Close?.Invoke();
|
||||||
|
Raylib.CloseWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="Raylib.WindowShouldClose"/>
|
/// <inheritdoc cref="Raylib.WindowShouldClose"/>
|
||||||
public bool ShouldClose() => Raylib.WindowShouldClose();
|
public bool ShouldClose() => Raylib.WindowShouldClose();
|
||||||
|
|
||||||
/// <inheritdoc cref="Raylib.CloseWindow"/>
|
|
||||||
public void Close() => Raylib.CloseWindow();
|
|
||||||
|
|
||||||
/// <inheritdoc cref="Raylib.TakeScreenshot(string)"/>
|
/// <inheritdoc cref="Raylib.TakeScreenshot(string)"/>
|
||||||
public void TakeScreenshot(string path) => Raylib.TakeScreenshot(path);
|
public void TakeScreenshot(string path) => Raylib.TakeScreenshot(path);
|
||||||
|
|
||||||
|
|
@ -162,10 +169,13 @@ public sealed class Window : IDisposable
|
||||||
/// <inheritdoc cref="Raylib.GetClipboardText_"/>
|
/// <inheritdoc cref="Raylib.GetClipboardText_"/>
|
||||||
public string GetClipboardText() => Raylib.GetClipboardText_();
|
public string GetClipboardText() => Raylib.GetClipboardText_();
|
||||||
|
|
||||||
public void Dispose()
|
public delegate void OnInit();
|
||||||
{
|
|
||||||
if (!IsReady()) return;
|
public delegate void OnUpdate();
|
||||||
this.Close();
|
|
||||||
_instance = null;
|
public delegate void OnDraw();
|
||||||
}
|
|
||||||
|
public delegate void OnClose();
|
||||||
|
|
||||||
|
public void Dispose() { }
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue