|
Tercio@11
|
1
|
|
Tercio@11
|
2 local DF = _G ["DetailsFramework"]
|
|
Tercio@20
|
3 if (not DF or not DetailsFrameworkCanLoad) then
|
|
Tercio@20
|
4 return
|
|
Tercio@20
|
5 end
|
|
Tercio@20
|
6
|
|
Tercio@11
|
7 local _
|
|
Tercio@11
|
8 local _rawset = rawset --> lua local
|
|
Tercio@11
|
9 local _rawget = rawget --> lua local
|
|
Tercio@11
|
10 local _setmetatable = setmetatable --> lua local
|
|
Tercio@11
|
11 local _unpack = unpack --> lua local
|
|
Tercio@11
|
12 local _type = type --> lua local
|
|
Tercio@11
|
13 local _math_floor = math.floor --> lua local
|
|
Tercio@11
|
14 local loadstring = loadstring --> lua local
|
|
Tercio@11
|
15
|
|
Tercio@11
|
16 local cleanfunction = function() end
|
|
Tercio@11
|
17 local APILabelFunctions = false
|
|
Tercio@39
|
18
|
|
Tercio@39
|
19 do
|
|
Tercio@39
|
20 local metaPrototype = {
|
|
Tercio@39
|
21 WidgetType = "label",
|
|
Tercio@39
|
22 SetHook = DF.SetHook,
|
|
Tercio@39
|
23 RunHooksForWidget = DF.RunHooksForWidget,
|
|
Tercio@39
|
24 }
|
|
Tercio@39
|
25
|
|
Tercio@39
|
26 _G [DF.GlobalWidgetControlNames ["label"]] = _G [DF.GlobalWidgetControlNames ["label"]] or metaPrototype
|
|
Tercio@39
|
27 end
|
|
Tercio@39
|
28
|
|
Tercio@39
|
29 local LabelMetaFunctions = _G [DF.GlobalWidgetControlNames ["label"]]
|
|
Tercio@11
|
30
|
|
Tercio@11
|
31 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
32 --> metatables
|
|
Tercio@11
|
33
|
|
Tercio@11
|
34 LabelMetaFunctions.__call = function (_table, value)
|
|
Tercio@11
|
35 return self.label:SetText (value)
|
|
Tercio@11
|
36 end
|
|
Tercio@11
|
37
|
|
Tercio@11
|
38 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
39 --> members
|
|
Tercio@11
|
40
|
|
Tercio@11
|
41 --> shown
|
|
Tercio@11
|
42 local gmember_shown = function (_object)
|
|
Tercio@11
|
43 return _object:IsShown()
|
|
Tercio@11
|
44 end
|
|
Tercio@11
|
45 --> frame width
|
|
Tercio@11
|
46 local gmember_width = function (_object)
|
|
Tercio@11
|
47 return _object.label:GetStringWidth()
|
|
Tercio@11
|
48 end
|
|
Tercio@11
|
49 --> frame height
|
|
Tercio@11
|
50 local gmember_height = function (_object)
|
|
Tercio@11
|
51 return _object.label:GetStringHeight()
|
|
Tercio@11
|
52 end
|
|
Tercio@11
|
53 --> text
|
|
Tercio@11
|
54 local gmember_text = function (_object)
|
|
Tercio@11
|
55 return _object.label:GetText()
|
|
Tercio@11
|
56 end
|
|
Tercio@11
|
57 --> text color
|
|
Tercio@11
|
58 local gmember_textcolor = function (_object)
|
|
Tercio@11
|
59 return _object.label:GetTextColor()
|
|
Tercio@11
|
60 end
|
|
Tercio@11
|
61 --> text font
|
|
Tercio@11
|
62 local gmember_textfont = function (_object)
|
|
Tercio@11
|
63 local fontface = _object.label:GetFont()
|
|
Tercio@11
|
64 return fontface
|
|
Tercio@11
|
65 end
|
|
Tercio@11
|
66 --> text size
|
|
Tercio@11
|
67 local gmember_textsize = function (_object)
|
|
Tercio@11
|
68 local _, fontsize = _object.label:GetFont()
|
|
Tercio@11
|
69 return fontsize
|
|
Tercio@11
|
70 end
|
|
Tercio@11
|
71
|
|
Tercio@39
|
72 LabelMetaFunctions.GetMembers = LabelMetaFunctions.GetMembers or {}
|
|
Tercio@39
|
73 LabelMetaFunctions.GetMembers ["shown"] = gmember_shown
|
|
Tercio@39
|
74 LabelMetaFunctions.GetMembers ["width"] = gmember_width
|
|
Tercio@39
|
75 LabelMetaFunctions.GetMembers ["height"] = gmember_height
|
|
Tercio@39
|
76 LabelMetaFunctions.GetMembers ["text"] = gmember_text
|
|
Tercio@39
|
77 LabelMetaFunctions.GetMembers ["fontcolor"] = gmember_textcolor
|
|
Tercio@39
|
78 LabelMetaFunctions.GetMembers ["fontface"] = gmember_textfont
|
|
Tercio@39
|
79 LabelMetaFunctions.GetMembers ["fontsize"] = gmember_textsize
|
|
Tercio@39
|
80 LabelMetaFunctions.GetMembers ["textcolor"] = gmember_textcolor --alias
|
|
Tercio@39
|
81 LabelMetaFunctions.GetMembers ["textfont"] = gmember_textfont --alias
|
|
Tercio@39
|
82 LabelMetaFunctions.GetMembers ["textsize"] = gmember_textsize --alias
|
|
Tercio@11
|
83
|
|
Tercio@11
|
84 LabelMetaFunctions.__index = function (_table, _member_requested)
|
|
Tercio@11
|
85
|
|
Tercio@39
|
86 local func = LabelMetaFunctions.GetMembers [_member_requested]
|
|
Tercio@11
|
87 if (func) then
|
|
Tercio@11
|
88 return func (_table, _member_requested)
|
|
Tercio@11
|
89 end
|
|
Tercio@11
|
90
|
|
Tercio@11
|
91 local fromMe = _rawget (_table, _member_requested)
|
|
Tercio@11
|
92 if (fromMe) then
|
|
Tercio@11
|
93 return fromMe
|
|
Tercio@11
|
94 end
|
|
Tercio@11
|
95
|
|
Tercio@11
|
96 return LabelMetaFunctions [_member_requested]
|
|
Tercio@11
|
97 end
|
|
Tercio@11
|
98
|
|
Tercio@11
|
99 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
100
|
|
Tercio@11
|
101 --> show
|
|
Tercio@11
|
102 local smember_show = function (_object, _value)
|
|
Tercio@11
|
103 if (_value) then
|
|
Tercio@11
|
104 return _object:Show()
|
|
Tercio@11
|
105 else
|
|
Tercio@11
|
106 return _object:Hide()
|
|
Tercio@11
|
107 end
|
|
Tercio@11
|
108 end
|
|
Tercio@11
|
109 --> hide
|
|
Tercio@11
|
110 local smember_hide = function (_object, _value)
|
|
Tercio@11
|
111 if (not _value) then
|
|
Tercio@11
|
112 return _object:Show()
|
|
Tercio@11
|
113 else
|
|
Tercio@11
|
114 return _object:Hide()
|
|
Tercio@11
|
115 end
|
|
Tercio@11
|
116 end
|
|
Tercio@11
|
117 --> text
|
|
Tercio@11
|
118 local smember_text = function (_object, _value)
|
|
Tercio@11
|
119 return _object.label:SetText (_value)
|
|
Tercio@11
|
120 end
|
|
Tercio@11
|
121 --> text color
|
|
Tercio@11
|
122 local smember_textcolor = function (_object, _value)
|
|
Tercio@11
|
123 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
|
|
Tercio@11
|
124 return _object.label:SetTextColor (_value1, _value2, _value3, _value4)
|
|
Tercio@11
|
125 end
|
|
Tercio@11
|
126 --> text font
|
|
Tercio@11
|
127 local smember_textfont = function (_object, _value)
|
|
Tercio@11
|
128 return DF:SetFontFace (_object.label, _value)
|
|
Tercio@11
|
129 end
|
|
Tercio@11
|
130 --> text size
|
|
Tercio@11
|
131 local smember_textsize = function (_object, _value)
|
|
Tercio@11
|
132 return DF:SetFontSize (_object.label, _value)
|
|
Tercio@11
|
133 end
|
|
Tercio@11
|
134 --> text align
|
|
Tercio@11
|
135 local smember_textalign = function (_object, _value)
|
|
Tercio@11
|
136 if (_value == "<") then
|
|
Tercio@11
|
137 _value = "left"
|
|
Tercio@11
|
138 elseif (_value == ">") then
|
|
Tercio@11
|
139 _value = "right"
|
|
Tercio@11
|
140 elseif (_value == "|") then
|
|
Tercio@11
|
141 _value = "center"
|
|
Tercio@11
|
142 end
|
|
Tercio@11
|
143 return _object.label:SetJustifyH (_value)
|
|
Tercio@11
|
144 end
|
|
Tercio@11
|
145 --> text valign
|
|
Tercio@11
|
146 local smember_textvalign = function (_object, _value)
|
|
Tercio@11
|
147 if (_value == "^") then
|
|
Tercio@11
|
148 _value = "top"
|
|
Tercio@11
|
149 elseif (_value == "_") then
|
|
Tercio@11
|
150 _value = "bottom"
|
|
Tercio@11
|
151 elseif (_value == "|") then
|
|
Tercio@11
|
152 _value = "middle"
|
|
Tercio@11
|
153 end
|
|
Tercio@11
|
154 return _object.label:SetJustifyV (_value)
|
|
Tercio@11
|
155 end
|
|
Tercio@11
|
156 --> field size width
|
|
Tercio@11
|
157 local smember_width = function (_object, _value)
|
|
Tercio@11
|
158 return _object.label:SetWidth (_value)
|
|
Tercio@11
|
159 end
|
|
Tercio@11
|
160 --> field size height
|
|
Tercio@11
|
161 local smember_height = function (_object, _value)
|
|
Tercio@11
|
162 return _object.label:SetHeight (_value)
|
|
Tercio@11
|
163 end
|
|
Tercio@11
|
164 --> outline (shadow)
|
|
Tercio@11
|
165 local smember_outline = function (_object, _value)
|
|
Tercio@11
|
166 DF:SetFontOutline (_object.label, _value)
|
|
Tercio@11
|
167 end
|
|
Tercio@11
|
168
|
|
Tercio@39
|
169 LabelMetaFunctions.SetMembers = LabelMetaFunctions.SetMembers or {}
|
|
Tercio@39
|
170 LabelMetaFunctions.SetMembers["show"] = smember_show
|
|
Tercio@39
|
171 LabelMetaFunctions.SetMembers["hide"] = smember_hide
|
|
Tercio@39
|
172 LabelMetaFunctions.SetMembers["align"] = smember_textalign
|
|
Tercio@39
|
173 LabelMetaFunctions.SetMembers["valign"] = smember_textvalign
|
|
Tercio@39
|
174 LabelMetaFunctions.SetMembers["text"] = smember_text
|
|
Tercio@39
|
175 LabelMetaFunctions.SetMembers["width"] = smember_width
|
|
Tercio@39
|
176 LabelMetaFunctions.SetMembers["height"] = smember_height
|
|
Tercio@39
|
177 LabelMetaFunctions.SetMembers["fontcolor"] = smember_textcolor
|
|
Tercio@39
|
178 LabelMetaFunctions.SetMembers["color"] = smember_textcolor--alias
|
|
Tercio@39
|
179 LabelMetaFunctions.SetMembers["fontface"] = smember_textfont
|
|
Tercio@39
|
180 LabelMetaFunctions.SetMembers["fontsize"] = smember_textsize
|
|
Tercio@39
|
181 LabelMetaFunctions.SetMembers["textcolor"] = smember_textcolor--alias
|
|
Tercio@39
|
182 LabelMetaFunctions.SetMembers["textfont"] = smember_textfont--alias
|
|
Tercio@39
|
183 LabelMetaFunctions.SetMembers["textsize"] = smember_textsize--alias
|
|
Tercio@39
|
184 LabelMetaFunctions.SetMembers["shadow"] = smember_outline
|
|
Tercio@39
|
185 LabelMetaFunctions.SetMembers["outline"] = smember_outline--alias
|
|
Tercio@11
|
186
|
|
Tercio@11
|
187 LabelMetaFunctions.__newindex = function (_table, _key, _value)
|
|
Tercio@39
|
188 local func = LabelMetaFunctions.SetMembers [_key]
|
|
Tercio@11
|
189 if (func) then
|
|
Tercio@11
|
190 return func (_table, _value)
|
|
Tercio@11
|
191 else
|
|
Tercio@11
|
192 return _rawset (_table, _key, _value)
|
|
Tercio@11
|
193 end
|
|
Tercio@11
|
194 end
|
|
Tercio@11
|
195
|
|
Tercio@11
|
196 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
197 --> methods
|
|
Tercio@11
|
198
|
|
Tercio@11
|
199 --> show & hide
|
|
Tercio@11
|
200 function LabelMetaFunctions:IsShown()
|
|
Tercio@11
|
201 return self.label:IsShown()
|
|
Tercio@11
|
202 end
|
|
Tercio@11
|
203 function LabelMetaFunctions:Show()
|
|
Tercio@11
|
204 return self.label:Show()
|
|
Tercio@11
|
205 end
|
|
Tercio@11
|
206 function LabelMetaFunctions:Hide()
|
|
Tercio@11
|
207 return self.label:Hide()
|
|
Tercio@11
|
208 end
|
|
Tercio@11
|
209
|
|
Tercio@11
|
210 -- textcolor
|
|
Tercio@11
|
211 function LabelMetaFunctions:SetTextColor (color, arg2, arg3, arg4)
|
|
Tercio@11
|
212 if (arg2) then
|
|
Tercio@11
|
213 return self.label:SetTextColor (color, arg2, arg3, arg4 or 1)
|
|
Tercio@11
|
214 end
|
|
Tercio@11
|
215 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
|
|
Tercio@11
|
216 return self.label:SetTextColor (_value1, _value2, _value3, _value4)
|
|
Tercio@11
|
217 end
|
|
Tercio@11
|
218
|
|
Tercio@11
|
219 -- setpoint
|
|
Tercio@11
|
220 function LabelMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
221 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
|
|
Tercio@11
|
222 if (not v1) then
|
|
Tercio@11
|
223 print ("Invalid parameter for SetPoint")
|
|
Tercio@11
|
224 return
|
|
Tercio@11
|
225 end
|
|
Tercio@11
|
226 return self.widget:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
227 end
|
|
Tercio@11
|
228
|
|
Tercio@11
|
229 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@22
|
230
|
|
Tercio@22
|
231 function LabelMetaFunctions:SetTemplate (template)
|
|
Tercio@22
|
232 if (template.size) then
|
|
Tercio@22
|
233 DF:SetFontSize (self.label, template.size)
|
|
Tercio@22
|
234 end
|
|
Tercio@22
|
235 if (template.color) then
|
|
Tercio@22
|
236 local r, g, b, a = DF:ParseColors (template.color)
|
|
Tercio@22
|
237 self:SetTextColor (r, g, b, a)
|
|
Tercio@22
|
238 end
|
|
Tercio@22
|
239 if (template.font) then
|
|
Tercio@22
|
240 local SharedMedia = LibStub:GetLibrary ("LibSharedMedia-3.0")
|
|
Tercio@22
|
241 local font = SharedMedia:Fetch ("font", template.font)
|
|
Tercio@22
|
242 DF:SetFontFace (self.label, font)
|
|
Tercio@22
|
243 end
|
|
Tercio@22
|
244 end
|
|
Tercio@22
|
245
|
|
Tercio@22
|
246 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
247 --> object constructor
|
|
Tercio@11
|
248 function DF:CreateLabel (parent, text, size, color, font, member, name, layer)
|
|
Tercio@11
|
249 return DF:NewLabel (parent, nil, name, member, text, font, size, color, layer)
|
|
Tercio@11
|
250 end
|
|
Tercio@11
|
251
|
|
Tercio@11
|
252 function DF:NewLabel (parent, container, name, member, text, font, size, color, layer)
|
|
Tercio@11
|
253
|
|
Tercio@11
|
254 if (not parent) then
|
|
Tercioo@29
|
255 return error ("Details! FrameWork: parent not found.", 2)
|
|
Tercio@11
|
256 end
|
|
Tercio@11
|
257 if (not container) then
|
|
Tercio@11
|
258 container = parent
|
|
Tercio@11
|
259 end
|
|
Tercio@11
|
260
|
|
Tercio@11
|
261 if (not name) then
|
|
Tercio@11
|
262 name = "DetailsFrameworkLabelNumber" .. DF.LabelNameCounter
|
|
Tercio@11
|
263 DF.LabelNameCounter = DF.LabelNameCounter + 1
|
|
Tercio@11
|
264 end
|
|
Tercio@11
|
265
|
|
Tercio@11
|
266 if (name:find ("$parent")) then
|
|
Tercioo@29
|
267 local parentName = DF.GetParentName (parent)
|
|
Tercioo@29
|
268 name = name:gsub ("$parent", parentName)
|
|
Tercio@11
|
269 end
|
|
Tercio@11
|
270
|
|
Tercio@11
|
271 local LabelObject = {type = "label", dframework = true}
|
|
Tercio@11
|
272
|
|
Tercio@11
|
273 if (member) then
|
|
Tercio@11
|
274 parent [member] = LabelObject
|
|
Tercio@11
|
275 --container [member] = LabelObject.label
|
|
Tercio@11
|
276 end
|
|
Tercio@11
|
277
|
|
Tercio@11
|
278 if (parent.dframework) then
|
|
Tercio@11
|
279 parent = parent.widget
|
|
Tercio@11
|
280 end
|
|
Tercio@11
|
281 if (container.dframework) then
|
|
Tercio@11
|
282 container = container.widget
|
|
Tercio@11
|
283 end
|
|
Tercio@11
|
284
|
|
Tercio@11
|
285 font = font or "GameFontHighlightSmall"
|
|
Tercio@11
|
286
|
|
Tercio@11
|
287 LabelObject.label = parent:CreateFontString (name, layer or "OVERLAY", font)
|
|
Tercio@11
|
288 LabelObject.widget = LabelObject.label
|
|
Tercio@11
|
289
|
|
Tercio@11
|
290 LabelObject.label.MyObject = LabelObject
|
|
Tercio@11
|
291
|
|
Tercio@11
|
292 if (not APILabelFunctions) then
|
|
Tercio@11
|
293 APILabelFunctions = true
|
|
Tercio@11
|
294 local idx = getmetatable (LabelObject.label).__index
|
|
Tercio@11
|
295 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
296 if (not LabelMetaFunctions [funcName]) then
|
|
Tercio@11
|
297 LabelMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@20
|
298 local x = loadstring ( "return _G['"..object.label:GetName().."']:"..funcName.."(...)")
|
|
Tercio@11
|
299 return x (...)
|
|
Tercio@11
|
300 end
|
|
Tercio@11
|
301 end
|
|
Tercio@11
|
302 end
|
|
Tercio@11
|
303 end
|
|
Tercio@11
|
304
|
|
Tercio@11
|
305 LabelObject.label:SetText (text)
|
|
Tercio@11
|
306
|
|
Tercio@11
|
307 if (color) then
|
|
Tercio@11
|
308 local r, g, b, a = DF:ParseColors (color)
|
|
Tercio@11
|
309 LabelObject.label:SetTextColor (r, g, b, a)
|
|
Tercio@20
|
310 end
|
|
Tercio@20
|
311
|
|
Tercio@20
|
312 if (size and type (size) == "number") then
|
|
Tercio@20
|
313 DF:SetFontSize (LabelObject.label, size)
|
|
Tercio@11
|
314 end
|
|
Tercio@11
|
315
|
|
Tercio@39
|
316 LabelObject.HookList = {
|
|
Tercio@39
|
317 }
|
|
Tercio@20
|
318
|
|
Tercio@11
|
319 LabelObject.label:SetJustifyH ("LEFT")
|
|
Tercio@11
|
320
|
|
Tercio@11
|
321 setmetatable (LabelObject, LabelMetaFunctions)
|
|
Tercio@22
|
322
|
|
Tercio@22
|
323 if (size and type (size) == "table") then
|
|
Tercio@22
|
324 LabelObject:SetTemplate (size)
|
|
Tercio@22
|
325 end
|
|
Tercio@11
|
326
|
|
Tercio@11
|
327 return LabelObject
|
|
Tercio@58
|
328 end
|