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