UI scale: size borders from the scale the game applies, mirror its options

GetPerfectPixel divided by the uiScale option, or by 1 while useUiScale was
off, though the game's automatic scale is never under 0.9, so default
borders came out about a tenth of a pixel thin. The game scales UIParent
only after add-ons and saved variables load, so the pixel now comes from
GetPhysicalScreenSize and the scale the game is about to apply, worked out
from the same options and rules as OnDisplaySizeChanged. UI_SCALE_CHANGED
offers a reload once when the pixel size changes.

The preset dropdown and the pixelperfect module go: its presets were pixel
perfect only at 1080p and its restore path never ran. The settings show the
game's own Use UI-Scale and UI-Scale options, plus a Pixel Perfect UI-Scale
checkbox (one UI unit per screen pixel, kept through window resizes) that
overrides them. The pixel perfect border and HiDPI options go too; border
sizes now count real pixels. CVAR settings rows write their option through
their own config instead of this:GetParent(), which a dropdown's menu
button is not. The first-run slider stops at 0.64, below which the game
drops uiScale for its automatic scale.
This commit is contained in:
Brues
2026-11-02 16:12:15 -06:00
parent f7769ec6ac
commit a0c47aa1cf
7 changed files with 79 additions and 102 deletions
+43 -18
View File
@@ -992,28 +992,53 @@ function pfUI.api.GetBorderSize(pref)
end
end
-- The scale UIParent ends up with: one UI unit per screen pixel when pixel
-- perfect, else the game's own. The game applies its scale only after the
-- add-ons and their saved variables are loaded (CGGameUI::Initialize ends in
-- OnDisplaySizeChanged), so at load time it is worked out from the same
-- options and rules: uiScale while useUiScale is on and it is at least 0.64,
-- else 768 over the window height kept within 0.9 and 1. Windows narrower
-- than 4:3 cap either at 3/4 of their aspect.
local function GetUIScale()
if pfUI_config.global.pixelperfect == "1" then return PixelUtil.GetPixelToUIUnitFactor() end
local width, height = GetPhysicalScreenSize()
local aspect = GetCVar("widescreen") == "1" and width / height or 4/3
local function fit(scale)
return aspect < 4/3 and math.min(scale, aspect * .75) or scale
end
if GetCVar("useUiScale") == "1" then
local scale = fit(tonumber(GetCVar("uiScale")))
if scale >= .64 then return scale end
end
return math.max(fit(height > 768 and 768 / height or 1), .9)
end
-- [ UpdateUIScale ]
-- Gives UIParent the pixel perfect scale when enabled, else leaves the game's
-- own. The engine puts its own scale back on every window resize and scale
-- option change, so this runs again on each UI_SCALE_CHANGED. Borders keep
-- the pixel size they were built with, so a change of it offers a reload once.
function pfUI.api.UpdateUIScale()
if pfUI_config.global.pixelperfect == "1" then
UIParent:SetScale(PixelUtil.GetPixelToUIUnitFactor())
end
if not pfUI.pixel or pfUI.scaleprompt then return end
if math.abs(PixelUtil.GetPixelToUIUnitFactor() / UIParent:GetScale() - pfUI.pixel) < .0001 then return end
pfUI.scaleprompt = true
CreateQuestionDialog(T["The UI-Scale has changed. Reload the UI to redraw the borders?"], ReloadUI)
end
-- [ GetPerfectPixel ]
-- Returns a number that equals a real pixel on regular scaled frames.
-- Respects the current UI-scale and calculates a real pixel based on
-- the screen resolution and the 768px sized drawlayer.
-- Returns the size of one physical pixel in UIParent units.
function pfUI.api.GetPerfectPixel()
if pfUI.pixel then return pfUI.pixel end
if pfUI_config.appearance.border.pixelperfect == "1" then
local scale = GetCVar("useUiScale") == "1" and GetCVar("uiScale") or "1"
local resolution = GetCVar("gxResolution")
local _, _, screenwidth, screenheight = strfind(resolution, "(.+)x(.+)")
pfUI.pixel = 768 / screenheight / scale
pfUI.pixel = pfUI.pixel > 1 and 1 or pfUI.pixel
-- autodetect and zoom for HiDPI displays
if pfUI_config.appearance.border.hidpi == "1" then
pfUI.pixel = pfUI.pixel < .5 and pfUI.pixel * 2 or pfUI.pixel
end
else
pfUI.pixel = .7
end
pfUI.pixel = PixelUtil.GetPixelToUIUnitFactor() / GetUIScale()
pfUI.backdrop = {
bgFile = "Interface\\BUTTONS\\WHITE8X8", tile = false, tileSize = 0,