Mercurial > wow > reaction
changeset 154:df67685b340e
Fixed some bar/overlay encapsulation
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 08 May 2009 17:30:22 +0000 |
parents | d5e11e924053 |
children | 806a61b331a0 |
files | classes/Bar.lua classes/Overlay.lua |
diffstat | 2 files changed, 59 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/classes/Bar.lua Fri May 08 17:14:36 2009 +0000 +++ b/classes/Bar.lua Fri May 08 17:30:22 2009 +0000 @@ -122,7 +122,9 @@ -- context will desync the bar list in the ReAction class. function Bar:SetName(name) self.name = name - self:SetLabel(self.name) -- Bar:SetLabel() defined in Overlay.lua + if self.overlay then + self.overlay:SetLabel(self.name) + end end function Bar:GetFrame() @@ -329,6 +331,35 @@ -- does nothing by default end +function Bar:ShowControls(show) + local f = self.overlay + if show then + if not f then + f = Bar.Overlay:New(self) -- see Overlay.lua + self.overlay = f + end + f:Show() + elseif f then + f:Hide() + end +end + +function Bar:RefreshControls() + if self.overlay and self.overlay:IsShown() then + self.overlay:RefreshControls() + end +end + +function Bar:SetLabelSubtext(text) + if self.overlay then + self.overlay:SetLabelSubtext(text) + end +end + +-- +-- Secure state functions +-- + -- pass unit=nil to set up the unit elsewhere, if you want something more complex function Bar:RegisterUnitWatch( unit, enable ) local f = self:GetFrame()
--- a/classes/Overlay.lua Fri May 08 17:14:36 2009 +0000 +++ b/classes/Overlay.lua Fri May 08 17:30:22 2009 +0000 @@ -103,8 +103,8 @@ SetButtonSize(bar, scale * bw, scale * bh, s) end -local function ComputeBarScale(bar) - local w, h = bar.controlFrame:GetWidth() - 8, bar.controlFrame:GetHeight() - 8 +local function ComputeBarScale(bar, overlay) + local w, h = overlay:GetWidth() - 8, overlay:GetHeight() - 8 local bw, bh = GetButtonSize(bar) local r, c, s = GetButtonGrid(bar) @@ -443,12 +443,12 @@ end end -local function UpdateLabelString(bar) - local label = bar.controlLabelString +local function UpdateLabelString(overlay) + local label = overlay.labelString if label then - local name = bar.labelName - if name and bar.labelSubtext then - name = format("%s (%s)", name, bar.labelSubtext) + local name = overlay.labelName + if name and overlay.labelSubtext then + name = format("%s (%s)", name, overlay.labelSubtext) end label:SetText(name or "") end @@ -499,7 +499,8 @@ label:SetTextColor(GetNormalTextColor()) label:SetText(bar:GetName()) label:Show() - bar.controlLabelString = label -- so that bar:SetLabel() can update it + overlay.labelString = label + overlay.labelName = bar:GetName() local function UpdateAnchorDecoration() local point, anchor, relPoint, x, y = f:GetPoint(1) @@ -538,7 +539,7 @@ if ss then f:SetMinResize( ((s+bw)*c*0.25)/ss, ((s+bh)*r*0.25)/ss ) f:SetMaxResize( ((s+bw)*c*2.5 + 1)/ss, ((s+bh)*r*2.5 + 1)/ss ) - scale = ComputeBarScale(bar) + scale = ComputeBarScale(bar, overlay) else f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) f:SetMaxResize( (s+128)*c+1, (s+128)*r+1 ) @@ -592,7 +593,7 @@ local ss = GetStateScale(bar) if ss then local state = bar:GetState() - SetStateScale(bar, ComputeBarScale(bar)) + SetStateScale(bar, ComputeBarScale(bar, overlay)) end StopResize() end) @@ -729,8 +730,7 @@ overlay:SetFrameLevel(1) end - bar:SetLabel(bar:GetName()) - UpdateLabelString(bar) + UpdateLabelString(overlay) UpdateAnchorDecoration() return overlay @@ -738,32 +738,25 @@ -- export methods to the Bar prototype - -function Bar:ShowControls(show) - local f = self.controlFrame - if show then - if not f then - f = CreateControls(self) - self.controlFrame = f - end - f:Show() - elseif f then - f:Hide() - end +Bar.Overlay = { } +function Bar.Overlay:New( bar ) + return setmetatable( {frame = CreateControls(bar)}, {__index=self} ) end -function Bar:RefreshControls() - if self.controlFrame and self.controlFrame:IsShown() then - self.controlFrame:RefreshControls() - end +function Bar.Overlay:SetLabel(name) + self.frame.labelName = name + UpdateLabelString(self.frame) end -function Bar:SetLabel(name) - self.labelName = name - UpdateLabelString(self) +function Bar.Overlay:SetLabelSubtext(text) + self.frame.labelSubtext = text + UpdateLabelString(self.frame) end -function Bar:SetLabelSubtext(text) - self.labelSubtext = text - UpdateLabelString(self) +function Bar.Overlay:Show() + self.frame:Show() end + +function Bar.Overlay:Hide() + self.frame:Hide() +end