Quantcast
Pixel Perfect UIScale - WoWInterface
Thread Tools Display Modes
02-27-20, 06:11 PM   #1
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 65
Pixel Perfect UIScale

Hello there,

I was wondering what solutions you guys have to achieve a pixel perfect UIScale.

Addons such as the following are outdated:
https://www.wowinterface.com/downloa...8-UIScale.html
https://www.wowinterface.com/downloa...-UIScaler.html

I know ElvUI can achieve pixel perfection but I'd rather not install elvui for that single feature.
Thanks.
__________________
-- Be3f.
  Reply With Quote
02-27-20, 11:40 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,980
I don't bother with pixel-perfect layouts, but there are a couple options.

First, there's the PixelUtil API provided by Blizzard.

Alternatively, you can calculate the optimal UI scale with a mathematical formula.
Code:
768 / select(2, GetPhysicalScreenSize())
768 is the normalized height of the drawing area before scaling takes place. The width is dynamic, as in it changes based on aspect ratio. GetPhysicalScreenSize() returns the pixel measurements of the drawing area. Keep in mind, if you're not setting the UI Scale to this, you need to adjust with the effective scale of your frame's parent.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-28-20, 01:17 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,124
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   #4
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
02-28-20, 03:04 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,124
I had a typo. It isn't "UIScale" but instead:
Code:
SetCVar("uiScale", pixelPerfectScale)
https://wow.gamepedia.com/Console_variables
  Reply With Quote
02-28-20, 04:06 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,980
Originally Posted by myrroddin View Post
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 screenHeight >= 1200 then
    UIParent:SetScale(pixelPerfectScale)
else
    SetCVar("useUiScale", 1)
    SetCVar("uiScale", pixelPerfectScale)
end
screenHeight is undefined in your if condition, do you mean physicalHeight?



Originally Posted by Be3f. View Post
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+)"))
The two are exactly the same in fullscreen, but this script doesn't account for window assets like the title bar or a resized window in windowed mode. Both affect the optimal scale. In some situations, the script doesn't work at all. GetCurrentResolution() keeps returning zero no matter what mode I run in on my laptop and causes the script to throw errors instead.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-28-20 at 06:22 PM.
  Reply With Quote
02-28-20, 04:54 PM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,124
Originally Posted by SDPhantom View Post
screenHeight is undefined in your if condition, do you mean physicalHeight?
Yes, thank you. I edited for the fix.
  Reply With Quote
05-21-20, 05:18 AM   #8
pleomax_b
A Defias Bandit
Join Date: May 2020
Posts: 2
I use this

## Interface: 50200
## Title: UIScaler
## Notes: Automatic UI scaling.
## Author: Haleth/Freethinker
## Version: 5.2.0.4


I dont know where I last got it tho.
  Reply With Quote
05-21-20, 12:16 PM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,124
Originally Posted by pleomax_b View Post
I use this

## Interface: 50200
## Title: UIScaler
## Notes: Automatic UI scaling.
## Author: Haleth/Freethinker
## Version: 5.2.0.4


I dont know where I last got it tho.
That is meaningless It is just an addon's .toc file contents without any addon code.
  Reply With Quote
05-21-20, 12:44 PM   #10
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 508
Looks like pleomax_b is using this: https://www.wowinterface.com/downloa...-UIScaler.html
  Reply With Quote

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

Thread Tools
Display Modes

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