View Single Post
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