View Single Post
10-16-17, 04:48 PM   #9
CC_WOW
A Deviate Faerie Dragon
 
CC_WOW's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2016
Posts: 19
I just have a bunch of frames, with lots of smaller (child) elements inside. Can I simply do a SetScale(UIParent:GetScale()) tfor he parent or do I still have to round the coordinates for everything?

I'm somewhat confused still, but my understanding is that there are several different issues at hand.

1) Scaling according to the user interface settings

No CVar is needed, I simply do SetScale on all top-level addon frames. This should always scale them properly so they will appear with the same relative size (but can have glitches due to floating point pixel coordinates). Also, their actual position may shift, but I think there's a library called LibWindow to handle that properly across resolutions.

Example:

MainFrame:SetWidth(500) as hardcoded value without scaling => results in exactly 500px no matter what BEFORE applying the UIScale. That is, it will be exactly 500 pixels at a 1.0 scale.
Now, the user sets their scale to 0.8, which means the frame will be 500px on the relative coordinates of the UIParent viewport, resulting in 500 * 1/0.8 = 600 px actual screen size. If 0.8 is the "correct" scale for their resolution there should be no problem, because every pixel on the viewport would align with one on the actual screen. If it isn't, there would be glitches and it gets tricky...

2) Pixel perfection

At a pixel perfect scale (i.e., one that matches the 768/screenWidth calculation in my first post), no glitches would occur (1:1 mapping between virtual/actual pixels). However, if the scale is arbitrary then frames will be sized and positioned "between" pixels, causing the shifting borders/alignment issues. To fix this, I could either "undo" the scaling for my frame, by multiplying by the UIScale which gives it a pixel perfect look, but also remains static - that is not really an option, or I can attempt to reposition it correctly on the <height>x768 pixel grid used internally (height based on aspect ratio - does that even matter here?).

Therefore, I have to round the main frames' coordinates and always use integer sizes (ideally, even ones so children can be positioned correctly) AFTER applying the user's UIScale to size them. I should also avoid elements such as FontStrings having an odd size if they are to be centered, but otherwise I could map out the children's layout exactly like on paper without changing anything in the code (using values directly, merely the parent would need to be scaled/rounded).

Is that correct or am I still missing something? I have played around with it, but the GUI code is incredibly messy so I'd rather do it right.
  Reply With Quote