Skip to content

Commit

Permalink
Improved window sizes (resolutions) on non 16:10 monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrdacor committed Jul 12, 2022
1 parent d9640bc commit e583721
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
29 changes: 25 additions & 4 deletions Ambermoon.Core/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,32 @@ public static List<Size> GetPossibleResolutions(Size maxSize)
{
var resolutions = new List<Size>(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;
Expand Down
14 changes: 13 additions & 1 deletion Ambermoon.net/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit e583721

Please sign in to comment.