vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Name: Tablet-2.0
3 Revision: $Rev: 8333 $
4 Author(s): ckknight (ckknight@gmail.com)
5 Website: http://ckknight.wowinterface.com/
6 Documentation: http://wiki.wowace.com/index.php/Tablet-2.0
7 SVN: http://svn.wowace.com/root/trunk/TabletLib/Tablet-2.0
8 Description: A library to provide an efficient, featureful tooltip-style display.
9 Dependencies: AceLibrary, (optional) Dewdrop-2.0, (optional) SEEmbedKeys
10 ]]
11  
12 local MAJOR_VERSION = "Tablet-2.0"
13 local MINOR_VERSION = "$Revision: 8333 $"
14  
15 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
16 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
17  
18 local DEBUG = false
19  
20 local SCROLL_UP, SCROLL_DOWN, HINT, DETACH, SIZE, CLOSE_MENU
21 if GetLocale() == "deDE" then
22 SCROLL_UP = "Hochscrolle"
23 SCROLL_DOWN = "Herunterscrolle"
24 HINT = "Hinweis"
25 DETACH = "Lösen"
26 SIZE = "Größe"
27 CLOSE_MENU = "Menü schließen"
28 elseif GetLocale() == "koKR" then
29 SCROLL_UP = "위로 올리기"
30 SCROLL_DOWN = "아래로 내리기"
31 HINT = "힌트"
32 DETACH = "떼내기"
33 SIZE = "크기"
34 CLOSE_MENU = "메뉴 닫기"
35 else
36 SCROLL_UP = "Scroll up"
37 SCROLL_DOWN = "Scroll down"
38 HINT = "Hint"
39 DETACH = "Detach"
40 SIZE = "Size"
41 CLOSE_MENU = "Close menu"
42 end
43  
44 local start = GetTime()
45 local wrap
46 local GetProfileInfo
47 if DEBUG then
48 local tree = {}
49 local treeMemories = {}
50 local treeTimes = {}
51 local memories = {}
52 local times = {}
53 function wrap(value, name)
54 if type(value) == "function" then
55 local oldFunction = value
56 memories[name] = 0
57 times[name] = 0
58 return function(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60)
59 local pos = table.getn(tree)
60 table.insert(tree, name)
61 table.insert(treeMemories, 0)
62 table.insert(treeTimes, 0)
63 local t, mem = GetTime(), gcinfo()
64 local r1, r2, r3, r4, r5, r6, r7, r8 = oldFunction(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60)
65 mem, t = gcinfo() - mem, GetTime() - t
66 if pos > 0 then
67 treeMemories[pos] = treeMemories[pos] + mem
68 treeTimes[pos] = treeTimes[pos] + t
69 end
70 local otherMem = table.remove(treeMemories)
71 if mem - otherMem > 0 then
72 memories[name] = memories[name] + mem - otherMem
73 end
74 times[name] = times[name] + t - table.remove(treeTimes)
75 table.remove(tree)
76 return r1, r2, r3, r4, r5, r6, r7, r8
77 end
78 end
79 end
80  
81 function GetProfileInfo()
82 return GetTime() - start, times, memories
83 end
84 else
85 function wrap(value)
86 return value
87 end
88 end
89  
90 local MIN_TOOLTIP_SIZE = 200
91 local Tablet = {}
92 local function getsecond(_, value)
93 return value
94 end
95 local Dewdrop
96 local sekeys
97 local CleanCategoryPool
98 local pool = {}
99 local function del(t)
100 if t then
101 if DEBUG and t[".poolprint"] then
102 print(t[".poolprint"])
103 end
104 for k in pairs(t) do
105 t[k] = nil
106 end
107 setmetatable(t, nil)
108 table.setn(t, 0)
109 table.insert(pool, t)
110 end
111 end
112  
113 local new
114  
115 local function copy(parent)
116 local t
117 if table.getn(pool) > 0 then
118 t = table.remove(pool)
119 else
120 t = {}
121 end
122 if parent then
123 for k,v in pairs(parent) do
124 t[k] = v
125 end
126 table.setn(t, table.getn(parent))
127 setmetatable(t, getmetatable(parent))
128 end
129 return t
130 end
131  
132 function new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
133 local t
134 if table.getn(pool) > 0 then
135 t = table.remove(pool)
136 else
137 t = {}
138 end
139 if k1 then t[k1] = v1
140 if k2 then t[k2] = v2
141 if k3 then t[k3] = v3
142 if k4 then t[k4] = v4
143 if k5 then t[k5] = v5
144 if k6 then t[k6] = v6
145 if k7 then t[k7] = v7
146 if k8 then t[k8] = v8
147 if k9 then t[k9] = v9
148 if k10 then t[k10] = v10
149 if k11 then t[k11] = v11
150 if k12 then t[k12] = v12
151 if k13 then t[k13] = v13
152 if k14 then t[k14] = v14
153 if k15 then t[k15] = v15
154 if k16 then t[k16] = v16
155 if k17 then t[k17] = v17
156 if k18 then t[k18] = v18
157 if k19 then t[k19] = v19
158 if k20 then t[k20] = v20
159 if k21 then t[k21] = v21
160 if k22 then t[k22] = v22
161 if k23 then t[k23] = v23
162 if k24 then t[k24] = v24
163 if k25 then t[k25] = v25
164 if k26 then t[k26] = v26
165 if k27 then t[k27] = v27
166 if k28 then t[k28] = v28
167 if k29 then t[k29] = v29
168 if k30 then t[k30] = v30
169 end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end
170 return t
171 end
172 local tmp
173 tmp = setmetatable({}, {__index = function(self, key)
174 local t = {}
175 tmp[key] = function(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
176 for k in pairs(t) do
177 t[k] = nil
178 end
179 if k1 then t[k1] = v1
180 if k2 then t[k2] = v2
181 if k3 then t[k3] = v3
182 if k4 then t[k4] = v4
183 if k5 then t[k5] = v5
184 if k6 then t[k6] = v6
185 if k7 then t[k7] = v7
186 if k8 then t[k8] = v8
187 if k9 then t[k9] = v9
188 if k10 then t[k10] = v10
189 if k11 then t[k11] = v11
190 if k12 then t[k12] = v12
191 if k13 then t[k13] = v13
192 if k14 then t[k14] = v14
193 if k15 then t[k15] = v15
194 if k16 then t[k16] = v16
195 if k17 then t[k17] = v17
196 if k18 then t[k18] = v18
197 if k19 then t[k19] = v19
198 if k20 then t[k20] = v20
199 if k21 then t[k21] = v21
200 if k22 then t[k22] = v22
201 if k23 then t[k23] = v23
202 if k24 then t[k24] = v24
203 if k25 then t[k25] = v25
204 if k26 then t[k26] = v26
205 if k27 then t[k27] = v27
206 if k28 then t[k28] = v28
207 if k29 then t[k29] = v29
208 if k30 then t[k30] = v30
209 end end end end end end end end end end end end end end end end end end end end end end end end end end end end end end
210 return t
211 end
212 return tmp[key]
213 end})
214  
215 local headerSize, normalSize
216 if GameTooltipHeaderText then
217 _,headerSize = GameTooltipHeaderText:GetFont()
218 else
219 headerSize = 14
220 end
221 if GameTooltipText then
222 _,normalSize = GameTooltipText:GetFont()
223 else
224 normalSize = 12
225 end
226 local tooltip
227 local testString
228 local TabletData = {}
229 local Category = {}
230 local Line = {}
231 do
232 local TabletData_mt = { __index = TabletData }
233 function TabletData:new(tablet)
234 if not testString then
235 testString = UIParent:CreateFontString()
236 testString:Hide()
237 end
238 local self = new()
239 self.categories = new()
240 self.id = 0
241 self.width = 0--(MIN_TOOLTIP_SIZE - 20)*tablet.fontSizePercent
242 self.tablet = tablet
243 self.title = "Title"
244 setmetatable(self, TabletData_mt)
245 return self
246 end
247  
248 function TabletData:del()
249 for k, v in ipairs(self.categories) do
250 v:del()
251 end
252 del(self.categories)
253 del(self)
254 end
255  
256 function TabletData:print(id)
257 printFull(id, self)
258 end
259  
260 function TabletData:Display()
261 if self.tablet == tooltip or self.tablet.registration.showEverythingWhenDetached then
262 local info = new(
263 'hideBlankLine', true,
264 'text', self.title,
265 'justify', "CENTER",
266 'font', GameTooltipHeaderText,
267 'isTitle', true
268 )
269 self:AddCategory(info, 1)
270 del(info)
271 if self.hint then
272 self:AddCategory(nil):AddLine(
273 'text', HINT .. ": " .. self.hint,
274 'textR', 0,
275 'textG', 1,
276 'textB', 0,
277 'wrap', true
278 )
279 end
280 end
281  
282 local tabletData = self.tabletData
283 local width
284 for k, v in ipairs(self.categories) do
285 if v.columns <= 2 then
286 width = v.x1
287 else
288 width = v.x1 + v.x2 + v.x3 + v.x4 + v.x5 + v.x6 + (v.columns - 1) * 20
289 end
290 if self.width < width then
291 self.width = width
292 end
293 end
294  
295 local good = false
296 local lastTitle = true
297 for k, v in ipairs(self.categories) do
298 if lastTitle then
299 v.hideBlankLine = true
300 lastTitle = false
301 end
302 if v:Display(self.tablet) then
303 good = true
304 end
305 if v.isTitle then
306 lastTitle = true
307 end
308 end
309 if not good then
310 local width
311 local info = new(
312 'hideBlankLine', true,
313 'text', self.title,
314 'justify', "CENTER",
315 'font', GameTooltipHeaderText,
316 'isTitle', true
317 )
318 local cat = self:AddCategory(info)
319 del(info)
320 self.width = self.categories[table.getn(self.categories)].x1
321 cat:Display(self.tablet)
322 end
323 end
324  
325 function TabletData:AddCategory(info, index)
326 local made = false
327 if not info then
328 made = true
329 info = new()
330 end
331 local cat = Category:new(self, info)
332 if index then
333 table.insert(self.categories, index, cat)
334 else
335 table.insert(self.categories, cat)
336 end
337 if made then
338 del(info)
339 end
340 return cat
341 end
342  
343 function TabletData:SetHint(hint)
344 self.hint = hint
345 end
346  
347 function TabletData:SetTitle(title)
348 self.title = title or "Title"
349 end
350 end
351 do
352 local Category_mt = { __index = Category }
353 function Category:new(tabletData, info, superCategory)
354 local self = copy(info)
355 if superCategory and not self.noInherit then
356 self.superCategory = superCategory.superCategory
357 for k, v in pairs(superCategory) do
358 if string.find(k, "^child_") then
359 local k = strsub(k, 7)
360 if self[k] == nil then
361 self[k] = v
362 end
363 end
364 end
365 self.columns = superCategory.columns
366 else
367 self.superCategory = self
368 end
369 self.tabletData = tabletData
370 self.lines = new()
371 if not self.columns then
372 self.columns = 1
373 end
374 self.x1 = 0
375 self.x2 = 0
376 self.x3 = 0
377 self.x4 = 0
378 self.x5 = 0
379 self.x6 = 0
380 setmetatable(self, Category_mt)
381 self.lastWasTitle = nil
382 if self.text or self.text2 or self.text3 or self.text4 or self.text5 or self.text6 then
383 local x = new(
384 'category', category,
385 'text', self.text,
386 'textR', self.textR or 1,
387 'textG', self.textG or 1,
388 'textB', self.textB or 1,
389 'fakeChild', true,
390 'func', self.func,
391 'arg1', info.arg1,
392 'arg2', self.arg2,
393 'arg3', self.arg3,
394 'hasCheck', self.hasCheck,
395 'checked', self.checked,
396 'checkIcon', self.checkIcon,
397 'isRadio', self.isRadio,
398 'font', self.font,
399 'size', self.size,
400 'wrap', self.wrap,
401 'catStart', true,
402 'indentation', self.indentation,
403 'noInherit', true,
404 'justify', self.justify,
405 'justify2', self.justify2,
406 'justify3', self.justify3,
407 'justify4', self.justify4,
408 'justify5', self.justify5,
409 'justify6', self.justify6
410 )
411 if self.isTitle then
412 x.textR = self.textR or 1
413 x.textG = self.textG or 0.823529
414 x.textB = self.textB or 0
415 else
416 x.textR = self.textR or 1
417 x.textG = self.textG or 1
418 x.textB = self.textB or 1
419 end
420 x.text2 = self.text2
421 x.text3 = self.text3
422 x.text4 = self.text4
423 x.text5 = self.text5
424 x.text6 = self.text6
425 x.text2R = self.text2R or self.textR2 or 1
426 x.text2G = self.text2G or self.textG2 or 1
427 x.text2B = self.text2B or self.textB2 or 1
428 x.text3R = self.text3R or self.textR3 or 1
429 x.text3G = self.text3G or self.textG3 or 1
430 x.text3B = self.text3B or self.textB3 or 1
431 x.text4R = self.text4R or self.textR4 or 1
432 x.text4G = self.text4G or self.textG4 or 1
433 x.text4B = self.text4B or self.textB4 or 1
434 x.text5R = self.text5R or self.textR5 or 1
435 x.text5G = self.text5G or self.textG5 or 1
436 x.text5B = self.text5B or self.textB5 or 1
437 x.text6R = self.text6R or self.textR6 or 1
438 x.text6G = self.text6G or self.textG6 or 1
439 x.text6B = self.text6B or self.textB6 or 1
440 x.font2 = self.font2
441 x.font3 = self.font3
442 x.font4 = self.font4
443 x.font5 = self.font5
444 x.font6 = self.font6
445 x.size2 = self.size2
446 x.size3 = self.size3
447 x.size4 = self.size4
448 x.size5 = self.size5
449 x.size6 = self.size6
450 self:AddLine(x)
451 del(x)
452 self.lastWasTitle = true
453 end
454 return self
455 end
456  
457 function Category:del()
458 local prev = garbageLine
459 for k, v in pairs(self.lines) do
460 v:del()
461 end
462 del(self.lines)
463 del(self)
464 end
465  
466 function Category:AddLine(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
467 self.lastWasTitle = nil
468 local line
469 if type(k1) == "table" then
470 Line:new(self, k1, v1)
471 else
472 local info = new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
473 Line:new(self, info)
474 del(info)
475 end
476 end
477  
478 function Category:AddCategory(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
479 local lastWasTitle = self.lastWasTitle
480 self.lastWasTitle = nil
481 local info
482 if type(k1) == "table" then
483 info = k1
484 else
485 info = new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
486 end
487 if lastWasTitle or table.getn(self.lines) == 0 then
488 info.hideBlankLine = true
489 end
490 local cat = Category:new(self.tabletData, info, self)
491 table.insert(self.lines, cat)
492 return cat
493 end
494  
495 function Category:HasChildren()
496 local hasChildren = false
497 for k, v in ipairs(self.lines) do
498 if v.HasChildren then
499 if v:HasChildren() then
500 return true
501 end
502 end
503 if not v.fakeChild then
504 return true
505 end
506 end
507 return false
508 end
509  
510 local lastWasTitle = false
511 function Category:Display(tablet)
512 if not self.isTitle and not self.showWithoutChildren and not self:HasChildren() then
513 return false
514 end
515 if not self.hideBlankLine and not lastWasTitle then
516 local info = new(
517 'blank', true,
518 'fakeChild', true
519 )
520 self:AddLine(info, 1)
521 del(info)
522 end
523 local good = false
524 if table.getn(self.lines) > 0 then
525 self.tabletData.id = self.tabletData.id + 1
526 self.id = self.tabletData.id
527 for k, v in ipairs(self.lines) do
528 if v:Display(tablet) then
529 good = true
530 end
531 end
532 end
533 lastWasTitle = self.isTitle
534 return good
535 end
536 end
537 do
538 local Line_mt = { __index = Line }
539 function Line:new(category, info, position)
540 local self = copy(info)
541 if not info.noInherit then
542 for k, v in pairs(category) do
543 if string.find(k, "^child_") then
544 local k = strsub(k, 7)
545 if self[k] == nil then
546 self[k] = v
547 end
548 end
549 end
550 end
551 self.category = category
552 if position then
553 table.insert(category.lines, position, self)
554 else
555 table.insert(category.lines, self)
556 end
557 setmetatable(self, Line_mt)
558 local columns = category.columns
559 if columns == 1 then
560 if not self.justify then
561 self.justify = "LEFT"
562 end
563 elseif columns == 2 then
564 self.justify = "LEFT"
565 self.justify2 = "RIGHT"
566 if self.wrap then
567 self.wrap2 = false
568 end
569 elseif columns == 3 then
570 if not self.justify then
571 self.justify = "LEFT"
572 end
573 if not self.justify2 then
574 self.justify2 = "CENTER"
575 end
576 if not self.justify3 then
577 self.justify3 = "RIGHT"
578 end
579 if self.wrap then
580 self.wrap2 = false
581 self.wrap3 = false
582 elseif self.wrap2 then
583 self.wrap3 = false
584 end
585 elseif columns == 4 then
586 if not self.justify then
587 self.justify = "LEFT"
588 end
589 if not self.justify2 then
590 self.justify2 = "CENTER"
591 end
592 if not self.justify3 then
593 self.justify3 = "CENTER"
594 end
595 if not self.justify4 then
596 self.justify4 = "RIGHT"
597 end
598 if self.wrap then
599 self.wrap2 = false
600 self.wrap3 = false
601 self.wrap4 = false
602 elseif self.wrap2 then
603 self.wrap3 = false
604 self.wrap4 = false
605 elseif self.wrap3 then
606 self.wrap4 = false
607 end
608 elseif columns == 5 then
609 if not self.justify then
610 self.justify = "LEFT"
611 end
612 if not self.justify2 then
613 self.justify2 = "CENTER"
614 end
615 if not self.justify3 then
616 self.justify3 = "CENTER"
617 end
618 if not self.justify4 then
619 self.justify4 = "CENTER"
620 end
621 if not self.justify5 then
622 self.justify5 = "RIGHT"
623 end
624 if self.wrap then
625 self.wrap2 = false
626 self.wrap3 = false
627 self.wrap4 = false
628 self.wrap5 = false
629 elseif self.wrap2 then
630 self.wrap3 = false
631 self.wrap4 = false
632 self.wrap5 = false
633 elseif self.wrap3 then
634 self.wrap4 = false
635 self.wrap5 = false
636 elseif self.wrap4 then
637 self.wrap5 = false
638 end
639 elseif columns == 6 then
640 if not self.justify then
641 self.justify = "LEFT"
642 end
643 if not self.justify2 then
644 self.justify2 = "CENTER"
645 end
646 if not self.justify3 then
647 self.justify3 = "CENTER"
648 end
649 if not self.justify4 then
650 self.justify4 = "CENTER"
651 end
652 if not self.justify5 then
653 self.justify5 = "CENTER"
654 end
655 if not self.justify6 then
656 self.justify6 = "RIGHT"
657 end
658 if self.wrap then
659 self.wrap2 = false
660 self.wrap3 = false
661 self.wrap4 = false
662 self.wrap5 = false
663 self.wrap6 = false
664 elseif self.wrap2 then
665 self.wrap3 = false
666 self.wrap4 = false
667 self.wrap5 = false
668 self.wrap6 = false
669 elseif self.wrap3 then
670 self.wrap4 = false
671 self.wrap5 = false
672 self.wrap6 = false
673 elseif self.wrap4 then
674 self.wrap5 = false
675 self.wrap6 = false
676 elseif self.wrap5 then
677 self.wrap6 = false
678 end
679 end
680 if self.textR2 then
681 self.text2R, self.textR2 = self.text2R or self.textR2
682 self.text2G, self.textG2 = self.text2G or self.textG2
683 self.text2B, self.textB2 = self.text2B or self.textB2
684 if self.textR3 then
685 self.text3R, self.textR3 = self.text3R or self.textR3
686 self.text3G, self.textG3 = self.text3G or self.textG3
687 self.text3B, self.textB3 = self.text3B or self.textB3
688 if self.textR4 then
689 self.text4R, self.textR4 = self.text4R or self.textR4
690 self.text4G, self.textG4 = self.text4G or self.textG4
691 self.text4B, self.textB4 = self.text4B or self.textB4
692 if self.textR5 then
693 self.text5R, self.textR5 = self.text5R or self.textR5
694 self.text5G, self.textG5 = self.text5G or self.textG5
695 self.text5B, self.textB5 = self.text5B or self.textB5
696 if self.textR5 then
697 self.text6R, self.textR6 = self.text6R or self.textR6
698 self.text6G, self.textG6 = self.text6G or self.textG6
699 self.text6B, self.textB6 = self.text6B or self.textB6
700 end
701 end
702 end
703 end
704 end
705 if not self.indentation or self.indentation < 0 then
706 self.indentation = 0
707 end
708 if not self.font then
709 self.font = GameTooltipText
710 end
711 if not self.font2 then
712 self.font2 = self.font
713 end
714 if not self.font3 then
715 self.font3 = self.font
716 end
717 if not self.font4 then
718 self.font4 = self.font
719 end
720 if not self.font5 then
721 self.font5 = self.font
722 end
723 if not self.font6 then
724 self.font6 = self.font
725 end
726 if not self.size then
727 _,self.size = self.font:GetFont()
728 end
729 if not self.size2 then
730 _,self.size2 = self.font2:GetFont()
731 end
732 if not self.size3 then
733 _,self.size3 = self.font3:GetFont()
734 end
735 if not self.size4 then
736 _,self.size4 = self.font4:GetFont()
737 end
738 if not self.size5 then
739 _,self.size5 = self.font5:GetFont()
740 end
741 if not self.size6 then
742 _,self.size6 = self.font6:GetFont()
743 end
744  
745 local fontSizePercent = category.tabletData.tablet.fontSizePercent
746 local w = 0
747 self.checkWidth = 0
748 if self.text then
749 if not self.wrap then
750 testString:SetWidth(0)
751 testString:SetFontObject(self.font)
752 local font,_,flags = testString:GetFont()
753 testString:SetFont(font, self.size * fontSizePercent, flags)
754 testString:SetText(self.text)
755 local checkWidth = self.hasCheck and self.size * fontSizePercent or 0
756 self.checkWidth = checkWidth
757 w = testString:GetWidth() + self.indentation * fontSizePercent + checkWidth
758 if category.superCategory.x1 < w then
759 category.superCategory.x1 = w
760 end
761 else
762 if columns == 1 then
763 testString:SetWidth(0)
764 testString:SetFontObject(self.font)
765 local font,_,flags = testString:GetFont()
766 testString:SetFont(font, self.size * fontSizePercent, flags)
767 testString:SetText(self.text)
768 local checkWidth = self.hasCheck and self.size * fontSizePercent or 0
769 self.checkWidth = checkWidth
770 w = testString:GetWidth() + self.indentation * fontSizePercent + checkWidth
771 if w > (MIN_TOOLTIP_SIZE - 20) * fontSizePercent then
772 w = (MIN_TOOLTIP_SIZE - 20) * fontSizePercent
773 end
774 else
775 w = MIN_TOOLTIP_SIZE * fontSizePercent / 2
776 end
777 if category.superCategory.x1 < w then
778 category.superCategory.x1 = w
779 end
780 end
781 end
782 if columns == 2 and self.text2 then
783 if not self.wrap2 then
784 testString:SetWidth(0)
785 testString:SetFontObject(self.font2)
786 local font,_,flags = testString:GetFont()
787 testString:SetFont(font, self.size2 * fontSizePercent, flags)
788 testString:SetText(self.text2)
789 w = w + 40 * fontSizePercent + testString:GetWidth()
790 if category.superCategory.x1 < w then
791 category.superCategory.x1 = w
792 end
793 else
794 w = w + 40 * fontSizePercent + MIN_TOOLTIP_SIZE * fontSizePercent / 2
795 if category.superCategory.x1 < w then
796 category.superCategory.x1 = w
797 end
798 end
799 elseif columns >= 3 then
800 if self.text2 then
801 if not self.wrap2 then
802 testString:SetWidth(0)
803 testString:SetFontObject(self.font2)
804 local font,_,flags = testString:GetFont()
805 testString:SetFont(font, self.size2 * fontSizePercent, flags)
806 testString:SetText(self.text2)
807 local w = testString:GetWidth()
808 if category.superCategory.x2 < w then
809 category.superCategory.x2 = w
810 end
811 else
812 local w = MIN_TOOLTIP_SIZE / 2
813 if category.superCategory.x2 < w then
814 category.superCategory.x2 = w
815 end
816 end
817 end
818 if self.text3 then
819 if not self.wrap3 then
820 testString:SetWidth(0)
821 testString:SetFontObject(self.font3)
822 local font,_,flags = testString:GetFont()
823 testString:SetFont(font, self.size3 * fontSizePercent, flags)
824 testString:SetText(self.text3)
825 local w = testString:GetWidth()
826 if category.superCategory.x3 < w then
827 category.superCategory.x3 = w
828 end
829 else
830 local w = MIN_TOOLTIP_SIZE / 2
831 if category.superCategory.x3 < w then
832 category.superCategory.x3 = w
833 end
834 end
835 end
836 if columns >= 4 then
837 if self.text4 then
838 if not self.wrap4 then
839 testString:SetWidth(0)
840 testString:SetFontObject(self.font4)
841 local font,_,flags = testString:GetFont()
842 testString:SetFont(font, self.size4 * fontSizePercent, flags)
843 testString:SetText(self.text4)
844 w = testString:GetWidth()
845 if category.superCategory.x4 < w then
846 category.superCategory.x4 = w
847 end
848 else
849 local w = MIN_TOOLTIP_SIZE / 2
850 if category.superCategory.x4 < w then
851 category.superCategory.x4 = w
852 end
853 end
854 end
855 if columns >= 5 then
856 if self.text5 then
857 if not self.wrap5 then
858 testString:SetWidth(0)
859 testString:SetFontObject(self.font5)
860 local font,_,flags = testString:GetFont()
861 testString:SetFont(font, self.size5 * fontSizePercent, flags)
862 testString:SetText(self.text5)
863 w = testString:GetWidth()
864 if category.superCategory.x5 < w then
865 category.superCategory.x5 = w
866 end
867 else
868 local w = MIN_TOOLTIP_SIZE / 2
869 if category.superCategory.x5 < w then
870 category.superCategory.x5 = w
871 end
872 end
873 end
874 if columns >= 6 then
875 if self.text6 then
876 if not self.wrap6 then
877 testString:SetWidth(0)
878 testString:SetFontObject(self.font6)
879 local font,_,flags = testString:GetFont()
880 testString:SetFont(font, self.size6 * fontSizePercent, flags)
881 testString:SetText(self.text6)
882 w = testString:GetWidth()
883 if category.superCategory.x6 < w then
884 category.superCategory.x6 = w
885 end
886 else
887 local w = MIN_TOOLTIP_SIZE / 2
888 if category.superCategory.x6 < w then
889 category.superCategory.x6 = w
890 end
891 end
892 end
893 end
894 end
895 end
896 end
897 return self
898 end
899  
900 function Line:del()
901 del(self)
902 end
903  
904 function Line:Display(tablet)
905 tablet:AddLine(self)
906 return true
907 end
908 end
909  
910 local function button_OnEnter()
911 if this.self:GetScript("OnEnter") then
912 this.self:GetScript("OnEnter")()
913 end
914 this.highlight:Show()
915 end
916  
917 local function button_OnLeave()
918 if this.self:GetScript("OnLeave") then
919 this.self:GetScript("OnLeave")()
920 end
921 this.highlight:Hide()
922 end
923  
924 local function NewLine(self)
925 if self.maxLines <= self.numLines then
926 self.maxLines = self.maxLines + 1
927 local button = CreateFrame("Button", nil, self)
928 button.indentation = 0
929 local check = button:CreateTexture(nil, "ARTWORK")
930 local left = button:CreateFontString(nil, "ARTWORK")
931 local right = button:CreateFontString(nil, "ARTWORK")
932 local third = button:CreateFontString(nil, "ARTWORK")
933 local fourth = button:CreateFontString(nil, "ARTWORK")
934 local fifth = button:CreateFontString(nil, "ARTWORK")
935 local sixth = button:CreateFontString(nil, "ARTWORK")
936 local highlight = button:CreateTexture(nil, "BACKGROUND")
937 highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
938 button.highlight = highlight
939 highlight:SetBlendMode("ADD")
940 highlight:SetAllPoints(button)
941 highlight:Hide()
942 table.insert(self.buttons, button)
943 table.insert(self.checks, check)
944 table.insert(self.lefts, left)
945 table.insert(self.rights, right)
946 table.insert(self.thirds, third)
947 table.insert(self.fourths, fourth)
948 table.insert(self.fifths, fifth)
949 table.insert(self.sixths, sixth)
950 left:SetWidth(0)
951 if self.maxLines == 1 then
952 left:SetFontObject(GameTooltipHeaderText)
953 right:SetFontObject(GameTooltipHeaderText)
954 third:SetFontObject(GameTooltipHeaderText)
955 fourth:SetFontObject(GameTooltipHeaderText)
956 fifth:SetFontObject(GameTooltipHeaderText)
957 sixth:SetFontObject(GameTooltipHeaderText)
958 left:SetJustifyH("CENTER")
959 button:SetPoint("TOPLEFT", self, "TOPLEFT", 8, -10)
960 else
961 left:SetFontObject(GameTooltipText)
962 right:SetFontObject(GameTooltipText)
963 third:SetFontObject(GameTooltipText)
964 fourth:SetFontObject(GameTooltipText)
965 fifth:SetFontObject(GameTooltipText)
966 sixth:SetFontObject(GameTooltipText)
967 button:SetPoint("TOPLEFT", self.buttons[self.maxLines - 1], "BOTTOMLEFT", 0, -2)
968 end
969 button:SetScript("OnEnter", button_OnEnter)
970 button:SetScript("OnLeave", button_OnLeave)
971 button.check = check
972 button.self = self
973 button:SetPoint("RIGHT", self, "RIGHT", -12, 0)
974 check.shown = false
975 check:SetPoint("TOPLEFT", button, "TOPLEFT")
976 left:SetPoint("TOPLEFT", check, "TOPLEFT")
977 right:SetPoint("TOPLEFT", left, "TOPRIGHT", 40 * self.fontSizePercent, 0)
978 third:SetPoint("TOPLEFT", right, "TOPRIGHT", 20 * self.fontSizePercent, 0)
979 fourth:SetPoint("TOPLEFT", third, "TOPRIGHT", 20 * self.fontSizePercent, 0)
980 fifth:SetPoint("TOPLEFT", fourth, "TOPRIGHT", 20 * self.fontSizePercent, 0)
981 sixth:SetPoint("TOPLEFT", fifth, "TOPRIGHT", 20 * self.fontSizePercent, 0)
982 right:SetJustifyH("RIGHT")
983 local _,size = GameTooltipText:GetFont()
984 check:SetHeight(size * 1.5)
985 check:SetWidth(size * 1.5)
986 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
987 check:SetAlpha(0)
988 if not button.clicked then
989 button:SetScript("OnMouseWheel", self:GetScript("OnMouseWheel"))
990 button:EnableMouseWheel(true)
991 button:Hide()
992 end
993 check:Show()
994 left:Hide()
995 right:Hide()
996 third:Hide()
997 fourth:Hide()
998 fifth:Hide()
999 sixth:Hide()
1000 end
1001 end
1002 NewLine = wrap(NewLine, "NewLine")
1003  
1004 local function GetMaxLinesPerScreen(self)
1005 if self == tooltip then
1006 return floor(50 / self.fontSizePercent)
1007 else
1008 return floor(30 / self.fontSizePercent)
1009 end
1010 end
1011 GetMaxLinesPerScreen = wrap(GetMaxLinesPerScreen, "GetMaxLinesPerScreen")
1012  
1013 local detachedTooltips = {}
1014 local AcquireDetachedFrame, ReleaseDetachedFrame
1015 local function AcquireFrame(self, registration, data, detachedData)
1016 if not detachedData then
1017 detachedData = data
1018 end
1019 if tooltip then
1020 tooltip.data = data
1021 tooltip.detachedData = detachedData
1022 local fontSizePercent = tooltip.data and tooltip.data.fontSizePercent or 1
1023 local transparency = tooltip.data and tooltip.data.transparency or 0.75
1024 local r = tooltip.data and tooltip.data.r or 0
1025 local g = tooltip.data and tooltip.data.g or 0
1026 local b = tooltip.data and tooltip.data.b or 0
1027 tooltip:SetFontSizePercent(fontSizePercent)
1028 tooltip:SetTransparency(transparency)
1029 tooltip:SetColor(r, g, b)
1030 else
1031 tooltip = CreateFrame("Frame", "TabletLibFrame", UIParent)
1032 self.tooltip = tooltip
1033 tooltip.data = data
1034 tooltip.detachedData = detachedData
1035 tooltip:EnableMouse(true)
1036 tooltip:EnableMouseWheel(true)
1037 tooltip:SetFrameStrata("TOOLTIP")
1038 tooltip:SetFrameLevel(10)
1039 local backdrop = new(
1040 'bgFile', "Interface\\Buttons\\WHITE8X8",
1041 'edgeFile', "Interface\\Tooltips\\UI-Tooltip-Border",
1042 'tile', true,
1043 'tileSize', 16,
1044 'edgeSize', 16,
1045 'insets', new(
1046 'left', 5,
1047 'right', 5,
1048 'top', 5,
1049 'bottom', 5
1050 )
1051 )
1052 tooltip:SetBackdrop(backdrop)
1053 del(backdrop.insets)
1054 del(backdrop)
1055 tooltip:SetBackdropColor(0, 0, 0, 1)
1056  
1057 tooltip.numLines = 0
1058 tooltip.owner = nil
1059 tooltip.fontSizePercent = tooltip.data and tooltip.data.fontSizePercent or 1
1060 tooltip.maxLines = 0
1061 tooltip.buttons = {}
1062 tooltip.checks = {}
1063 tooltip.lefts = {}
1064 tooltip.rights = {}
1065 tooltip.thirds = {}
1066 tooltip.fourths = {}
1067 tooltip.fifths = {}
1068 tooltip.sixths = {}
1069 tooltip.transparency = tooltip.data and tooltip.data.transparency or 0.75
1070 tooltip:SetBackdropColor(0, 0, 0, tooltip.transparency)
1071 tooltip:SetBackdropBorderColor(1, 1, 1, tooltip.transparency)
1072 tooltip.scroll = 0
1073  
1074 tooltip:SetScript("OnUpdate", function()
1075 if not tooltip.updating and not tooltip.enteredFrame then
1076 tooltip.scroll = 0
1077 tooltip:Hide()
1078 tooltip.registration.tooltip = nil
1079 tooltip.registration = nil
1080 end
1081 end)
1082  
1083 tooltip:SetScript("OnEnter", function()
1084 if tooltip.clickable then
1085 tooltip.enteredFrame = true
1086 end
1087 end)
1088  
1089 tooltip:SetScript("OnLeave", function()
1090 if not tooltip.updating then
1091 tooltip.enteredFrame = false
1092 end
1093 end)
1094  
1095 tooltip:SetScript("OnMouseWheel", function()
1096 tooltip.updating = true
1097 tooltip:Scroll(arg1 < 0)
1098 tooltip.updating = false
1099 end)
1100  
1101 NewLine(tooltip)
1102  
1103 tooltip.scrollUp = tooltip:CreateFontString(nil, "ARTWORK")
1104 tooltip.scrollUp:SetPoint("TOPLEFT", tooltip.buttons[1], "BOTTOMLEFT", 0, -2)
1105 tooltip.scrollUp:SetPoint("RIGHT", tooltip, "RIGHT", 0, -10)
1106 tooltip.scrollUp:SetFontObject(GameTooltipText)
1107 tooltip.scrollUp:Hide()
1108 local font,_,flags = tooltip.scrollUp:GetFont()
1109 tooltip.scrollUp:SetFont(font, normalSize * tooltip.fontSizePercent, flags)
1110 tooltip.scrollUp:SetJustifyH("CENTER")
1111 tooltip.scrollUp:SetTextColor(1, 0.823529, 0)
1112 tooltip.scrollUp:SetText(" ")
1113  
1114 tooltip.scrollDown = tooltip:CreateFontString(nil, "ARTWORK")
1115 tooltip.scrollDown:SetPoint("TOPLEFT", tooltip.buttons[1], "BOTTOMLEFT", 0, -2)
1116 tooltip.scrollDown:SetPoint("RIGHT", tooltip, "RIGHT", 0, -10)
1117 tooltip.scrollDown:SetFontObject(GameTooltipText)
1118 tooltip.scrollDown:Hide()
1119 local font,_,flags = tooltip.scrollUp:GetFont()
1120 tooltip.scrollDown:SetFont(font, normalSize * tooltip.fontSizePercent, flags)
1121 tooltip.scrollDown:SetJustifyH("CENTER")
1122 tooltip.scrollDown:SetTextColor(1, 0.823529, 0)
1123 tooltip.scrollDown:SetText(" ")
1124  
1125 function tooltip:SetOwner(o)
1126 self:Hide(o)
1127 self.owner = o
1128 end
1129 tooltip.SetOwner = wrap(tooltip.SetOwner, "tooltip:SetOwner")
1130  
1131 function tooltip:IsOwned(o)
1132 return self.owner == o
1133 end
1134 tooltip.IsOwned = wrap(tooltip.IsOwned, "tooltip:IsOwned")
1135  
1136 function tooltip:ClearLines(hide)
1137 CleanCategoryPool(self)
1138 for i = 1, self.numLines do
1139 local button = self.buttons[i]
1140 local check = self.checks[i]
1141 if not button.clicked or hide then
1142 button:Hide()
1143 end
1144 check.shown = false
1145 check:SetAlpha(0)
1146 end
1147 self.numLines = 0
1148 end
1149 tooltip.ClearLines = wrap(tooltip.ClearLines, "tooltip:ClearLines")
1150  
1151 function tooltip:NumLines()
1152 return self.numLines
1153 end
1154  
1155 local lastWidth
1156 local old_tooltip_Hide = tooltip.Hide
1157 function tooltip:Hide(newOwner)
1158 if self == tooltip or newOwner == nil then
1159 old_tooltip_Hide(self)
1160 end
1161 self:ClearLines(true)
1162 self.owner = nil
1163 self.lastWidth = nil
1164 end
1165 tooltip.Hide = wrap(tooltip.Hide, "tooltip:Hide")
1166  
1167 local old_tooltip_Show = tooltip.Show
1168 function tooltip:Show(tabletData)
1169 if self.owner == nil or self.notInUse then
1170 return
1171 end
1172 old_tooltip_Show(self)
1173  
1174 local maxWidth = tabletData and tabletData.width or self:GetWidth() - 20
1175 local hasWrap = false
1176 local screenWidth = GetScreenWidth()
1177 local scrollMax = self.numLines
1178 if scrollMax > GetMaxLinesPerScreen(self) + self.scroll then
1179 scrollMax = GetMaxLinesPerScreen(self) + self.scroll
1180 end
1181 local numColumns
1182  
1183 local height = 20
1184 if scrollMax ~= self.numLines then
1185 self.scrollDown:SetWidth(maxWidth)
1186 height = height + self.scrollDown:GetHeight() + 2
1187 end
1188 if self.scroll ~= 0 then
1189 self.scrollUp:SetWidth(maxWidth)
1190 height = height + self.scrollUp:GetHeight() + 2
1191 end
1192 self:SetWidth(maxWidth + 20)
1193  
1194 local tmp = self.scroll + 1
1195 if tmp ~= 1 then
1196 tmp = tmp + 1
1197 end
1198 for i = 1, self.numLines do
1199 if i < tmp or i > scrollMax or (i == scrollMax and i ~= self.numLines) then
1200 self.buttons[i]:ClearAllPoints()
1201 self.buttons[i]:Hide()
1202 else
1203 local button = self.buttons[i]
1204 local left = self.lefts[i]
1205 local right = self.rights[i]
1206 local check = self.checks[i]
1207 button:SetWidth(maxWidth)
1208 button:SetHeight(math.max(left:GetHeight(), right:GetHeight()))
1209 height = height + button:GetHeight() + 2
1210 if i == self.scroll + 1 then
1211 button:SetPoint("TOPLEFT", self, "TOPLEFT", 10, -10)
1212 else
1213 button:SetPoint("TOPLEFT", self.buttons[i - 1], "BOTTOMLEFT", 0, -2)
1214 end
1215 if button.clicked then
1216 check:SetPoint("TOPLEFT", button, "TOPLEFT", button.indentation * self.fontSizePercent + (check.width - check:GetWidth()) / 2 + 1, -1)
1217 else
1218 check:SetPoint("TOPLEFT", button, "TOPLEFT", button.indentation * self.fontSizePercent + (check.width - check:GetWidth()) / 2, 0)
1219 end
1220 button:Show()
1221 end
1222 end
1223 if self.scroll ~= 0 then
1224 self.scrollUp:SetPoint("TOPLEFT", self, "TOPLEFT", 10, -10)
1225 self.buttons[self.scroll + 2]:SetPoint("TOPLEFT", self.scrollUp, "BOTTOMLEFT", 0, -2)
1226 self.scrollUp:SetText(SCROLL_UP .. " (" .. self.scroll + 2 .. " / " .. self.numLines .. ")")
1227 self.scrollUp:Show()
1228 else
1229 self.scrollUp:Hide()
1230 end
1231 if scrollMax ~= self.numLines and self.buttons[scrollMax - 1] then
1232 self.scrollDown:SetPoint("TOPLEFT", self.buttons[scrollMax - 1], "BOTTOMLEFT", 0, -2)
1233 self.scrollDown:SetText(SCROLL_DOWN .. " (" .. scrollMax - 1 .. " / " .. self.numLines .. ")")
1234 self.scrollDown:Show()
1235 else
1236 self.scrollDown:Hide()
1237 end
1238 self:SetHeight(height)
1239 end
1240 tooltip.Show = wrap(tooltip.Show, "tooltip:Show")
1241  
1242 local lastMouseDown
1243 local function button_OnClick()
1244 if this.self:HasScript("OnClick") and this.self:GetScript("OnClick") then
1245 this.self:GetScript("OnClick")()
1246 end
1247 if arg1 == "RightButton" then
1248 if this.self:HasScript("OnClick") and this.self:GetScript("OnClick") then
1249 this.self:GetScript("OnClick")()
1250 end
1251 elseif arg1 == "LeftButton" then
1252 if this.self.preventClick == nil or GetTime() > this.self.preventClick and GetTime() < lastMouseDown + 0.5 then
1253 this.self.preventClick = nil
1254 this.self.updating = true
1255 this.self.preventRefresh = true
1256 this.func(this.a1, this.a2, this.a3)
1257 if this.self then
1258 this.self.preventRefresh = false
1259 this.self:children()
1260 this.self.updating = false
1261 end
1262 end
1263 end
1264 end
1265 local function button_OnMouseUp()
1266 if this.self:HasScript("OnMouseUp") and this.self:GetScript("OnMouseUp") then
1267 this.self:GetScript("OnMouseUp")()
1268 end
1269 if arg1 ~= "RightButton" then
1270 if this.clicked then
1271 local a,b,c,d,e = this.check:GetPoint(1)
1272 this.check:SetPoint(a,b,c,d-1,e+1)
1273 this.clicked = false
1274 end
1275 end
1276 end
1277 local function button_OnMouseDown()
1278 if this.self:HasScript("OnMouseDown") and this.self:GetScript("OnMouseDown") then
1279 this.self:GetScript("OnMouseDown")()
1280 end
1281 lastMouseDown = GetTime()
1282 if arg1 ~= "RightButton" then
1283 local a,b,c,d,e = this.check:GetPoint(1)
1284 this.check:SetPoint(a,b,c,d+1,e-1)
1285 this.clicked = true
1286 end
1287 end
1288 function tooltip:AddLine(info)
1289 local category = info.category.superCategory
1290 local maxWidth = category.tabletData.width
1291 local text = info.blank and "\n" or info.text
1292 local id = info.id
1293 local func = info.func
1294 local checked = info.checked
1295 local isRadio = info.isRadio
1296 local checkTexture = info.checkTexture
1297 local fontSizePercent = self.fontSizePercent
1298 if not info.font then
1299 info.font = GameTooltipText
1300 end
1301 if not info.size then
1302 _,info.size = info.font:GetFont()
1303 end
1304 local catStart = false
1305 local columns = category and category.columns or 1
1306 local x1, x2, x3, x4, x5, x6
1307 if category then
1308 x1, x2, x3, x4, x5, x6 = category.x1, category.x2, category.x3, category.x4, category.x5, category.x6
1309 else
1310 x1, x2, x3, x4, x5, x6 = 0, 0, 0, 0, 0, 0
1311 end
1312 if info.isTitle then
1313 justAddedTitle = true
1314 end
1315  
1316 self.numLines = self.numLines + 1
1317 NewLine(self)
1318 self.lefts[self.numLines]:Show()
1319 self.buttons[self.numLines]:Show()
1320 num = self.numLines
1321  
1322 local button = self.buttons[num]
1323 button.indentation = info.indentation
1324 local left = self.lefts[num]
1325 local right = self.rights[num]
1326 local third = self.thirds[num]
1327 local fourth = self.fourths[num]
1328 local fifth = self.fifths[num]
1329 local sixth = self.sixths[num]
1330 local check = self.checks[num]
1331 do -- if columns >= 1 then
1332 left:SetFontObject(info.font)
1333 left:SetText(text)
1334 left:Show()
1335 if info.textR and info.textG and info.textB then
1336 left:SetTextColor(info.textR, info.textG, info.textB)
1337 else
1338 left:SetTextColor(1, 0.823529, 0)
1339 end
1340 local a,_,b = left:GetFont()
1341 left:SetFont(a, info.size * fontSizePercent, b)
1342 left:SetJustifyH(info.justify)
1343 if columns < 2 then
1344 right:SetText(nil)
1345 right:Hide()
1346 right:SetPoint("TOPLEFT", left, "TOPRIGHT", 40 * fontSizePercent, 0)
1347 right:SetPoint("TOPRIGHT", button, "TOPRIGHT", -5, 0)
1348 third:SetText(nil)
1349 third:Hide()
1350 fourth:SetText(nil)
1351 fourth:Hide()
1352 fifth:SetText(nil)
1353 fifth:Hide()
1354 sixth:SetText(nil)
1355 sixth:Hide()
1356 else
1357 right:SetFontObject(info.font2)
1358 right:SetText(info.text2)
1359 right:Show()
1360 if info.text2R and info.text2G and info.text2B then
1361 right:SetTextColor(info.text2R, info.text2G, info.text2B)
1362 else
1363 right:SetTextColor(1, 0.823529, 0)
1364 end
1365 local a,_,b = right:GetFont()
1366 right:SetFont(a, info.size2 * fontSizePercent, b)
1367 right:SetJustifyH(info.justify2)
1368 if columns < 3 then
1369 right:SetPoint("TOPLEFT", left, "TOPRIGHT", 40 * fontSizePercent, 0)
1370 right:SetPoint("TOPRIGHT", button, "TOPRIGHT", -5, 0)
1371 third:SetText(nil)
1372 third:Hide()
1373 fourth:SetText(nil)
1374 fourth:Hide()
1375 fifth:SetText(nil)
1376 fifth:Hide()
1377 sixth:SetText(nil)
1378 sixth:Hide()
1379 else
1380 third:SetFontObject(info.font3)
1381 third:SetText(info.text3)
1382 third:Show()
1383 if info.text3R and info.text3G and info.text3B then
1384 third:SetTextColor(info.text3R, info.text3G, info.text3B)
1385 else
1386 third:SetTextColor(1, 0.823529, 0)
1387 end
1388 local a,_,b = third:GetFont()
1389 third:SetFont(a, info.size3 * fontSizePercent, b)
1390 right:ClearAllPoints()
1391 right:SetPoint("TOPLEFT", left, "TOPRIGHT", 20 * fontSizePercent, 0)
1392 third:SetJustifyH(info.justify3)
1393 if columns < 4 then
1394 fourth:SetText(nil)
1395 fourth:Hide()
1396 fifth:SetText(nil)
1397 fifth:Hide()
1398 sixth:SetText(nil)
1399 sixth:Hide()
1400 else
1401 fourth:SetFontObject(info.font4)
1402 fourth:SetText(info.text4)
1403 fourth:Show()
1404 if info.text4R and info.text4G and info.text4B then
1405 fourth:SetTextColor(info.text4R, info.text4G, info.text4B)
1406 else
1407 fourth:SetTextColor(1, 0.823529, 0)
1408 end
1409 local a,_,b = fourth:GetFont()
1410 fourth:SetFont(a, info.size4 * fontSizePercent, b)
1411 fourth:SetJustifyH(info.justify4)
1412 if columns < 5 then
1413 fifth:SetText(nil)
1414 fifth:Hide()
1415 sixth:SetText(nil)
1416 sixth:Hide()
1417 else
1418 fifth:SetFontObject(info.font5)
1419 fifth:SetText(info.text5)
1420 fifth:Show()
1421 if info.text5R and info.text5G and info.text5B then
1422 fifth:SetTextColor(info.text5R, info.text5G, info.text5B)
1423 else
1424 fifth:SetTextColor(1, 0.823529, 0)
1425 end
1426 local a,_,b = fourth:GetFont()
1427 fifth:SetFont(a, info.size5 * fontSizePercent, b)
1428 fifth:SetJustifyH(info.justify5)
1429 if columns < 6 then
1430 sixth:SetText(nil)
1431 sixth:Hide()
1432 else
1433 sixth:SetFontObject(info.font6)
1434 sixth:SetText(info.text6)
1435 sixth:Show()
1436 if info.text5R and info.text6G and info.text6B then
1437 sixth:SetTextColor(info.text6R, info.text6G, info.text6B)
1438 else
1439 sixth:SetTextColor(1, 0.823529, 0)
1440 end
1441 local a,_,b = fourth:GetFont()
1442 sixth:SetFont(a, info.size6 * fontSizePercent, b)
1443 sixth:SetJustifyH(info.justify6)
1444 end
1445 end
1446 end
1447 end
1448 end
1449 end
1450  
1451 check:SetWidth(info.size)
1452 check:SetHeight(info.size)
1453 check.width = info.size
1454 if info.hasCheck then
1455 check.shown = true
1456 check:Show()
1457 if isRadio then
1458 check:SetTexture(info.checkIcon or "Interface\\Buttons\\UI-RadioButton")
1459 if info.checked then
1460 check:SetAlpha(1)
1461 check:SetTexCoord(0.25, 0.5, 0, 1)
1462 else
1463 check:SetAlpha(self.transparency)
1464 check:SetTexCoord(0, 0.25, 0, 1)
1465 end
1466 else
1467 if info.checkIcon then
1468 check:SetTexture(info.checkIcon)
1469 if string.sub(info.checkIcon, 1, 16) == "Interface\\Icons\\" then
1470 check:SetTexCoord(0.05, 0.95, 0.05, 0.95)
1471 else
1472 check:SetTexCoord(0, 1, 0, 1)
1473 end
1474 else
1475 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
1476 check:SetWidth(info.size * 1.5)
1477 check:SetHeight(info.size * 1.5)
1478 check.width = info.size * 1.2
1479 check:SetTexCoord(0, 1, 0, 1)
1480 end
1481 check:SetAlpha(info.checked and 1 or 0)
1482 end
1483 left:SetPoint("TOPLEFT", check, "TOPLEFT", check.width, 0)
1484 else
1485 left:SetPoint("TOPLEFT", check, "TOPLEFT")
1486 end
1487 if columns == 1 then
1488 left:SetWidth(maxWidth)
1489 elseif columns == 2 then
1490 left:SetWidth(0)
1491 right:SetWidth(0)
1492 if info.wrap then
1493 left:SetWidth(maxWidth - right:GetWidth() - 40 * fontSizePercent)
1494 elseif info.wrap2 then
1495 right:SetWidth(maxWidth - left:GetWidth() - 40 * fontSizePercent)
1496 end
1497 right:ClearAllPoints()
1498 right:SetPoint("TOPRIGHT", button, "TOPRIGHT", 0, 0)
1499 if not info.text2 then
1500 left:SetJustifyH(info.justify or "LEFT")
1501 end
1502 elseif columns == 3 then
1503 left:SetWidth(x1 - info.checkWidth)
1504 right:SetWidth(x2)
1505 third:SetWidth(x3)
1506 right:ClearAllPoints()
1507 local num = (category.tabletData.width - x1 - x2 - x3) / 2
1508 right:SetPoint("TOPLEFT", left, "TOPRIGHT", num, 0)
1509 third:SetPoint("TOPLEFT", right, "TOPRIGHT", num, 0)
1510 elseif columns == 4 then
1511 left:SetWidth(x1 - info.checkWidth)
1512 right:SetWidth(x2)
1513 third:SetWidth(x3)
1514 fourth:SetWidth(x4)
1515 local num = (category.tabletData.width - x1 - x2 - x3 - x4) / 3
1516 right:SetPoint("TOPLEFT", left, "TOPRIGHT", num, 0)
1517 third:SetPoint("TOPLEFT", right, "TOPRIGHT", num, 0)
1518 fourth:SetPoint("TOPLEFT", third, "TOPRIGHT", num, 0)
1519 elseif columns == 5 then
1520 left:SetWidth(x1 - info.checkWidth)
1521 right:SetWidth(x2)
1522 third:SetWidth(x3)
1523 fourth:SetWidth(x4)
1524 fifth:SetWidth(x5)
1525 local num = (category.tabletData.width - x1 - x2 - x3 - x4 - x5) / 4
1526 right:SetPoint("TOPLEFT", left, "TOPRIGHT", num, 0)
1527 third:SetPoint("TOPLEFT", right, "TOPRIGHT", num, 0)
1528 fourth:SetPoint("TOPLEFT", third, "TOPRIGHT", num, 0)
1529 fifth:SetPoint("TOPLEFT", fourth, "TOPRIGHT", num, 0)
1530 elseif columns == 6 then
1531 left:SetWidth(x1 - info.checkWidth)
1532 right:SetWidth(x2)
1533 third:SetWidth(x3)
1534 fourth:SetWidth(x4)
1535 fifth:SetWidth(x5)
1536 sixth:SetWidth(x6)
1537 local num = (category.tabletData.width - x1 - x2 - x3 - x4 - x5 - x6) / 5
1538 right:SetPoint("TOPLEFT", left, "TOPRIGHT", num, 0)
1539 third:SetPoint("TOPLEFT", right, "TOPRIGHT", num, 0)
1540 fourth:SetPoint("TOPLEFT", third, "TOPRIGHT", num, 0)
1541 fifth:SetPoint("TOPLEFT", fourth, "TOPRIGHT", num, 0)
1542 sixth:SetPoint("TOPLEFT", fifth, "TOPRIGHT", num, 0)
1543 end
1544 if not self.locked or (sekeys and IsAltKeyDown()) then
1545 local func = info.func
1546 if func then
1547 if type(func) == "string" then
1548 Tablet:assert(type(info.arg1) == "table", "Cannot call method " .. info.func .. " on a non-table")
1549 func = info.arg1[func]
1550 Tablet:assert(type(func) == "function", "Method " .. info.func .. " nonexistant")
1551 end
1552 Tablet:assert(type(func) == "function", "func must be a function or method")
1553 button.func = func
1554 button.a1 = info.arg1
1555 button.a2 = info.arg2
1556 button.a3 = info.arg3
1557 button.self = self
1558 button:SetScript("OnMouseUp", button_OnMouseUp)
1559 button:SetScript("OnMouseDown", button_OnMouseDown)
1560 button:SetScript("OnClick", button_OnClick)
1561 if button.clicked then
1562 button:SetButtonState("PUSHED")
1563 end
1564 button:EnableMouse(true)
1565 else
1566 button:SetScript("OnMouseDown", nil)
1567 button:SetScript("OnMouseUp", nil)
1568 button:SetScript("OnClick", nil)
1569 button:EnableMouse(false)
1570 end
1571 else
1572 button:SetScript("OnMouseDown", nil)
1573 button:SetScript("OnMouseUp", nil)
1574 button:SetScript("OnClick", nil)
1575 button:EnableMouse(false)
1576 end
1577 end
1578 tooltip.AddLine = wrap(tooltip.AddLine, "tooltip:AddLine")
1579  
1580 function tooltip:SetFontSizePercent(percent)
1581 local data, detachedData = self.data, self.detachedData
1582 if detachedData and detachedData.detached then
1583 data = detachedData
1584 end
1585 local lastSize = self.fontSizePercent
1586 percent = tonumber(percent) or 1
1587 if percent < 0.25 then
1588 percent = 0.25
1589 elseif percent > 4 then
1590 percent = 4
1591 end
1592 self.fontSizePercent = percent
1593 if data then
1594 data.fontSizePercent = percent ~= 1 and percent or nil
1595 end
1596 self.scrollUp:SetFont(font, normalSize * self.fontSizePercent, flags)
1597 self.scrollDown:SetFont(font, normalSize * self.fontSizePercent, flags)
1598 local ratio = self.fontSizePercent / lastSize
1599 for i = 1, self.numLines do
1600 local left = self.lefts[i]
1601 local right = self.rights[i]
1602 local third = self.thirds[i]
1603 local fourth = self.fourths[i]
1604 local fifth = self.fifths[i]
1605 local sixth = self.sixths[i]
1606 local check = self.checks[i]
1607 local font, size, flags = left:GetFont()
1608 left:SetFont(font, size * ratio, flags)
1609 font, size, flags = right:GetFont()
1610 right:SetFont(font, size * ratio, flags)
1611 font, size, flags = third:GetFont()
1612 third:SetFont(font, size * ratio, flags)
1613 font, size, flags = fourth:GetFont()
1614 fourth:SetFont(font, size * ratio, flags)
1615 font, size, flags = fifth:GetFont()
1616 fifth:SetFont(font, size * ratio, flags)
1617 font, size, flags = sixth:GetFont()
1618 sixth:SetFont(font, size * ratio, flags)
1619 check.width = check.width * ratio
1620 check:SetWidth(check:GetWidth() * ratio)
1621 check:SetHeight(check:GetHeight() * ratio)
1622 end
1623 self:SetWidth((self:GetWidth() - 51) * ratio + 51)
1624 self:SetHeight((self:GetHeight() - 51) * ratio + 51)
1625 if self:IsShown() and self.children then
1626 self:Show()
1627 end
1628 end
1629 tooltip.SetFontSizePercent = wrap(tooltip.SetFontSizePercent, "tooltip:SetFontSizePercent")
1630  
1631 function tooltip:GetFontSizePercent()
1632 return self.fontSizePercent
1633 end
1634  
1635 function tooltip:SetTransparency(alpha)
1636 local data, detachedData = self.data, self.detachedData
1637 if detachedData and detachedData.detached then
1638 data = detachedData
1639 end
1640 self.transparency = alpha
1641 if data then
1642 data.transparency = alpha ~= 0.75 and alpha or nil
1643 end
1644 self:SetBackdropColor(self.r or 0, self.g or 0, self.b or 0, alpha)
1645 self:SetBackdropBorderColor(1, 1, 1, alpha)
1646 end
1647 tooltip.SetTransparency = wrap(tooltip.SetTransparency, "tooltip:SetTransparency")
1648  
1649 function tooltip:GetTransparency()
1650 return self.transparency
1651 end
1652  
1653 function tooltip:SetColor(r, g, b)
1654 local data, detachedData = self.data, self.detachedData
1655 if detachedData and detachedData.detached then
1656 data = detachedData
1657 end
1658 self.r = r
1659 self.g = g
1660 self.b = b
1661 if data then
1662 data.r = r ~= 0 and r or nil
1663 data.g = g ~= 0 and g or nil
1664 data.b = b ~= 0 and b or nil
1665 end
1666 self:SetBackdropColor(r or 0, g or 0, b or 0, self.transparency)
1667 self:SetBackdropBorderColor(1, 1, 1, self.transparency)
1668 end
1669 tooltip.SetColor = wrap(tooltip.SetColor, "tooltip:SetColor")
1670  
1671 function tooltip:GetColor()
1672 return self.r, self.g, self.b
1673 end
1674  
1675 function tooltip:Scroll(down)
1676 if down then
1677 if IsShiftKeyDown() then
1678 self.scroll = self.numLines - GetMaxLinesPerScreen(self)
1679 else
1680 self.scroll = self.scroll + 3
1681 end
1682 else
1683 if IsShiftKeyDown() then
1684 self.scroll = 0
1685 else
1686 self.scroll = self.scroll - 3
1687 end
1688 end
1689 if self.scroll > self.numLines - GetMaxLinesPerScreen(self) then
1690 self.scroll = self.numLines - GetMaxLinesPerScreen(self)
1691 end
1692 if self.scroll < 0 then
1693 self.scroll = 0
1694 end
1695 if self:IsShown() then
1696 self:Show()
1697 end
1698 end
1699 tooltip.Scroll = wrap(tooltip.Scroll, "tooltip:Scroll")
1700  
1701 function tooltip.Detach(tooltip)
1702 local owner = tooltip.owner
1703 tooltip:Hide()
1704 self:assert(tooltip.detachedData, "You cannot detach if detachedData is not present")
1705 tooltip.detachedData.detached = true
1706 local detached = AcquireDetachedFrame(self, tooltip.registration, tooltip.data, tooltip.detachedData)
1707  
1708 detached.menu, tooltip.menu = tooltip.menu, nil
1709 detached.children = tooltip.children
1710 tooltip.children = nil
1711 detached:SetOwner(owner)
1712 detached:children()
1713 detached:Show()
1714 end
1715 tooltip.Detach = wrap(tooltip.Detach, "tooltip:Detach")
1716  
1717 end
1718  
1719 tooltip.registration = registration
1720 registration.tooltip = tooltip
1721 return tooltip
1722 end
1723 AcquireFrame = wrap(AcquireFrame, "AcquireFrame")
1724  
1725 function ReleaseDetachedFrame(self, data, detachedData)
1726 if not detachedData then
1727 detachedData = data
1728 end
1729 for _, detached in ipairs(detachedTooltips) do
1730 if detached.detachedData == detachedData then
1731 detached.notInUse = true
1732 detached:Hide()
1733 detached.registration.tooltip = nil
1734 detached.registration = nil
1735 end
1736 end
1737 end
1738 ReleaseDetachedFrame = wrap(ReleaseDetachedFrame, "ReleaseDetachedFrame")
1739  
1740 function AcquireDetachedFrame(self, registration, data, detachedData)
1741 if not detachedData then
1742 detachedData = data
1743 end
1744 for _, detached in ipairs(detachedTooltips) do
1745 if detached.notInUse then
1746 detached.data = data
1747 detached.detachedData = detachedData
1748 detached.notInUse = nil
1749 local fontSizePercent = detachedData.fontSizePercent or 1
1750 local transparency = detachedData.transparency or 0.75
1751 local r = detachedData.r or 0
1752 local g = detachedData.g or 0
1753 local b = detachedData.b or 0
1754 detached:SetFontSizePercent(fontSizePercent)
1755 detached:SetTransparency(transparency)
1756 detached:SetColor(r, g, b)
1757 detached:ClearAllPoints()
1758 detached:SetPoint(detachedData.anchor or "CENTER", UIParent, detachedData.anchor or "CENTER", detachedData.offsetx or 0, detachedData.offsety or 0)
1759 detached.registration = registration
1760 registration.tooltip = detached
1761 return detached
1762 end
1763 end
1764  
1765 if not Dewdrop and AceLibrary:HasInstance("Dewdrop-2.0") then
1766 Dewdrop = AceLibrary("Dewdrop-2.0")
1767 end
1768 if not sekeys and SpecialEventsEmbed and SpecialEventsEmbed.versions["Keys 1"] then
1769 sekeys = SpecialEventsEmbed:GetInstance("Keys 1")
1770 sekeys:RegisterEvent(self, "SPECIAL_ALTKEY_DOWN")
1771 sekeys:RegisterEvent(self, "SPECIAL_ALTKEY_UP")
1772  
1773 function self:SPECIAL_ALTKEY_DOWN()
1774 for _, detached in ipairs(detachedTooltips) do
1775 if detached:IsShown() and detached.locked then
1776 detached:EnableMouse(IsAltKeyDown())
1777 detached:children()
1778 end
1779 end
1780 end
1781  
1782 self.SPECIAL_ALTKEY_UP = self.SPECIAL_ALTKEY_DOWN
1783 end
1784 if not tooltip then
1785 AcquireFrame(self, {})
1786 end
1787 local detached = CreateFrame("Frame", "TabletLibDetachedFrame" .. (table.getn(detachedTooltips) + 1), UIParent)
1788 table.insert(detachedTooltips, detached)
1789 detached.notInUse = true
1790 detached:EnableMouse(not data.locked)
1791 detached:EnableMouseWheel(true)
1792 detached:SetMovable(true)
1793 detached:SetPoint(data.anchor or "CENTER", UIParent, data.anchor or "CENTER", data.offsetx or 0, data.offsety or 0)
1794  
1795 detached.numLines = 0
1796 detached.owner = nil
1797 detached.fontSizePercent = 1
1798 detached.maxLines = 0
1799 detached.buttons = {}
1800 detached.checks = {}
1801 detached.lefts = {}
1802 detached.rights = {}
1803 detached.thirds = {}
1804 detached.fourths = {}
1805 detached.fifths = {}
1806 detached.sixths = {}
1807 detached.transparency = 0.75
1808 detached.r = 0
1809 detached.g = 0
1810 detached.b = 0
1811 detached:SetFrameStrata("BACKGROUND")
1812 detached:SetBackdrop(tmp.a(
1813 'bgFile', "Interface\\Buttons\\WHITE8X8",
1814 'edgeFile', "Interface\\Tooltips\\UI-Tooltip-Border",
1815 'tile', true,
1816 'tileSize', 16,
1817 'edgeSize', 16,
1818 'insets', tmp.b(
1819 'left', 5,
1820 'right', 5,
1821 'top', 5,
1822 'bottom', 5
1823 )
1824 ))
1825 detached.locked = detachedData.locked
1826 detached.scroll = 0
1827 detached:EnableMouse(not detached.locked)
1828  
1829 local width = GetScreenWidth()
1830 local height = GetScreenHeight()
1831 detached:SetScript("OnMouseDown", function()
1832 if arg1 == "LeftButton" then
1833 if not detached.locked then
1834 detached:StartMoving()
1835 end
1836 end
1837 end)
1838  
1839 detached:SetScript("OnMouseUp", function()
1840 if arg1 == "LeftButton" then
1841 if not detached.locked then
1842 detached:StopMovingOrSizing()
1843 local anchor
1844 local offsetx
1845 local offsety
1846 if detached:GetTop() + detached:GetBottom() < height then
1847 anchor = "BOTTOM"
1848 offsety = detached:GetBottom()
1849 if offsety < 0 then
1850 offsety = 0
1851 end
1852 if offsety < MainMenuBar:GetTop() and MainMenuBar:IsVisible() then
1853 offsety = MainMenuBar:GetTop()
1854 end
1855 local top = 0
1856 if FuBar then
1857 for i = 1, FuBar:GetNumPanels() do
1858 local panel = FuBar:GetPanel(i)
1859 if panel:GetAttachPoint() == "BOTTOM" then
1860 if panel.frame:GetTop() > top then
1861 top = panel.frame:GetTop()
1862 break
1863 end
1864 end
1865 end
1866 end
1867 if offsety < top then
1868 offsety = top
1869 end
1870 else
1871 anchor = "TOP"
1872 offsety = detached:GetTop() - height
1873 if offsety > 0 then
1874 offsety = 0
1875 end
1876 local bottom = GetScreenHeight()
1877 if FuBar then
1878 for i = 1, FuBar:GetNumPanels() do
1879 local panel = FuBar:GetPanel(i)
1880 if panel:GetAttachPoint() == "TOP" then
1881 if panel.frame:GetBottom() < bottom then
1882 bottom = panel.frame:GetBottom()
1883 break
1884 end
1885 end
1886 end
1887 end
1888 bottom = bottom - GetScreenHeight()
1889 if offsety > bottom then
1890 offsety = bottom
1891 end
1892 end
1893 if detached:GetLeft() + detached:GetRight() < width * 2 / 3 then
1894 anchor = anchor .. "LEFT"
1895 offsetx = detached:GetLeft()
1896 if offsetx < 0 then
1897 offsetx = 0
1898 end
1899 elseif detached:GetLeft() + detached:GetRight() < width * 4 / 3 then
1900 if anchor == "" then
1901 anchor = "CENTER"
1902 end
1903 offsetx = (detached:GetLeft() + detached:GetRight() - GetScreenWidth()) / 2
1904 else
1905 anchor = anchor .. "RIGHT"
1906 offsetx = detached:GetRight() - width
1907 if offsetx > 0 then
1908 offsetx = 0
1909 end
1910 end
1911 detached:ClearAllPoints()
1912 detached:SetPoint(anchor, UIParent, anchor, offsetx, offsety)
1913 local t = detached.detachedData
1914 if t.anchor ~= anchor or math.abs(t.offsetx - offsetx) > 8 or math.abs(t.offsety - offsety) > 8 then
1915 detached.preventClick = GetTime() + 0.05
1916 end
1917 t.anchor = anchor
1918 t.offsetx = offsetx
1919 t.offsety = offsety
1920 detached:Show()
1921 end
1922 end
1923 end)
1924  
1925 Dewdrop:Register(detached,
1926 'children', function(level, value)
1927 if not detached.registration then
1928 return
1929 end
1930 if detached.menu then
1931 detached.menu(level, value)
1932 if level == 1 then
1933 Dewdrop:AddLine()
1934 end
1935 end
1936 if level == 1 then
1937 if not detached.registration.cantAttach then
1938 Dewdrop:AddLine(
1939 'text', DETACH,
1940 'checked', true,
1941 'arg1', detached,
1942 'func', "Attach",
1943 'closeWhenClicked', true
1944 )
1945 end
1946 Dewdrop:AddLine(
1947 'text', LOCK,
1948 'checked', detached:IsLocked(),
1949 'arg1', detached,
1950 'func', "Lock",
1951 'closeWhenClicked', not detached:IsLocked()
1952 )
1953 Dewdrop:AddLine(
1954 'text', COLOR,
1955 'hasColorSwatch', true,
1956 'r', detached.r,
1957 'g', detached.g,
1958 'b', detached.b,
1959 'hasOpacity', true,
1960 'opacity', detached.transparency,
1961 'colorFunc', function(r, g, b, a)
1962 detached:SetColor(r, g, b)
1963 detached:SetTransparency(a)
1964 end
1965 )
1966 Dewdrop:AddLine(
1967 'text', SIZE,
1968 'hasArrow', true,
1969 'hasSlider', true,
1970 'sliderFunc', function(value)
1971 detached:SetFontSizePercent(value)
1972 end,
1973 'sliderMax', 2,
1974 'sliderMin', 0.5,
1975 'sliderStep', 0.05,
1976 'sliderIsPercent', true,
1977 'sliderValue', detached:GetFontSizePercent()
1978 )
1979 Dewdrop:AddLine(
1980 'text', CLOSE_MENU,
1981 'func', function()
1982 Dewdrop:Close()
1983 end
1984 )
1985 end
1986 end,
1987 'point', function()
1988 local x, y = detached:GetCenter()
1989 if x < GetScreenWidth() / 2 then
1990 if y < GetScreenHeight() / 2 then
1991 return "BOTTOMLEFT", "BOTTOMRIGHT"
1992 else
1993 return "TOPLEFT", "TOPRIGHT"
1994 end
1995 else
1996 if y < GetScreenHeight() / 2 then
1997 return "BOTTOMRIGHT", "BOTTOMLEFT"
1998 else
1999 return "TOPRIGHT", "TOPLEFT"
2000 end
2001 end
2002 end
2003 )
2004  
2005 NewLine(detached)
2006  
2007 detached.scrollUp = detached:CreateFontString(nil, "ARTWORK")
2008 detached.scrollUp:SetPoint("TOPLEFT", detached.buttons[1], "BOTTOMLEFT", 0, -2)
2009 detached.scrollUp:SetPoint("RIGHT", detached, "RIGHT", 0, -10)
2010 detached.scrollUp:SetFontObject(GameTooltipText)
2011 detached.scrollUp:Hide()
2012 local font,_,flags = detached.scrollUp:GetFont()
2013 detached.scrollUp:SetFont(font, normalSize * detached.fontSizePercent, flags)
2014 detached.scrollUp:SetJustifyH("CENTER")
2015 detached.scrollUp:SetTextColor(1, 0.823529, 0)
2016 detached.scrollUp:SetText(" ")
2017  
2018 detached.scrollDown = detached:CreateFontString(nil, "ARTWORK")
2019 detached.scrollDown:SetPoint("TOPLEFT", detached.buttons[1], "BOTTOMLEFT", 0, -2)
2020 detached.scrollDown:SetPoint("RIGHT", detached, "RIGHT", 0, -10)
2021 detached.scrollDown:SetFontObject(GameTooltipText)
2022 detached.scrollDown:Hide()
2023 local font,_,flags = detached.scrollUp:GetFont()
2024 detached.scrollDown:SetFont(font, normalSize * detached.fontSizePercent, flags)
2025 detached.scrollDown:SetJustifyH("CENTER")
2026 detached.scrollDown:SetTextColor(1, 0.823529, 0)
2027 detached.scrollDown:SetText(" ")
2028  
2029 detached:SetScript("OnMouseWheel", function()
2030 detached:Scroll(arg1 < 0)
2031 end)
2032  
2033 detached.SetTransparency = tooltip.SetTransparency
2034 detached.GetTransparency = tooltip.GetTransparency
2035 detached.SetColor = tooltip.SetColor
2036 detached.GetColor = tooltip.GetColor
2037 detached.SetFontSizePercent = tooltip.SetFontSizePercent
2038 detached.GetFontSizePercent = tooltip.GetFontSizePercent
2039 detached.SetOwner = tooltip.SetOwner
2040 detached.IsOwned = tooltip.IsOwned
2041 detached.ClearLines = tooltip.ClearLines
2042 detached.NumLines = tooltip.NumLines
2043 detached.Hide = tooltip.Hide
2044 detached.Show = tooltip.Show
2045 detached.AddLine = tooltip.AddLine
2046 detached.Scroll = tooltip.Scroll
2047 function detached:IsLocked()
2048 return self.locked
2049 end
2050 function detached:Lock()
2051 self:EnableMouse(self.locked)
2052 self.locked = not self.locked
2053 self.detachedData.locked = self.locked or nil
2054 self:children()
2055 end
2056  
2057 function detached.Attach(detached)
2058 self:assert(detached, "Detached tooltip not given.")
2059 self:assert(detached.AddLine, "detached argument not a Tooltip.")
2060 self:assert(detached.owner, "Detached tooltip has no owner.")
2061 self:assert(not detached.notInUse, "Detached tooltip not in use.")
2062 detached.menu = nil
2063 detached.detachedData.detached = nil
2064 detached:SetOwner(nil)
2065 detached.notInUse = TRUE
2066 end
2067  
2068 return AcquireDetachedFrame(self, registration, data, detachedData)
2069 end
2070 AcquireDetachedFrame = wrap(AcquireDetachedFrame, "AcquireDetachedFrame")
2071  
2072 function Tablet:Close(parent)
2073 if not parent then
2074 if tooltip and tooltip:IsShown() then
2075 tooltip:Hide()
2076 tooltip.registration.tooltip = nil
2077 tooltip.registration = nil
2078 end
2079 return
2080 else
2081 self:argCheck(parent, 2, "table", "string")
2082 end
2083 local info = self.registry[parent]
2084 self:assert(info, "You cannot close a tablet with an unregistered parent frame.")
2085 local data = info.data
2086 local detachedData = info.detachedData
2087 if detachedData and detachedData.detached then
2088 ReleaseDetachedFrame(self, data, detachedData)
2089 elseif tooltip.data == data then
2090 tooltip:Hide()
2091 tooltip.registration.tooltip = nil
2092 tooltip.registration = nil
2093 end
2094 end
2095 Tablet.Close = wrap(Tablet.Close, "Tablet:Close")
2096  
2097 local currentFrame
2098 local currentTabletData
2099  
2100 function Tablet:Open(parent)
2101 self:argCheck(parent, 2, "table", "string")
2102 local info = self.registry[parent]
2103 self:assert(info, "You cannot open a tablet with an unregistered parent frame.")
2104 self:Close()
2105 local data = info.data
2106 local detachedData = info.detachedData
2107 local children = info.children
2108 if not children then
2109 return
2110 end
2111 local frame = AcquireFrame(self, info, data, detachedData)
2112 frame.clickable = info.clickable
2113 frame.menu = info.menu
2114 local children = info.children
2115 function frame:children()
2116 if not self.preventRefresh then
2117 currentFrame = self
2118 currentTabletData = TabletData:new(self)
2119 self:ClearLines()
2120 if children then
2121 children()
2122 end
2123 currentTabletData:Display(currentFrame)
2124 self:Show(currentTabletData)
2125 currentTabletData:del()
2126 currentTabletData = nil
2127 currentFrame = nil
2128 end
2129 end
2130 frame:SetOwner(parent)
2131 frame:children()
2132 local point = info.point
2133 local relativePoint = info.point
2134 if type(point) == "function" then
2135 local b
2136 point, b = point(parent)
2137 if b then
2138 relativePoint = b
2139 end
2140 end
2141 if type(relativePoint) == "function" then
2142 relativePoint = relativePoint(parent)
2143 end
2144 if not point then
2145 point = "CENTER"
2146 end
2147 if not relativePoint then
2148 relativePoint = point
2149 end
2150 frame:ClearAllPoints()
2151 if type(parent) ~= "string" then
2152 frame:SetPoint(point, parent, relativePoint)
2153 end
2154 local offsetx = 0
2155 local offsety = 0
2156 if frame:GetBottom() and frame:GetLeft() then
2157 if frame:GetRight() > GetScreenWidth() then
2158 offsetx = frame:GetRight() - GetScreenWidth()
2159 elseif frame:GetLeft() < 0 then
2160 offsetx = -frame:GetLeft()
2161 end
2162 local ratio = GetScreenWidth() / GetScreenHeight()
2163 if ratio >= 2.4 and frame:GetRight() > GetScreenWidth() / 2 and frame:GetLeft() < GetScreenWidth() / 2 then
2164 if frame:GetCenter() < GetScreenWidth() / 2 then
2165 offsetx = frame:GetRight() - GetScreenWidth() / 2
2166 else
2167 offsetx = frame:GetLeft() - GetScreenWidth() / 2
2168 end
2169 end
2170 if frame:GetBottom() < 0 then
2171 offsety = frame:GetBottom()
2172 elseif frame:GetTop() and frame:GetTop() > GetScreenHeight() then
2173 offsety = frame:GetTop() - GetScreenHeight()
2174 end
2175 if MainMenuBar:IsVisible() and frame:GetBottom() < MainMenuBar:GetTop() and offsety < frame:GetBottom() - MainMenuBar:GetTop() then
2176 offsety = frame:GetBottom() - MainMenuBar:GetTop()
2177 end
2178  
2179 if FuBar then
2180 local top = 0
2181 if FuBar then
2182 for i = 1, FuBar:GetNumPanels() do
2183 local panel = FuBar:GetPanel(i)
2184 if panel:GetAttachPoint() == "BOTTOM" then
2185 if panel.frame:GetTop() and panel.frame:GetTop() > top then
2186 top = panel.frame:GetTop()
2187 break
2188 end
2189 end
2190 end
2191 end
2192 if frame:GetBottom() < top and offsety < frame:GetBottom() - top then
2193 offsety = frame:GetBottom() - top
2194 end
2195 local bottom = GetScreenHeight()
2196 if FuBar then
2197 for i = 1, FuBar:GetNumPanels() do
2198 local panel = FuBar:GetPanel(i)
2199 if panel:GetAttachPoint() == "TOP" then
2200 if panel.frame:GetBottom() and panel.frame:GetBottom() < bottom then
2201 bottom = panel.frame:GetBottom()
2202 break
2203 end
2204 end
2205 end
2206 end
2207 if frame:GetTop() > bottom and offsety < frame:GetTop() - bottom then
2208 offsety = frame:GetTop() - bottom
2209 end
2210 end
2211 end
2212 if type(parent) ~= "string" then
2213 frame:SetPoint(point, parent, relativePoint, -offsetx, -offsety)
2214 end
2215  
2216 if detachedData and (info.cantAttach or detachedData.detached) and frame == tooltip then
2217 detachedData.detached = false
2218 frame:Detach()
2219 end
2220 end
2221 Tablet.Open = wrap(Tablet.Open, "Tablet:Open")
2222  
2223 function Tablet:Register(parent, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
2224 self:argCheck(parent, 2, "table", "string")
2225 if self.registry[parent] then
2226 self:Unregister(parent)
2227 end
2228 local info
2229 if type(k1) == "table" and k1[0] then
2230 self:assert(type(self.registry[k1]) == "table", "Other parent not registered")
2231 info = copy(self.registry[k1])
2232 if type(v1) == "function" then
2233 info.point = v1
2234 info.relativePoint = nil
2235 end
2236 else
2237 info = new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
2238 end
2239 self.registry[parent] = info
2240 info.data = info.data or info.detachedData or {}
2241 info.detachedData = info.detachedData or info.data
2242 local data = info.data
2243 local detachedData = info.detachedData
2244 if not self.onceRegistered[parent] and type(parent) == "table" and type(parent.SetScript) == "function" and not info.dontHook then
2245 if not Dewdrop then
2246 Dewdrop = AceLibrary("Dewdrop-2.0")
2247 end
2248 local script = parent:GetScript("OnEnter")
2249 parent:SetScript("OnEnter", function()
2250 if script then
2251 script()
2252 end
2253 if self.registry[parent] then
2254 if (not data or not detachedData.detached) and not Dewdrop:IsOpen(parent) then
2255 self:Open(parent)
2256 self.tooltip.enteredFrame = true
2257 end
2258 end
2259 end)
2260 local script = parent:GetScript("OnLeave")
2261 parent:SetScript("OnLeave", function()
2262 if script then
2263 script()
2264 end
2265 if self.registry[parent] then
2266 if self.tooltip and (not data or not detachedData or not detachedData.detached) then
2267 self.tooltip.enteredFrame = false
2268 end
2269 end
2270 end)
2271 if parent:HasScript("OnMouseDown") then
2272 local script = parent:GetScript("OnMouseDown")
2273 parent:SetScript("OnMouseDown", function()
2274 if script then
2275 script()
2276 end
2277 if self.registry[parent] and self.registry[parent].tooltip and self.registry[parent].tooltip == self.tooltip then
2278 self.tooltip:Hide()
2279 end
2280 end)
2281 end
2282 if parent:HasScript("OnMouseWheel") then
2283 local script = parent:GetScript("OnMouseWheel")
2284 parent:SetScript("OnMouseWheel", function()
2285 if script then
2286 script()
2287 end
2288 if self.registry[parent] and self.registry[parent].tooltip then
2289 self.registry[parent].tooltip:Scroll(arg1 < 0)
2290 end
2291 end)
2292 end
2293 end
2294 self.onceRegistered[parent] = true
2295 if GetMouseFocus() == parent then
2296 self:Open(parent)
2297 end
2298 end
2299 Tablet.Register = wrap(Tablet.Register, "Tablet:Register")
2300  
2301 function Tablet:Unregister(parent)
2302 self:argCheck(parent, 2, "table", "string")
2303 self:assert(self.registry[parent], "You cannot unregister a parent frame if it has not been registered already.")
2304 self.registry[parent] = nil
2305 end
2306 Tablet.Unregister = wrap(Tablet.Unregister, "Tablet:Unregister")
2307  
2308 function Tablet:IsRegistered(parent)
2309 self:argCheck(parent, 2, "table", "string")
2310 return self.registry[parent] and true
2311 end
2312 Tablet.IsRegistered = wrap(Tablet.IsRegistered, "Tablet:IsRegistered")
2313  
2314 local _id = 0
2315 local addedCategory
2316 local currentCategoryInfo
2317 local depth = 0
2318 local categoryPool = {}
2319 function CleanCategoryPool(self)
2320 for k,v in pairs(categoryPool) do
2321 del(v)
2322 categoryPool[k] = nil
2323 end
2324 _id = 0
2325 end
2326  
2327 function Tablet:AddCategory(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
2328 self:assert(currentFrame, "You must add categories in within a registration.")
2329 local info = new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20, k21, v21, k22, v22, k23, v23, k24, v24, k25, v25, k26, v26, k27, v27, k28, v28, k29, v29, k30, v30)
2330 local cat = currentTabletData:AddCategory(info)
2331 del(info)
2332 return cat
2333 end
2334 Tablet.AddCategory = wrap(Tablet.AddCategory, "Tablet:AddCategory")
2335  
2336 function Tablet:SetHint(text)
2337 self:assert(currentFrame, "You must set hint within a registration.")
2338 self:assert(not currentCategoryInfo, "You cannot set hint in a category.")
2339 currentTabletData:SetHint(text)
2340 end
2341 Tablet.SetHint = wrap(Tablet.SetHint, "Tablet:SetHint")
2342  
2343 function Tablet:SetTitle(text)
2344 self:assert(currentFrame, "You must set title within a registration")
2345 self:assert(not currentCategoryInfo, "You cannot set title in a category.")
2346 currentTabletData:SetTitle(text)
2347 end
2348 Tablet.SetTitle = wrap(Tablet.SetTitle, "Tablet:SetTitle")
2349  
2350 function Tablet:GetNormalFontSize()
2351 return normalSize
2352 end
2353  
2354 function Tablet:GetHeaderFontSize()
2355 return headerSize
2356 end
2357  
2358 function Tablet:GetNormalFontObject()
2359 return GameTooltipText
2360 end
2361  
2362 function Tablet:GetHeaderFontObject()
2363 return GameTooltipHeaderText
2364 end
2365  
2366 function Tablet:SetFontSizePercent(parent, percent)
2367 self:argCheck(parent, 2, "table", "string")
2368 local info = self.registry[parent]
2369 if info then
2370 if info.tooltip then
2371 info.tooltip:SetFontSizePercent(percent)
2372 else
2373 if detachedData.detached then
2374 detachedData.fontSizePercent = percent
2375 else
2376 data.fontSizePercent = percent
2377 end
2378 end
2379 elseif type(parent) == "table" then
2380 parent.fontSizePercent = percent
2381 else
2382 self:assert(false, "You cannot change font size with an unregistered parent frame.")
2383 end
2384 end
2385 Tablet.SetFontSizePercent = wrap(Tablet.SetFontSizePercent, "Tablet:SetFontSizePercent")
2386  
2387 function Tablet:GetFontSizePercent(parent)
2388 self:argCheck(parent, 2, "table", "string")
2389 local info = self.registry[parent]
2390 if info then
2391 local data = info.data
2392 local detachedData = info.detachedData
2393 if detachedData.detached then
2394 return detachedData.fontSizePercent or 1
2395 else
2396 return data.fontSizePercent or 1
2397 end
2398 elseif type(parent) == "table" then
2399 return parent.fontSizePercent or 1
2400 else
2401 self:assert(false, "You cannot check font size with an unregistered parent frame.")
2402 end
2403 end
2404 Tablet.GetFontSizePercent = wrap(Tablet.GetFontSizePercent, "Tablet:GetFontSizePercent")
2405  
2406 function Tablet:SetTransparency(parent, percent)
2407 self:argCheck(parent, 2, "table", "string")
2408 local info = self.registry[parent]
2409 if info then
2410 if info.tooltip then
2411 info.tooltip:SetTransparency(percent)
2412 else
2413 if detachedData.detached then
2414 detachedData.transparency = percent
2415 else
2416 data.transparency = percent
2417 end
2418 end
2419 elseif type(parent) == "table" then
2420 parent.transparency = percent
2421 else
2422 self:assert(false, "You cannot change transparency with an unregistered parent frame.")
2423 end
2424 end
2425 Tablet.SetTransparency = wrap(Tablet.SetTransparency, "Tablet:SetTransparency")
2426  
2427 function Tablet:GetTransparency(parent)
2428 self:argCheck(parent, 2, "table", "string")
2429 local info = self.registry[parent]
2430 if info then
2431 self:assert(info, "You cannot check transparency with an unregistered parent frame.")
2432 local data = info.data
2433 local detachedData = info.detachedData
2434 if detachedData.detached then
2435 return detachedData.transparency or 0.75
2436 else
2437 return data.transparency or 0.75
2438 end
2439 elseif type(parent) == "table" then
2440 return parent.transparency or 0.75
2441 else
2442 self:assert(parent, "You must provide a parent frame to check transparency")
2443 end
2444 end
2445 Tablet.GetTransparency = wrap(Tablet.GetTransparency, "Tablet:GetTransparency")
2446  
2447 function Tablet:SetColor(parent, r, g, b)
2448 self:argCheck(parent, 2, "table", "string")
2449 local info = self.registry[parent]
2450 if info then
2451 if info.tooltip then
2452 info.tooltip:SetColor(r, g, b)
2453 else
2454 if detachedData.detached then
2455 detachedData.r = r
2456 detachedData.g = g
2457 detachedData.b = b
2458 else
2459 data.r = r
2460 data.g = g
2461 data.b = b
2462 end
2463 end
2464 elseif type(parent) == "table" then
2465 parent.r = r
2466 parent.g = g
2467 parent.b = b
2468 else
2469 self:assert(false, "You cannot change color with an unregistered parent frame.")
2470 end
2471 end
2472 Tablet.SetColor = wrap(Tablet.SetColor, "Tablet:SetColor")
2473  
2474 function Tablet:GetColor(parent)
2475 self:argCheck(parent, 2, "table", "string")
2476 local info = self.registry[parent]
2477 if info then
2478 local data = info.data
2479 local detachedData = info.detachedData
2480 if detachedData.detached then
2481 return detachedData.r or 0, detachedData.g or 0, detachedData.b or 0
2482 else
2483 return data.r or 0, data.g or 0, data.b or 0
2484 end
2485 elseif type(parent) == "table" then
2486 return parent.r or 0, parent.g or 0, parent.b or 0
2487 else
2488 self:assert(parent, "You must provide a parent frame to check color")
2489 end
2490 end
2491 Tablet.GetColor = wrap(Tablet.GetColor, "Tablet:GetColor")
2492  
2493 function Tablet:Detach(parent)
2494 self:argCheck(parent, 2, "table", "string")
2495 local info = self.registry[parent]
2496 self:assert(info, "You cannot detach tablet with an unregistered parent frame.")
2497 self:assert(info.detachedData, "You cannot detach tablet without a data field.")
2498 if info.tooltip and info.tooltip == tooltip then
2499 tooltip:Detach()
2500 else
2501 info.detachedData.detached = true
2502 local detached = AcquireDetachedFrame(self, info, info.data, info.detachedData)
2503  
2504 detached.menu = info.menu
2505 local children = info.children
2506 function detached:children()
2507 if not self.preventRefresh then
2508 currentFrame = self
2509 currentTabletData = TabletData:new(self)
2510 self:ClearLines()
2511 if children then
2512 children()
2513 end
2514 currentTabletData:Display(currentFrame)
2515 self:Show(currentTabletData)
2516 currentTabletData:del()
2517 currentTabletData = nil
2518 currentFrame = nil
2519 end
2520 end
2521 detached:SetOwner(parent)
2522 detached:children()
2523 end
2524 end
2525 Tablet.Detach = wrap(Tablet.Detach, "Tablet:Detach")
2526  
2527 function Tablet:Attach(parent)
2528 self:argCheck(parent, 2, "table", "string")
2529 local info = self.registry[parent]
2530 self:assert(info, "You cannot detach tablet with an unregistered parent frame.")
2531 self:assert(info.detachedData, "You cannot attach tablet without a data field.")
2532 if info.tooltip and info.tooltip ~= tooltip then
2533 info.tooltip:Attach()
2534 else
2535 info.detachedData.detached = false
2536 end
2537 end
2538 Tablet.Attach = wrap(Tablet.Attach, "Tablet:Attach")
2539  
2540 function Tablet:IsAttached(parent)
2541 self:argCheck(parent, 2, "table", "string")
2542 local info = self.registry[parent]
2543 self:assert(info, "You cannot check tablet with an unregistered parent frame.")
2544 return not info.detachedData or not info.detachedData.detached
2545 end
2546 Tablet.IsAttached = wrap(Tablet.IsAttached, "Tablet:IsAttached")
2547  
2548 function Tablet:Refresh(parent)
2549 self:argCheck(parent, 2, "table", "string")
2550 local info = self.registry[parent]
2551 self:assert(info, "You cannot refresh tablet with an unregistered parent frame.")
2552 local tt = info.tooltip
2553 if tt and not tt.preventRefresh and tt:IsShown() then
2554 tt.updating = true
2555 tt:children()
2556 tt.updating = false
2557 end
2558 end
2559 Tablet.Refresh = wrap(Tablet.Refresh, "Tablet:Refresh")
2560  
2561 function Tablet:IsLocked(parent)
2562 self:argCheck(parent, 2, "table", "string")
2563 local info = self.registry[parent]
2564 self:assert(info, "You cannot detach tablet with an unregistered parent frame.")
2565 return info.detachedData and info.detachedData.locked
2566 end
2567 Tablet.IsLocked = wrap(Tablet.IsLocked, "Tablet:IsLocked")
2568  
2569 function Tablet:ToggleLocked(parent)
2570 self:argCheck(parent, 2, "table", "string")
2571 local info = self.registry[parent]
2572 self:assert(info, "You cannot detach tablet with an unregistered parent frame.")
2573 if info.tooltip and info.tooltip ~= tooltip then
2574 info.tooltip:Lock()
2575 elseif info.detachedData then
2576 info.detachedData.locked = info.detachedData.locked
2577 end
2578 end
2579 Tablet.ToggleLocked = wrap(Tablet.ToggleLocked, "Tablet:ToggleLocked")
2580  
2581 function Tablet:UpdateDetachedData(parent, detachedData)
2582 self:argCheck(parent, 2, "table", "string")
2583 local info = self.registry[parent]
2584 self:assert(info, "You cannot detach tablet with an unregistered parent frame.")
2585 self:argCheck(detachedData, 3, "table")
2586 if info.data == info.detachedData then
2587 info.data = detachedData
2588 end
2589 info.detachedData = detachedData
2590 if info.detachedData.detached then
2591 self:Detach(parent)
2592 elseif info.tooltip and info.tooltip.owner then
2593 self:Attach(parent)
2594 end
2595 end
2596 Tablet.UpdateDetachedData = wrap(Tablet.UpdateDetachedData, "Tablet:UpdateDetachedData")
2597  
2598 if DEBUG then
2599 function Tablet:ListProfileInfo()
2600 local duration, times, memories = GetProfileInfo()
2601 self:assert(duration and times and memories)
2602 local t = new()
2603 for method in pairs(memories) do
2604 table.insert(t, method)
2605 end
2606 table.sort(t, function(alpha, bravo)
2607 if memories[alpha] ~= memories[bravo] then
2608 return memories[alpha] < memories[bravo]
2609 elseif times[alpha] ~= times[bravo] then
2610 return times[alpha] < times[bravo]
2611 else
2612 return alpha < bravo
2613 end
2614 end)
2615 local memory = 0
2616 local time = 0
2617 for _,method in ipairs(t) do
2618 DEFAULT_CHAT_FRAME:AddMessage(format("%s || %.3f s || %.3f%% || %d KiB", method, times[method], times[method] / duration * 100, memories[method]))
2619 memory = memory + memories[method]
2620 time = time + times[method]
2621 end
2622 DEFAULT_CHAT_FRAME:AddMessage(format("%s || %.3f s || %.3f%% || %d KiB", "Total", time, time / duration * 100, memory))
2623 table.setn(t, 0)
2624 del(t)
2625 end
2626 SLASH_TABLET1 = "/tablet"
2627 SLASH_TABLET2 = "/tabletlib"
2628 SlashCmdList["TABLET"] = function(msg)
2629 TabletLib:GetInstance(MAJOR_VERSION):ListProfileInfo()
2630 end
2631 end
2632  
2633 local function activate(self, oldLib, oldDeactivate)
2634 Tablet = self
2635 if oldLib then
2636 self.registry = oldLib.registry
2637 self.onceRegistered = oldLib.onceRegistered
2638 self.tooltip = oldLib.tooltip
2639 else
2640 self.registry = {}
2641 self.onceRegistered = {}
2642 end
2643  
2644 tooltip = self.tooltip
2645  
2646 if oldDeactivate then
2647 oldDeactivate(oldLib)
2648 end
2649 end
2650  
2651 AceLibrary:Register(Tablet, MAJOR_VERSION, MINOR_VERSION, activate)