WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Adding one pixel in a frame's height instead adds two? (https://www.wowinterface.com/forums/showthread.php?t=57364)

spychalski 08-17-19 01:51 AM

Adding one pixel in a frame's height instead adds two?
 
Hey, it's my first time messing around with addons, trying to make a simple frame and ran into a very intriguing issue.

For starters, here is some code:
Lua Code:
  1. local function CreateUnitFrame(self, unit)
  2.     self:SetSize(220, 41)
  3.     self:SetBackdrop(settings.textures.backdrop)
  4.     self:SetBackdropColor(0, 0, 0)
  5.  
  6.     -- health bar
  7.     local hp = CreateFrame("StatusBar", nil, self)
  8.     hp:SetPoint("TOPLEFT")
  9.     hp:SetPoint("TOPRIGHT")
  10.     hp:SetHeight(30)
  11.     hp:SetStatusBarTexture(settings.textures.main)
  12.     hp:SetStatusBarColor(unpack(settings.colors.hpBar))
  13.  
  14.     hp.bg = hp:CreateTexture(nil, "BACKGROUND")
  15.     hp.bg:SetAllPoints(hp)
  16.     hp.bg:SetTexture(settings.textures.backdrop.bgFile)
  17.  
  18.     hp.frequentUpdates = true
  19.     hp.PostUpdate = core.SetBackground
  20.     self.Health = hp
  21.  
  22.     -- power bar
  23.     local pb = CreateFrame("StatusBar", nil, self)
  24.     pb:SetPoint("BOTTOMLEFT", 0, 0)
  25.     pb:SetPoint("BOTTOMRIGHT", 0, 0)
  26.     pb:SetHeight(10)
  27.     pb:SetStatusBarTexture(settings.textures.main)
  28.  
  29.     pb.bg = pb:CreateTexture(nil, "BACKGROUND")
  30.     pb.bg:SetAllPoints(pb)
  31.     pb.bg:SetTexture(settings.textures.backdrop.bgFile)
  32.     pb.bg:SetVertexColor(unpack(settings.colors.hpBar))
  33.  
  34.     pb.colorPower = true
  35.     self.Power = pb
  36. end

This is a simple Frame with a Health bar and a Power bar. My goal is to have 1px borders around the frame itself and one pixel separating the two bars. Instead, this is what I get:



and in case you can't see it:


the frame's height is 44, when it should be 43:

1 px top
40 px health
1 px gap
10 px power
1 px bottom

Now, checking the second image, I can tell you the Power bar is only 9 pixels high. The underlying frame is "taking" one pixel from it.

Does anybody have any ideas how to approach and fix this?

I already messed around with UI scales, no matter what it is (0.5333, 0.64, 0.7111 and 1 tested), the issue persists.

The only way I can fix this is by instead drawing one of the inner bars with one less pixel.

elcius 08-17-19 05:58 AM

most likely caused by floating point errors on a parent frames position or size.
doing this may work:
Lua Code:
  1. self:SetSize(220.1, 41.1)

Kanegasi 08-17-19 07:51 AM

As elcius points out, sizing is off on every UI element due to UI scale. If you don't use the UI scale option, WoW does not default it to 1, it attempts to give you a pixel perfect size, which is about 0.7 for a 1920x1080 screen. In the past, WoW gave you 1, which is why older screenshots, especially vanilla, had bigger screen elements like the bottom bar taking up the whole screen width.

The problem with a UI scale under 1 is that while sizing and positioning attributes go with the screen size, the "absolute" values are hidden and configured for us behind the scenes, which are approximately "screen / scale". This means a 1920x1080 screen using a scale of 0.7 has an absolute size of 2742x1542 "underneath". There is no way to directly get these values, at least no way I'm aware of, but MoveAnything gives you the absolute values of a frame, which is what I use when carefully moving something to avoid weird thick or antialiased borders. The "visible" values end up with decimal places but the frame I'm moving gets a razor sharp edge.


All times are GMT -6. The time now is 07:23 PM.

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