Skip to content

Commit d499fd3

Browse files
meehlLocalIdentity
andcommitted
Add missing screen size conversions (PathOfBuildingCommunity#9373)
* Add missing screen size conversions `GetScreenSize` returns the size in physical units if the "DPI_AWARE" flag is passed to `RenderInit`. The error popup and restart screen have the wrong position and size at UI scaling factor != 1.0 due to missing conversions to virtual units. This introduces a utility function for getting the virtual screen size and uses it to add the missing conversions. * Update export scripts --------- Co-authored-by: Jack Lockwood <[email protected]>
1 parent 31217e0 commit d499fd3

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

src/Export/Launch.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function launch:OnFrame()
6767
self:DrawPopup(r, g, b, "^0%s", self.promptMsg)
6868
end
6969
if self.doRestart then
70-
local screenW, screenH = GetScreenSize()
70+
local screenW, screenH = GetVirtualScreenSize()
7171
SetDrawColor(0, 0, 0, 0.75)
7272
DrawImage(nil, 0, 0, screenW, screenH)
7373
SetDrawColor(1, 1, 1)
@@ -180,7 +180,7 @@ function launch:RunPromptFunc(key)
180180
end
181181

182182
function launch:DrawPopup(r, g, b, fmt, ...)
183-
local screenW, screenH = GetScreenSize()
183+
local screenW, screenH = GetVirtualScreenSize()
184184
SetDrawColor(0, 0, 0, 0.5)
185185
DrawImage(nil, 0, 0, screenW, screenH)
186186
local txt = string.format(fmt, ...)

src/Export/Main.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function main:Shutdown()
415415
end
416416

417417
function main:OnFrame()
418-
self.screenW, self.screenH = GetScreenSize()
418+
self.screenW, self.screenH = GetVirtualScreenSize()
419419

420420
self.viewPort = { x = 0, y = 0, width = self.screenW, height = self.screenH }
421421

src/Launch.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function launch:OnFrame()
122122
self:DrawPopup(r, g, b, "^0%s", self.promptMsg)
123123
end
124124
if self.doRestart then
125-
local screenW, screenH = GetScreenSize()
125+
local screenW, screenH = GetVirtualScreenSize()
126126
SetDrawColor(0, 0, 0, 0.75)
127127
DrawImage(nil, 0, 0, screenW, screenH)
128128
SetDrawColor(1, 1, 1)
@@ -387,7 +387,7 @@ function launch:RunPromptFunc(key)
387387
end
388388

389389
function launch:DrawPopup(r, g, b, fmt, ...)
390-
local screenW, screenH = GetScreenSize()
390+
local screenW, screenH = GetVirtualScreenSize()
391391
SetDrawColor(0, 0, 0, 0.5)
392392
DrawImage(nil, 0, 0, screenW, screenH)
393393
local txt = string.format(fmt, ...)

src/Modules/Common.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,3 +963,14 @@ function ImportBuild(importLink, callback)
963963
callback(Inflate(common.base64.decode(importLink:gsub("-", "+"):gsub("_", "/"))), nil)
964964
end
965965
end
966+
967+
-- Returns virtual screen size
968+
function GetVirtualScreenSize()
969+
local width, height = GetScreenSize()
970+
local scale = GetScreenScale and GetScreenScale() or 1.0
971+
if scale ~= 1.0 then
972+
width = math.floor(width / scale)
973+
height = math.floor(height / scale)
974+
end
975+
return width, height
976+
end

src/Modules/Main.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,7 @@ function main:Shutdown()
339339
end
340340

341341
function main:OnFrame()
342-
self.screenW, self.screenH = GetScreenSize()
343-
self.screenScale = GetScreenScale and GetScreenScale() or 1
344-
if self.screenScale ~= 1.0 then
345-
self.screenW = math.floor(self.screenW / self.screenScale)
346-
self.screenH = math.floor(self.screenH / self.screenScale)
347-
end
342+
self.screenW, self.screenH = GetVirtualScreenSize()
348343

349344
if self.screenH > self.screenW then
350345
self.portraitMode = true

0 commit comments

Comments
 (0)