vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 --[[--------------------------------------------------------------------------------
3 Definition
4 -----------------------------------------------------------------------------------]]
5  
6 AceGUIElement = AceModuleClass:new({
7 defSmallBackdropColor = {0.1, 0.1, 0.1},
8 defSmallBackdropBorderColor = {0.4, 0.4, 0.4},
9 normalFontColor = {NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b},
10 highlightFontColor = {HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b},
11 disabledFontColor = {GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b},
12 })
13  
14 function AceGUIElement:Initialize(parent, name, def, unit, handler)
15 local ctl
16  
17 if( parent ) then
18 ctl = getglobal(parent:GetName()..name)
19 if( not ctl ) then
20 error("'"..parent:GetName().."' has no child '"..name.."'.", 3)
21 end
22 parent[name] = ctl
23 ctl.handler = handler or parent.handler
24 else
25 ctl = getglobal(name)
26 if( not ctl ) then
27 error("'"..parent:GetName().."' has no child '"..name.."'.", 3)
28 end
29 ctl.handler = handler
30 end
31  
32 ctl.parentUnit = unit or (parent and parent.parentUnit)
33 ctl._driver = self
34 ctl._def = def
35 ctl._lookup = getmetatable(ctl).__index
36  
37 setmetatable(ctl, {__index =
38 function(self, key)
39 return self._driver[key] or self:_lookup(key)
40 end
41 })
42  
43 ctl:Setup()
44 ctl:BuildElements()
45 ctl:ApplySettings()
46 ctl:Configure()
47 return ctl
48 end
49  
50  
51 --[[--------------------------------------------------------------------------------
52 Method Handlers
53 -----------------------------------------------------------------------------------]]
54  
55 function AceGUIElement:_CALL(key, ...)
56 return self:_lookup(key)(self, unpack(arg))
57 end
58  
59 function AceGUIElement:CallHandler(handler, ...)
60 if( self._def[handler] ) then
61 self.handler[self._def[handler]](self.handler, unpack(arg))
62 end
63 if( self.parentUnit and self.parentUnit[handler] ) then
64 self.parentUnit[handler](self.parentUnit, unpack(arg))
65 elseif( self[handler] ) then
66 self[handler](self, unpack(arg))
67 end
68 end
69  
70 function AceGUIElement:CallMethod(meth, ...)
71 if( self._def[meth] ) then
72 return self.handler[self._def[meth]](self.handler, unpack(arg))
73 end
74 end
75  
76  
77 --[[--------------------------------------------------------------------------------
78 Create the Element
79 -----------------------------------------------------------------------------------]]
80  
81 function AceGUIElement:Setup() end
82 function AceGUIElement:Configure() end
83  
84 function AceGUIElement:ApplySettings()
85 local def = self._def
86  
87 if( def.value ) then self:SetValue(def.value) end
88 if( def.width ) then self:SetWidth(def.width) end
89 if( def.height ) then self:SetHeight(def.height) end
90 if( def.anchors ) then self:ApplyAnchors(def.anchors) end
91 end
92  
93 function AceGUIElement:ApplyAnchors(anchors, clear)
94 if( clear ) then self:ClearAllPoints() end
95 for anchor, options in anchors do
96 if( options.relTo ) then
97 options.relTo = gsub(options.relTo, "$parent", self:GetParent():GetName(), 1)
98 end
99 self:SetPoint(strupper(anchor),
100 options.relTo or self:GetParent():GetName(),
101 strupper(options.relPoint or anchor),
102 options.xOffset or 0,
103 options.yOffset or 0
104 )
105 end
106 end
107  
108 function AceGUIElement:BuildElements()
109 if( not self._def.elements ) then return end
110  
111 for name, def in self._def.elements do
112 local ctl = ACEGUI_DRIVER_MAP[def.type or 0]:Initialize(
113 self,
114 name,
115 def,
116 self.isUnit and self
117 )
118 if( ctl ) then
119 if( def.disabled ) then ctl:Disable() end
120 if( def.OnLoad ) then self:CallHandler("OnLoad") end
121 end
122 end
123 end
124  
125 function AceGUIElement:SetLabel(text)
126 if( self.Title ) then
127 self.Title:SetText(text or self._def.title)
128 elseif( self.Label ) then
129 self.Label:SetText(text or self._def.title)
130 else
131 return
132 end
133  
134 if( not self._def.labelOptions ) then return end
135  
136 local options = self._def.labelOptions
137 if( options.align == "left" ) then
138 self.Label:ClearAllPoints()
139 self.Label:SetPoint("RIGHT",
140 self:GetName(),
141 "LEFT",
142 (options.hOffset or 0) + (self.labelHorzAdjust or 0),
143 (options.vOffset or 0) + (self.labelVertAdjust or 0)
144 )
145 elseif( options.align == "right" ) then
146 self.Label:ClearAllPoints()
147 self.Label:SetPoint("LEFT",
148 self:GetName(),
149 "RIGHT",
150 (options.hOffset or 0) + (self.labelHorzAdjust or 0),
151 (options.vOffset or 0) + (self.labelVertAdjust or 0)
152 )
153 else
154 self.Label:ClearAllPoints()
155 self.Label:SetPoint("BOTTOMLEFT",
156 self:GetName(),
157 "TOPLEFT",
158 (options.hOffset or 5) + (self.labelHorzAdjust or 0),
159 (options.vOffset or 1) + (self.labelVertAdjust or 0)
160 )
161 end
162 end
163  
164  
165 --[[--------------------------------------------------------------------------------
166 Value Access
167 -----------------------------------------------------------------------------------]]
168  
169 function AceGUIElement:GetValue()
170 if( self:_lookup("GetValue") ) then
171 return self:_CALL("GetValue")
172 elseif( self.SetText ) then
173 return self:GetText()
174 end
175 end
176  
177 function AceGUIElement:SetValue(val)
178 if( self:_lookup("SetValue") ) then
179 self:_CALL("SetValue", val)
180 elseif( self.SetText ) then
181 self:SetText(val or "")
182 end
183 end
184  
185 function AceGUIElement:Clear()
186 if( self.SetText ) then self:SetText("") end
187 end
188  
189  
190 --[[--------------------------------------------------------------------------------
191 Miscellaneous Shared Tools
192 -----------------------------------------------------------------------------------]]
193  
194 function AceGUIElement:ShowTooltip(owner, text)
195 GameTooltip:ClearAllPoints()
196 GameTooltip:SetOwner(owner, "ANCHOR_NONE")
197 GameTooltip:SetPoint("BOTTOMLEFT", owner:GetName(), "TOPLEFT", 20, 2)
198 GameTooltip:SetText(text, nil, nil, nil, nil, 1)
199 end
200  
201 function AceGUIElement:CloseDropDowns()
202 for _, ctl in ACEGUI_REGISTRY.dropDowns do
203 if( ctl.Menu:IsVisible() ) then ctl.Menu:Hide() end
204 end
205 end