Originally Posted by Fizzlemizz
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:
Castbar:SetSize(250, 32);
Castbar:SetPoint("CENTER");
Icon:SetSize(32, 32);
Icon:SetPoint("RIGHT", Castbar, "LEFT", -2, 0);
Castbar:ClearAllPoints();
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:
A.CreateCastBar = function(f, unit)
local point, relativeTo, relativePoint, xOfs, yOfs = unpack(G[unit]["castbar"]["point"]);
local CastBar = CreateFrame("Frame", f:GetName() .. "Castbar", f);
CastBar:SetFrameStrata("LOW");
CastBar:SetSize(G[unit]["castbar"]["width"], G[unit]["castbar"]["height"]);
CastBar:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 200);
local Bar = CreateFrame("StatusBar", nil, CastBar);
Bar:SetSize(CastBar:GetWidth() - 36, CastBar:GetHeight() - 2);
Bar:SetPoint("RIGHT", CastBar, "RIGHT", -1, 0);
Bar:SetStatusBarTexture(CAST_BAR);
Bar:SetStatusBarColor(playerColor.r, playerColor.g, playerColor.b, 1);
CastBar.Bar = Bar;
local backdrop = CreateFrame("Frame", nil, Bar);
backdrop:SetSize(Bar:GetWidth() + 2, Bar:GetHeight() + 2);
backdrop:SetPoint("CENTER", Bar, "CENTER");
backdrop:SetBackdrop({
bgFile = nil,
edgeFile = BACKDROP,
edgeSize = 1,
insets = {
left = 1,
right = 1,
top = 1,
bottom = 1,
},
});
backdrop:SetBackdropBorderColor(0, 0, 0, 1);
Bar.backdrop = backdrop;
local bg = Bar:CreateTexture(nil, "BACKGROUND");
bg:SetAllPoints(true);
bg:SetTexture(BACKDROP);
bg:SetVertexColor(playerColor.r * 0.2, playerColor.g * 0.2, playerColor.b * 0.2, 1);
Bar.bg = bg;
local Icon = CreateFrame("Frame", nil, CastBar);
Icon:SetSize(CastBar:GetWidth() - 254, CastBar:GetHeight() - 2);
Icon:SetPoint("LEFT", CastBar, "LEFT", 1, 0);
CastBar.Icon = Icon;
backdrop = CreateFrame("Frame", nil, Icon);
backdrop:SetSize(Icon:GetWidth() + 2, Icon:GetHeight() + 2);
backdrop:SetPoint("CENTER", Icon, "CENTER");
backdrop:SetBackdrop({
bgFile = nil,
edgeFile = BACKDROP,
edgeSize = 1,
insets = {
left = 1,
right = 1,
top = 1,
bottom = 1,
},
});
backdrop:SetBackdropBorderColor(0, 0, 0, 1);
Icon.backdrop = backdrop;
local texture = Icon:CreateTexture(nil, "OVERLAY");
texture:SetAllPoints(true);
texture:SetTexture(BACKDROP);
texture:SetVertexColor(playerColor.r * 0.2, playerColor.g * 0.2, playerColor.b * 0.2, 1);
Icon.texture = texture;
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?