Quantcast
Is there any possible way to temporarily group frames up? - WoWInterface
Thread Tools Display Modes
02-28-16, 06:48 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Is there any possible way to temporarily group frames up?

So, my plan was to create a cast bar frame which has icon and bar.

Icon has it's base frame and texture (which becomes actual icon displayer), while bar has base frame, status bar frame and texture (which becomes background of status bar), and I would like to (temporarily) group up two base frames.

e.g:
Lua Code:
  1. -- Castbar (Bar)
  2. local Castbar = CreateFrame("StatusBar", nil, UIParent);
  3.  
  4. local backdrop = CreateFrame("Frame"), nil, Castbar);
  5.  
  6. local bg = Castbar:CreateTexture(nil, "BACKGROUND");
  7.  
  8. Castbar.backdrop = backdrop;
  9. Castbar.bg = bg;
  10.  
  11.  
  12. -- Castbar (Icon)
  13. local Icon = CreateFrame("Frame", nil, UIParent);
  14.  
  15. backdrop = CreateFrame("Frame", nil, Icon);
  16.  
  17. local texture = Icon:CreateTexture(nil, "OVERLAY");
  18.  
  19. Icon.backdrop = backdrop;
  20. Icon.texture = texture;

The reason that I'm trying to group them is to SetPoint() as single frame.

I'm not sure if my explanation was clear enough, but any helps that I could get?

(Of course, I could create another base frame which would contain Castbar and Icon, but I would like to ask if there is any alternatives.)

Last edited by Layback_ : 02-28-16 at 06:57 AM.
  Reply With Quote
02-28-16, 10:08 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
You can use SetPoint to make one frame an anchor for another frame. If you move the anchor, the anchored frame moves with it.

local f1 = CreateFrame("Frame")
f1:SetPoint(CENTER)

local f2 = CreateFrame("Frame")
f2:SetPoint(CENTER, f1)

f1:ClearAllPoints()
f1:SetPoint(LEFT)

f1 and f2 are now both set left. Of course they will stay anchored until you SetPoint f2 to something else (another frame or UIParent).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-28-16, 04:11 PM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Fizzlemizz View Post
You can use SetPoint to make one frame an anchor for another frame. If you move the anchor, the anchored frame moves with it.

local f1 = CreateFrame("Frame")
f1:SetPoint(CENTER)

local f2 = CreateFrame("Frame")
f2:SetPoint(CENTER, f1)

f1:ClearAllPoints()
f1:SetPoint(LEFT)

f1 and f2 are now both set left. Of course they will stay anchored until you SetPoint f2 to something else (another frame or UIParent).
Hi Fizzlemizz!

Hm.... I think I need provide more clarifications regarding my question.

Your method is pretty close to what I'm expecting to achieve.

Have a look at this image here.



So, like I mentioned on initial thread, it has Icon and Castbar like any other Castbar addons.

If I would like to "CENTER" them on screen with your method, it would become something like this:

Lua Code:
  1. Castbar:SetSize(250, 32);
  2. Castbar:SetPoint("CENTER");
  3.  
  4. Icon:SetSize(32, 32);
  5. Icon:SetPoint("RIGHT", Castbar, "LEFT", -2, 0);
  6.  
  7. Castbar:ClearAllPoints();
  8. Castbar:SetPoint("CENTER", UIParent, "CENTER", ((Icon:GetWidth() + 2) / 2), 0);

I know that those two frames will move together since Icon is anchored to Castbar.

However, in order to set their position to center of the screen, I'll have to do a calculation like ((Icon:GetWidth() + 2) / 2) to get xOffset instead of just putting 0.

This would still work, and I'm happy enough to use this if there is no possible alternatives, but I would like to ask any simpler approaches(?) for this.

Last edited by Layback_ : 02-28-16 at 04:23 PM.
  Reply With Quote
02-28-16, 04:34 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,745
This is the only way apart from having a main anchor frame that your castbar and icon are both anchored/attached to.

Code:
------------------------------------------------------- <--anchor frame
|------- ---------------------------------------------|
||Icon | |     Castbar                               ||
|------- ---------------------------------------------|
-------------------------------------------------------
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-28-16, 04:41 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
First, are you actually planning to centre the overall display directly over, above or below you character? If not it may not be a big deal.

That said, even adding a third "background" bar to anchor the icon and statusbar too to then centre, you would sill need to calculate the width of the icon and bar to centre the anchor properly.

One way saves you a frame but you might have to save the offset if you are going to "align" it to various objects. The other saves you having to save the offset but creates a frame.

All things being equal frames are relatively cheap, even in the standard UI there are thousands so in this case, it probably comes down to what is easiest for you to manage/maintain.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-28-16, 04:56 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,745
Originally Posted by Fizzlemizz View Post
That said, even adding a third "background" bar to anchor the icon and statusbar too to then centre, you would sill need to calculate the width of the icon and bar to centre the anchor properly.
Not necessarily.

Lua Code:
  1. local anchor = CreateFrame("Frame", nil, UIParent)
  2. anchor:SetWidth(300)
  3. anchor:SetHeight(40)
  4. anchor:SetPoint("CENTER")
  5.  
  6. local icon = anchor:CreateTexture()
  7. icon:SetWidth(38)
  8. icon:SetHeight(38)
  9. icon:SetPoint("TOPLEFT", anchor, "TOPLEFT", 1, -1)
  10.  
  11. local sbar = CreateFrame("StatusBar", nil, anchor)
  12. sbar:SetHeight(38)
  13. sbar:SetPoint("TOPRIGHT", anchor, "TOPRIGHT", -1, -1)
  14. sbar:SetPoint("TOPLEFT", icon, "TOPRIGHT", 1, 0)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-28-16, 05:09 PM   #7
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Fizzlemizz View Post
First, are you actually planning to centre the overall display directly over, above or below you character? If not it may not be a big deal.

That said, even adding a third "background" bar to anchor the icon and statusbar too to then centre, you would sill need to calculate the width of the icon and bar to centre the anchor properly.

One way saves you a frame but you might have to save the offset if you are going to "align" it to various objects. The other saves you having to save the offset but creates a frame.

All things being equal frames are relatively cheap, even in the standard UI there are thousands so in this case, it probably comes down to what is easiest for you to manage/maintain.
For the player's cast bar, I'm planning to position it about 200 pixels above UIParent's "BOTTOM" point.

So, if I'd enhance(?) my previous code, it would be something like this.

Lua Code:
  1. Castbar:SetSize(250, 32);
  2. Castbar:SetPoint("CENTER");
  3.  
  4. Icon:SetSize(32, 32);
  5. Icon:SetPoint("RIGHT", Castbar, "LEFT", -2, 0);
  6.  
  7. Castbar:ClearAllPoints();
  8. Castbar:SetPoint("BOTTOM", UIParent, "BOTTOM", ((Icon:GetWidth() + 2) / 2), 200);

And in fact, my previous version of castbar already has third "background" frame which I actually made as a Parent frame of Bar and Icon.

Here's the entire code for it:

Lua Code:
  1. A.CreateCastBar = function(f, unit)
  2.     local point, relativeTo, relativePoint, xOfs, yOfs = unpack(G[unit]["castbar"]["point"]);
  3.  
  4.     local CastBar = CreateFrame("Frame", f:GetName() .. "Castbar", f);
  5.     CastBar:SetFrameStrata("LOW");
  6.     CastBar:SetSize(G[unit]["castbar"]["width"], G[unit]["castbar"]["height"]);
  7.     CastBar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 200);
  8.  
  9.     local Bar = CreateFrame("StatusBar", nil, CastBar);
  10.     Bar:SetSize(CastBar:GetWidth() - 36, CastBar:GetHeight() - 2);
  11.     Bar:SetPoint("RIGHT", CastBar, "RIGHT", -1, 0);
  12.     Bar:SetStatusBarTexture(CAST_BAR);
  13.     Bar:SetStatusBarColor(playerColor.r, playerColor.g, playerColor.b, 1);
  14.  
  15.     CastBar.Bar = Bar;
  16.  
  17.     local backdrop = CreateFrame("Frame", nil, Bar);
  18.     backdrop:SetSize(Bar:GetWidth() + 2, Bar:GetHeight() + 2);
  19.     backdrop:SetPoint("CENTER", Bar, "CENTER");
  20.     backdrop:SetBackdrop({
  21.         bgFile = nil,
  22.         edgeFile = BACKDROP,
  23.         edgeSize = 1,
  24.         insets = {
  25.             left = 1,
  26.             right = 1,
  27.             top = 1,
  28.             bottom = 1,
  29.         },
  30.     });
  31.     backdrop:SetBackdropBorderColor(0, 0, 0, 1);
  32.  
  33.     Bar.backdrop = backdrop;
  34.  
  35.     local bg = Bar:CreateTexture(nil, "BACKGROUND");
  36.     bg:SetAllPoints(true);
  37.     bg:SetTexture(BACKDROP);
  38.     bg:SetVertexColor(playerColor.r * 0.2, playerColor.g * 0.2, playerColor.b * 0.2, 1);
  39.  
  40.     Bar.bg = bg;
  41.  
  42.     local Icon = CreateFrame("Frame", nil, CastBar);
  43.     Icon:SetSize(CastBar:GetWidth() - 254, CastBar:GetHeight() - 2);
  44.     Icon:SetPoint("LEFT", CastBar, "LEFT", 1, 0);
  45.  
  46.     CastBar.Icon = Icon;
  47.  
  48.     backdrop = CreateFrame("Frame", nil, Icon);
  49.     backdrop:SetSize(Icon:GetWidth() + 2, Icon:GetHeight() + 2);
  50.     backdrop:SetPoint("CENTER", Icon, "CENTER");
  51.     backdrop:SetBackdrop({
  52.         bgFile = nil,
  53.         edgeFile = BACKDROP,
  54.         edgeSize = 1,
  55.         insets = {
  56.             left = 1,
  57.             right = 1,
  58.             top = 1,
  59.             bottom = 1,
  60.         },
  61.     });
  62.     backdrop:SetBackdropBorderColor(0, 0, 0, 1);
  63.  
  64.     Icon.backdrop = backdrop;
  65.  
  66.     local texture = Icon:CreateTexture(nil, "OVERLAY");
  67.     texture:SetAllPoints(true);
  68.     texture:SetTexture(BACKDROP);
  69.     texture:SetVertexColor(playerColor.r * 0.2, playerColor.g * 0.2, playerColor.b * 0.2, 1);
  70.  
  71.     Icon.texture = texture;
  72. end

I'm personally thinking that this would be the easiest approach to create castbar, but ain't sure of how others would think.

Like you mentioned it eases me on setting the offsets of frames, but concluded me creating another frame called "CastBar".

Should I maintain this approach if I think it would be easier for me to manage with?

Last edited by Layback_ : 02-28-16 at 05:11 PM.
  Reply With Quote
02-28-16, 05:09 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
Originally Posted by Seerah View Post
Not necessarily.
My use of the words bar and frame might not be technically correct but you've still created three distinct widgets, a frame, a texture and a statusbar.

Edit: My bad, the frame is required for the texture . Too much swapping between languages.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-28-16 at 05:17 PM.
  Reply With Quote
02-28-16, 05:12 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
Originally Posted by Layback_ View Post
Should I maintain this approach if I think it would be easier for me to manage with?
Yes you should.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-28-16, 05:18 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,745
Originally Posted by Fizzlemizz View Post
My use of the words bar and frame might not be technically correct but you've still created three distinct widgets, a frame, a texture and a statusbar.

Edit: My bad, the frame is required for the texture . Too much swapping between languages.
I said "not necessarily" in response to your comment of
you would sill need to calculate the width of the icon and bar to centre the anchor properly.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
02-28-16, 05:25 PM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
Originally Posted by Seerah View Post
I said "not necessarily" in response to your comment of

It's 10:30am, is that too early to go to bed and just start again tomorrow?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
02-28-16, 08:15 PM   #12
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,745
Nah...
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Is there any possible way to temporarily group frames up?

Thread Tools
Display Modes

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