Skip to content

Instantly share code, notes, and snippets.

@lhog
Created January 9, 2022 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lhog/dd91516aa33f3d2561ac619647bb41b4 to your computer and use it in GitHub Desktop.
Save lhog/dd91516aa33f3d2561ac619647bb41b4 to your computer and use it in GitHub Desktop.
resolution_test.lua
function widget:GetInfo()
return {
name = "Resolution Testing",
desc = "Debug changing fulscreen/borderless/resolution",
layer = 0,
enabled = true,
}
end
local windowType = {
fs_bl = 1,
fs_ex = 2,
borderless = 3,
windowed = 4,
}
local screenModes = {}
local display = -1
for _, videoMode in ipairs(Platform.availableVideoModes) do
if display ~= videoMode.display then
display = videoMode.display
local fsb = {
display = display,
name = "Fullscreen Borderless[" .. display .. "]",
type = windowType.fs_bl,
width = videoMode.w,
height = videoMode.h,
}
local fse = {
display = display,
name = "Fullscreen Exclusive[" .. display .. "]",
type = windowType.fs_ex,
width = videoMode.w,
height = videoMode.h,
}
-- only capture the first occurance of the display index. Will contain maximum supported resolution
table.insert(screenModes, fsb)
table.insert(screenModes, fse)
end
if videoMode.w >= 800 and videoMode.h > 600 then
local bl = {
display = display,
name = "Borderless[" .. display .. "] " .. videoMode.w .. " × " .. videoMode.h,
type = windowType.borderless,
width = videoMode.w,
height = videoMode.h,
}
local wn = {
display = display,
name = "Decorated[" .. display .. "] " .. videoMode.w .. " × " .. videoMode.h,
type = windowType.windowed,
width = videoMode.w,
height = videoMode.h,
}
table.insert(screenModes, bl)
table.insert(screenModes, wn)
end
end
local function changeScreenMode(index)
if index > #screenModes or index < 1 then return end
local screenMode = screenModes[index]
if screenMode.type == windowType.fs_bl then
Spring.Echo("windowType.fs_bl", screenMode.width, screenMode.height)
Spring.SetWindowGeometry(screenMode.display, 0, 0, screenMode.width, screenMode.height, true, true)
elseif screenMode.type == windowType.fs_ex then
Spring.Echo("windowType.fs_ex", screenMode.width, screenMode.height)
Spring.SetWindowGeometry(screenMode.display, 0, 0, screenMode.width, screenMode.height, true, false)
elseif screenMode.type == windowType.borderless then
Spring.Echo("windowType.borderless", 0, 0, screenMode.width, screenMode.height)
Spring.SetWindowGeometry(screenMode.display, 0, math.random(0, 100), screenMode.width, screenMode.height - 100, false, true)
elseif screenMode.type == windowType.windowed then
Spring.Echo("windowType.windowed", 0, 100, screenMode.width, screenMode.height - 100)
Spring.SetWindowGeometry(screenMode.display, 0, math.random(0, 100), screenMode.width, screenMode.height - 100, false, false)
end
end
function widget:Initialize()
Spring.Echo("[Resolution Test] Use command '\\res #' to change screen specs")
for i, mode in ipairs(screenModes) do
Spring.Echo(i .. ": " .. mode.name)
end
end
function widget:TextCommand(command)
if string.sub(command, 1, 4) == "res " then
local screenModeIndex = tonumber(string.sub(command, 5))
changeScreenMode(screenModeIndex)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment