Mercurial > wow > reaction
view lib/LibShowActionGrid-1.0/LibShowActionGrid-1.0.lua @ 308:08bd2dec1f01 stable tip
Merge 1.1 beta 13 to stable
author | Flick |
---|---|
date | Wed, 14 Nov 2012 20:32:03 -0800 |
parents | 576c50e51fc5 |
children |
line wrap: on
line source
-- -- 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