Thread Tools Display Modes
02-28-20, 01:17 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
You need to check if GetPhysicalScreenSize()'s second return is >= 1200; if it is, modify SDPhantom's method to scale UIParent.
Code:
local physicalWidth, physicalHeight = GetPhysicalScreenSize()
local pixelPerfectScale = 768 / physicalHeight
if physicalHeight >= 1200 then
    UIParent:SetScale(pixelPerfectScale)
else
    SetCVar("useUiScale", 1)
    SetCVar("uiScale", pixelPerfectScale)
end
Source: https://wow.gamepedia.com/UI_Scale#P...ct_UIs_and_you

Last edited by myrroddin : 02-28-20 at 04:52 PM. Reason: enable custom scale via CVar with useUiScale
  Reply With Quote
02-28-20, 02:24 PM   #2
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 65
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

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » Pixel Perfect UIScale


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off