diff --git a/src/Lab/MonitorPlayground/MonitorPlayground.csproj b/src/Lab/MonitorPlayground/MonitorPlayground.csproj index 90128c32f2..3f44235b31 100644 --- a/src/Lab/MonitorPlayground/MonitorPlayground.csproj +++ b/src/Lab/MonitorPlayground/MonitorPlayground.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + netcoreapp3.0 diff --git a/src/Windowing/Silk.NET.Windowing.Common/Interfaces/IMonitor.cs b/src/Windowing/Silk.NET.Windowing.Common/Interfaces/IMonitor.cs index 20c74ba5c7..e08aff2f98 100644 --- a/src/Windowing/Silk.NET.Windowing.Common/Interfaces/IMonitor.cs +++ b/src/Windowing/Silk.NET.Windowing.Common/Interfaces/IMonitor.cs @@ -1,17 +1,47 @@ -// This file is part of Silk.NET. -// -// You may modify and distribute Silk.NET under the terms -// of the MIT license. See the LICENSE file for details. - -using System.Drawing; - -namespace Silk.NET.Windowing.Common -{ - public interface IMonitor : IWindowHost - { - string Name { get; } - int Index { get; } - Rectangle Bounds { get; } - VideoMode VideoMode { get; } - } -} +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +using System.Collections.Generic; +using System.Drawing; + +namespace Silk.NET.Windowing.Common +{ + /// + /// An interface representing a monitor. + /// + public interface IMonitor : IWindowHost + { + /// + /// The name of this monitor. + /// + string Name { get; } + + /// + /// The index of this monitor. + /// + int Index { get; } + + /// + /// The bounds of this monitor. + /// + Rectangle Bounds { get; } + + /// + /// The current video mode of this monitor. + /// + VideoMode VideoMode { get; } + + /// + /// This monitor's gamma correction. + /// + float Gamma { get; set; } + + /// + /// Get all video modes that this monitor supports. + /// + /// An array of all video modes. + IEnumerable GetAllVideoModes(); + } +} diff --git a/src/Windowing/Silk.NET.Windowing.Desktop/GlfwMonitor.cs b/src/Windowing/Silk.NET.Windowing.Desktop/GlfwMonitor.cs index 1ba23c4bf1..9c0537ac70 100644 --- a/src/Windowing/Silk.NET.Windowing.Desktop/GlfwMonitor.cs +++ b/src/Windowing/Silk.NET.Windowing.Desktop/GlfwMonitor.cs @@ -1,59 +1,85 @@ -// This file is part of Silk.NET. -// -// You may modify and distribute Silk.NET under the terms -// of the MIT license. See the LICENSE file for details. - -using System; -using System.Drawing; -using Silk.NET.GLFW; -using Silk.NET.Windowing.Common; -using VideoMode = Silk.NET.Windowing.Common.VideoMode; - -namespace Silk.NET.Windowing.Desktop -{ - internal unsafe class GlfwMonitor : IMonitor - { - public Monitor* Handle { get; } - - public GlfwMonitor(Monitor* monitor, int index) - { - Handle = monitor; - Index = index; - } - - public IWindow CreateWindow(WindowOptions opts) - { - if (opts.WindowState == WindowState.Fullscreen) - { - return new GlfwWindow(opts, null, this); - } - - opts.Position = new Point(opts.Position.X + Bounds.X, opts.Position.Y + Bounds.Y); - return new GlfwWindow(opts, null, null); - } - - public string Name => GlfwProvider.GLFW.Value.GetMonitorName(Handle); - public int Index { get; } - - public Rectangle Bounds - { - get - { - GlfwProvider.GLFW.Value.GetMonitorWorkarea(Handle, out var x, out var y, out var w, out var h); - return new Rectangle(x, y, w, h); - } - } - - public VideoMode VideoMode - { - get - { - var videoMode = GlfwProvider.GLFW.Value.GetVideoMode(Handle); - return new VideoMode( - new Size(videoMode->Width, videoMode->Height), - videoMode->RefreshRate - ); - } - } - } -} +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +using System.Collections.Generic; +using System.Drawing; +using Silk.NET.GLFW; +using Silk.NET.Windowing.Common; +using VideoMode = Silk.NET.Windowing.Common.VideoMode; + +namespace Silk.NET.Windowing.Desktop +{ + internal unsafe class GlfwMonitor : IMonitor + { + private float _gamma = 1.0f; + + public Monitor* Handle { get; } + + public GlfwMonitor(Monitor* monitor, int index) + { + Handle = monitor; + Index = index; + } + + public IWindow CreateWindow(WindowOptions opts) + { + if (opts.WindowState == WindowState.Fullscreen) + { + return new GlfwWindow(opts, null, this); + } + + opts.Position = new Point(opts.Position.X + Bounds.X, opts.Position.Y + Bounds.Y); + return new GlfwWindow(opts, null, null); + } + + public string Name => GlfwProvider.GLFW.Value.GetMonitorName(Handle); + public int Index { get; } + + public Rectangle Bounds + { + get + { + GlfwProvider.GLFW.Value.GetMonitorWorkarea(Handle, out var x, out var y, out var w, out var h); + return new Rectangle(x, y, w, h); + } + } + + public VideoMode VideoMode + { + get + { + var videoMode = GlfwProvider.GLFW.Value.GetVideoMode(Handle); + return new VideoMode( + new Size(videoMode->Width, videoMode->Height), + videoMode->RefreshRate + ); + } + } + + public float Gamma + { + get => _gamma; + set + { + _gamma = value; + GlfwProvider.GLFW.Value.SetGamma(Handle, value); + } + } + + public IEnumerable GetAllVideoModes() + { + var rawVideoModes = GlfwProvider.GLFW.Value.GetVideoModes(Handle, out var count); + + var videoModes = new List(); + + for (var i = 0; i < count; i++) + { + videoModes.Add(new VideoMode(new Size(rawVideoModes[i].Width, rawVideoModes[i].Height), rawVideoModes[i].RefreshRate)); + } + + return videoModes; + } + } +} diff --git a/src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs b/src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs index 79e695c4bd..5e023cbd8a 100644 --- a/src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs +++ b/src/Windowing/Silk.NET.Windowing.Desktop/GlfwWindow.cs @@ -159,16 +159,7 @@ public bool IsVisible public bool ShouldSwapAutomatically { get; } /// - public unsafe VideoMode VideoMode - { - get - { - var monitor = Monitor; - return monitor != null - ? monitor.VideoMode - : _initialOptions.VideoMode; - } - } + public VideoMode VideoMode => Monitor?.VideoMode ?? _initialOptions.VideoMode; /// public int? PreferredDepthBufferBits => _initialOptions.PreferredDepthBufferBits; @@ -193,7 +184,7 @@ public Point Position } } - /// + /// public Size Size { get => _size; @@ -315,8 +306,8 @@ public WindowState WindowState _glfw.SetWindowMonitor ( _windowPtr, monitor, 0, 0, - resolution.HasValue ? resolution.Value.Width : mode->Width, - resolution.HasValue ? resolution.Value.Height : mode->Height, + resolution?.Width ?? mode->Width, + resolution?.Height ?? mode->Height, videoMode.RefreshRate ?? mode->RefreshRate ); break;