diff State.lua @ 103:890e4c4ab143

- added alpha settings (base and stateful) - added scale settings (stateful only) - updated overlay to work with stateful anchor/scale (though when in a state with scale, the button size/spacing can't be manipulated)
author Flick <flickerstreak@gmail.com>
date Thu, 06 Nov 2008 01:28:07 +0000
parents 3699d7dad312
children
line wrap: on
line diff
--- a/State.lua	Sun Oct 26 02:26:31 2008 +0000
+++ b/State.lua	Thu Nov 06 01:28:07 2008 +0000
@@ -76,7 +76,7 @@
 do
 
   -- the field names must match the field names of the options table, below
-  -- the field values are secure snippets
+  -- the field values are secure snippets or 'true' to skip the snippet for that property.
   local properties = { 
     hide = 
       [[
@@ -90,7 +90,7 @@
           hidden = h
         end
         if showAll then
-          control:CallMethod("UpdateHiddenLabel",hide[state])
+          control:CallMethod("UpdateHiddenLabel", hide and hide[state])
         end
       ]],
 
@@ -122,8 +122,35 @@
     anchorRelPoint = true,
     anchorX = true,
     anchorY = true,
-    enableScale = true,
+
+
+    enableScale = 
+      [[
+        local old_scale = scalestate
+        scalestate = (enableScale and enableScale[state]) and state
+        if old_scale ~= scalestate or not set_state then
+          if scalestate and scale then
+            if scale[state] then
+              self:SetScale(scale[state])
+            end
+          else
+            self:SetScale(1.0)
+          end
+        end
+      ]],
+      -- enableScale handles scale
     scale = true,
+
+    enableAlpha = 
+      [[
+        local old_alpha = alphastate
+        alphastate = (enableAlpha and enableAlpha[state]) and state
+        if old_alpha ~= alphastate or not set_state then
+          control:CallMethod("UpdateAlpha", alphastate and alpha[state] or defaultAlpha)
+        end
+      ]],
+      -- enableAlpha handles alpha
+    alpha = true,
   }
 
   local weak         = { __mode = "k" }
@@ -156,6 +183,10 @@
       end
       
       control:ChildUpdate()
+
+      if oldState ~= state then
+        control:CallMethod("StateRefresh", state)
+      end
     ]]
 
     local onClickHandler = 
@@ -168,6 +199,12 @@
       end
     ]] .. onStateHandler
 
+    local function UpdateAlpha( frame, alpha )
+      if alpha then
+        frame:SetAlpha(alpha)
+      end
+    end
+
     -- Construct a lua assignment as a code string and execute it within the header
     -- frame's sandbox. 'value' must be a string, boolean, number, or nil. If called
     -- with four arguments, then it treats 'varname' as an existing global table and
@@ -203,8 +240,10 @@
       SetHandlerData(bar, "defaultAnchor", relPoint, "relPoint")
       SetHandlerData(bar, "defaultAnchor", x, "x")
       SetHandlerData(bar, "defaultAnchor", y, "y")
+      SetHandlerData(bar, "defaultAlpha",  bar:GetAlpha())
 
       local f = bar:GetFrame()
+      f.UpdateAlpha = UpdateAlpha
       SetFrameRef(f, "defaultAnchor", _G[frame or "UIParent"])
       f:Execute(
         [[
@@ -231,6 +270,10 @@
         end
       end
 
+      function f:StateRefresh( state )
+        bar:RefreshControls()
+      end
+
       local props = { }
       for p, h in pairs(properties) do
         if type(h) == "string" then
@@ -737,17 +780,46 @@
               name  = L["Scale"],
               order = 2,
               type  = "range",
-              min   = 0.1,
+              min   = 0.25,
               max   = 2.5,
               step  = 0.05,
               isPercent = true,
               set   = "SetProp",
-              get   = "GetProp",
+              get   = "GetScale",
               disabled = "GetScaleDisabled",
               hidden = "GetScaleDisabled",
             },
           },
         },
+        alpha = {
+          name  = L["Transparency"],
+          order = 94,
+          type  = "group",
+          inline = true,
+          args = {
+            enableAlpha = {
+              name  = L["Set Transparency"],
+              order = 1,
+              type  = "toggle",
+              set   = "SetProp",
+              get   = "GetProp",
+            },
+            alpha = {
+              name  = L["Transparency"],
+              order = 2,
+              type  = "range",
+              min   = 0,
+              max   = 1,
+              step  = 0.01,
+              bigStep = 0.05,
+              isPercent = true,
+              set   = "SetProp",
+              get   = "GetAlpha",
+              disabled = "GetAlphaDisabled",
+              hidden = "GetAlphaDisabled",
+            },
+          },
+        },
       },
       plugins = { }
     },
@@ -1053,10 +1125,22 @@
     return self:GetProp(info) or "NONE"
   end
 
+  function StateHandler:GetScale(info)
+    return self:GetProp(info) or 1.0
+  end
+
   function StateHandler:GetScaleDisabled()
     return not GetProperty(self.bar, self:GetName(), "enableScale")
   end
 
+  function StateHandler:GetAlpha(info)
+    return self:GetProp(info) or 1.0
+  end
+
+  function StateHandler:GetAlphaDisabled()
+    return not GetProperty(self.bar, self:GetName(), "enableAlpha")
+  end
+
   function StateHandler:SetType(info, value)
     self:SetRuleField("type", value)
     self:FixAll()
@@ -1242,3 +1326,13 @@
   UnregisterProperty(field)
   UnregisterPropertyOptions(field)
 end
+
+
+-- Export methods to Bar class --
+
+function ReAction.Bar:GetState()
+  return GetManagedEnvironment(self:GetFrame()).state
+end
+
+ReAction.Bar.GetStateProperty = GetProperty
+ReAction.Bar.SetStateProperty = SetProperty