diff classes/Overlay.lua @ 154:df67685b340e

Fixed some bar/overlay encapsulation
author Flick <flickerstreak@gmail.com>
date Fri, 08 May 2009 17:30:22 +0000
parents 5c0591a31163
children 806a61b331a0
line wrap: on
line diff
--- 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