Use properties in Renderer.

This commit is contained in:
2024-01-20 19:25:05 +01:00
parent 0299a0724e
commit 2c42856fc2
8 changed files with 123 additions and 41 deletions

View File

@@ -7,44 +7,64 @@ namespace DaggerFramework.Rendering
{
public class RaylibRenderer : Renderer
{
public override Vector2 WindowSize => new Vector2(Raylib.GetScreenWidth(), Raylib.GetScreenHeight());
public override bool ShouldRun => !WindowShouldClose();
public override Vector2 WindowSize => new Vector2(Raylib.GetScreenWidth(), Raylib.GetScreenHeight());
public override Vector2 MonitorSize => new Vector2(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
public override string WindowTitle
{
get => _windowTitle; set
{
SetWindowTitle(value);
}
}
public override int TargetFps { get => _targetFps; set => SetTargetFps(value); }
public override bool VSync { get => _vsync; set => SetWindowVSync(value); }
// public override void CreateWindow(string title, Vector2 size)
// {
// Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
// _windowSize = size;
// Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, title);
// }
public override void CreateWindow(WindowSettings windowSettings)
{
Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
_windowSize = windowSettings.Size;
_windowSize = windowSettings.Size;
ConfigFlags windowFlags = 0;
windowFlags |= windowSettings.Resizable ? ConfigFlags.FLAG_WINDOW_RESIZABLE : 0;
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title);
_windowTitle = windowSettings.Title;
if (_fullscreen)
{
var monitorSize = MonitorSize;
Raylib.InitWindow((int)monitorSize.X, (int)monitorSize.Y, windowSettings.Title);
}
else
{
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title);
}
Raylib.SetWindowState(windowFlags);
}
public override void SetWindowTitle(string title)
protected override void SetWindowTitle(string title)
{
Raylib.SetWindowTitle(title);
}
public override void SetWindowVSync(bool value)
protected override void SetWindowVSync(bool value)
{
_vsync = value;
// TODO: implement VSync toggle for Raylib.
}
public override void SetTargetFps(int fps)
protected override void SetTargetFps(int fps)
{
_targetFps = fps;
Raylib.SetTargetFPS(fps);
}
public override bool WindowShouldClose()
protected override bool WindowShouldClose()
{
return Raylib.WindowShouldClose();
}
@@ -181,6 +201,8 @@ namespace DaggerFramework.Rendering
public override void Initialize(RendererSettings settings)
{
_targetFps = settings.TargetFps;
ConfigFlags flags = 0;
// MSAA
@@ -190,8 +212,10 @@ namespace DaggerFramework.Rendering
flags |= settings.UseVSync ? ConfigFlags.FLAG_VSYNC_HINT : 0;
// Fullscreen
flags |= settings.Fullscreen ? ConfigFlags.FLAG_FULLSCREEN_MODE : 0;
flags |= settings.Fullscreen ? ConfigFlags.FLAG_WINDOW_MAXIMIZED : 0;
flags |= settings.Fullscreen ? ConfigFlags.FLAG_WINDOW_UNDECORATED : 0;
_fullscreen = settings.Fullscreen;
Raylib.SetConfigFlags(flags);
}
@@ -200,8 +224,8 @@ namespace DaggerFramework.Rendering
public override void CreateAndInitialize(WindowSettings windowSettings, RendererSettings renderSettings)
{
CreateWindow(windowSettings);
Initialize(renderSettings);
CreateWindow(windowSettings);
}
private Raylib_cs.Color DaggerColorToRaylibColor(Color color)
@@ -215,10 +239,30 @@ namespace DaggerFramework.Rendering
Raylib.DrawTextPro(font, text, _position, Vector2.Zero, _rotation, fontSize, 0.0f, DaggerColorToRaylibColor(color));
}
protected override int GetMonitorWidth(int monitorId)
{
return Raylib.GetMonitorWidth(monitorId);
}
protected override int GetMonitorHeight(int monitorId)
{
return Raylib.GetMonitorHeight(monitorId);
}
protected override int GetCurrentMonitor()
{
return Raylib.GetCurrentMonitor();
}
private List<Texture2D> _texturePool = new();
private List<Raylib_cs.Font> _fontPool = new();
private Vector2 _position, _offset;
private float _rotation;
private Vector2 _windowSize;
private bool _vsync;
private string _windowTitle = string.Empty;
private int _targetFps;
private bool _fullscreen;
}
}