diff lib/LibShowActionGrid-1.0/LibShowActionGrid-1.0.lua @ 193:576c50e51fc5

LibShowGrid-1.0 external library --> LibShowActionGrid-1.0 internal library
author Flick <flickerstreak@gmail.com>
date Mon, 15 Nov 2010 10:22:45 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/LibShowActionGrid-1.0/LibShowActionGrid-1.0.lua	Mon Nov 15 10:22:45 2010 -0800
@@ -0,0 +1,94 @@
+--
+-- A secure proxy for ACTIONBAR_SHOW/HIDEGRID events
+-- The events are transmitted via SetAttribute("state-showgrid",count) to frames registered with :AddFrame()
+-- and can be handled by an appropriate SecureHandlerStateTemplate or SecureHandlerAttributeTemplate.
+--
+
+-- This library is internal to ReAction. If an addon author finds another use for this library, PM me on wowace
+-- and I'll see about re-exporting it as a standalone library.
+
+local libName = "ReAction-LibShowActionGrid-1.0"
+local minor = 1
+assert(LibStub, libName.." requires LibStub")
+local lib = LibStub:NewLibrary(libName, minor)
+if not lib then return end
+
+-- this being v1, no upgrade actions necessary
+
+local f = CreateFrame("CheckButton","LibShowActionGridProxyFrame-1.0-"..minor,UIParent,"ActionBarButtonTemplate, SecureHandlerAttributeTemplate")
+
+f:UnregisterAllEvents()
+f:RegisterEvent("ACTIONBAR_SHOWGRID");
+f:RegisterEvent("ACTIONBAR_HIDEGRID");
+
+f:SetScript("OnEnter",nil)
+f:SetScript("OnLeave",nil)
+f:SetScript("PostClick",nil)
+f:SetScript("OnDragStart",nil)
+f:SetScript("OnReceiveDrag",nil)
+f:SetScript("OnUpdate",nil)
+-- leave OnEvent
+
+f:SetAttribute("showgrid",10) -- set to >0 to prevent a call to HasAction(nil) that will cause a lua error
+f:SetAttribute("action",0)
+f:EnableMouse(false)
+for _, child in ipairs({f:GetChildren()}) do
+  child:Hide()
+end
+for _, region in ipairs({f:GetRegions()}) do
+  region:Hide()
+end
+f:SetPoint("TOPLEFT")
+f:Hide()
+
+f:Execute(
+  [[
+    frames = newtable()
+  ]])
+
+f:SetAttribute("_onattributechanged", 
+  -- function _onattributechanged(self,name,value)
+  [[
+    if name == "showgrid" then
+      for _, f in ipairs(frames) do
+        f:SetAttribute("state-showgrid",(tonumber(value) or 10) - 10)
+      end
+    end
+  ]])
+
+lib.frame = f
+lib.framelist = setmetatable({},{__mode="k"})
+
+---
+--- library interface
+---
+
+function lib:AddFrame(frame)
+  self.framelist[frame] = true
+  self.frame:SetFrameRef("add-frame",frame)
+  self.frame:Execute(
+    [[
+      local frame = self:GetFrameRef("add-frame")
+      for _, f in ipairs(frames) do
+        if f == frame then return end
+      end
+      table.insert(frames,frame)
+    ]])
+end
+
+function lib:RemoveFrame(frame)
+  self.frame:SetFrameRef("remove-frame",frame)
+  self.frame:Execute(
+    [[
+      local frame = self:GetFrameRef("remove-frame")
+      for idx, f in ipairs(frames) do
+        if f == frame then
+          table.remove(frames,idx)
+          return 
+        end
+      end
+    ]])
+  self.framelist[frame] = nil
+end
+
+