Add fullscreen property to Renderer. Still needs to be properly implemented for RaylibRenderer.
This commit is contained in:
@@ -8,7 +8,17 @@ namespace DaggerFramework.Rendering
|
|||||||
public class RaylibRenderer : Renderer
|
public class RaylibRenderer : Renderer
|
||||||
{
|
{
|
||||||
public override bool ShouldRun => !WindowShouldClose();
|
public override bool ShouldRun => !WindowShouldClose();
|
||||||
public override Vector2 WindowSize => new Vector2(Raylib.GetScreenWidth(), Raylib.GetScreenHeight());
|
public override Vector2 WindowSize
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new Vector2(Raylib.GetScreenWidth(), Raylib.GetScreenHeight());
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Raylib.SetWindowSize((int)value.X, (int)value.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
public override Vector2 MonitorSize => new Vector2(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
|
public override Vector2 MonitorSize => new Vector2(GetMonitorWidth(GetCurrentMonitor()), GetMonitorHeight(GetCurrentMonitor()));
|
||||||
|
|
||||||
public override string WindowTitle
|
public override string WindowTitle
|
||||||
@@ -21,12 +31,14 @@ namespace DaggerFramework.Rendering
|
|||||||
|
|
||||||
public override int TargetFps { get => _targetFps; set => SetTargetFps(value); }
|
public override int TargetFps { get => _targetFps; set => SetTargetFps(value); }
|
||||||
public override bool VSync { get => _vsync; set => SetWindowVSync(value); }
|
public override bool VSync { get => _vsync; set => SetWindowVSync(value); }
|
||||||
|
public override bool Fullscreen { get => _fullscreen; set => SetFullscreen(value); }
|
||||||
|
|
||||||
public override void CreateWindow(WindowSettings windowSettings)
|
public override void CreateWindow(WindowSettings windowSettings)
|
||||||
{
|
{
|
||||||
Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
|
Raylib.SetTraceLogLevel(TraceLogLevel.LOG_NONE);
|
||||||
|
|
||||||
|
_defaultWindowSettings = windowSettings;
|
||||||
|
|
||||||
_windowSize = windowSettings.Size;
|
_windowSize = windowSettings.Size;
|
||||||
ConfigFlags windowFlags = 0;
|
ConfigFlags windowFlags = 0;
|
||||||
windowFlags |= windowSettings.Resizable ? ConfigFlags.FLAG_WINDOW_RESIZABLE : 0;
|
windowFlags |= windowSettings.Resizable ? ConfigFlags.FLAG_WINDOW_RESIZABLE : 0;
|
||||||
@@ -37,13 +49,14 @@ namespace DaggerFramework.Rendering
|
|||||||
{
|
{
|
||||||
var monitorSize = MonitorSize;
|
var monitorSize = MonitorSize;
|
||||||
Raylib.InitWindow((int)monitorSize.X, (int)monitorSize.Y, windowSettings.Title);
|
Raylib.InitWindow((int)monitorSize.X, (int)monitorSize.Y, windowSettings.Title);
|
||||||
|
Fullscreen = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title);
|
Raylib.InitWindow((int)_windowSize.X, (int)_windowSize.Y, windowSettings.Title);
|
||||||
}
|
}
|
||||||
|
|
||||||
Raylib.SetWindowState(windowFlags);
|
// Raylib.SetWindowState(windowFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetWindowTitle(string title)
|
protected override void SetWindowTitle(string title)
|
||||||
@@ -122,7 +135,6 @@ namespace DaggerFramework.Rendering
|
|||||||
|
|
||||||
public override void DrawRectangle(Vector2 size, Color color)
|
public override void DrawRectangle(Vector2 size, Color color)
|
||||||
{
|
{
|
||||||
// Raylib.DrawRectangleV(_position, size, SystemColorToRaylibColor(color));
|
|
||||||
Raylib.DrawRectanglePro(new Rectangle()
|
Raylib.DrawRectanglePro(new Rectangle()
|
||||||
{
|
{
|
||||||
x = transformPosition.X,
|
x = transformPosition.X,
|
||||||
@@ -154,14 +166,30 @@ namespace DaggerFramework.Rendering
|
|||||||
// VSync
|
// VSync
|
||||||
flags |= settings.UseVSync ? ConfigFlags.FLAG_VSYNC_HINT : 0;
|
flags |= settings.UseVSync ? ConfigFlags.FLAG_VSYNC_HINT : 0;
|
||||||
|
|
||||||
// Fullscreen
|
|
||||||
flags |= settings.Fullscreen ? ConfigFlags.FLAG_WINDOW_MAXIMIZED : 0;
|
|
||||||
flags |= settings.Fullscreen ? ConfigFlags.FLAG_WINDOW_UNDECORATED : 0;
|
|
||||||
|
|
||||||
_fullscreen = settings.Fullscreen;
|
_fullscreen = settings.Fullscreen;
|
||||||
|
|
||||||
|
_defaultFlags = flags;
|
||||||
|
|
||||||
Raylib.SetConfigFlags(flags);
|
Raylib.SetConfigFlags(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetFullscreen(bool fullscreen)
|
||||||
|
{
|
||||||
|
// var flags = _defaultFlags;
|
||||||
|
// if (fullscreen && !Raylib.IsWindowFullscreen())
|
||||||
|
// {
|
||||||
|
// WindowSize = MonitorSize;
|
||||||
|
// Raylib.ToggleFullscreen();
|
||||||
|
// }
|
||||||
|
// else if (Raylib.IsWindowFullscreen())
|
||||||
|
// {
|
||||||
|
// // Raylib.ToggleFullscreen();
|
||||||
|
// WindowSize = _windowSize;
|
||||||
|
// }
|
||||||
|
|
||||||
|
_fullscreen = fullscreen;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
public override void SetTransform(Matrix4x4 transform) { }
|
public override void SetTransform(Matrix4x4 transform) { }
|
||||||
|
|
||||||
@@ -264,5 +292,7 @@ namespace DaggerFramework.Rendering
|
|||||||
private string _windowTitle = string.Empty;
|
private string _windowTitle = string.Empty;
|
||||||
private int _targetFps;
|
private int _targetFps;
|
||||||
private bool _fullscreen;
|
private bool _fullscreen;
|
||||||
|
private WindowSettings _defaultWindowSettings;
|
||||||
|
private ConfigFlags _defaultFlags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,9 +36,10 @@ namespace DaggerFramework.Rendering
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The size of the render window.
|
/// The size of the render window.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract Vector2 WindowSize { get; }
|
public abstract Vector2 WindowSize { get; set; }
|
||||||
|
|
||||||
public abstract string WindowTitle { get; set; }
|
public abstract string WindowTitle { get; set; }
|
||||||
|
public abstract bool Fullscreen { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Active monitor's size.
|
/// Active monitor's size.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace DaggerFramework.Rendering
|
|||||||
public class StandardRenderer : Renderer
|
public class StandardRenderer : Renderer
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Vector2 WindowSize => throw new NotImplementedException();
|
public override Vector2 WindowSize { get; set; }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool ShouldRun => throw new NotImplementedException();
|
public override bool ShouldRun => throw new NotImplementedException();
|
||||||
|
|
||||||
@@ -21,6 +21,8 @@ namespace DaggerFramework.Rendering
|
|||||||
public override int TargetFps { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public override int TargetFps { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
public override bool VSync { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public override bool VSync { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
public override string WindowTitle { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public override string WindowTitle { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
public override bool Fullscreen { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using DaggerFramework.Rendering;
|
|||||||
using DaggerFramework.Audio;
|
using DaggerFramework.Audio;
|
||||||
using DaggerFramework.Resources;
|
using DaggerFramework.Resources;
|
||||||
using DaggerFramework.SceneGraph;
|
using DaggerFramework.SceneGraph;
|
||||||
|
using DaggerFramework.Utils;
|
||||||
|
|
||||||
|
|
||||||
public class TestGame : Game
|
public class TestGame : Game
|
||||||
@@ -26,7 +27,7 @@ public class TestGame : Game
|
|||||||
}, new RendererSettings()
|
}, new RendererSettings()
|
||||||
{
|
{
|
||||||
UseVSync = true,
|
UseVSync = true,
|
||||||
Fullscreen = false
|
Fullscreen = true
|
||||||
});
|
});
|
||||||
|
|
||||||
_audioBackend.Initialize();
|
_audioBackend.Initialize();
|
||||||
@@ -71,6 +72,7 @@ public class TestGame : Game
|
|||||||
{
|
{
|
||||||
_inputHandler!.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
_inputHandler!.AddInputMapping("play", new InputAction[] { new KeyInputAction(KeyboardKey.Spacebar) });
|
||||||
_inputHandler.AddInputMapping("sprint", new InputAction[] { new KeyInputAction(KeyboardKey.LeftShift) });
|
_inputHandler.AddInputMapping("sprint", new InputAction[] { new KeyInputAction(KeyboardKey.LeftShift) });
|
||||||
|
_inputHandler.AddInputMapping("toggle_fullscreen", new InputAction[] { new KeyInputAction(KeyboardKey.F11) });
|
||||||
|
|
||||||
_scene!.AddLayer("World", _worldLayer!);
|
_scene!.AddLayer("World", _worldLayer!);
|
||||||
|
|
||||||
@@ -78,14 +80,6 @@ public class TestGame : Game
|
|||||||
_worldLayer.AddEntity(new TestPlayer());
|
_worldLayer.AddEntity(new TestPlayer());
|
||||||
|
|
||||||
_scene.AddLayer("UI", _uiLayer!);
|
_scene.AddLayer("UI", _uiLayer!);
|
||||||
|
|
||||||
SerializedScene serializedScene;
|
|
||||||
|
|
||||||
if (_scene!.TrySerialize(out serializedScene))
|
|
||||||
{
|
|
||||||
_resourceManager.TrySave(Path.Combine(_resourceManager.ResourceRoot, "main.scene"), in serializedScene);
|
|
||||||
}
|
|
||||||
|
|
||||||
_scene.Start();
|
_scene.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +88,13 @@ public class TestGame : Game
|
|||||||
while (_scene!.ShouldRun)
|
while (_scene!.ShouldRun)
|
||||||
{
|
{
|
||||||
_scene.Update();
|
_scene.Update();
|
||||||
|
|
||||||
|
if (_inputHandler!.IsActionPressed("toggle_fullscreen"))
|
||||||
|
{
|
||||||
|
_renderer!.Fullscreen = !_renderer.Fullscreen;
|
||||||
|
_logger.Info($"Fullscreen: {_renderer.Fullscreen}");
|
||||||
|
}
|
||||||
|
|
||||||
_scene.BeginDraw();
|
_scene.BeginDraw();
|
||||||
_scene.EndDraw();
|
_scene.EndDraw();
|
||||||
}
|
}
|
||||||
@@ -109,4 +110,5 @@ public class TestGame : Game
|
|||||||
|
|
||||||
private UiLayer? _uiLayer;
|
private UiLayer? _uiLayer;
|
||||||
private EntityLayer? _worldLayer;
|
private EntityLayer? _worldLayer;
|
||||||
|
private Logger _logger = new(nameof(TestGame));
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user