comparison 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
comparison
equal deleted inserted replaced
191:2c05008464e5 193:576c50e51fc5
1 --
2 -- A secure proxy for ACTIONBAR_SHOW/HIDEGRID events
3 -- The events are transmitted via SetAttribute("state-showgrid",count) to frames registered with :AddFrame()
4 -- and can be handled by an appropriate SecureHandlerStateTemplate or SecureHandlerAttributeTemplate.
5 --
6
7 -- This library is internal to ReAction. If an addon author finds another use for this library, PM me on wowace
8 -- and I'll see about re-exporting it as a standalone library.
9
10 local libName = "ReAction-LibShowActionGrid-1.0"
11 local minor = 1
12 assert(LibStub, libName.." requires LibStub")
13 local lib = LibStub:NewLibrary(libName, minor)
14 if not lib then return end
15
16 -- this being v1, no upgrade actions necessary
17
18 local f = CreateFrame("CheckButton","LibShowActionGridProxyFrame-1.0-"..minor,UIParent,"ActionBarButtonTemplate, SecureHandlerAttributeTemplate")
19
20 f:UnregisterAllEvents()
21 f:RegisterEvent("ACTIONBAR_SHOWGRID");
22 f:RegisterEvent("ACTIONBAR_HIDEGRID");
23
24 f:SetScript("OnEnter",nil)
25 f:SetScript("OnLeave",nil)
26 f:SetScript("PostClick",nil)
27 f:SetScript("OnDragStart",nil)
28 f:SetScript("OnReceiveDrag",nil)
29 f:SetScript("OnUpdate",nil)
30 -- leave OnEvent
31
32 f:SetAttribute("showgrid",10) -- set to >0 to prevent a call to HasAction(nil) that will cause a lua error
33 f:SetAttribute("action",0)
34 f:EnableMouse(false)
35 for _, child in ipairs({f:GetChildren()}) do
36 child:Hide()
37 end
38 for _, region in ipairs({f:GetRegions()}) do
39 region:Hide()
40 end
41 f:SetPoint("TOPLEFT")
42 f:Hide()
43
44 f:Execute(
45 [[
46 frames = newtable()
47 ]])
48
49 f:SetAttribute("_onattributechanged",
50 -- function _onattributechanged(self,name,value)
51 [[
52 if name == "showgrid" then
53 for _, f in ipairs(frames) do
54 f:SetAttribute("state-showgrid",(tonumber(value) or 10) - 10)
55 end
56 end
57 ]])
58
59 lib.frame = f
60 lib.framelist = setmetatable({},{__mode="k"})
61
62 ---
63 --- library interface
64 ---
65
66 function lib:AddFrame(frame)
67 self.framelist[frame] = true
68 self.frame:SetFrameRef("add-frame",frame)
69 self.frame:Execute(
70 [[
71 local frame = self:GetFrameRef("add-frame")
72 for _, f in ipairs(frames) do
73 if f == frame then return end
74 end
75 table.insert(frames,frame)
76 ]])
77 end
78
79 function lib:RemoveFrame(frame)
80 self.frame:SetFrameRef("remove-frame",frame)
81 self.frame:Execute(
82 [[
83 local frame = self:GetFrameRef("remove-frame")
84 for idx, f in ipairs(frames) do
85 if f == frame then
86 table.remove(frames,idx)
87 return
88 end
89 end
90 ]])
91 self.framelist[frame] = nil
92 end
93
94