|
Tercio@11
|
1
|
|
Tercio@11
|
2 local DF = _G ["DetailsFramework"]
|
|
Tercio@11
|
3
|
|
Tercio@11
|
4 local _
|
|
Tercio@11
|
5 local _rawset = rawset --> lua local
|
|
Tercio@11
|
6 local _rawget = rawget --> lua local
|
|
Tercio@11
|
7 local _setmetatable = setmetatable --> lua local
|
|
Tercio@11
|
8 local _unpack = unpack --> lua local
|
|
Tercio@11
|
9 local _type = type --> lua local
|
|
Tercio@11
|
10 local _math_floor = math.floor --> lua local
|
|
Tercio@11
|
11 local loadstring = loadstring --> lua local
|
|
Tercio@11
|
12
|
|
Tercio@11
|
13 local cleanfunction = function() end
|
|
Tercio@11
|
14 local APIButtonFunctions = false
|
|
Tercio@11
|
15 local ButtonMetaFunctions = {}
|
|
Tercio@11
|
16
|
|
Tercio@11
|
17 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
18 --> metatables
|
|
Tercio@11
|
19
|
|
Tercio@11
|
20 ButtonMetaFunctions.__call = function (_table, value, ...)
|
|
Tercio@11
|
21 return self.func (_table.param1, _table.param2, value, ...)
|
|
Tercio@11
|
22 end
|
|
Tercio@11
|
23
|
|
Tercio@11
|
24 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
25 --> members
|
|
Tercio@11
|
26
|
|
Tercio@11
|
27 --> tooltip
|
|
Tercio@11
|
28 local gmember_tooltip = function (_object)
|
|
Tercio@11
|
29 return _object:GetTooltip()
|
|
Tercio@11
|
30 end
|
|
Tercio@11
|
31 --> shown
|
|
Tercio@11
|
32 local gmember_shown = function (_object)
|
|
Tercio@11
|
33 return _object:IsShown()
|
|
Tercio@11
|
34 end
|
|
Tercio@11
|
35 --> frame width
|
|
Tercio@11
|
36 local gmember_width = function (_object)
|
|
Tercio@11
|
37 return _object.button:GetWidth()
|
|
Tercio@11
|
38 end
|
|
Tercio@11
|
39 --> frame height
|
|
Tercio@11
|
40 local gmember_height = function (_object)
|
|
Tercio@11
|
41 return _object.button:GetHeight()
|
|
Tercio@11
|
42 end
|
|
Tercio@11
|
43 --> text
|
|
Tercio@11
|
44 local gmember_text = function (_object)
|
|
Tercio@11
|
45 return _object.button.text:GetText()
|
|
Tercio@11
|
46 end
|
|
Tercio@11
|
47 --> function
|
|
Tercio@11
|
48 local gmember_function = function (_object)
|
|
Tercio@11
|
49 return _rawget (_object, "func")
|
|
Tercio@11
|
50 end
|
|
Tercio@11
|
51 --> text color
|
|
Tercio@11
|
52 local gmember_textcolor = function (_object)
|
|
Tercio@11
|
53 return _object.button.text:GetTextColor()
|
|
Tercio@11
|
54 end
|
|
Tercio@11
|
55 --> text font
|
|
Tercio@11
|
56 local gmember_textfont = function (_object)
|
|
Tercio@11
|
57 local fontface = _object.button.text:GetFont()
|
|
Tercio@11
|
58 return fontface
|
|
Tercio@11
|
59 end
|
|
Tercio@11
|
60 --> text size
|
|
Tercio@11
|
61 local gmember_textsize = function (_object)
|
|
Tercio@11
|
62 local _, fontsize = _object.button.text:GetFont()
|
|
Tercio@11
|
63 return fontsize
|
|
Tercio@11
|
64 end
|
|
Tercio@11
|
65 --> texture
|
|
Tercio@11
|
66 local gmember_texture = function (_object)
|
|
Tercio@11
|
67 return {_object.button:GetNormalTexture(), _object.button:GetHighlightTexture(), _object.button:GetPushedTexture(), _object.button:GetDisabledTexture()}
|
|
Tercio@11
|
68 end
|
|
Tercio@11
|
69 --> locked
|
|
Tercio@11
|
70 local gmember_locked = function (_object)
|
|
Tercio@11
|
71 return _rawget (_object, "is_locked")
|
|
Tercio@11
|
72 end
|
|
Tercio@11
|
73
|
|
Tercio@11
|
74 local get_members_function_index = {
|
|
Tercio@11
|
75 ["tooltip"] = gmember_tooltip,
|
|
Tercio@11
|
76 ["shown"] = gmember_shown,
|
|
Tercio@11
|
77 ["width"] = gmember_width,
|
|
Tercio@11
|
78 ["height"] = gmember_height,
|
|
Tercio@11
|
79 ["text"] = gmember_text,
|
|
Tercio@11
|
80 ["clickfunction"] = gmember_function,
|
|
Tercio@11
|
81 ["texture"] = gmember_texture,
|
|
Tercio@11
|
82 ["locked"] = gmember_locked,
|
|
Tercio@11
|
83 ["fontcolor"] = gmember_textcolor,
|
|
Tercio@11
|
84 ["fontface"] = gmember_textfont,
|
|
Tercio@11
|
85 ["fontsize"] = gmember_textsize,
|
|
Tercio@11
|
86 ["textcolor"] = gmember_textcolor, --alias
|
|
Tercio@11
|
87 ["textfont"] = gmember_textfont, --alias
|
|
Tercio@11
|
88 ["textsize"] = gmember_textsize --alias
|
|
Tercio@11
|
89 }
|
|
Tercio@11
|
90
|
|
Tercio@11
|
91 ButtonMetaFunctions.__index = function (_table, _member_requested)
|
|
Tercio@11
|
92
|
|
Tercio@11
|
93 local func = get_members_function_index [_member_requested]
|
|
Tercio@11
|
94 if (func) then
|
|
Tercio@11
|
95 return func (_table, _member_requested)
|
|
Tercio@11
|
96 end
|
|
Tercio@11
|
97
|
|
Tercio@11
|
98 local fromMe = _rawget (_table, _member_requested)
|
|
Tercio@11
|
99 if (fromMe) then
|
|
Tercio@11
|
100 return fromMe
|
|
Tercio@11
|
101 end
|
|
Tercio@11
|
102
|
|
Tercio@11
|
103 return ButtonMetaFunctions [_member_requested]
|
|
Tercio@11
|
104 end
|
|
Tercio@11
|
105
|
|
Tercio@11
|
106 -------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
107
|
|
Tercio@11
|
108 --> tooltip
|
|
Tercio@11
|
109 local smember_tooltip = function (_object, _value)
|
|
Tercio@11
|
110 return _object:SetTooltip (_value)
|
|
Tercio@11
|
111 end
|
|
Tercio@11
|
112 --> show
|
|
Tercio@11
|
113 local smember_show = function (_object, _value)
|
|
Tercio@11
|
114 if (_value) then
|
|
Tercio@11
|
115 return _object:Show()
|
|
Tercio@11
|
116 else
|
|
Tercio@11
|
117 return _object:Hide()
|
|
Tercio@11
|
118 end
|
|
Tercio@11
|
119 end
|
|
Tercio@11
|
120 --> hide
|
|
Tercio@11
|
121 local smember_hide = function (_object, _value)
|
|
Tercio@11
|
122 if (not _value) then
|
|
Tercio@11
|
123 return _object:Show()
|
|
Tercio@11
|
124 else
|
|
Tercio@11
|
125 return _object:Hide()
|
|
Tercio@11
|
126 end
|
|
Tercio@11
|
127 end
|
|
Tercio@11
|
128 --> frame width
|
|
Tercio@11
|
129 local smember_width = function (_object, _value)
|
|
Tercio@11
|
130 return _object.button:SetWidth (_value)
|
|
Tercio@11
|
131 end
|
|
Tercio@11
|
132 --> frame height
|
|
Tercio@11
|
133 local smember_height = function (_object, _value)
|
|
Tercio@11
|
134 return _object.button:SetHeight (_value)
|
|
Tercio@11
|
135 end
|
|
Tercio@11
|
136 --> text
|
|
Tercio@11
|
137 local smember_text = function (_object, _value)
|
|
Tercio@11
|
138 return _object.button.text:SetText (_value)
|
|
Tercio@11
|
139 end
|
|
Tercio@11
|
140 --> function
|
|
Tercio@11
|
141 local smember_function = function (_object, _value)
|
|
Tercio@11
|
142 return _rawset (_object, "func", _value)
|
|
Tercio@11
|
143 end
|
|
Tercio@11
|
144 --> text color
|
|
Tercio@11
|
145 local smember_textcolor = function (_object, _value)
|
|
Tercio@11
|
146 local _value1, _value2, _value3, _value4 = DF:ParseColors (_value)
|
|
Tercio@11
|
147 return _object.button.text:SetTextColor (_value1, _value2, _value3, _value4)
|
|
Tercio@11
|
148 end
|
|
Tercio@11
|
149 --> text font
|
|
Tercio@11
|
150 local smember_textfont = function (_object, _value)
|
|
Tercio@11
|
151 return DF:SetFontFace (_object.button.text, _value)
|
|
Tercio@11
|
152 end
|
|
Tercio@11
|
153 --> text size
|
|
Tercio@11
|
154 local smember_textsize = function (_object, _value)
|
|
Tercio@11
|
155 return DF:SetFontSize (_object.button.text, _value)
|
|
Tercio@11
|
156 end
|
|
Tercio@11
|
157 --> texture
|
|
Tercio@11
|
158 local smember_texture = function (_object, _value)
|
|
Tercio@11
|
159 if (_type (_value) == "table") then
|
|
Tercio@11
|
160 local _value1, _value2, _value3, _value4 = unpack (_value)
|
|
Tercio@11
|
161 if (_value1) then
|
|
Tercio@11
|
162 _object.button:SetNormalTexture (_value1)
|
|
Tercio@11
|
163 end
|
|
Tercio@11
|
164 if (_value2) then
|
|
Tercio@11
|
165 _object.button:SetHighlightTexture (_value2, "ADD")
|
|
Tercio@11
|
166 end
|
|
Tercio@11
|
167 if (_value3) then
|
|
Tercio@11
|
168 _object.button:SetPushedTexture (_value3)
|
|
Tercio@11
|
169 end
|
|
Tercio@11
|
170 if (_value4) then
|
|
Tercio@11
|
171 _object.button:SetDisabledTexture (_value4)
|
|
Tercio@11
|
172 end
|
|
Tercio@11
|
173 else
|
|
Tercio@11
|
174 _object.button:SetNormalTexture (_value)
|
|
Tercio@11
|
175 _object.button:SetHighlightTexture (_value, "ADD")
|
|
Tercio@11
|
176 _object.button:SetPushedTexture (_value)
|
|
Tercio@11
|
177 _object.button:SetDisabledTexture (_value)
|
|
Tercio@11
|
178 end
|
|
Tercio@11
|
179 return
|
|
Tercio@11
|
180 end
|
|
Tercio@11
|
181 --> locked
|
|
Tercio@11
|
182 local smember_locked = function (_object, _value)
|
|
Tercio@11
|
183 if (_value) then
|
|
Tercio@11
|
184 _object.button:SetMovable (false)
|
|
Tercio@11
|
185 return _rawset (_object, "is_locked", true)
|
|
Tercio@11
|
186 else
|
|
Tercio@11
|
187 _object.button:SetMovable (true)
|
|
Tercio@11
|
188 _rawset (_object, "is_locked", false)
|
|
Tercio@11
|
189 return
|
|
Tercio@11
|
190 end
|
|
Tercio@11
|
191 end
|
|
Tercio@11
|
192 --> text align
|
|
Tercio@11
|
193 local smember_textalign = function (_object, _value)
|
|
Tercio@11
|
194 if (_value == "left" or _value == "<") then
|
|
Tercio@11
|
195 _object.button.text:SetPoint ("left", _object.button, "left", 2, 0)
|
|
Tercio@11
|
196 _object.capsule_textalign = "left"
|
|
Tercio@11
|
197 elseif (_value == "center" or _value == "|") then
|
|
Tercio@11
|
198 _object.button.text:SetPoint ("center", _object.button, "center", 0, 0)
|
|
Tercio@11
|
199 _object.capsule_textalign = "center"
|
|
Tercio@11
|
200 elseif (_value == "right" or _value == ">") then
|
|
Tercio@11
|
201 _object.button.text:SetPoint ("right", _object.button, "right", -2, 0)
|
|
Tercio@11
|
202 _object.capsule_textalign = "right"
|
|
Tercio@11
|
203 end
|
|
Tercio@11
|
204 end
|
|
Tercio@11
|
205
|
|
Tercio@11
|
206 local set_members_function_index = {
|
|
Tercio@11
|
207 ["tooltip"] = smember_tooltip,
|
|
Tercio@11
|
208 ["show"] = smember_show,
|
|
Tercio@11
|
209 ["hide"] = smember_hide,
|
|
Tercio@11
|
210 ["width"] = smember_width,
|
|
Tercio@11
|
211 ["height"] = smember_height,
|
|
Tercio@11
|
212 ["text"] = smember_text,
|
|
Tercio@11
|
213 ["clickfunction"] = smember_function,
|
|
Tercio@11
|
214 ["textcolor"] = smember_textcolor,
|
|
Tercio@11
|
215 ["textfont"] = smember_textfont,
|
|
Tercio@11
|
216 ["textsize"] = smember_textsize,
|
|
Tercio@11
|
217 ["texture"] = smember_texture,
|
|
Tercio@11
|
218 ["locked"] = smember_locked,
|
|
Tercio@11
|
219 ["textalign"] = smember_textalign,
|
|
Tercio@11
|
220 }
|
|
Tercio@11
|
221
|
|
Tercio@11
|
222 ButtonMetaFunctions.__newindex = function (_table, _key, _value)
|
|
Tercio@11
|
223 local func = set_members_function_index [_key]
|
|
Tercio@11
|
224 if (func) then
|
|
Tercio@11
|
225 return func (_table, _value)
|
|
Tercio@11
|
226 else
|
|
Tercio@11
|
227 return _rawset (_table, _key, _value)
|
|
Tercio@11
|
228 end
|
|
Tercio@11
|
229 end
|
|
Tercio@11
|
230
|
|
Tercio@11
|
231 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
232 --> methods
|
|
Tercio@11
|
233
|
|
Tercio@11
|
234 --> show & hide
|
|
Tercio@11
|
235 function ButtonMetaFunctions:IsShown()
|
|
Tercio@11
|
236 return self.button:IsShown()
|
|
Tercio@11
|
237 end
|
|
Tercio@11
|
238 function ButtonMetaFunctions:Show()
|
|
Tercio@11
|
239 return self.button:Show()
|
|
Tercio@11
|
240 end
|
|
Tercio@11
|
241 function ButtonMetaFunctions:Hide()
|
|
Tercio@11
|
242 return self.button:Hide()
|
|
Tercio@11
|
243 end
|
|
Tercio@11
|
244
|
|
Tercio@11
|
245 -- setpoint
|
|
Tercio@11
|
246 function ButtonMetaFunctions:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
247 v1, v2, v3, v4, v5 = DF:CheckPoints (v1, v2, v3, v4, v5, self)
|
|
Tercio@11
|
248 if (not v1) then
|
|
Tercio@11
|
249 error ("SetPoint: Invalid parameter.")
|
|
Tercio@11
|
250 return
|
|
Tercio@11
|
251 end
|
|
Tercio@11
|
252 return self.widget:SetPoint (v1, v2, v3, v4, v5)
|
|
Tercio@11
|
253 end
|
|
Tercio@11
|
254
|
|
Tercio@11
|
255 -- sizes
|
|
Tercio@11
|
256 function ButtonMetaFunctions:SetSize (w, h)
|
|
Tercio@11
|
257 if (w) then
|
|
Tercio@11
|
258 self.button:SetWidth (w)
|
|
Tercio@11
|
259 end
|
|
Tercio@11
|
260 if (h) then
|
|
Tercio@11
|
261 return self.button:SetHeight (h)
|
|
Tercio@11
|
262 end
|
|
Tercio@11
|
263 end
|
|
Tercio@11
|
264
|
|
Tercio@11
|
265 -- tooltip
|
|
Tercio@11
|
266 function ButtonMetaFunctions:SetTooltip (tooltip)
|
|
Tercio@11
|
267 if (tooltip) then
|
|
Tercio@11
|
268 return _rawset (self, "have_tooltip", tooltip)
|
|
Tercio@11
|
269 else
|
|
Tercio@11
|
270 return _rawset (self, "have_tooltip", nil)
|
|
Tercio@11
|
271 end
|
|
Tercio@11
|
272 end
|
|
Tercio@11
|
273 function ButtonMetaFunctions:GetTooltip()
|
|
Tercio@11
|
274 return _rawget (self, "have_tooltip")
|
|
Tercio@11
|
275 end
|
|
Tercio@11
|
276
|
|
Tercio@11
|
277 -- functions
|
|
Tercio@11
|
278 function ButtonMetaFunctions:SetClickFunction (func, param1, param2, clicktype)
|
|
Tercio@11
|
279 if (not clicktype or string.find (string.lower (clicktype), "left")) then
|
|
Tercio@11
|
280 if (func) then
|
|
Tercio@11
|
281 _rawset (self, "func", func)
|
|
Tercio@11
|
282 else
|
|
Tercio@11
|
283 _rawset (self, "func", cleanfunction)
|
|
Tercio@11
|
284 end
|
|
Tercio@11
|
285
|
|
Tercio@11
|
286 if (param1 ~= nil) then
|
|
Tercio@11
|
287 _rawset (self, "param1", param1)
|
|
Tercio@11
|
288 end
|
|
Tercio@11
|
289 if (param2 ~= nil) then
|
|
Tercio@11
|
290 _rawset (self, "param2", param2)
|
|
Tercio@11
|
291 end
|
|
Tercio@11
|
292
|
|
Tercio@11
|
293 elseif (clicktype or string.find (string.lower (clicktype), "right")) then
|
|
Tercio@11
|
294 if (func) then
|
|
Tercio@11
|
295 _rawset (self, "funcright", func)
|
|
Tercio@11
|
296 else
|
|
Tercio@11
|
297 _rawset (self, "funcright", cleanfunction)
|
|
Tercio@11
|
298 end
|
|
Tercio@11
|
299 end
|
|
Tercio@11
|
300 end
|
|
Tercio@11
|
301
|
|
Tercio@11
|
302 -- text
|
|
Tercio@11
|
303 function ButtonMetaFunctions:SetText (text)
|
|
Tercio@11
|
304 if (text) then
|
|
Tercio@11
|
305 self.button.text:SetText (text)
|
|
Tercio@11
|
306 else
|
|
Tercio@11
|
307 self.button.text:SetText (nil)
|
|
Tercio@11
|
308 end
|
|
Tercio@11
|
309 end
|
|
Tercio@11
|
310
|
|
Tercio@11
|
311 -- textcolor
|
|
Tercio@11
|
312 function ButtonMetaFunctions:SetTextColor (color, arg2, arg3, arg4)
|
|
Tercio@11
|
313 if (arg2) then
|
|
Tercio@11
|
314 return self.button.text:SetTextColor (color, arg2, arg3, arg4 or 1)
|
|
Tercio@11
|
315 end
|
|
Tercio@11
|
316 local _value1, _value2, _value3, _value4 = DF:ParseColors (color)
|
|
Tercio@11
|
317 return self.button.text:SetTextColor (_value1, _value2, _value3, _value4)
|
|
Tercio@11
|
318 end
|
|
Tercio@11
|
319
|
|
Tercio@11
|
320 -- textsize
|
|
Tercio@11
|
321 function ButtonMetaFunctions:SetTextSize (size)
|
|
Tercio@11
|
322 return DF:SetFontSize (self.button.text, _value)
|
|
Tercio@11
|
323 end
|
|
Tercio@11
|
324
|
|
Tercio@11
|
325 -- textfont
|
|
Tercio@11
|
326 function ButtonMetaFunctions:SetTextFont (font)
|
|
Tercio@11
|
327 return DF:SetFontFace (_object.button.text, _value)
|
|
Tercio@11
|
328 end
|
|
Tercio@11
|
329
|
|
Tercio@11
|
330 -- textures
|
|
Tercio@11
|
331 function ButtonMetaFunctions:SetTexture (normal, highlight, pressed, disabled)
|
|
Tercio@11
|
332 if (normal) then
|
|
Tercio@11
|
333 self.button:SetNormalTexture (normal)
|
|
Tercio@11
|
334 elseif (_type (normal) ~= "boolean") then
|
|
Tercio@11
|
335 self.button:SetNormalTexture (nil)
|
|
Tercio@11
|
336 end
|
|
Tercio@11
|
337
|
|
Tercio@11
|
338 if (_type (highlight) == "boolean") then
|
|
Tercio@11
|
339 if (highlight and normal and _type (normal) ~= "boolean") then
|
|
Tercio@11
|
340 self.button:SetHighlightTexture (normal, "ADD")
|
|
Tercio@11
|
341 end
|
|
Tercio@11
|
342 elseif (highlight == nil) then
|
|
Tercio@11
|
343 self.button:SetHighlightTexture (nil)
|
|
Tercio@11
|
344 else
|
|
Tercio@11
|
345 self.button:SetHighlightTexture (highlight, "ADD")
|
|
Tercio@11
|
346 end
|
|
Tercio@11
|
347
|
|
Tercio@11
|
348 if (_type (pressed) == "boolean") then
|
|
Tercio@11
|
349 if (pressed and normal and _type (normal) ~= "boolean") then
|
|
Tercio@11
|
350 self.button:SetPushedTexture (normal)
|
|
Tercio@11
|
351 end
|
|
Tercio@11
|
352 elseif (pressed == nil) then
|
|
Tercio@11
|
353 self.button:SetPushedTexture (nil)
|
|
Tercio@11
|
354 else
|
|
Tercio@11
|
355 self.button:SetPushedTexture (pressed, "ADD")
|
|
Tercio@11
|
356 end
|
|
Tercio@11
|
357
|
|
Tercio@11
|
358 if (_type (disabled) == "boolean") then
|
|
Tercio@11
|
359 if (disabled and normal and _type (normal) ~= "boolean") then
|
|
Tercio@11
|
360 self.button:SetDisabledTexture (normal)
|
|
Tercio@11
|
361 end
|
|
Tercio@11
|
362 elseif (disabled == nil) then
|
|
Tercio@11
|
363 self.button:SetDisabledTexture (nil)
|
|
Tercio@11
|
364 else
|
|
Tercio@11
|
365 self.button:SetDisabledTexture (disabled, "ADD")
|
|
Tercio@11
|
366 end
|
|
Tercio@11
|
367
|
|
Tercio@11
|
368 end
|
|
Tercio@11
|
369
|
|
Tercio@11
|
370 -- frame levels
|
|
Tercio@11
|
371 function ButtonMetaFunctions:GetFrameLevel()
|
|
Tercio@11
|
372 return self.button:GetFrameLevel()
|
|
Tercio@11
|
373 end
|
|
Tercio@11
|
374 function ButtonMetaFunctions:SetFrameLevel (level, frame)
|
|
Tercio@11
|
375 if (not frame) then
|
|
Tercio@11
|
376 return self.button:SetFrameLevel (level)
|
|
Tercio@11
|
377 else
|
|
Tercio@11
|
378 local framelevel = frame:GetFrameLevel (frame) + level
|
|
Tercio@11
|
379 return self.button:SetFrameLevel (framelevel)
|
|
Tercio@11
|
380 end
|
|
Tercio@11
|
381 end
|
|
Tercio@11
|
382
|
|
Tercio@11
|
383 -- icon
|
|
Tercio@11
|
384 function ButtonMetaFunctions:SetIcon (texture, width, height, layout, texcoord, overlay, textdistance, leftpadding)
|
|
Tercio@11
|
385 if (not self.icon) then
|
|
Tercio@11
|
386 self.icon = self:CreateTexture (nil, "artwork")
|
|
Tercio@11
|
387 self.icon:SetSize (self.height*0.8, self.height*0.8)
|
|
Tercio@11
|
388 self.icon:SetPoint ("left", self.widget, "left", 4 + (leftpadding or 0), 0)
|
|
Tercio@11
|
389 self.icon.leftpadding = leftpadding or 0
|
|
Tercio@11
|
390 self.widget.text:ClearAllPoints()
|
|
Tercio@11
|
391 self.widget.text:SetPoint ("left", self.icon, "right", textdistance or 2, 0)
|
|
Tercio@11
|
392 end
|
|
Tercio@11
|
393
|
|
Tercio@11
|
394 self.icon:SetTexture (texture)
|
|
Tercio@11
|
395 self.icon:SetSize (width or self.height*0.8, height or self.height*0.8)
|
|
Tercio@11
|
396 self.icon:SetDrawLayer (layout or "artwork")
|
|
Tercio@11
|
397 if (texcoord) then
|
|
Tercio@11
|
398 self.icon:SetTexCoord (unpack (texcoord))
|
|
Tercio@11
|
399 else
|
|
Tercio@11
|
400 self.icon:SetTexCoord (0, 1, 0, 1)
|
|
Tercio@11
|
401 end
|
|
Tercio@11
|
402 if (overlay) then
|
|
Tercio@11
|
403 if (type (overlay) == "string") then
|
|
Tercio@11
|
404 local r, g, b, a = DF:ParseColors (overlay)
|
|
Tercio@11
|
405 self.icon:SetVertexColor (r, g, b, a)
|
|
Tercio@11
|
406 else
|
|
Tercio@11
|
407 self.icon:SetVertexColor (unpack (overlay))
|
|
Tercio@11
|
408 end
|
|
Tercio@11
|
409 else
|
|
Tercio@11
|
410 self.icon:SetVertexColor (1, 1, 1, 1)
|
|
Tercio@11
|
411 end
|
|
Tercio@11
|
412
|
|
Tercio@11
|
413 local w = self.button:GetWidth()
|
|
Tercio@11
|
414 local iconw = self.icon:GetWidth()
|
|
Tercio@11
|
415 local text_width = self.button.text:GetStringWidth()
|
|
Tercio@11
|
416 if (text_width > w-15-iconw) then
|
|
Tercio@11
|
417 if (not short_method) then
|
|
Tercio@11
|
418 local new_width = text_width+15+iconw
|
|
Tercio@11
|
419 self.button:SetWidth (new_width)
|
|
Tercio@11
|
420 elseif (short_method == 1) then
|
|
Tercio@11
|
421 local loop = true
|
|
Tercio@11
|
422 local textsize = 11
|
|
Tercio@11
|
423 while (loop) do
|
|
Tercio@11
|
424 if (text_width+15+iconw < w or textsize < 8) then
|
|
Tercio@11
|
425 loop = false
|
|
Tercio@11
|
426 break
|
|
Tercio@11
|
427 else
|
|
Tercio@11
|
428 DF:SetFontSize (self.button.text, textsize)
|
|
Tercio@11
|
429 text_width = self.button.text:GetStringWidth()
|
|
Tercio@11
|
430 textsize = textsize - 1
|
|
Tercio@11
|
431 end
|
|
Tercio@11
|
432 end
|
|
Tercio@11
|
433 end
|
|
Tercio@11
|
434 end
|
|
Tercio@11
|
435
|
|
Tercio@11
|
436 end
|
|
Tercio@11
|
437
|
|
Tercio@11
|
438 -- frame stratas
|
|
Tercio@11
|
439 function ButtonMetaFunctions:SetFrameStrata()
|
|
Tercio@11
|
440 return self.button:GetFrameStrata()
|
|
Tercio@11
|
441 end
|
|
Tercio@11
|
442 function ButtonMetaFunctions:SetFrameStrata (strata)
|
|
Tercio@11
|
443 if (_type (strata) == "table") then
|
|
Tercio@11
|
444 self.button:SetFrameStrata (strata:GetFrameStrata())
|
|
Tercio@11
|
445 else
|
|
Tercio@11
|
446 self.button:SetFrameStrata (strata)
|
|
Tercio@11
|
447 end
|
|
Tercio@11
|
448 end
|
|
Tercio@11
|
449
|
|
Tercio@11
|
450 -- enabled
|
|
Tercio@11
|
451 function ButtonMetaFunctions:IsEnabled()
|
|
Tercio@11
|
452 return self.button:IsEnabled()
|
|
Tercio@11
|
453 end
|
|
Tercio@11
|
454 function ButtonMetaFunctions:Enable()
|
|
Tercio@11
|
455 return self.button:Enable()
|
|
Tercio@11
|
456 end
|
|
Tercio@11
|
457 function ButtonMetaFunctions:Disable()
|
|
Tercio@11
|
458 return self.button:Disable()
|
|
Tercio@11
|
459 end
|
|
Tercio@11
|
460
|
|
Tercio@11
|
461 -- exec
|
|
Tercio@11
|
462 function ButtonMetaFunctions:Exec()
|
|
Tercio@11
|
463 return self.func (self.param1, self.param2)
|
|
Tercio@11
|
464 end
|
|
Tercio@11
|
465 function ButtonMetaFunctions:Click()
|
|
Tercio@11
|
466 return self.func (self.param1, self.param2)
|
|
Tercio@11
|
467 end
|
|
Tercio@11
|
468 function ButtonMetaFunctions:RightClick()
|
|
Tercio@11
|
469 return self.funcright()
|
|
Tercio@11
|
470 end
|
|
Tercio@11
|
471
|
|
Tercio@11
|
472 --> hooks
|
|
Tercio@11
|
473 function ButtonMetaFunctions:SetHook (hookType, func)
|
|
Tercio@11
|
474 if (func) then
|
|
Tercio@11
|
475 _rawset (self, hookType.."Hook", func)
|
|
Tercio@11
|
476 else
|
|
Tercio@11
|
477 _rawset (self, hookType.."Hook", nil)
|
|
Tercio@11
|
478 end
|
|
Tercio@11
|
479 end
|
|
Tercio@11
|
480
|
|
Tercio@11
|
481 --> custom textures
|
|
Tercio@11
|
482 function ButtonMetaFunctions:InstallCustomTexture (texture, rect, coords, use_split, side_textures, side_textures2)
|
|
Tercio@11
|
483
|
|
Tercio@11
|
484 self.button:SetNormalTexture (nil)
|
|
Tercio@11
|
485 self.button:SetPushedTexture (nil)
|
|
Tercio@11
|
486 self.button:SetDisabledTexture (nil)
|
|
Tercio@11
|
487 self.button:SetHighlightTexture (nil)
|
|
Tercio@11
|
488
|
|
Tercio@11
|
489 local button = self.button
|
|
Tercio@11
|
490
|
|
Tercio@11
|
491 if (use_split) then
|
|
Tercio@11
|
492
|
|
Tercio@11
|
493 --> 4 corners
|
|
Tercio@11
|
494 button.textureTopLeft = button:CreateTexture (nil, "artwork"); button.textureTopLeft:SetSize (8, 8); button.textureTopLeft:SetPoint ("topleft", button)
|
|
Tercio@11
|
495 button.textureTopRight = button:CreateTexture (nil, "artwork"); button.textureTopRight:SetSize (8, 8); button.textureTopRight:SetPoint ("topright", button)
|
|
Tercio@11
|
496 button.textureBottomLeft = button:CreateTexture (nil, "artwork"); button.textureBottomLeft:SetSize (8, 8); button.textureBottomLeft:SetPoint ("bottomleft", button)
|
|
Tercio@11
|
497 button.textureBottomRight = button:CreateTexture (nil, "artwork"); button.textureBottomRight:SetSize (8, 8); button.textureBottomRight:SetPoint ("bottomright", button)
|
|
Tercio@11
|
498
|
|
Tercio@11
|
499 button.textureLeft = button:CreateTexture (nil, "artwork"); button.textureLeft:SetWidth (4); button.textureLeft:SetPoint ("topleft", button.textureTopLeft, "bottomleft"); button.textureLeft:SetPoint ("bottomleft", button.textureBottomLeft, "topleft")
|
|
Tercio@11
|
500 button.textureRight = button:CreateTexture (nil, "artwork"); button.textureRight:SetWidth (4); button.textureRight:SetPoint ("topright", button.textureTopRight, "bottomright"); button.textureRight:SetPoint ("bottomright", button.textureBottomRight, "topright")
|
|
Tercio@11
|
501 button.textureTop = button:CreateTexture (nil, "artwork"); button.textureTop:SetHeight (4); button.textureTop:SetPoint ("topleft", button.textureTopLeft, "topright"); button.textureTop:SetPoint ("topright", button.textureTopRight, "topleft");
|
|
Tercio@11
|
502 button.textureBottom = button:CreateTexture (nil, "artwork"); button.textureBottom:SetHeight (4); button.textureBottom:SetPoint ("bottomleft", button.textureBottomLeft, "bottomright"); button.textureBottom:SetPoint ("bottomright", button.textureBottomRight, "bottomleft");
|
|
Tercio@11
|
503
|
|
Tercio@11
|
504 button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128)
|
|
Tercio@11
|
505 button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128)
|
|
Tercio@11
|
506 button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128)
|
|
Tercio@11
|
507 button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128)
|
|
Tercio@11
|
508
|
|
Tercio@11
|
509 button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128)
|
|
Tercio@11
|
510 button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128)
|
|
Tercio@11
|
511 button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128)
|
|
Tercio@11
|
512 button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128)
|
|
Tercio@11
|
513
|
|
Tercio@11
|
514 button.textureTopLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
515 button.textureTopRight:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
516 button.textureBottomLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
517 button.textureBottomRight:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
518 button.textureLeft:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
519 button.textureRight:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
520 button.textureTop:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
521 button.textureBottom:SetTexture ([[Interface\AddOns\Details\images\default_button]])
|
|
Tercio@11
|
522
|
|
Tercio@11
|
523 else
|
|
Tercio@11
|
524 texture = texture or "Interface\\AddOns\\Details\\images\\default_button"
|
|
Tercio@11
|
525 self.button.texture = self.button:CreateTexture (nil, "artwork")
|
|
Tercio@11
|
526
|
|
Tercio@11
|
527 if (not rect) then
|
|
Tercio@11
|
528 self.button.texture:SetAllPoints (self.button)
|
|
Tercio@11
|
529 else
|
|
Tercio@11
|
530 self.button.texture:SetPoint ("topleft", self.button, "topleft", rect.x1, rect.y1)
|
|
Tercio@11
|
531 self.button.texture:SetPoint ("bottomright", self.button, "bottomright", rect.x2, rect.y2)
|
|
Tercio@11
|
532 end
|
|
Tercio@11
|
533
|
|
Tercio@11
|
534 if (coords) then
|
|
Tercio@11
|
535 self.button.texture.coords = coords
|
|
Tercio@11
|
536 self.button.texture:SetTexCoord (_unpack (coords.Normal))
|
|
Tercio@11
|
537 else
|
|
Tercio@11
|
538 self.button.texture:SetTexCoord (0, 1, 0, 0.24609375)
|
|
Tercio@11
|
539 end
|
|
Tercio@11
|
540
|
|
Tercio@11
|
541 self.button.texture:SetTexture (texture)
|
|
Tercio@11
|
542 end
|
|
Tercio@11
|
543
|
|
Tercio@11
|
544 if (side_textures) then
|
|
Tercio@11
|
545 local left = self.button:CreateTexture (nil, "overlay")
|
|
Tercio@11
|
546 left:SetTexture ([[Interface\TALENTFRAME\talent-main]])
|
|
Tercio@11
|
547 left:SetTexCoord (0.13671875, 0.25, 0.486328125, 0.576171875)
|
|
Tercio@11
|
548 left:SetPoint ("left", self.button, 0, 0)
|
|
Tercio@11
|
549 left:SetWidth (10)
|
|
Tercio@11
|
550 left:SetHeight (self.button:GetHeight()+2)
|
|
Tercio@11
|
551 self.button.left_border = left
|
|
Tercio@11
|
552
|
|
Tercio@11
|
553 local right = self.button:CreateTexture (nil, "overlay")
|
|
Tercio@11
|
554 right:SetTexture ([[Interface\TALENTFRAME\talent-main]])
|
|
Tercio@11
|
555 right:SetTexCoord (0.01953125, 0.13671875, 0.486328125, 0.576171875)
|
|
Tercio@11
|
556 right:SetPoint ("right", self.button, 0, 0)
|
|
Tercio@11
|
557 right:SetWidth (10)
|
|
Tercio@11
|
558 right:SetHeight (self.button:GetHeight()+2)
|
|
Tercio@11
|
559 self.button.right_border = right
|
|
Tercio@11
|
560
|
|
Tercio@11
|
561 elseif (side_textures2) then
|
|
Tercio@11
|
562
|
|
Tercio@11
|
563 local left = self.button:CreateTexture (nil, "overlay")
|
|
Tercio@11
|
564 left:SetTexture ([[Interface\AddOns\Details\images\icons]])
|
|
Tercio@11
|
565 left:SetTexCoord (94/512, 123/512, 42/512, 87/512)
|
|
Tercio@11
|
566 left:SetPoint ("left", self.button, 0, 0)
|
|
Tercio@11
|
567 left:SetWidth (10)
|
|
Tercio@11
|
568 left:SetHeight (self.button:GetHeight()+2)
|
|
Tercio@11
|
569 self.button.left_border = left
|
|
Tercio@11
|
570
|
|
Tercio@11
|
571 local right = self.button:CreateTexture (nil, "overlay")
|
|
Tercio@11
|
572 right:SetTexture ([[Interface\AddOns\Details\images\icons]])
|
|
Tercio@11
|
573 right:SetTexCoord (65/512, 94/512, 42/512, 87/512)
|
|
Tercio@11
|
574 right:SetPoint ("right", self.button, 0, 0)
|
|
Tercio@11
|
575 right:SetWidth (10)
|
|
Tercio@11
|
576 right:SetHeight (self.button:GetHeight()+2)
|
|
Tercio@11
|
577 self.button.right_border = right
|
|
Tercio@11
|
578 end
|
|
Tercio@11
|
579 end
|
|
Tercio@11
|
580
|
|
Tercio@11
|
581 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
582 --> scripts
|
|
Tercio@11
|
583
|
|
Tercio@11
|
584 local OnEnter = function (button)
|
|
Tercio@11
|
585
|
|
Tercio@11
|
586 if (button.textureTopLeft) then
|
|
Tercio@11
|
587 button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128)
|
|
Tercio@11
|
588 button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128)
|
|
Tercio@11
|
589 button.textureTop:SetTexCoord (9/128, 120/128, 33/128, 37/128)
|
|
Tercio@11
|
590 button.textureBottom:SetTexCoord (9/128, 119/128, 60/128, 64/128)
|
|
Tercio@11
|
591
|
|
Tercio@11
|
592 button.textureTopLeft:SetTexCoord (0, 8/128, 33/128, 40/128)
|
|
Tercio@11
|
593 button.textureTopRight:SetTexCoord (121/128, 1, 33/128, 40/128)
|
|
Tercio@11
|
594 button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128)
|
|
Tercio@11
|
595 button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128)
|
|
Tercio@11
|
596 end
|
|
Tercio@11
|
597
|
|
Tercio@11
|
598 if (button.MyObject.OnEnterHook) then
|
|
Tercio@11
|
599 local interrupt = button.MyObject.OnEnterHook (button, button.MyObject)
|
|
Tercio@11
|
600 if (interrupt) then
|
|
Tercio@11
|
601 return
|
|
Tercio@11
|
602 end
|
|
Tercio@11
|
603 end
|
|
Tercio@11
|
604
|
|
Tercio@11
|
605 button.MyObject.is_mouse_over = true
|
|
Tercio@11
|
606
|
|
Tercio@11
|
607 if (button.texture) then
|
|
Tercio@11
|
608 if (button.texture.coords) then
|
|
Tercio@11
|
609 button.texture:SetTexCoord (_unpack (button.texture.coords.Highlight))
|
|
Tercio@11
|
610 else
|
|
Tercio@11
|
611 button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375)
|
|
Tercio@11
|
612 end
|
|
Tercio@11
|
613 end
|
|
Tercio@11
|
614
|
|
Tercio@11
|
615 if (button.MyObject.have_tooltip) then
|
|
Tercio@11
|
616 GameCooltip2:Preset (2)
|
|
Tercio@11
|
617 if (type (button.MyObject.have_tooltip) == "function") then
|
|
Tercio@11
|
618 GameCooltip2:AddLine (button.MyObject.have_tooltip() or "")
|
|
Tercio@11
|
619 else
|
|
Tercio@11
|
620 GameCooltip2:AddLine (button.MyObject.have_tooltip)
|
|
Tercio@11
|
621 end
|
|
Tercio@11
|
622 GameCooltip2:ShowCooltip (button, "tooltip")
|
|
Tercio@11
|
623 end
|
|
Tercio@11
|
624
|
|
Tercio@11
|
625 local parent = button:GetParent().MyObject
|
|
Tercio@11
|
626 if (parent and parent.type == "panel") then
|
|
Tercio@11
|
627 if (parent.GradientEnabled) then
|
|
Tercio@11
|
628 parent:RunGradient()
|
|
Tercio@11
|
629 end
|
|
Tercio@11
|
630 end
|
|
Tercio@11
|
631 end
|
|
Tercio@11
|
632
|
|
Tercio@11
|
633 local OnLeave = function (button)
|
|
Tercio@11
|
634
|
|
Tercio@11
|
635 if (button.textureLeft and not button.MyObject.is_mouse_down) then
|
|
Tercio@11
|
636 button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128)
|
|
Tercio@11
|
637 button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128)
|
|
Tercio@11
|
638 button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128)
|
|
Tercio@11
|
639 button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128)
|
|
Tercio@11
|
640
|
|
Tercio@11
|
641 button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128)
|
|
Tercio@11
|
642 button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128)
|
|
Tercio@11
|
643 button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128)
|
|
Tercio@11
|
644 button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128)
|
|
Tercio@11
|
645 end
|
|
Tercio@11
|
646
|
|
Tercio@11
|
647 if (button.MyObject.OnLeaveHook) then
|
|
Tercio@11
|
648 local interrupt = button.MyObject.OnLeaveHook (button, button.MyObject)
|
|
Tercio@11
|
649 if (interrupt) then
|
|
Tercio@11
|
650 return
|
|
Tercio@11
|
651 end
|
|
Tercio@11
|
652 end
|
|
Tercio@11
|
653
|
|
Tercio@11
|
654 button.MyObject.is_mouse_over = false
|
|
Tercio@11
|
655
|
|
Tercio@11
|
656 if (button.texture and not button.MyObject.is_mouse_down) then
|
|
Tercio@11
|
657 if (button.texture.coords) then
|
|
Tercio@11
|
658 button.texture:SetTexCoord (_unpack (button.texture.coords.Normal))
|
|
Tercio@11
|
659 else
|
|
Tercio@11
|
660 button.texture:SetTexCoord (0, 1, 0, 0.24609375)
|
|
Tercio@11
|
661 end
|
|
Tercio@11
|
662 end
|
|
Tercio@11
|
663
|
|
Tercio@11
|
664 if (button.MyObject.have_tooltip) then
|
|
Tercio@11
|
665 if (GameCooltip2:GetText (1) == button.MyObject.have_tooltip or type (button.MyObject.have_tooltip) == "function") then
|
|
Tercio@11
|
666 GameCooltip2:Hide()
|
|
Tercio@11
|
667 end
|
|
Tercio@11
|
668 end
|
|
Tercio@11
|
669
|
|
Tercio@11
|
670 local parent = button:GetParent().MyObject
|
|
Tercio@11
|
671 if (parent and parent.type == "panel") then
|
|
Tercio@11
|
672 if (parent.GradientEnabled) then
|
|
Tercio@11
|
673 parent:RunGradient (false)
|
|
Tercio@11
|
674 end
|
|
Tercio@11
|
675 end
|
|
Tercio@11
|
676 end
|
|
Tercio@11
|
677
|
|
Tercio@11
|
678 local OnHide = function (button)
|
|
Tercio@11
|
679 if (button.MyObject.OnHideHook) then
|
|
Tercio@11
|
680 local interrupt = button.MyObject.OnHideHook (button, button.MyObject)
|
|
Tercio@11
|
681 if (interrupt) then
|
|
Tercio@11
|
682 return
|
|
Tercio@11
|
683 end
|
|
Tercio@11
|
684 end
|
|
Tercio@11
|
685 end
|
|
Tercio@11
|
686
|
|
Tercio@11
|
687 local OnShow = function (button)
|
|
Tercio@11
|
688 if (button.MyObject.OnShowHook) then
|
|
Tercio@11
|
689 local interrupt = button.MyObject.OnShowHook (button, button.MyObject)
|
|
Tercio@11
|
690 if (interrupt) then
|
|
Tercio@11
|
691 return
|
|
Tercio@11
|
692 end
|
|
Tercio@11
|
693 end
|
|
Tercio@11
|
694 end
|
|
Tercio@11
|
695
|
|
Tercio@11
|
696 local OnMouseDown = function (button, buttontype)
|
|
Tercio@11
|
697 if (not button:IsEnabled()) then
|
|
Tercio@11
|
698 return
|
|
Tercio@11
|
699 end
|
|
Tercio@11
|
700
|
|
Tercio@11
|
701 if (button.textureTopLeft) then
|
|
Tercio@11
|
702 button.textureLeft:SetTexCoord (0, 4/128, 72/128, 88/128)
|
|
Tercio@11
|
703 button.textureRight:SetTexCoord (124/128, 1, 72/128, 88/128)
|
|
Tercio@11
|
704 button.textureTop:SetTexCoord (9/128, 120/128, 65/128, 68/128)
|
|
Tercio@11
|
705 button.textureBottom:SetTexCoord (9/128, 119/128, 92/128, 96/128)
|
|
Tercio@11
|
706
|
|
Tercio@11
|
707 button.textureTopLeft:SetTexCoord (0, 8/128, 65/128, 71/128)
|
|
Tercio@11
|
708 button.textureTopRight:SetTexCoord (121/128, 1, 65/128, 71/128)
|
|
Tercio@11
|
709 button.textureBottomLeft:SetTexCoord (0, 8/128, 88/128, 96/128)
|
|
Tercio@11
|
710 button.textureBottomRight:SetTexCoord (120/128, 1, 88/128, 96/128)
|
|
Tercio@11
|
711 end
|
|
Tercio@11
|
712
|
|
Tercio@11
|
713 if (button.MyObject.OnMouseDownHook) then
|
|
Tercio@11
|
714 local interrupt = button.MyObject.OnMouseDownHook (button, buttontype, button.MyObject)
|
|
Tercio@11
|
715 if (interrupt) then
|
|
Tercio@11
|
716 return
|
|
Tercio@11
|
717 end
|
|
Tercio@11
|
718 end
|
|
Tercio@11
|
719
|
|
Tercio@11
|
720 button.MyObject.is_mouse_down = true
|
|
Tercio@11
|
721
|
|
Tercio@11
|
722 if (button.texture) then
|
|
Tercio@11
|
723 if (button.texture.coords) then
|
|
Tercio@11
|
724 button.texture:SetTexCoord (_unpack (button.texture.coords.Pushed))
|
|
Tercio@11
|
725 else
|
|
Tercio@11
|
726 button.texture:SetTexCoord (0, 1, 0.5078125, 0.75)
|
|
Tercio@11
|
727 end
|
|
Tercio@11
|
728 end
|
|
Tercio@11
|
729
|
|
Tercio@11
|
730 if (button.MyObject.capsule_textalign) then
|
|
Tercio@11
|
731 if (button.MyObject.icon) then
|
|
Tercio@11
|
732 button.MyObject.icon:SetPoint ("left", button, "left", 5 + (button.MyObject.icon.leftpadding or 0), -1)
|
|
Tercio@11
|
733 elseif (button.MyObject.capsule_textalign == "left") then
|
|
Tercio@11
|
734 button.text:SetPoint ("left", button, "left", 3, -1)
|
|
Tercio@11
|
735 elseif (button.MyObject.capsule_textalign == "center") then
|
|
Tercio@11
|
736 button.text:SetPoint ("center", button, "center", 1, -1)
|
|
Tercio@11
|
737 elseif (button.MyObject.capsule_textalign == "right") then
|
|
Tercio@11
|
738 button.text:SetPoint ("right", button, "right", -1, -1)
|
|
Tercio@11
|
739 end
|
|
Tercio@11
|
740 else
|
|
Tercio@11
|
741 if (button.MyObject.icon) then
|
|
Tercio@11
|
742 button.MyObject.icon:SetPoint ("left", button, "left", 7 + (button.MyObject.icon.leftpadding or 0), -2)
|
|
Tercio@11
|
743 else
|
|
Tercio@11
|
744 button.text:SetPoint ("center", button,"center", 1, -1)
|
|
Tercio@11
|
745 end
|
|
Tercio@11
|
746 end
|
|
Tercio@11
|
747
|
|
Tercio@11
|
748 button.mouse_down = GetTime()
|
|
Tercio@11
|
749 local x, y = GetCursorPosition()
|
|
Tercio@11
|
750 button.x = _math_floor (x)
|
|
Tercio@11
|
751 button.y = _math_floor (y)
|
|
Tercio@11
|
752
|
|
Tercio@11
|
753 if (not button.MyObject.container.isLocked and button.MyObject.container:IsMovable()) then
|
|
Tercio@11
|
754 if (not button.isLocked and button:IsMovable()) then
|
|
Tercio@11
|
755 button.MyObject.container.isMoving = true
|
|
Tercio@11
|
756 button.MyObject.container:StartMoving()
|
|
Tercio@11
|
757 end
|
|
Tercio@11
|
758 end
|
|
Tercio@11
|
759
|
|
Tercio@11
|
760 if (button.MyObject.options.OnGrab) then
|
|
Tercio@11
|
761 if (_type (button.MyObject.options.OnGrab) == "string" and button.MyObject.options.OnGrab == "PassClick") then
|
|
Tercio@11
|
762 if (buttontype == "LeftButton") then
|
|
Tercio@11
|
763 button.MyObject.func (button.MyObject.param1, button.MyObject.param2)
|
|
Tercio@11
|
764 else
|
|
Tercio@11
|
765 button.MyObject.funcright (button.MyObject.param1, button.MyObject.param2)
|
|
Tercio@11
|
766 end
|
|
Tercio@11
|
767 end
|
|
Tercio@11
|
768 end
|
|
Tercio@11
|
769 end
|
|
Tercio@11
|
770
|
|
Tercio@11
|
771 local OnMouseUp = function (button, buttontype)
|
|
Tercio@11
|
772 if (not button:IsEnabled()) then
|
|
Tercio@11
|
773 return
|
|
Tercio@11
|
774 end
|
|
Tercio@11
|
775
|
|
Tercio@11
|
776 if (button.textureLeft) then
|
|
Tercio@11
|
777 if (button.MyObject.is_mouse_over) then
|
|
Tercio@11
|
778 button.textureLeft:SetTexCoord (0, 4/128, 40/128, 56/128)
|
|
Tercio@11
|
779 button.textureRight:SetTexCoord (124/128, 1, 40/128, 56/128)
|
|
Tercio@11
|
780 button.textureTop:SetTexCoord (9/128, 120/128, 33/128, 37/128)
|
|
Tercio@11
|
781 button.textureBottom:SetTexCoord (9/128, 119/128, 60/128, 64/128)
|
|
Tercio@11
|
782
|
|
Tercio@11
|
783 button.textureTopLeft:SetTexCoord (0, 8/128, 33/128, 40/128)
|
|
Tercio@11
|
784 button.textureTopRight:SetTexCoord (121/128, 1, 33/128, 40/128)
|
|
Tercio@11
|
785 button.textureBottomLeft:SetTexCoord (0, 8/128, 56/128, 64/128)
|
|
Tercio@11
|
786 button.textureBottomRight:SetTexCoord (120/128, 1, 56/128, 64/128)
|
|
Tercio@11
|
787 else
|
|
Tercio@11
|
788 button.textureLeft:SetTexCoord (0, 4/128, 9/128, 24/128)
|
|
Tercio@11
|
789 button.textureRight:SetTexCoord (124/128, 1, 9/128, 24/128)
|
|
Tercio@11
|
790 button.textureTop:SetTexCoord (9/128, 120/128, 0, 4/128)
|
|
Tercio@11
|
791 button.textureBottom:SetTexCoord (9/128, 119/128, 28/128, 32/128)
|
|
Tercio@11
|
792
|
|
Tercio@11
|
793 button.textureTopLeft:SetTexCoord (0, 8/128, 0, 8/128)
|
|
Tercio@11
|
794 button.textureTopRight:SetTexCoord (121/128, 1, 0, 8/128)
|
|
Tercio@11
|
795 button.textureBottomLeft:SetTexCoord (0, 8/128, 24/128, 32/128)
|
|
Tercio@11
|
796 button.textureBottomRight:SetTexCoord (120/128, 1, 24/128, 32/128)
|
|
Tercio@11
|
797 end
|
|
Tercio@11
|
798 end
|
|
Tercio@11
|
799
|
|
Tercio@11
|
800 if (button.MyObject.OnMouseUpHook) then
|
|
Tercio@11
|
801 local interrupt = button.MyObject.OnMouseUpHook (button, buttontype, button.MyObject)
|
|
Tercio@11
|
802 if (interrupt) then
|
|
Tercio@11
|
803 return
|
|
Tercio@11
|
804 end
|
|
Tercio@11
|
805 end
|
|
Tercio@11
|
806
|
|
Tercio@11
|
807 button.MyObject.is_mouse_down = false
|
|
Tercio@11
|
808
|
|
Tercio@11
|
809 if (button.texture) then
|
|
Tercio@11
|
810 if (button.texture.coords) then
|
|
Tercio@11
|
811 if (button.MyObject.is_mouse_over) then
|
|
Tercio@11
|
812 button.texture:SetTexCoord (_unpack (button.texture.coords.Highlight))
|
|
Tercio@11
|
813 else
|
|
Tercio@11
|
814 button.texture:SetTexCoord (_unpack (coords.Normal))
|
|
Tercio@11
|
815 end
|
|
Tercio@11
|
816 else
|
|
Tercio@11
|
817 if (button.MyObject.is_mouse_over) then
|
|
Tercio@11
|
818 button.texture:SetTexCoord (0, 1, 0.24609375, 0.49609375)
|
|
Tercio@11
|
819 else
|
|
Tercio@11
|
820 button.texture:SetTexCoord (0, 1, 0, 0.24609375)
|
|
Tercio@11
|
821 end
|
|
Tercio@11
|
822 end
|
|
Tercio@11
|
823 end
|
|
Tercio@11
|
824
|
|
Tercio@11
|
825 if (button.MyObject.capsule_textalign) then
|
|
Tercio@11
|
826 if (button.MyObject.icon) then
|
|
Tercio@11
|
827 button.MyObject.icon:SetPoint ("left", button, "left", 4 + (button.MyObject.icon.leftpadding or 0), 0)
|
|
Tercio@11
|
828 elseif (button.MyObject.capsule_textalign == "left") then
|
|
Tercio@11
|
829 button.text:SetPoint ("left", button, "left", 2, 0)
|
|
Tercio@11
|
830 elseif (button.MyObject.capsule_textalign == "center") then
|
|
Tercio@11
|
831 button.text:SetPoint ("center", button, "center", 0, 0)
|
|
Tercio@11
|
832 elseif (button.MyObject.capsule_textalign == "right") then
|
|
Tercio@11
|
833 button.text:SetPoint ("right", button, "right", -2, 0)
|
|
Tercio@11
|
834 end
|
|
Tercio@11
|
835 else
|
|
Tercio@11
|
836 if (button.MyObject.icon) then
|
|
Tercio@11
|
837 button.MyObject.icon:SetPoint ("left", button, "left", 4 + (button.MyObject.icon.leftpadding or 0), 0)
|
|
Tercio@11
|
838 else
|
|
Tercio@11
|
839 button.text:SetPoint ("center", button,"center", 0, 0)
|
|
Tercio@11
|
840 end
|
|
Tercio@11
|
841 end
|
|
Tercio@11
|
842
|
|
Tercio@11
|
843 if (button.MyObject.container.isMoving) then
|
|
Tercio@11
|
844 button.MyObject.container:StopMovingOrSizing()
|
|
Tercio@11
|
845 button.MyObject.container.isMoving = false
|
|
Tercio@11
|
846 end
|
|
Tercio@11
|
847
|
|
Tercio@11
|
848 local x, y = GetCursorPosition()
|
|
Tercio@11
|
849 x = _math_floor (x)
|
|
Tercio@11
|
850 y = _math_floor (y)
|
|
Tercio@11
|
851 if ((button.mouse_down+0.4 > GetTime() and (x == button.x and y == button.y)) or (x == button.x and y == button.y)) then
|
|
Tercio@11
|
852 if (buttontype == "LeftButton") then
|
|
Tercio@11
|
853 button.MyObject.func (button, buttontype, button.MyObject.param1, button.MyObject.param2)
|
|
Tercio@11
|
854 else
|
|
Tercio@11
|
855 button.MyObject.funcright (button, buttontype, button.MyObject.param1, button.MyObject.param2)
|
|
Tercio@11
|
856 end
|
|
Tercio@11
|
857 end
|
|
Tercio@11
|
858 end
|
|
Tercio@11
|
859
|
|
Tercio@11
|
860 ------------------------------------------------------------------------------------------------------------
|
|
Tercio@11
|
861 --> object constructor
|
|
Tercio@11
|
862
|
|
Tercio@11
|
863 function DF:CreateButton (parent, func, w, h, text, param1, param2, texture, member, name, short_method)
|
|
Tercio@11
|
864 return DF:NewButton (parent, parent, name, member, w, h, func, param1, param2, texture, text, short_method)
|
|
Tercio@11
|
865 end
|
|
Tercio@11
|
866
|
|
Tercio@11
|
867 function DF:NewButton (parent, container, name, member, w, h, func, param1, param2, texture, text, short_method)
|
|
Tercio@11
|
868
|
|
Tercio@11
|
869 if (not name) then
|
|
Tercio@11
|
870 name = "DetailsFrameworkButtonNumber" .. DF.ButtonCounter
|
|
Tercio@11
|
871 DF.ButtonCounter = DF.ButtonCounter + 1
|
|
Tercio@11
|
872
|
|
Tercio@11
|
873 elseif (not parent) then
|
|
Tercio@11
|
874 return nil
|
|
Tercio@11
|
875 end
|
|
Tercio@11
|
876 if (not container) then
|
|
Tercio@11
|
877 container = parent
|
|
Tercio@11
|
878 end
|
|
Tercio@11
|
879
|
|
Tercio@11
|
880 if (name:find ("$parent")) then
|
|
Tercio@11
|
881 name = name:gsub ("$parent", parent:GetName())
|
|
Tercio@11
|
882 end
|
|
Tercio@11
|
883
|
|
Tercio@11
|
884
|
|
Tercio@11
|
885 local ButtonObject = {type = "button", dframework = true}
|
|
Tercio@11
|
886
|
|
Tercio@11
|
887 if (member) then
|
|
Tercio@11
|
888 parent [member] = ButtonObject
|
|
Tercio@11
|
889 end
|
|
Tercio@11
|
890
|
|
Tercio@11
|
891 if (parent.dframework) then
|
|
Tercio@11
|
892 parent = parent.widget
|
|
Tercio@11
|
893 end
|
|
Tercio@11
|
894 if (container.dframework) then
|
|
Tercio@11
|
895 container = container.widget
|
|
Tercio@11
|
896 end
|
|
Tercio@11
|
897
|
|
Tercio@11
|
898 --> default members:
|
|
Tercio@11
|
899 --> hooks
|
|
Tercio@11
|
900 ButtonObject.OnEnterHook = nil
|
|
Tercio@11
|
901 ButtonObject.OnLeaveHook = nil
|
|
Tercio@11
|
902 ButtonObject.OnHideHook = nil
|
|
Tercio@11
|
903 ButtonObject.OnShowHook = nil
|
|
Tercio@11
|
904 ButtonObject.OnMouseDownHook = nil
|
|
Tercio@11
|
905 ButtonObject.OnMouseUpHook = nil
|
|
Tercio@11
|
906 --> misc
|
|
Tercio@11
|
907 ButtonObject.is_locked = true
|
|
Tercio@11
|
908 ButtonObject.container = container
|
|
Tercio@11
|
909 ButtonObject.have_tooltip = nil
|
|
Tercio@11
|
910 ButtonObject.options = {OnGrab = false}
|
|
Tercio@11
|
911
|
|
Tercio@11
|
912
|
|
Tercio@11
|
913 ButtonObject.button = CreateFrame ("button", name, parent, "DetailsFrameworkButtonTemplate")
|
|
Tercio@11
|
914 ButtonObject.widget = ButtonObject.button
|
|
Tercio@11
|
915
|
|
Tercio@11
|
916 ButtonObject.button:SetBackdrop ({bgFile = DF.folder .. "background", tileSize = 64, edgeFile = DF.folder .. "border_2", edgeSize = 10, insets = {left = 1, right = 1, top = 1, bottom = 1}})
|
|
Tercio@11
|
917 ButtonObject.button:SetBackdropColor (0, 0, 0, 0.4)
|
|
Tercio@11
|
918 ButtonObject.button:SetBackdropBorderColor (1, 1, 1, 1)
|
|
Tercio@11
|
919
|
|
Tercio@11
|
920 if (not APIButtonFunctions) then
|
|
Tercio@11
|
921 APIButtonFunctions = true
|
|
Tercio@11
|
922 local idx = getmetatable (ButtonObject.button).__index
|
|
Tercio@11
|
923 for funcName, funcAddress in pairs (idx) do
|
|
Tercio@11
|
924 if (not ButtonMetaFunctions [funcName]) then
|
|
Tercio@11
|
925 ButtonMetaFunctions [funcName] = function (object, ...)
|
|
Tercio@11
|
926 local x = loadstring ( "return _G."..object.button:GetName()..":"..funcName.."(...)")
|
|
Tercio@11
|
927 return x (...)
|
|
Tercio@11
|
928 end
|
|
Tercio@11
|
929 end
|
|
Tercio@11
|
930 end
|
|
Tercio@11
|
931 end
|
|
Tercio@11
|
932
|
|
Tercio@11
|
933 ButtonObject.button:SetWidth (w or 100)
|
|
Tercio@11
|
934 ButtonObject.button:SetHeight (h or 20)
|
|
Tercio@11
|
935 ButtonObject.button.MyObject = ButtonObject
|
|
Tercio@11
|
936
|
|
Tercio@11
|
937 ButtonObject.text_overlay = _G [name .. "_Text"]
|
|
Tercio@11
|
938 ButtonObject.disabled_overlay = _G [name .. "_TextureDisabled"]
|
|
Tercio@11
|
939
|
|
Tercio@11
|
940 ButtonObject.button:SetNormalTexture (texture)
|
|
Tercio@11
|
941 ButtonObject.button:SetPushedTexture (texture)
|
|
Tercio@11
|
942 ButtonObject.button:SetDisabledTexture (texture)
|
|
Tercio@11
|
943 ButtonObject.button:SetHighlightTexture (texture, "ADD")
|
|
Tercio@11
|
944
|
|
Tercio@11
|
945 ButtonObject.button.text:SetText (text)
|
|
Tercio@11
|
946 ButtonObject.button.text:SetPoint ("center", ButtonObject.button, "center")
|
|
Tercio@11
|
947
|
|
Tercio@11
|
948 local text_width = ButtonObject.button.text:GetStringWidth()
|
|
Tercio@11
|
949 if (text_width > w-15 and ButtonObject.button.text:GetText() ~= "") then
|
|
Tercio@11
|
950 if (not short_method) then
|
|
Tercio@11
|
951 local new_width = text_width+15
|
|
Tercio@11
|
952 ButtonObject.button:SetWidth (new_width)
|
|
Tercio@11
|
953 elseif (short_method == 1) then
|
|
Tercio@11
|
954 local loop = true
|
|
Tercio@11
|
955 local textsize = 11
|
|
Tercio@11
|
956 while (loop) do
|
|
Tercio@11
|
957 if (text_width+15 < w or textsize < 8) then
|
|
Tercio@11
|
958 loop = false
|
|
Tercio@11
|
959 break
|
|
Tercio@11
|
960 else
|
|
Tercio@11
|
961 DF:SetFontSize (ButtonObject.button.text, textsize)
|
|
Tercio@11
|
962 text_width = ButtonObject.button.text:GetStringWidth()
|
|
Tercio@11
|
963 textsize = textsize - 1
|
|
Tercio@11
|
964 end
|
|
Tercio@11
|
965 end
|
|
Tercio@11
|
966 end
|
|
Tercio@11
|
967 end
|
|
Tercio@11
|
968
|
|
Tercio@11
|
969 ButtonObject.func = func or cleanfunction
|
|
Tercio@11
|
970 ButtonObject.funcright = cleanfunction
|
|
Tercio@11
|
971 ButtonObject.param1 = param1
|
|
Tercio@11
|
972 ButtonObject.param2 = param2
|
|
Tercio@11
|
973
|
|
Tercio@11
|
974 ButtonObject.short_method = short_method
|
|
Tercio@11
|
975
|
|
Tercio@11
|
976 --> hooks
|
|
Tercio@11
|
977 ButtonObject.button:SetScript ("OnEnter", OnEnter)
|
|
Tercio@11
|
978 ButtonObject.button:SetScript ("OnLeave", OnLeave)
|
|
Tercio@11
|
979 ButtonObject.button:SetScript ("OnHide", OnHide)
|
|
Tercio@11
|
980 ButtonObject.button:SetScript ("OnShow", OnShow)
|
|
Tercio@11
|
981 ButtonObject.button:SetScript ("OnMouseDown", OnMouseDown)
|
|
Tercio@11
|
982 ButtonObject.button:SetScript ("OnMouseUp", OnMouseUp)
|
|
Tercio@11
|
983
|
|
Tercio@11
|
984 _setmetatable (ButtonObject, ButtonMetaFunctions)
|
|
Tercio@11
|
985
|
|
Tercio@11
|
986 return ButtonObject
|
|
Tercio@11
|
987
|
|
Tercio@11
|
988 end
|
|
Tercio@11
|
989
|
|
Tercio@11
|
990 local pickcolor_callback = function (self, r, g, b, a, button)
|
|
Tercio@11
|
991 button.MyObject.color_texture:SetVertexColor (r, g, b, a)
|
|
Tercio@11
|
992 button.MyObject:color_callback (r, g, b, a)
|
|
Tercio@11
|
993 end
|
|
Tercio@11
|
994 local pickcolor = function (alpha, param2, self)
|
|
Tercio@11
|
995 local r, g, b, a = self.MyObject.color_texture:GetVertexColor()
|
|
Tercio@11
|
996 DF:ColorPick (self, r, g, b, a, pickcolor_callback)
|
|
Tercio@11
|
997 end
|
|
Tercio@11
|
998
|
|
Tercio@11
|
999 local color_button_height = 16
|
|
Tercio@11
|
1000 local color_button_width = 16
|
|
Tercio@11
|
1001
|
|
Tercio@11
|
1002 local set_colorpick_color = function (button, r, g, b, a)
|
|
Tercio@11
|
1003 button.color_texture:SetVertexColor (r, g, b, a)
|
|
Tercio@11
|
1004 end
|
|
Tercio@11
|
1005
|
|
Tercio@11
|
1006 local colorpick_cancel = function (self)
|
|
Tercio@11
|
1007 ColorPickerFrame:Hide()
|
|
Tercio@11
|
1008 end
|
|
Tercio@11
|
1009
|
|
Tercio@11
|
1010 function DF:CreateColorPickButton (parent, name, member, callback, alpha)
|
|
Tercio@11
|
1011 return DF:NewColorPickButton (parent, name, member, callback, alpha)
|
|
Tercio@11
|
1012 end
|
|
Tercio@11
|
1013
|
|
Tercio@11
|
1014 function DF:NewColorPickButton (parent, name, member, callback, alpha)
|
|
Tercio@11
|
1015
|
|
Tercio@11
|
1016 --button
|
|
Tercio@11
|
1017 local button = DF:NewButton (parent, _, name, member, color_button_width, color_button_height, pickcolor, alpha, "param2")
|
|
Tercio@11
|
1018 button:InstallCustomTexture()
|
|
Tercio@11
|
1019 button.color_callback = callback
|
|
Tercio@11
|
1020 button.Cancel = colorpick_cancel
|
|
Tercio@11
|
1021 button.SetColor = set_colorpick_color
|
|
Tercio@11
|
1022
|
|
Tercio@11
|
1023 button:SetBackdrop ({edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 6,
|
|
Tercio@11
|
1024 bgFile = [[Interface\DialogFrame\UI-DialogBox-Background]], insets = {left = 0, right = 0, top = 0, bottom = 0}})
|
|
Tercio@11
|
1025
|
|
Tercio@11
|
1026 --textura do fundo
|
|
Tercio@11
|
1027 local background = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, nil, "$parentBck")
|
|
Tercio@11
|
1028 --background:SetTexture ([[Interface\AddOns\Details\images\icons]])
|
|
Tercio@11
|
1029 background:SetPoint ("topleft", button.widget, "topleft", 1, -2)
|
|
Tercio@11
|
1030 background:SetPoint ("bottomright", button.widget, "bottomright", -1, 1)
|
|
Tercio@11
|
1031 background:SetTexCoord (0.337890625, 0.390625, 0.625, 0.658203125)
|
|
Tercio@11
|
1032 background:SetDrawLayer ("background", 1)
|
|
Tercio@11
|
1033
|
|
Tercio@11
|
1034 --textura da cor
|
|
Tercio@11
|
1035 local img = DF:NewImage (button, nil, color_button_width, color_button_height, nil, nil, "color_texture", "$parentTex")
|
|
Tercio@11
|
1036 img:SetTexture (1, 1, 1)
|
|
Tercio@11
|
1037 img:SetPoint ("topleft", button.widget, "topleft", 1, -2)
|
|
Tercio@11
|
1038 img:SetPoint ("bottomright", button.widget, "bottomright", -1, 1)
|
|
Tercio@11
|
1039 img:SetDrawLayer ("background", 2)
|
|
Tercio@11
|
1040
|
|
Tercio@11
|
1041 return button
|
|
Tercio@11
|
1042
|
|
Tercio@11
|
1043 end |