View Single Post
06-08-17, 01:17 PM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by MunkDev View Post
This happens because you're trying to fit a square peg into a round hole. Your edge file is being drawn on fractioned pixels, meaning the calculations by the UI engine are uneven to the point where your frame's edges end up in between pixels to be drawn on screen.

Normally, this aliasing effect isn't that big a of a deal if you're using larger edge textures, but when you're down to 2 px borders, it matters how large your frame is and where it's placed on screen. This function can eliminate one such case, by forcing your frame to only allow even numbers for width and height:

Lua Code:
  1. -- Force the frame to redraw on even pixels.
  2. function frame:OnSizeChanged(width, height)
  3.     width, height = floor(width + 0.5), floor(height + 0.5)
  4.     self:SetSize(width - (width % 2), height - (height % 2))
  5. end
  6.  
  7. frame:SetScript('OnSizeChanged', frame.OnSizeChanged)

Note that this might cause an infinite loop since the size is set from within the handler that responds to size changes, but find a way to bake this function into your frame.

The other case in which this happens is placing a frame so that its size causes one of the border to not fit perfectly onto a pixel. This can be fixed by the same approach as the function I just posted, but operating on the x and y offsets of your frame:GetPoint() values.
This is not enough by default, you also have to be sure that the frame is not on fraction pixels by itself too:

Lua Code:
  1. local left, bottom = self:GetLeft(), self:GetBottom()
  2.  
  3. local x = math.round(left)
  4. local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
  5.  
  6. self:ClearAllPoints()
  7. self:SetPoint("TopLeft", UIParent, "TopLeft", x, y)

And if the frame is move complex or ancored to another frame than things get even more complicated. I've managed to do pixel perfect scaling but it's well complicated as hell.
  Reply With Quote