Add method that returns a list of standard monitor resolutions

This commit is contained in:
Ruan Lucas
2022-10-20 19:57:23 -04:00
parent 37c8aacd8b
commit a65e812b45
2 changed files with 105 additions and 0 deletions

View File

@@ -66,6 +66,104 @@ void Screen::SetSize(const Float2& value)
Size = value;
}
Array<Float2> Screen::GetAllResolutions() {
// reference: https://en.wikipedia.org/wiki/List_of_common_resolutions
// all list of monitors and video resolutions
Float2 rawResolutions[66] = {
Float2(480, 480),
Float2(528, 480),
Float2(544, 576),
Float2(544, 480),
Float2(640, 480),
Float2(704, 480),
Float2(704, 576),
Float2(720, 480),
Float2(720, 486),
Float2(720, 576),
Float2(768, 480),
Float2(800, 480),
Float2(800, 600),
Float2(960, 720),
Float2(1024, 600),
Float2(1024, 768),
Float2(1024, 1024),
Float2(1280, 720),
Float2(1280, 800),
Float2(1280, 1024),
Float2(1280, 1080),
Float2(1366, 768),
Float2(1440, 900),
Float2(1440, 1024),
Float2(1440, 1080),
Float2(1600, 900),
Float2(1600, 1024),
Float2(1600, 1200),
Float2(1680, 1050),
Float2(1828, 1332),
Float2(1920, 1080),
Float2(1920, 1400),
Float2(1920, 1440),
Float2(1990, 1080),
Float2(2048, 858),
Float2(2048, 1080),
Float2(2048, 1280),
Float2(2048, 1440),
Float2(2048, 1536),
Float2(2304, 1728),
Float2(2400, 1080),
Float2(2560, 1080),
Float2(2560, 1440),
Float2(2560, 1600),
Float2(2800, 2100),
Float2(3840, 2160),
Float2(2048, 1556),
Float2(3000, 2000),
Float2(3240, 2160),
Float2(3840, 2160),
Float2(4096, 1714),
Float2(4096, 2304),
Float2(5120, 2160),
Float2(5120, 2880),
Float2(5120, 1440),
Float2(5120, 3200),
Float2(6012, 3384),
Float2(7200, 3600),
Float2(7680, 4320),
Float2(7680, 4320),
Float2(8192, 4320),
Float2(10240, 4320),
Float2(15360, 8640)
};
Float2 primaryResolution = Platform::GetDesktopSize();
Array<Float2> resolutions = Array<Float2>();
// invert horizontal resolutions to vertical
if (primaryResolution.Y > primaryResolution.X)
{
for (int i = 0; i < rawResolutions->Length(); i++)
{
rawResolutions[i] = Float2(rawResolutions[i].Y, rawResolutions[i].Y);
}
}
for each (Float2 r in rawResolutions)
{
if (r.X >= primaryResolution.X && r.Y >= primaryResolution.Y)
{
break;
}
resolutions.Add(r);
}
resolutions.Add(primaryResolution);
return resolutions;
}
Float2 Screen::ScreenToGameViewport(const Float2& screenPos)
{
#if USE_EDITOR

View File

@@ -5,6 +5,7 @@
#include "Engine/Scripting/ScriptingType.h"
#include "Engine/Input/Enums.h"
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Collections/Array.h"
/// <summary>
/// Helper class to access display information.
@@ -34,6 +35,12 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen);
/// <returns>The value</returns>
API_PROPERTY() static Float2 GetSize();
/// <summary>
/// returns a list of standard resolutions used in monitors and media
/// </summary>
/// <returns>List of resolutions</returns>
API_PROPERTY() static Array<Float2> GetAllResolutions();
/// <summary>
/// Converts the screen-space position to the game viewport position.
/// </summary>