Quantcast WoWInterface - View Single Post - What parts of an addon's GUI should be "pixel perfect"?
View Single Post
10-15-17, 03:25 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,007
Pixel perfection is like counting money: start at the largest possible then work down to the smallest. The first thing is to get your perfect scale as you've done (0.71111) and apply that to the SetCVars as appropriate.

Next, assuming you want to release your code to the public, is check if your new scale is <= 0.64 which is the lowest WoW allows for the CVars. If your scale is lower, as will happen with 4K screens, apply your new scale to UIParent.
Code:
-- already set the CVars, now check UIParent
if newScale <= 0.64 then
    UIParent:SetScale(newScale)
end
Now you are ready to begin. Create a frame and set its scale to 1, which if you read above, is actually 1/newScale behind the scenes. If you applied newScale to myFrame a second time, that is exactly what you would be doing effectively setting the scale on myFrame twice. If myFrame is too large or too small, then SetScale(0.5) or SetScale(2) that way.

If you set the scale on myFrame the way most people think, you'd be setting it as 1/newScale/newScale which is probably not what you want. Let the CVar and UIParent's scale do most of the work for you.

Okay, good. Next you will need to get the TOPLEFT and BOTTOMRIGHT attributes of myFrame, possibly height and width as well, and either floor or ceil to make sure they are sitting on pixel integers. The other method is SetPoint one corner of myFrame, usually myFrame's TOPLEFT directly on a pixel integer, then calculate if BOTTOMRIGHT is also sitting on a pixel integer. If not, adjust the height or width using floor or ceil until that is the case. TOPLEFT should still be anchored correctly.

Voila, myFrame is now pixel perfect.
  Reply With Quote