From e5837211f5e9cb472991d558fea2415917fc229d Mon Sep 17 00:00:00 2001 From: Pyrdacor Date: Tue, 12 Jul 2022 09:36:28 +0200 Subject: [PATCH] Improved window sizes (resolutions) on non 16:10 monitors --- Ambermoon.Core/IConfiguration.cs | 29 +++++++++++++++++++++++++---- Ambermoon.net/GameWindow.cs | 14 +++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/Ambermoon.Core/IConfiguration.cs b/Ambermoon.Core/IConfiguration.cs index cfa8ebe4..7ce00bc5 100644 --- a/Ambermoon.Core/IConfiguration.cs +++ b/Ambermoon.Core/IConfiguration.cs @@ -36,11 +36,32 @@ public static List GetPossibleResolutions(Size maxSize) { var resolutions = new List(4); - // 4/8, 5/8, 6/8 and 7/8 of max size - for (int i = 0; i < 4; ++i) + const float defaultResolution = 16.0f / 10.0f; + float resolution = (float)maxSize.Width / maxSize.Height; + + if (resolution <= defaultResolution + 0.0001f) + { + // 16:10, 4:3, etc + // Width is the leading dimension for resolutions. + + // 4/8, 5/8, 6/8 and 7/8 of max size + for (int i = 0; i < 4; ++i) + { + int width = maxSize.Width * (4 + i) / 8; + resolutions.Add(new Size(width, width * 10 / 16)); + } + } + else { - int width = maxSize.Width * (4 + i) / 8; - resolutions.Add(new Size(width, width * 10 / 16)); + // 16:9, etc + // Height is the leading dimension for resolutions. + + // 4/8, 5/8, 6/8 and 7/8 of max size + for (int i = 0; i < 4; ++i) + { + int height = maxSize.Height * (4 + i) / 8; + resolutions.Add(new Size(height * 16 / 10, height)); + } } return resolutions; diff --git a/Ambermoon.net/GameWindow.cs b/Ambermoon.net/GameWindow.cs index f8e9a3cd..30842c69 100644 --- a/Ambermoon.net/GameWindow.cs +++ b/Ambermoon.net/GameWindow.cs @@ -1159,7 +1159,7 @@ void Window_Load() if (configuration.Width == null || configuration.Height == null) { var monitorSize = window.Monitor.Bounds.Size; - var size = ScreenResolutions.GetPossibleResolutions(new Size(monitorSize.X, monitorSize.Y))[1]; + var size = ScreenResolutions.GetPossibleResolutions(new Size(monitorSize.X, monitorSize.Y))[2]; configuration.Width = Width = size.Width; configuration.Height = Height = size.Height; if (!configuration.Fullscreen) @@ -1183,6 +1183,18 @@ void Window_Load() configuration.WindowY = window.Position.Y; configuration.MonitorIndex = window.Monitor.Index; } + + var monitorSize = window.Monitor.Bounds.Size; + var realBorderSize = window.BorderSize.Origin + window.BorderSize.Size; + var realWindowSize = window.Size + realBorderSize; + + if (realWindowSize.X > monitorSize.X || realWindowSize.Y > monitorSize.Y) + { + var size = ScreenResolutions.GetPossibleResolutions(new Size(monitorSize.X, monitorSize.Y))[2]; + configuration.Width = Width = size.Width; + configuration.Height = Height = size.Height; + window.Size = new WindowDimension(Width, Height); + } } initialized = true;