Achieving pixel perfection
Hi all,
I wasn't really worried about the pixel perfection, but my frames started to cause an issue with the placement and sizing. Where should I start? If possible, I would like to get some explanation on how and why(?) it works rather than just using an already existing solution. Could anyone please help me out regarding this? Thank you! |
WoW screen is using these sort of floating point virtual pixels, they go up to 768 in height and proportionally for aspect ratio in width, and they map onto your real resolution. And then there's possibly global UI scale in the mix. In the end the line that you wanted to be 2 virtual pixels wide ends up snapping to either 2 or 3 real pixels depending on where it is
So you need to reverse this process and find out what amount of virtual pixels is corresponding to real pixels Here's what i use to find it: Code:
local res = GetCVar("gxWindowedResolution") |
If your display, or if writing a public addon, the user's display, is greater than 1920x1080, you need to do two things:
If the height is equal to or less than 1920, only do the first thing. Now here are the hard parts:
|
Quote:
And after all what I'll have to do is multiply pmult whenever I'm setting the position or the size? Like: Lua Code:
Quote:
If the screen size is greater than 1920x1080, I'll have to set both UIScale CVar and UIParent's scale to 768/height as you have advised. However, if I switch UIParent's scale to such, wouldn't that affect all other frames having UIParent as a parent frame? If the answer is yes, would it be okay to use my own UIParent like the following to avoid such issues? Lua Code:
|
About UIParent, yes, that would be true, which is why, among other pixel perfect enabled addons, ElvUI creates their own "ElvUIParent". I'm not 100% sure of what name they chose, but it doesn't matter, as that is just a variable.
When doing pixel perfection, ElvUI doesn't scale UIParent, instead scaling their own version then SetAllPoints so it fits on UIParent. This has the added benefit of not messing with other addons that depend on UIParent's scale. |
While I have never tested it, I'm going to assume that your pmult example will be not what you want if you multiply height and width.
Height and width are integers representing pixels. If pmult is not an integer (it will always be a real or whole number, never an integer) then there is no possible way for either height or width to sit on a pixel. Instead, height and width will sit in between pixels, and look wrong. That's why I suggested to never apply pmult to height or width. Scale on the other hand is a whole or real number, which means it includes integers, albeit as 1.0, 2.0, 3.0 rather than 1, 2, 3. Should you be hellbent on allowing pmult on height or width, then you need to round up or down to the nearest integer after you multiply by pmult. It's a couple of extra steps. When rounding, I further suggest a couple of sanity checks:
|
Quote:
Hm... if that's the case I should stick to your way. Let me test them first and I'll come back for further advice. Thank you! |
Quote:
If you don't mind, could you please provide me some working example? My current screen resolution is 1920x1080, but am not willing to limit this to such. Many thanks! |
|
All times are GMT -6. The time now is 05:58 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI