Thread Tools Display Modes
02-08-17, 07:09 PM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Setting layer level of backdrop's border

Hi all,

Just a quick question regarding backdrop.

Before I start, let's have a look at the example code first.

Lua Code:
  1. local myPortrait = CreateFrame("PlayerModel", nil, UIParent);
  2. myPortrait:SetSize(50, 50);
  3. myPortrait:SetPoint("CENTER");
  4. ...(rest of codes to set the appearance of myPortrait)
  5.  
  6. local myTemplate = CreateFrame("Frame", nil, myPortrait);
  7. myTemplate:SetFrameLevel(myPortrait:GetFrameLevel);
  8. myTemplate:SetPoint("TOPLEFT", -1, 1);
  9. myTemplate:SetPoint("BOTTOMRIGHT", 1, -1);
  10. myTemplate:SetBackdrop({
  11.     bgFile = myBG,
  12.     edgeFile = myEdge,
  13. });
  14. myTemplate:SetBackdropColor(0.2, 0.2, 0.2);
  15. myTemplate:SetBackdropBorderColor(0, 0, 0);
  16.  
  17. myPortrait.template = myTemplate;

This will create a 50 by 50 3D portrait at the center of the screen and will also create another frame at the same frame level as portrait with the size of 52 by 52.

The problem is that since the template frame is at the same level as portrait, its backdrop will cover up the portrait (portrait is hidden at the back of template frame's backdrop).

My question here is would it be possible to send only backdrop's background to the back, but maintain border at its position and level?

So, basically the order from top to the bottom would be:

1. template frame's backdrop border
2. portrait frame
3. template frame's backdrop background

I could create a backdrop directly on portrait frame itself which would be the fastest option, and I am aware of that creating an extra frame only for backdrop is waste of resources, but still willing to know whether my concern above is possible or not

Thank you!

EDIT: :SetFrameStrata() doesn't seem to be working as I expected

Last edited by Layback_ : 02-08-17 at 07:41 PM.
  Reply With Quote
02-08-17, 11:43 PM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
My answer to one of your previous posts is applicable here as well:
Code:
local function ChangeDrawLayer(regionType, oldDrawLayer, newDrawLayer, ...)
	for index = 1, select('#', ...) do
		local region = select(index, ...)
		if region:IsObjectType(regionType) and region:GetDrawLayer() == oldDrawLayer then
			region:SetDrawLayer(newDrawLayer)
		end
	end
end

local myPortrait = CreateFrame("PlayerModel", nil, UIParent);
myPortrait:SetSize(50, 50);
myPortrait:SetPoint("CENTER");
--...(rest of codes to set the appearance of myPortrait)
 
local myTemplate = CreateFrame("Frame", nil, myPortrait);
myTemplate:SetFrameLevel(myPortrait:GetFrameLevel());
myTemplate:SetPoint("TOPLEFT", -1, 1);
myTemplate:SetPoint("BOTTOMRIGHT", 1, -1);
myTemplate:SetBackdrop({
    bgFile = myBG,
    edgeFile = myEdge,
});
myTemplate:SetBackdropColor(0.2, 0.2, 0.2);
myTemplate:SetBackdropBorderColor(0, 0, 0);
 
myPortrait.template = myTemplate;

ChangeDrawLayer('Texture', 'BORDER', 'OVERLAY', myTemplate:GetRegions())
  Reply With Quote
02-09-17, 01:43 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
This is similar to what I do with one of my personal addons that adds a portrait model to the GameTooltip.

Lua Code:
  1. local container=CreateFrame("Frame",nil,UIParent);
  2. container:SetPoint("CENTER");
  3. container:SetSize(52,52);
  4.  
  5. container:SetBackdrop({
  6.     bgFile="Interface/Tooltips/UI-Tooltip-Background",
  7.     edgeFile="Interface/Tooltips/UI-Tooltip-Border",
  8.     tile=true,tileSize=16,edgeSize=16,
  9.     insets={left=5,right=5,top=5,bottom=5}
  10. });
  11.  
  12. container:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r,TOOLTIP_DEFAULT_COLOR.g,TOOLTIP_DEFAULT_COLOR.b);
  13. container:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r,TOOLTIP_DEFAULT_BACKGROUND_COLOR.g,TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
  14.  
  15. local portrait=CreateFrame("PlayerModel",nil,container);
  16. portrait:SetPoint("TOPLEFT",4,-4);
  17. portrait:SetPoint("BOTTOMRIGHT",-5,-5);

The trick is sizing the model so it looks like it's behind the border, but it's actually in front of it.



PS: I've tried adding the backdrop directly to the model frame before, but the border never sizes correctly and you could see the edges of the model protruding from it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-09-17 at 01:46 AM.
  Reply With Quote
02-09-17, 05:23 AM   #4
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Many thanks to Vrul and SDPhantom.

For now, I'll try to stick with Vrul's approach and see how I go with it.

Can't realize I didn't even thought of about that function

Looks like I haven't learnt much since then haha...
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Setting layer level of backdrop's border


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