Quantcast
WoWInterface - View Single Post - Pixel Perfect UIScale
View Single Post
02-28-20, 02:24 PM   #4
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 63
Code:
local screenHeight = GetScreenHeight()
local physicalWidth, physicalHeight = GetPhysicalScreenSize()
local pixelPerfectScale = 768 / physicalHeight
if screenHeight >= 1200 then
    UIParent:SetScale(pixelPerfectScale)
else
    SetCVar("useUiScale", 1)
    SetCVar("UIScale", pixelPerfectScale)
end
Thanks for the replies, both of you. Using your code snippet does not produce the desired result unfortunately similar to this script

Code:
/script SetCVar("uiScale", 768/string.match(({GetScreenResolutions()})[GetCurrentResolution()], "%d+x(%d+)"))
Digging through Elvui's pixelperfect.lua there seems to be more to it. What I think I'm looking for is within this section but I am unsure what it means or how to incorporate it in a custom addon.

Code:
function E:UIScale(init)
	local scale = E.global.general.UIScale
	-- `init` will be the `event` if its triggered after combat
	if init == true then -- E.OnInitialize
		--Set variables for pixel scaling
		local pixel, ratio = 1, 768 / E.screenheight
		E.mult = (pixel / scale) - ((pixel - ratio) / scale)
		E.Spacing = (E.PixelMode and 0) or E.mult
		E.Border = ((not E.twoPixelsPlease) and E.PixelMode and E.mult) or E.mult*2
	elseif InCombatLockdown() then
		E:RegisterEventForObject('PLAYER_REGEN_ENABLED', E.UIScale, E.UIScale)
	else -- E.Initialize
		UIParent:SetScale(scale)

		--Check if we are using `E.eyefinity`
		local width, height = E.screenwidth, E.screenheight
		E.eyefinity = E:IsEyefinity(width, height)

		--Resize E.UIParent if Eyefinity is on.
		local testingEyefinity = false
		if testingEyefinity then
			--Eyefinity Test: Resize the E.UIParent to be smaller than it should be, all objects inside should relocate.
			--Dragging moveable frames outside the box and reloading the UI ensures that they are saving position correctly.
			local uiWidth, uiHeight = UIParent:GetSize()
			width, height = uiWidth-250, uiHeight-250
		elseif E.eyefinity then
			--Find a new width value of E.UIParent for screen #1.
			local uiHeight = UIParent:GetHeight()
			width, height = E.eyefinity / (height / uiHeight), uiHeight
		else
			width, height = UIParent:GetSize()
		end

		E.UIParent:SetSize(width, height)
		E.UIParent.origHeight = E.UIParent:GetHeight()

		--Calculate potential coordinate differences
		E.diffGetLeft = E:Round(abs(UIParent:GetLeft() - E.UIParent:GetLeft()))
		E.diffGetRight = E:Round(abs(UIParent:GetRight() - E.UIParent:GetRight()))
		E.diffGetBottom = E:Round(abs(UIParent:GetBottom() - E.UIParent:GetBottom()))
		E.diffGetTop = E:Round(abs(UIParent:GetTop() - E.UIParent:GetTop()))

		if E:IsEventRegisteredForObject('PLAYER_REGEN_ENABLED', E.UIScale) then
			E:UnregisterEventForObject('PLAYER_REGEN_ENABLED', E.UIScale, E.UIScale)
		end
	end
end

function E:PixelBestSize()
	local scale = E:Round(768 / E.screenheight, 5)
	return max(0.4, min(1.15, scale))
end

function E:PixelScaleChanged(event)
	if event == 'UI_SCALE_CHANGED' then
		E.screenwidth, E.screenheight = GetPhysicalScreenSize()
		E.resolution = format('%dx%d', E.screenwidth, E.screenheight)
	end

	E:UIScale(true) --Repopulate variables
	E:UIScale() --Setup the scale

	E:Config_UpdateSize(true) --Reposition config
end

function E:Scale(x)
	local mult = E.mult
	return mult * floor(x / mult + 0.5)
end
__________________
-- Be3f.
  Reply With Quote