WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Pixel Perfect UIScale (https://www.wowinterface.com/forums/showthread.php?t=57848)

Be3f. 02-27-20 06:11 PM

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.

SDPhantom 02-27-20 11:40 PM

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.

myrroddin 02-28-20 01:17 PM

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

Be3f. 02-28-20 02:24 PM

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


myrroddin 02-28-20 03:04 PM

I had a typo. It isn't "UIScale" but instead:
Code:

SetCVar("uiScale", pixelPerfectScale)
https://wow.gamepedia.com/Console_variables

SDPhantom 02-28-20 04:06 PM

Quote:

Originally Posted by myrroddin (Post 335241)
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?



Quote:

Originally Posted by Be3f. (Post 335243)
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.

myrroddin 02-28-20 04:54 PM

Quote:

Originally Posted by SDPhantom (Post 335247)
screenHeight is undefined in your if condition, do you mean physicalHeight?

Yes, thank you. I edited for the fix.

pleomax_b 05-21-20 05:18 AM

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.

myrroddin 05-21-20 12:16 PM

Quote:

Originally Posted by pleomax_b (Post 335974)
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.

Kanegasi 05-21-20 12:44 PM

Looks like pleomax_b is using this: https://www.wowinterface.com/downloa...-UIScaler.html


All times are GMT -6. The time now is 06:09 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI