Thread Tools Display Modes
07-27-16, 06:35 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Creating castbar

Hi again all,

First of all, I apologize as I feel like I'm spamming on this forum ...

I was trying to create a castbar and it was pretty easy to handle with.

Here's what I have done so far.

Lua Code:
  1. A.CreateCastbar = function(f, unit)
  2.     local Castbar = CreateFrame("StatusBar", "$parentCastbar", f);
  3.     Castbar:SetStatusBarTexture(POWER_BAR);
  4.     Castbar:SetSize(348, 33);
  5.     Castbar:SetPoint("CENTER", UIParent, "CENTER", 20, -350);
  6.  
  7.     Castbar.border = {};
  8.     A.CreateEightBorders(Castbar, Castbar, "Border", BACKDROP, {0, 0, 0, 1});
  9.  
  10.     Castbar.bg = Castbar:CreateTexture(nil, "BACKGROUND");
  11.     Castbar.bg:SetAllPoints(true);
  12.     Castbar.bg:SetTexture(BACKDROP);
  13.     Castbar.bg:SetVertexColor(0.20, 0.20, 0.20, 1);
  14.  
  15.     local Spark = Castbar:CreateTexture(nil, "OVERLAY");
  16.     Spark:SetSize(20, 20);
  17.     Spark:SetBlendMode("ADD");
  18.  
  19.     local Time = Castbar:CreateFontString(nil, "OVERLAY");
  20.     Time:SetFont(VALUE_FONT, 15, "OUTLINE");
  21.     Time:SetPoint("RIGHT", Castbar, "RIGHT", -5, 0);
  22.  
  23.     local Icon = Castbar:CreateTexture(nil, "OVERLAY");
  24.     Icon:SetSize(33, 33);
  25.     Icon:SetPoint("RIGHT", Castbar, "LEFT", -5, 0);
  26.  
  27.     Icon.border = {};
  28.     A.CreateEightBorders(Icon, Castbar, "Border", BACKDROP, {0, 0, 0, 1});
  29.  
  30.     f.Castbar = Castbar;
  31.     f.Castbar.bg = Castbar.bg;
  32.     f.Castbar.Spark = Spark;
  33.     f.Castbar.Time = Time;
  34.     f.Castbar.Icon = Icon;
  35. end



This is working fine, but I currently have one concern.

Since Castbar and Castbar.Icon are two different objects(?) (I know Icon is a child object, texture, of Castbar...), in order for me to center the entire thing, it looks like I'll have to manually move the castbar to the right by certain amount and that's why I moved Castbar frame by 20.

So, my question is that whether it is possible or not to move two things, Castbar and Castbar.Icon, as a group so that it maintain x-offset of Castbar to 0.

I hope you guys understand what I'm trying to say lel

Last edited by Layback_ : 07-27-16 at 06:44 AM.
  Reply With Quote
07-27-16, 09:01 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
You have already done this :
Lua Code:
  1. Icon:SetPoint("RIGHT", Castbar, "LEFT", -5, 0);
Your point is already relative to your castbar.
http://wowprogramming.com/docs/widgets/Region/SetPoint

Moving the castbar will move the icon aswell.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
07-27-16, 05:39 PM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
You have already done this :
Lua Code:
  1. Icon:SetPoint("RIGHT", Castbar, "LEFT", -5, 0);
Your point is already relative to your castbar.
http://wowprogramming.com/docs/widgets/Region/SetPoint

Moving the castbar will move the icon aswell.
Hi zork,

Yeah I know moving Castbar will also move Icon as well

Hm...... how should I explain this...

When Castbar is on its original point while the Icon is created, it would look something like this.



And currently, Castbar has an x-offset of 20 in order to center Castbar and Icon.



So, what I am hoping to achieve is...

1. Maintain x-offset of Castbar to 0 (like first image)

2. Center the Castbar and Icon (like second image)

3. Keep Icon to be anchored to Castbar (not Castbar anchored to Icon)

I guess it's like creating a parent frame or a helper frame that manages this..... maybe...................



Hope you understand what I am trying to say




EDIT: One extra question apart from the main one!

Does "PostUpdate~~~~", "PostCreate~~~~", "PreUpdate~~~~" and "PreCreate~~~~" functions exist as a placeholder(?) for developers to create themselves a variation on frames?

Last edited by Layback_ : 07-27-16 at 07:33 PM.
  Reply With Quote
07-28-16, 12:31 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
The post functions are hooks. We already had that discussion for PostUpdate on Health.
You can use the hooks on any of your castbars or you don't.

If you know the width of the icon, the offset between both objects and the width of the castbar you can just offset the point of the castbar via calculation.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
07-28-16, 01:54 AM   #5
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
The post functions are hooks. We already had that discussion for PostUpdate on Health.
You can use the hooks on any of your castbars or you don't.
Yeah, I definitely remember that we discussed about it few months ago as I have personally gone through your oUF_Doom over 50 times which I still could've not understand 100%, but I feel like I can get it now

Originally Posted by zork View Post
If you know the width of the icon, the offset between both objects and the width of the castbar you can just offset the point of the castbar via calculation.
You are right! I should re-visit my code and make some changes

Thank you for enlightening me!!
  Reply With Quote
07-28-16, 03:37 AM   #6
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Arua element and '/fstack' command

Deleted this reply as I just created a new thread... Sorry...

Last edited by Layback_ : 07-28-16 at 08:20 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Creating castbar


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