changeset 71:3d2cef5dc459

Implemented state anchoring and scaling
author Flick <flickerstreak@gmail.com>
date Wed, 04 Jun 2008 21:46:51 +0000
parents 2c12e2b1752e
children aa88aed52124
files Bar.lua State.lua
diffstat 2 files changed, 69 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Bar.lua	Tue Jun 03 23:24:03 2008 +0000
+++ b/Bar.lua	Wed Jun 04 21:46:51 2008 +0000
@@ -7,6 +7,7 @@
 local min = math.min
 local format = string.format
 local GameTooltip = GameTooltip
+local SecureStateHeader_Refresh = SecureStateHeader_Refresh
 
 
 
@@ -169,6 +170,8 @@
   self.buttons[f] = true
 end
 
+
+-- multi-state functions --
 function Bar:GetNumPages()
   return self.config.nPages or 1
 end
@@ -183,6 +186,7 @@
 end
 
 function Bar:SetStateKeybind(key, state, defaultstate)
+  -- set a keybind to toggle transitioning unconditionally to a state
   -- use a tiny offscreen button to get around making the bar itself a clickable button
   local f = self.statebuttonframe
   local off = ("%s_off"):format(state)
@@ -220,10 +224,11 @@
   local f = self.frame
   local tmp = { }
   for s, p in pairs(map) do
-    table.insert(tmp, ("%s:%d"):format(s,p))
+    table.insert(tmp, ("%s:page%d"):format(s,p))
   end
   local spec = table.concat(tmp,";")
   f:SetAttribute("statebutton",spec)
+  SecureStateHeader_Refresh(f)
 end
 
 function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled
@@ -232,14 +237,44 @@
     local s = states[i]
     states[i] = ("%s:%s"):format(s,s)
   end
-  table.insert(states,"_default")
+  table.insert(states,"_defaultbindings")
   f:SetAttribute("statebindings",table.concat(states,";"))
+  SecureStateHeader_Refresh(f)
   for b in pairs(self.buttons) do
-    -- TODO: signal child frames that they should 
-    -- maintain multiple bindings
+    -- TODO: signal child frames that they should maintain multiple bindings
   end
 end
 
+local _ofskeys = { "point", "relpoint", "x", "y" }
+function Bar:SetStateAnchorMap( map ) -- 'map' is a { ["statename"] = { point=point, relpoint=relpoint, x=x, y=y } } table
+  local f = self.frame
+  local c = self.config
+  local default = { point = c.anchor, relpoint = c.relativePoint, x = c.x, y = c.y }
+  for _, key in pairs(_ofskeys) do
+    local t = { }
+    for state, info in pairs(map) do
+      if info[key] then
+        table.insert(t, ("%s:%s"):format(state, info[key]))
+      end
+    end
+    if #t > 0 and default[key] then table.insert(t, tostring(default[key])) end
+    f:SetAttribute(("headofs%s"):format(key), table.concat(t,";") or "")
+  end
+  SecureStateHeader_Refresh(f)
+end
+
+function Bar:SetStateScaleMap( map ) -- 'map' is a { ["statename"] = scalevalue } table
+  local f = self.frame
+  local t = { }
+  for state, scale in pairs(map) do
+    table.insert( t, ("%s:%s"):format(state,scale) )
+  end
+  if #t > 0 then table.insert(t, "1.0") end
+  f:SetAttribute("headscale",table.concat(t,";") or "")
+  SecureStateHeader_Refresh(f)
+end
+
+
 --
 -- Bar config overlay
 --
@@ -597,7 +632,7 @@
     end
   end
 
-  CreateControls = function(bar)
+  function CreateControls(bar)
     local f = bar.frame
 
     f:SetMovable(true)
@@ -647,7 +682,7 @@
     label:Show()
     bar.controlLabelString = label  -- so that bar:SetName() can update it
 
-    local StopResize = function()
+    local function StopResize()
       f:StopMovingOrSizing()
       f.isMoving = false
       f:SetScript("OnUpdate",nil)
@@ -715,7 +750,7 @@
       tex:SetBlendMode("ADD")
       tex:SetAllPoints()
       corner:RegisterForDrag("LeftButton","RightButton")
-      local updateTooltip = function()
+      local function updateTooltip()
         local size, size2 = bar:GetButtonSize()
         local rows, cols, spacing = bar:GetButtonGrid()
         size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
@@ -863,10 +898,10 @@
   -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's
   -- a bit tricky to convert from AceConfig3-struct
   local Dewdrop = AceLibrary("Dewdrop-2.0")
-  OpenMenu = function(frame, opts)
+  function OpenMenu (frame, opts)
     Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true)
   end
-  CloseMenu = function(frame)
+  function CloseMenu(frame)
     if Dewdrop:GetOpenedParent() == frame then
       Dewdrop:Close()
     end
--- a/State.lua	Tue Jun 03 23:24:03 2008 +0000
+++ b/State.lua	Wed Jun 04 21:46:51 2008 +0000
@@ -236,33 +236,34 @@
     bar:SetStateKeybindOverrideMap(map)
   end
 
-  function propertyFuncs.enableanchor( bar, states )
-
+  local function updateAnchor(bar, states)
+    local map = { }
+    for state, c in pairs(states) do
+      if c.enableAnchor then
+        map[state] = { point = c.anchorPoint, relpoint = c.anchorRelPoint, x = c.anchorX, y = c.anchorY }
+      end
+    end
+    bar:SetStateAnchorMap(map)
   end
 
-  function propertyFuncs.anchorPoint( bar, states )
+  propertyFuncs.enableAnchor   = updateAnchor
+  propertyFuncs.anchorPoint    = updateAnchor
+  propertyFuncs.anchorRelPoint = updateAnchor
+  propertyFuncs.anchorX        = updateAnchor
+  propertyFuncs.anchorY        = updateAnchor
 
+  local function updateScale( bar, states )
+    local map = { }
+    for state, c in pairs(states) do
+      if c.enablescale then
+        map[state] = c.scale
+      end
+    end
+    bar:SetStateScaleMap(map)
   end
 
-  function propertyFuncs.anchorRelPoint( bar, states )
-
-  end
-
-  function propertyFuncs.anchorX( bar, states )
-
-  end
-
-  function propertyFuncs.anchorY( bar, states )
-
-  end
-
-  function propertyFuncs.enablescale( bar, states )
-
-  end
-
-  function propertyFuncs.scale( bar, states )
-
-  end
+  propertyFuncs.enablescale = updateScale
+  propertyFuncs.scale       = updateScale
 
 end
 
@@ -466,7 +467,7 @@
     end
 
     local function anchordisable()
-      return not GetProperty(bar, opts.name, "enableanchor")
+      return not GetProperty(bar, opts.name, "enableAnchor")
     end
 
     tbuild(states, name)
@@ -616,7 +617,7 @@
             type  = "group",
             inline = true,
             args = {
-              enableanchor = {
+              enableAnchor = {
                 name  = L["Set New Position"],
                 order = 1,
                 type  = "toggle",