changeset 153:d5e11e924053

Code formatting, separate accessors from other methods in Bar.lua
author Flick <flickerstreak@gmail.com>
date Fri, 08 May 2009 17:14:36 +0000
parents 6d7ef2a3f828
children df67685b340e
files classes/Bar.lua
diffstat 1 files changed, 94 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/classes/Bar.lua	Fri May 08 01:16:08 2009 +0000
+++ b/classes/Bar.lua	Fri May 08 17:14:36 2009 +0000
@@ -110,30 +110,38 @@
   self:SetKeybindMode(false)
 end
 
-function Bar:ApplyAnchor()
-  local f = self:GetFrame()
+--
+-- Accessors
+--
+
+function Bar:GetName()
+  return self.name
+end
+
+-- only ReAction:RenameBar() should call this function. Calling from any other
+-- 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
+end
+
+function Bar:GetFrame()
+  -- this method is included for documentation purposes. It is overridden
+  -- for each object in the :New() method.
+  error("Invalid Bar object: used without initialization")
+end
+
+function Bar:GetConfig()
+  return self.config
+end
+
+function Bar:GetAnchor()
   local c = self.config
-  local p = c.point
-
-  f:SetWidth(c.width)
-  f:SetHeight(c.height)
-  f:ClearAllPoints()
-  
-  if p then
-    local a = f:GetParent()
-    if c.anchor then
-      local bar = ReAction:GetBar(c.anchor)
-      if bar then
-        a = bar:GetFrame()
-      else
-        a = _G[c.anchor]
-      end
-    end
-    local fr = a or f:GetParent()
-    f:SetPoint(p, a or f:GetParent(), c.relpoint, c.x or 0, c.y or 0)
-  else
-    f:SetPoint("CENTER")
-  end
+  return (c.point or "CENTER"), 
+         (c.anchor or self:GetFrame():GetParent():GetName()), 
+         (c.relpoint or c.point or "CENTER"), 
+         (c.x or 0), 
+         (c.y or 0)
 end
 
 function Bar:SetAnchor(point, frame, relativePoint, x, y)
@@ -147,15 +155,6 @@
   ReAction:RefreshBar(self)
 end
 
-function Bar:GetAnchor()
-  local c = self.config
-  return (c.point or "CENTER"), 
-         (c.anchor or self:GetFrame():GetParent():GetName()), 
-         (c.relpoint or c.point or "CENTER"), 
-         (c.x or 0), 
-         (c.y or 0)
-end
-
 function Bar:GetSize()
   local f = self:GetFrame()
   return f:GetWidth(), f:GetHeight()
@@ -184,6 +183,11 @@
   ReAction:RefreshBar(self)
 end
 
+function Bar:GetNumButtons()
+  local r,c = self:GetButtonGrid()
+  return r*c
+end
+
 function Bar:GetButtonGrid()
   local cfg = self.config
   local r = cfg.btnRows or 1
@@ -192,11 +196,6 @@
   return r,c,s
 end
 
-function Bar:GetNumButtons()
-  local r,c = self:GetButtonGrid()
-  return r*c
-end
-
 function Bar:SetButtonGrid(r,c,s)
   if r > 0 and c > 0 and s > 0 then
     local cfg = self.config
@@ -207,32 +206,6 @@
   ReAction:RefreshBar(self)
 end
 
-function Bar:ClipNButtons( n )
-  local cfg = self.config
-  local r = cfg.btnRows or 1
-  local c = cfg.btnColumns or 1
-
-  cfg.btnRows = ceil(n/c)
-  cfg.btnColumns = min(n,c)
-end
-
-function Bar:GetName()
-  return self.name
-end
-
-function Bar:GetFrame()
-  -- this method is included for documentation purposes. It is overridden
-  -- for each object in the :New() method.
-  error("Invalid Bar object: used without initialization")
-end
-
--- only ReAction:RenameBar() should call this function. Calling from any other
--- 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
-end
-
 function Bar:GetAlpha()
   return self.config.alpha or 1.0
 end
@@ -243,30 +216,15 @@
   ReAction:RefreshBar(self)
 end
 
-function Bar:AddButton(idx, button)
-  local f = self:GetFrame()
-
-  -- store in a weak reverse-index array
-  self.buttons[button] = idx
-
-  -- Store a properly wrapped reference to the child frame as an attribute 
-  -- (accessible via "frameref-btn#")
-  f:SetFrameRef(format("btn%d",idx), button:GetFrame())
-end
-
-function Bar:RemoveButton(button)
-  local idx = self.buttons[button]
-  if idx then
-    self:GetFrame():SetAttribute(format("frameref-btn%d",idx),nil)
-    self.buttons[button] = nil
-  end
-end
-
 -- iterator returns button, idx and does NOT iterate in index order
 function Bar:IterateButtons()
   return pairs(self.buttons)
 end
 
+--
+-- Methods
+--
+
 function Bar:SetConfigMode(mode)
   self:ShowControls(mode)
   if self.unitwatch then
@@ -297,6 +255,60 @@
   end
 end
 
+function Bar:ApplyAnchor()
+  local f = self:GetFrame()
+  local c = self.config
+  local p = c.point
+
+  f:SetWidth(c.width)
+  f:SetHeight(c.height)
+  f:ClearAllPoints()
+  
+  if p then
+    local a = f:GetParent()
+    if c.anchor then
+      local bar = ReAction:GetBar(c.anchor)
+      if bar then
+        a = bar:GetFrame()
+      else
+        a = _G[c.anchor]
+      end
+    end
+    local fr = a or f:GetParent()
+    f:SetPoint(p, a or f:GetParent(), c.relpoint, c.x or 0, c.y or 0)
+  else
+    f:SetPoint("CENTER")
+  end
+end
+
+function Bar:ClipNButtons( n )
+  local cfg = self.config
+  local r = cfg.btnRows or 1
+  local c = cfg.btnColumns or 1
+
+  cfg.btnRows = ceil(n/c)
+  cfg.btnColumns = min(n,c)
+end
+
+function Bar:AddButton(idx, button)
+  local f = self:GetFrame()
+
+  -- store in a weak reverse-index array
+  self.buttons[button] = idx
+
+  -- Store a properly wrapped reference to the child frame as an attribute 
+  -- (accessible via "frameref-btn#")
+  f:SetFrameRef(format("btn%d",idx), button:GetFrame())
+end
+
+function Bar:RemoveButton(button)
+  local idx = self.buttons[button]
+  if idx then
+    self:GetFrame():SetAttribute(format("frameref-btn%d",idx),nil)
+    self.buttons[button] = nil
+  end
+end
+
 function Bar:PlaceButton(button, baseW, baseH)
   local idx = self.buttons[button]
   if idx then