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