Thread Tools Display Modes
11-05-14, 09:39 AM   #1
Namir
A Murloc Raider
Join Date: Nov 2014
Posts: 5
[Lua] Apply border around texture

Hey there,

I've been messing around with various approaches of creating icons which have a border. So far I have been using
Code:
f.icon:SetTexCoord(.08, .92, .08, .92)
to remove the default borders which are included in the icon texture. Similiar to ElvUI AddOnSkins I did search for some hints on how they are applying a border around the icon, yet I am having trouble of finding some more information. Basically I want to write a function which takes any frame (like f in this example), gives it a black border which is either 1px or 2px thick and insets an icon of the frame in it.

Using the code from RealUI I still had some issues because the borders were not 1px thick on every side which seemed pretty inconsistent. This might just be the texture used for this, though. The adapted code I used for testing purposes is
Code:
function CreateBD(frame, alpha)
    frame:SetBackdrop({
        bgFile = [[Interface/AddOns/nAuras/Media/BackgroundFlat]], 
        edgeFile = [[Interface/Buttons/WHITE8X8]], 
        edgeSize = 1, 
    })
    frame:SetBackdropColor(0.15, 0.15, 0.15, alpha)
    frame:SetBackdropBorderColor(0, 0, 0)
end

function CreateBDFrame(frame, alpha)
    local f
    if frame:GetObjectType() == "Texture" then
        f = frame:GetParent()
    else
        f = frame
    end
    local lvl = f:GetFrameLevel()
    local bg = CreateFrame("Frame", nil, f)
    bg:SetParent(f)
    bg:SetPoint("TOPLEFT", f, -1, 1)
    bg:SetPoint("BOTTOMRIGHT", f, 1, -1)
    bg:SetFrameLevel(lvl == 0 and 1 or lvl - 1)

    CreateBD(bg, alpha)

    return bg
end
I did even mess around with the addon rSetBackdrop yet I am stuck with getting this done with a nice approach. Do you have any suggestions how I could achieve what I am looking for?

Here is a sample image which describes my current problem.


You will notice that the first, fourth and seventh icon are displayed perfectly - the second and fifth icon however have a thick border on their left while the third and sixth icon have them on their right side.
  Reply With Quote
11-05-14, 10:03 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
This can be caused by one of three things:

1. You have UI scaling turned on. You should generally not use this option, since WoW now scales the UI correctly to be "pixel perfect" for whatever screen resolution you use by default. Setting a different UI scale will cause UI pixels to no longer align with the physical pixels on your monitor. Solution: Turn off UI scaling, and manually scale UI elements you need to be bigger/smaller.

2. You are playing in non-maximized windowed mode. This may (depending on your setup) again cause WoW's in-game resolution to not match up with the actual physical resolution of your monitor. Solution: Stop doing that.

3. Your frames are positioned between pixels. If you've dragged and dropped your frames in-game, they may be set to coordinates like 127.483792434 which, not being an integer, causes their pixels to not match up with real pixels. Solution: Position your frames using integer coordinates. If it's your own frame, you already know how to do this. If it's an addon's frame, editing the saved variables is probably the easiest method.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-05-14, 10:13 AM   #3
Namir
A Murloc Raider
Join Date: Nov 2014
Posts: 5
Originally Posted by Phanx View Post
3. Your frames are positioned between pixels.
I did create some debug outputs with the points of the frames and it appears that this is the case. Right now I am dynamically computing the point where I want the frame to be (based on how many of them should be visible) and I am not operating on floating point numbers, yet the game tells me that my frame is at xOffset -123.99999237061 although I event tried to manually set it to xOffset = -124. What might cause this precision issues?

EDIT: I turned off UIScale and I have tried Fullscreen / Windowed (Fullscreen) modes - same result.

EDIT2: Setting the xOffset to -124.5 of this specific frame fixes the issue surprisingly for this specific frame I was messing around with.

Last edited by Namir : 11-05-14 at 10:17 AM.
  Reply With Quote
11-05-14, 11:20 AM   #4
Namir
A Murloc Raider
Join Date: Nov 2014
Posts: 5
Surprisingly I resolved the issue with a simple fix - changing the parent of my indicators. It seems as if my previous parent frame was causing some issues with the proper positioning. As I don't need it anymore I just deleted it and I'm good to go. Thank you though for your suggestions on what to test exactly.
  Reply With Quote
11-05-14, 12:21 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Phanx View Post
1. You have UI scaling turned on. You should generally not use this option, since WoW now scales the UI correctly to be "pixel perfect" for whatever screen resolution you use by default.
What? I'll have to investigate that. I currently bounce between ElvUI and SupervillianUI; just testing stuff. I will have to turn off scaling and see what happens! Now you have me curious...
  Reply With Quote
11-05-14, 04:23 PM   #6
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by myrroddin View Post
What? I'll have to investigate that. I currently bounce between ElvUI and SupervillianUI; just testing stuff. I will have to turn off scaling and see what happens! Now you have me curious...
Do post with the results - I am curious as well (I play without scaling now)
__________________
  Reply With Quote
11-05-14, 05:22 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
In the past you may have used a macro to calculate the proper UI scale for your screen resolution. This is no longer necessary or useful, as the UI is scaled properly by default.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-10-14, 01:14 AM   #8
Xandr
A Kobold Labourer
Join Date: Aug 2011
Posts: 1
I believe WoW's automatic UI Scaling only works properly up to a certain resolution. I'm playing on 2560x1440 and need to scale UIParent manually to get "pixel perfect" rendering.

Code:
local screenResolution = ({GetScreenResolutions()})[GetCurrentResolution()];
local screenWidth, screenHeight = strsplit("x", screenResolution);

UIParent:SetScale(768/screenHeight);
This is how I do it during the PLAYER_ENTERING_WORLD event.
  Reply With Quote
11-10-14, 08:13 AM   #9
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by MoonWitch View Post
Do post with the results - I am curious as well (I play without scaling now)
I have no turned off the scaling check box, and tried ElvUI, SpartanUI, and SupervillianUI, and all three still scale exactly the same as when I had the toggle on. There is no visible difference with the setting on or off.

It should be noted that SVUI expressly states in its setup up to NOT adjust the scaling slider. I did not heed the advice, and slid the slider all the way down. SupervillianUI stopped working in any visible condition until I exited out of the game entirely. A reload of the UI did nothing to fix my self-inflicted problem.

tl;dr: if UI scaling is on, leave it on. If it is off, do not turn it on. And never adjust it!
  Reply With Quote
11-14-14, 02:17 PM   #10
Munglunch
Premium Member
 
Munglunch's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 34
Originally Posted by myrroddin View Post
I have no turned off the scaling check box, and tried ElvUI, SpartanUI, and SupervillianUI, and all three still scale exactly the same as when I had the toggle on. There is no visible difference with the setting on or off.

It should be noted that SVUI expressly states in its setup up to NOT adjust the scaling slider. I did not heed the advice, and slid the slider all the way down. SupervillianUI stopped working in any visible condition until I exited out of the game entirely. A reload of the UI did nothing to fix my self-inflicted problem.

tl;dr: if UI scaling is on, leave it on. If it is off, do not turn it on. And never adjust it!

That warning just screams "I am a lazy bastard of a developer and do not really want to make this feature work properly"!

My apologies for that I have been working on completely redesigning my screen management and should have it revised in the coming weeks.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » [Lua] Apply border around texture


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off