comparison Libs/DF/cooltip.lua @ 11:2f09fe4be15c

Added an Options Panel.
author Tercio
date Mon, 20 Apr 2015 16:34:18 -0300
parents
children dc1c77254f80
comparison
equal deleted inserted replaced
10:f1e32be6773e 11:2f09fe4be15c
1
2 local DF = _G ["DetailsFramework"]
3 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
4
5 local _
6 --lua locals
7 local _math_floor= math.floor
8 local _type = type
9 local _math_abs = math.abs
10 local _tinsert = tinsert
11 local _unpack = unpack
12 local _ipairs = ipairs
13 local _table_wipe = table.wipe
14 local _table_insert = table.insert
15 local _math_max = math.max
16 --api locals
17 local _GetScreenWidth = GetScreenWidth
18 local _GetScreenHeight = GetScreenHeight
19 local _UIParent = UIParent
20 local _CreateFrame = CreateFrame
21
22 local version = 1
23
24 function DF:CreateCoolTip()
25
26 ----------------------------------------------------------------------
27 --> Cooltip Startup
28 ----------------------------------------------------------------------
29
30 if (_G.GameCooltip2 and _G.GameCooltip2.version >= version) then
31 return
32 end
33
34 --> Start Cooltip Table
35 local CoolTip = {version = version}
36 _G.GameCooltip2 = CoolTip
37
38 --> Containers
39 CoolTip.LeftTextTable = {}
40 CoolTip.LeftTextTableSub = {}
41 CoolTip.RightTextTable = {}
42 CoolTip.RightTextTableSub = {}
43 CoolTip.LeftIconTable = {}
44 CoolTip.LeftIconTableSub = {}
45 CoolTip.RightIconTable = {}
46 CoolTip.RightIconTableSub = {}
47 CoolTip.Banner = {false, false, false}
48 CoolTip.TopIconTableSub = {}
49 CoolTip.StatusBarTable = {}
50 CoolTip.StatusBarTableSub = {}
51 CoolTip.WallpaperTable = {}
52 CoolTip.WallpaperTableSub = {}
53
54 CoolTip.FunctionsTableMain = {} --> menus
55 CoolTip.FunctionsTableSub = {} --> menus
56 CoolTip.ParametersTableMain = {} --> menus
57 CoolTip.ParametersTableSub = {} --> menus
58
59 CoolTip.FixedValue = nil --> menus
60 CoolTip.SelectedIndexMain = nil --> menus
61 CoolTip.SelectedIndexSec = {} --> menus
62
63 --options table
64 CoolTip.OptionsList = {
65 ["IconSize"] = true,
66 ["HeightAnchorMod"] = true,
67 ["WidthAnchorMod"] = true,
68 ["MinWidth"] = true,
69 ["FixedWidth"] = true,
70 ["FixedHeight"] = true,
71 ["FixedWidthSub"] = true,
72 ["FixedHeightSub"] = true,
73 ["AlignAsBlizzTooltip"] = true,
74 ["IgnoreSubMenu"] = true,
75 ["IgnoreButtonAutoHeight"] = true,
76 ["TextHeightMod"] = true,
77 ["ButtonHeightMod"] = true,
78 ["ButtonHeightModSub"] = true,
79 ["YSpacingMod"] = true,
80 ["YSpacingModSub"] = true,
81 ["ButtonsYMod"] = true,
82 ["ButtonsYModSub"] = true,
83 ["IconHeightMod"] = true,
84 ["StatusBarHeightMod"] = true,
85 ["StatusBarTexture"] = true,
86 ["TextSize"] = true,
87 ["TextFont"] = true,
88 ["TextColor"] = true,
89 ["TextColorRight"] = true,
90 ["TextShadow"] = true,
91 ["LeftTextWidth"] = true,
92 ["RightTextWidth"] = true,
93 ["LeftTextHeight"] = true,
94 ["RightTextHeight"] = true,
95 ["NoFade"] = true,
96 ["MyAnchor"] = true,
97 ["Anchor"] = true,
98 ["RelativeAnchor"] = true,
99 ["NoLastSelectedBar"] = true,
100 ["SubMenuIsTooltip"] = true,
101 ["LeftBorderSize"] = true,
102 ["RightBorderSize"] = true,
103 ["HeighMod"] = true,
104 ["HeighModSub"] = true,
105 ["IconBlendMode"] = true,
106 ["IconBlendModeHover"] = true,
107 ["SubFollowButton"] = true,
108 ["IgnoreArrows"] = true,
109 ["SelectedTopAnchorMod"] = true,
110 ["SelectedBottomAnchorMod"] = true,
111 ["SelectedLeftAnchorMod"] = true,
112 ["SelectedRightAnchorMod"] = true,
113 }
114
115 CoolTip.OptionsTable = {}
116
117 --cprops
118 CoolTip.Indexes = 0 --> amount of lines current on shown
119 CoolTip.IndexesSub = {} --> amount of lines current on shown
120 CoolTip.HaveSubMenu = false --> amount of lines current on shown
121 CoolTip.SubIndexes = 0 --> amount of lines current on shown on sub menu
122 CoolTip.Type = 1 --> 1 tooltip 2 tooltip with bars 3 menu 4 menu + submenus
123 CoolTip.Host = nil --> frame to anchor
124 CoolTip.LastSize = 0 --> last size
125
126 CoolTip.LastIndex = 0
127
128 CoolTip.internal_x_mod = 0
129 CoolTip.internal_y_mod = 0
130 CoolTip.overlap_checked = false
131
132 --defaults
133 CoolTip.default_height = 20
134 CoolTip.default_text_size = 10.5
135 CoolTip.default_text_font = "GameFontHighlight"
136
137 CoolTip.selected_anchor = {}
138 CoolTip.selected_anchor.left = 2
139 CoolTip.selected_anchor.right = 0
140 CoolTip.selected_anchor.top = 0
141 CoolTip.selected_anchor.bottom = 0
142
143 CoolTip._default_font = SharedMedia:Fetch ("font", "Friz Quadrata TT")
144
145 --> Create Frames
146
147 --> main frame
148 local frame1
149 if (not GameCooltipFrame1) then
150 frame1 = CreateFrame ("Frame", "GameCooltipFrame1", UIParent, "DFCooltipMainFrameTemplate")
151 tinsert (UISpecialFrames, "GameCooltipFrame1")
152 DF:CreateFlashAnimation (frame1)
153 else
154 frame1 = GameCooltipFrame1
155 end
156
157 GameCooltipFrame1_FrameBackgroundCenter:SetTexture (DF.folder .. "cooltip_background")
158 GameCooltipFrame1_FrameBackgroundCenter:SetTexCoord (0.10546875, 0.89453125, 0, 1)
159 GameCooltipFrame1_FrameBackgroundLeft:SetTexture (DF.folder .. "cooltip_background")
160 GameCooltipFrame1_FrameBackgroundLeft:SetTexCoord (0, 0.103515625, 0, 1)
161 GameCooltipFrame1_FrameBackgroundRight:SetTexture (DF.folder .. "cooltip_background")
162 GameCooltipFrame1_FrameBackgroundRight:SetTexCoord (0.896484375, 1, 0, 1)
163
164 --> secondary frame
165 local frame2
166 if (not GameCooltipFrame2) then
167 frame2 = CreateFrame ("Frame", "GameCooltipFrame2", UIParent, "DFCooltipMainFrameTemplate")
168 tinsert (UISpecialFrames, "GameCooltipFrame2")
169 DF:CreateFlashAnimation (frame2)
170 frame2:SetClampedToScreen (true)
171 else
172 frame2 = GameCooltipFrame2
173 end
174
175 frame2:SetPoint ("bottomleft", frame1, "bottomright")
176
177 GameCooltipFrame2_FrameBackgroundCenter:SetTexture (DF.folder .. "cooltip_background")
178 GameCooltipFrame2_FrameBackgroundCenter:SetTexCoord (0.10546875, 0.89453125, 0, 1)
179 GameCooltipFrame2_FrameBackgroundLeft:SetTexture (DF.folder .. "cooltip_background")
180 GameCooltipFrame2_FrameBackgroundLeft:SetTexCoord (0, 0.103515625, 0, 1)
181 GameCooltipFrame2_FrameBackgroundRight:SetTexture (DF.folder .. "cooltip_background")
182 GameCooltipFrame2_FrameBackgroundRight:SetTexCoord (0.896484375, 1, 0, 1)
183
184 CoolTip.frame1 = frame1
185 CoolTip.frame2 = frame2
186 DF:Fade (frame1, 0)
187 DF:Fade (frame2, 0)
188
189 --> button containers
190 frame1.Lines = {}
191 frame2.Lines = {}
192
193 ----------------------------------------------------------------------
194 --> Title Function
195 ----------------------------------------------------------------------
196
197 function CoolTip:SetTitle (_f, text)
198 if (_f == 1) then
199 CoolTip.title1 = true
200 CoolTip.title_text = text
201 end
202 end
203
204 function CoolTip:SetTitleAnchor (_f, _anchor, ...)
205 _anchor = string.lower (_anchor)
206 if (_f == 1) then
207 self.frame1.titleIcon:ClearAllPoints()
208 self.frame1.titleText:ClearAllPoints()
209
210 if (_anchor == "left") then
211 self.frame1.titleIcon:SetPoint ("left", frame1, "left", ...)
212 self.frame1.titleText:SetPoint ("left", frame1.titleIcon, "right")
213
214 elseif (_anchor == "center") then
215 self.frame1.titleIcon:SetPoint ("center", frame1, "center")
216 self.frame1.titleIcon:SetPoint ("bottom", frame1, "top")
217 self.frame1.titleText:SetPoint ("left", frame1.titleIcon, "right")
218 self.frame1.titleText:SetText ("TESTE")
219
220 self.frame1.titleText:Show()
221 self.frame1.titleIcon:Show()
222
223 elseif (_anchor == "right") then
224 self.frame1.titleIcon:SetPoint ("right", frame1, "right", ...)
225 self.frame1.titleText:SetPoint ("right", frame1.titleIcon, "left")
226
227 end
228 elseif (_f == 2) then
229 self.frame2.titleIcon:ClearAllPoints()
230 self.frame2.titleText:ClearAllPoints()
231 if (_anchor == "left") then
232 self.frame2.titleIcon:SetPoint ("left", frame2, "left", ...)
233 self.frame2.titleText:SetPoint ("left", frame2.titleIcon, "right")
234 elseif (_anchor == "center") then
235 self.frame2.titleIcon:SetPoint ("center", frame2, "center", ...)
236 self.frame2.titleText:SetPoint ("left", frame2.titleIcon, "right")
237 elseif (_anchor == "right") then
238 self.frame2.titleIcon:SetPoint ("right", frame2, "right", ...)
239 self.frame2.titleText:SetPoint ("right", frame2.titleIcon, "left")
240 end
241 end
242 end
243
244 ----------------------------------------------------------------------
245 --> Button Hide and Show Functions
246 ----------------------------------------------------------------------
247
248 local elapsedTime = 0
249
250 CoolTip.mouseOver = false
251 CoolTip.buttonClicked = false
252
253 frame1:SetScript ("OnEnter", function (self)
254 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then --> menu
255 CoolTip.active = true
256 CoolTip.mouseOver = true
257 self:SetScript ("OnUpdate", nil)
258 DF:Fade (self, 0)
259 --rever
260 if (CoolTip.sub_menus) then
261 DF:Fade (frame2, 0)
262 end
263 end
264 end)
265
266 frame2:SetScript ("OnEnter", function (self)
267 if (CoolTip.OptionsTable.SubMenuIsTooltip) then
268 return CoolTip:Close()
269 end
270 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then
271 CoolTip.active = true
272 CoolTip.mouseOver = true
273 self:SetScript ("OnUpdate", nil)
274 DF:Fade (self, 0)
275 DF:Fade (frame1, 0)
276 end
277 end)
278
279 local OnLeaveUpdateFrame1 = function (self, elapsed)
280 elapsedTime = elapsedTime+elapsed
281 if (elapsedTime > 0.7) then
282 if (not CoolTip.active and not CoolTip.buttonClicked and self == CoolTip.Host) then
283 DF:Fade (self, 1)
284 DF:Fade (frame2, 1)
285 elseif (not CoolTip.active) then
286 DF:Fade (self, 1)
287 DF:Fade (frame2, 1)
288 end
289 self:SetScript ("OnUpdate", nil)
290 frame2:SetScript ("OnUpdate", nil)
291 end
292 end
293
294 frame1:SetScript ("OnLeave", function (self)
295
296 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then
297 CoolTip.active = false
298 CoolTip.mouseOver = false
299 elapsedTime = 0
300 self:SetScript ("OnUpdate", OnLeaveUpdateFrame1)
301 else
302 CoolTip.active = false
303 CoolTip.mouseOver = false
304 elapsedTime = 0
305 self:SetScript ("OnUpdate", OnLeaveUpdateFrame1)
306 end
307 end)
308
309 local OnLeaveUpdateFrame2 = function (self, elapsed)
310 elapsedTime = elapsedTime+elapsed
311 if (elapsedTime > 0.7) then
312 if (not CoolTip.active and not CoolTip.buttonClicked and self == CoolTip.Host) then
313 DF:Fade (self, 1)
314 DF:Fade (frame2, 1)
315 elseif (not CoolTip.active) then
316 DF:Fade (self, 1)
317 DF:Fade (frame2, 1)
318 end
319 self:SetScript ("OnUpdate", nil)
320 frame1:SetScript ("OnUpdate", nil)
321 end
322 end
323
324 frame2:SetScript ("OnLeave", function (self)
325 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then
326 CoolTip.active = false
327 CoolTip.mouseOver = false
328 elapsedTime = 0
329 self:SetScript ("OnUpdate", OnLeaveUpdateFrame2)
330 else
331 CoolTip.active = false
332 CoolTip.mouseOver = false
333 elapsedTime = 0
334 self:SetScript ("OnUpdate", OnLeaveUpdateFrame2)
335
336 end
337 end)
338
339 frame1:SetScript ("OnHide", function (self)
340 CoolTip.active = false
341 CoolTip.buttonClicked = false
342 CoolTip.mouseOver = false
343 end)
344
345
346 ----------------------------------------------------------------------
347 --> Button Creation Functions
348 ----------------------------------------------------------------------
349
350 function GameCooltipButtonMouseDown (button)
351 local mod = CoolTip.OptionsTable.TextHeightMod or 0
352 button.leftText:SetPoint ("center", button.leftIcon, "center", 0, 0+mod)
353 button.leftText:SetPoint ("left", button.leftIcon, "right", 4, -1+mod)
354 end
355
356 function GameCooltipButtonMouseUp (button)
357 local mod = CoolTip.OptionsTable.TextHeightMod or 0
358 button.leftText:SetPoint ("center", button.leftIcon, "center", 0, 0+mod)
359 button.leftText:SetPoint ("left", button.leftIcon, "right", 3, 0+mod)
360 end
361
362 function CoolTip:CreateButton (index, frame, name)
363 local new_button = CreateFrame ("Button", name, frame, "DFCooltipButtonTemplate")
364 frame.Lines [index] = new_button
365 return new_button
366 end
367
368 local OnEnterUpdateButton = function (self, elapsed)
369 elapsedTime = elapsedTime+elapsed
370 if (elapsedTime > 0.001) then
371 --> search key: ~onenterupdatemain
372 CoolTip:ShowSub (self.index)
373 CoolTip.last_button = self.index
374 self:SetScript ("OnUpdate", nil)
375 end
376 end
377
378 local OnLeaveUpdateButton = function (self, elapsed)
379 elapsedTime = elapsedTime+elapsed
380 if (elapsedTime > 0.7) then
381 if (not CoolTip.active and not CoolTip.buttonClicked) then
382 DF:Fade (frame1, 1)
383 DF:Fade (frame2, 1)
384
385 elseif (not CoolTip.active) then
386 DF:Fade (frame1, 1)
387 DF:Fade (frame2, 1)
388 end
389 frame1:SetScript ("OnUpdate", nil)
390 end
391 end
392
393 function CoolTip:NewMainButton (i)
394 local botao = CoolTip:CreateButton (i, frame1, "GameCooltipMainButton"..i)
395
396 --> serach key: ~onenter
397 botao:SetScript ("OnEnter", function()
398 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not botao.isDiv) then
399 CoolTip.active = true
400 CoolTip.mouseOver = true
401
402 frame1:SetScript ("OnUpdate", nil)
403 frame2:SetScript ("OnUpdate", nil)
404
405 botao.background:Show()
406
407 if (CoolTip.OptionsTable.IconBlendModeHover) then
408 botao.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendModeHover)
409 else
410 botao.leftIcon:SetBlendMode ("BLEND")
411 end
412
413 if (CoolTip.IndexesSub [botao.index] and CoolTip.IndexesSub [botao.index] > 0) then
414 if (CoolTip.OptionsTable.SubMenuIsTooltip) then
415 CoolTip:ShowSub (botao.index)
416 botao.index = i
417 else
418 if (CoolTip.last_button) then
419 CoolTip:ShowSub (CoolTip.last_button)
420 else
421 CoolTip:ShowSub (botao.index)
422 end
423 elapsedTime = 0
424 botao.index = i
425 botao:SetScript ("OnUpdate", OnEnterUpdateButton)
426 end
427
428 else
429 --hide second frame
430 DF:Fade (frame2, 1)
431 CoolTip.last_button = nil
432 end
433 else
434 CoolTip.mouseOver = true
435 end
436 end)
437
438 botao:SetScript ("OnLeave", function()
439 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not botao.isDiv) then
440 CoolTip.active = false
441 CoolTip.mouseOver = false
442 botao:SetScript ("OnUpdate", nil)
443
444 botao.background:Hide()
445
446 if (CoolTip.OptionsTable.IconBlendMode) then
447 botao.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode)
448 botao.rightIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode)
449 else
450 botao.leftIcon:SetBlendMode ("BLEND")
451 botao.rightIcon:SetBlendMode ("BLEND")
452 end
453
454 elapsedTime = 0
455 frame1:SetScript ("OnUpdate", OnLeaveUpdateButton)
456 --CoolTip:HideSub (i)
457 else
458 CoolTip.active = false
459 elapsedTime = 0
460 frame1:SetScript ("OnUpdate", OnLeaveUpdateButton)
461 CoolTip.mouseOver = false
462 end
463 end)
464
465 return botao
466 end
467
468 local OnLeaveUpdateButtonSec = function (self, elapsed)
469 elapsedTime = elapsedTime+elapsed
470 if (elapsedTime > 0.7) then
471 if (not CoolTip.active and not CoolTip.buttonClicked) then
472 DF:Fade (frame1, 1)
473 DF:Fade (frame2, 1)
474 elseif (not CoolTip.active) then
475 DF:Fade (frame1, 1)
476 DF:Fade (frame2, 1)
477 end
478 frame2:SetScript ("OnUpdate", nil)
479 end
480 end
481
482 function CoolTip:NewSecondaryButton (i)
483 local botao = CoolTip:CreateButton (i, frame2, "GameCooltipSecButton"..i)
484
485 botao:SetScript ("OnEnter", function()
486 if (CoolTip.OptionsTable.SubMenuIsTooltip) then
487 return CoolTip:Close()
488 end
489 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2 and not botao.isDiv) then
490 CoolTip.active = true
491 CoolTip.mouseOver = true
492
493 botao.background:Show()
494
495 if (CoolTip.OptionsTable.IconBlendModeHover) then
496 botao.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendModeHover)
497 else
498 botao.leftIcon:SetBlendMode ("BLEND")
499 end
500
501 frame1:SetScript ("OnUpdate", nil)
502 frame2:SetScript ("OnUpdate", nil)
503
504 DF:Fade (frame1, 0)
505 DF:Fade (frame2, 0)
506 else
507 CoolTip.mouseOver = true
508 end
509 end)
510
511 botao:SetScript ("OnLeave", function()
512 if (CoolTip.Type ~= 1 and CoolTip.Type ~= 2) then
513 CoolTip.active = false
514 CoolTip.mouseOver = false
515
516 botao.background:Hide()
517
518 if (CoolTip.OptionsTable.IconBlendMode) then
519 botao.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode)
520 botao.rightIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode)
521 else
522 botao.leftIcon:SetBlendMode ("BLEND")
523 botao.rightIcon:SetBlendMode ("BLEND")
524 end
525
526 elapsedTime = 0
527 frame2:SetScript ("OnUpdate", OnLeaveUpdateButtonSec)
528 else
529 CoolTip.active = false
530 CoolTip.mouseOver = false
531 elapsedTime = 0
532 frame2:SetScript ("OnUpdate", OnLeaveUpdateButtonSec)
533 end
534 end)
535
536 return botao
537 end
538
539 ----------------------------------------------------------------------
540 --> Button Click Functions
541 ----------------------------------------------------------------------
542
543 CoolTip.selected_anchor.left = 4
544 CoolTip.selected_anchor.right = -4
545 CoolTip.selected_anchor.top = 0
546 CoolTip.selected_anchor.bottom = 0
547
548 function CoolTip:HideSelectedTexture (frame)
549 frame.selectedTop:Hide()
550 frame.selectedBottom:Hide()
551 frame.selectedMiddle:Hide()
552 end
553
554 function CoolTip:ShowSelectedTexture (frame)
555 frame.selectedTop:Show()
556 frame.selectedBottom:Show()
557 frame.selectedMiddle:Show()
558 end
559
560 function CoolTip:SetSelectedAnchor (frame, button)
561
562 local left = CoolTip.selected_anchor.left + (CoolTip.OptionsTable.SelectedLeftAnchorMod or 0)
563 local right = CoolTip.selected_anchor.right + (CoolTip.OptionsTable.SelectedRightAnchorMod or 0)
564
565 local top = CoolTip.selected_anchor.top + (CoolTip.OptionsTable.SelectedTopAnchorMod or 0)
566 local bottom = CoolTip.selected_anchor.bottom + (CoolTip.OptionsTable.SelectedBottomAnchorMod or 0)
567
568 frame.selectedTop:ClearAllPoints()
569 frame.selectedBottom:ClearAllPoints()
570
571 frame.selectedTop:SetPoint ("topleft", button, "topleft", left, top) --
572 frame.selectedTop:SetPoint ("topright", button, "topright", right, top) --
573
574 frame.selectedBottom:SetPoint ("bottomleft", button, "bottomleft", left, bottom) --
575 frame.selectedBottom:SetPoint ("bottomright", button, "bottomright", right, bottom) --
576
577 CoolTip:ShowSelectedTexture (frame)
578 end
579
580 local OnClickFunctionButtonPrincipal = function (self)
581 if (CoolTip.IndexesSub [self.index] and CoolTip.IndexesSub [self.index] > 0) then
582 CoolTip:ShowSub (self.index)
583 CoolTip.last_button = self.index
584 end
585
586 CoolTip.buttonClicked = true
587 CoolTip:SetSelectedAnchor (frame1, self)
588
589 if (not CoolTip.OptionsTable.NoLastSelectedBar) then
590 CoolTip:ShowSelectedTexture (frame1)
591
592 end
593 CoolTip.SelectedIndexMain = self.index
594
595 if (CoolTip.FunctionsTableMain [self.index]) then
596 local parameterTable = CoolTip.ParametersTableMain [self.index]
597 CoolTip.FunctionsTableMain [self.index] (_, CoolTip.FixedValue, parameterTable [1], parameterTable [2], parameterTable [3])
598 end
599 end
600
601 local OnClickFunctionButtonSecundario = function (self)
602 CoolTip.buttonClicked = true
603
604 CoolTip:SetSelectedAnchor (frame2, self)
605
606 if (CoolTip.FunctionsTableSub [self.mainIndex] and CoolTip.FunctionsTableSub [self.mainIndex] [self.index]) then
607 local parameterTable = CoolTip.ParametersTableSub [self.mainIndex] [self.index]
608 CoolTip.FunctionsTableSub [self.mainIndex] [self.index] (_, CoolTip.FixedValue, parameterTable [1], parameterTable [2], parameterTable [3])
609 end
610
611 local botao_p = frame1.Lines [self.mainIndex]
612 CoolTip:SetSelectedAnchor (frame1, botao_p)
613
614 if (not CoolTip.OptionsTable.NoLastSelectedBar) then
615 CoolTip:ShowSelectedTexture (frame1)
616 end
617
618 CoolTip.SelectedIndexMain = self.mainIndex
619 CoolTip.SelectedIndexSec [self.mainIndex] = self.index
620
621 end
622
623 function CoolTip:TextAndIcon (index, frame, menuButton, leftTextTable, rightTextTable, leftIconTable, rightIconTable, isSub)
624
625 --> reset width
626 menuButton.leftText:SetWidth (0)
627 menuButton.leftText:SetHeight (0)
628 menuButton.rightText:SetWidth (0)
629 menuButton.rightText:SetHeight (0)
630
631 --> set text
632 if (leftTextTable) then
633
634 menuButton.leftText:SetText (leftTextTable [1])
635
636 local r, g, b, a = leftTextTable [2], leftTextTable [3], leftTextTable [4], leftTextTable [5]
637
638 if (r == 0 and g == 0 and b == 0 and a == 0) then
639 if (CoolTip.OptionsTable.TextColor) then
640 r, g, b, a = DF:ParseColors (CoolTip.OptionsTable.TextColor)
641 menuButton.leftText:SetTextColor (r, g, b, a)
642 else
643 menuButton.leftText:SetTextColor (1, 1, 1, 1)
644 end
645 else
646 menuButton.leftText:SetTextColor (r, g, b, a)
647 end
648
649 if (CoolTip.OptionsTable.TextSize and not leftTextTable [6]) then
650 DF:SetFontSize (menuButton.leftText, CoolTip.OptionsTable.TextSize)
651 end
652
653 if (CoolTip.OptionsTable.LeftTextWidth) then
654 menuButton.leftText:SetWidth (CoolTip.OptionsTable.LeftTextWidth)
655 else
656 menuButton.leftText:SetWidth (0)
657 end
658
659 if (CoolTip.OptionsTable.LeftTextHeight) then
660 menuButton.leftText:SetHeight (CoolTip.OptionsTable.LeftTextHeight)
661 else
662 menuButton.leftText:SetHeight (0)
663 end
664
665 if (CoolTip.OptionsTable.TextFont and not leftTextTable [7]) then --font
666
667 if (_G [CoolTip.OptionsTable.TextFont]) then
668 menuButton.leftText:SetFontObject (GameFontRed or CoolTip.OptionsTable.TextFont)
669 else
670 local font = SharedMedia:Fetch ("font", CoolTip.OptionsTable.TextFont)
671 local _, size, flags = menuButton.leftText:GetFont()
672 flags = leftTextTable [8] or CoolTip.OptionsTable.TextShadow or nil
673 size = leftTextTable [6] or CoolTip.OptionsTable.TextSize or size
674 menuButton.leftText:SetFont (font, size, flags)
675 end
676
677 elseif (leftTextTable [7]) then
678 if (_G [leftTextTable [7]]) then
679 menuButton.leftText:SetFontObject (leftTextTable [7])
680 local face, size, flags = menuButton.leftText:GetFont()
681 flags = leftTextTable [8] or CoolTip.OptionsTable.TextShadow or nil
682 size = leftTextTable [6] or CoolTip.OptionsTable.TextSize or size
683 menuButton.leftText:SetFont (face, size, flags)
684 else
685 local font = SharedMedia:Fetch ("font", leftTextTable [7])
686 local face, size, flags = menuButton.leftText:GetFont()
687 flags = leftTextTable [8] or CoolTip.OptionsTable.TextShadow or nil
688 size = leftTextTable [6] or CoolTip.OptionsTable.TextSize or size
689 menuButton.leftText:SetFont (face, size, flags)
690 end
691 else
692 menuButton.leftText:SetFont (CoolTip._default_font, leftTextTable [6] or CoolTip.OptionsTable.TextSize or 10, leftTextTable [8] or CoolTip.OptionsTable.TextShadow)
693 end
694
695 local height_mod = CoolTip.OptionsTable.TextHeightMod or 0
696 menuButton.leftText:SetPoint ("center", menuButton.leftIcon, "center", 0, 0+height_mod)
697 menuButton.leftText:SetPoint ("left", menuButton.leftIcon, "right", 3, 0+height_mod)
698
699 else
700 menuButton.leftText:SetText ("")
701 end
702
703 if (rightTextTable) then
704 menuButton.rightText:SetText (rightTextTable [1])
705
706 local r, g, b, a = rightTextTable [2], rightTextTable [3], rightTextTable [4], rightTextTable [5]
707
708 if (r == 0 and g == 0 and b == 0 and a == 0) then
709
710 if (CoolTip.OptionsTable.TextColorRight) then
711 r, g, b, a = DF:ParseColors (CoolTip.OptionsTable.TextColorRight)
712 menuButton.rightText:SetTextColor (r, g, b, a)
713 elseif (CoolTip.OptionsTable.TextColor) then
714 r, g, b, a = DF:ParseColors (CoolTip.OptionsTable.TextColor)
715 menuButton.rightText:SetTextColor (r, g, b, a)
716 else
717 menuButton.rightText:SetTextColor (1, 1, 1, 1)
718 end
719 else
720 menuButton.rightText:SetTextColor (r, g, b, a)
721 end
722
723 if (CoolTip.OptionsTable.TextSize and not rightTextTable [6]) then
724 DF:SetFontSize (menuButton.rightText, CoolTip.OptionsTable.TextSize)
725 end
726
727 if (CoolTip.OptionsTable.RightTextWidth) then
728 menuButton.rightText:SetWidth (CoolTip.OptionsTable.RightTextWidth)
729 else
730 menuButton.rightText:SetWidth (0)
731 end
732
733 if (CoolTip.OptionsTable.RightTextHeight) then
734 menuButton.rightText:SetHeight (CoolTip.OptionsTable.RightTextHeight)
735 else
736 menuButton.rightText:SetHeight (0)
737 end
738
739 if (CoolTip.OptionsTable.TextFont and not rightTextTable [7]) then
740 if (_G [CoolTip.OptionsTable.TextFont]) then
741 menuButton.rightText:SetFontObject (CoolTip.OptionsTable.TextFont)
742 else
743 local font = SharedMedia:Fetch ("font", CoolTip.OptionsTable.TextFont)
744 local _, size, flags = menuButton.rightText:GetFont()
745 flags = rightTextTable [8] or CoolTip.OptionsTable.TextShadow or nil
746 size = rightTextTable [6] or CoolTip.OptionsTable.TextSize or size
747 menuButton.rightText:SetFont (font, size, flags)
748 end
749
750 elseif (rightTextTable [7]) then
751 if (_G [rightTextTable [7]]) then
752 menuButton.rightText:SetFontObject (rightTextTable [7])
753 local face, size, flags = menuButton.rightText:GetFont()
754 flags = rightTextTable [8] or CoolTip.OptionsTable.TextShadow or nil
755 size = rightTextTable [6] or CoolTip.OptionsTable.TextSize or size
756 menuButton.rightText:SetFont (face, size, flags)
757 else
758 local font = SharedMedia:Fetch ("font", rightTextTable [7])
759 local face, size, flags = menuButton.rightText:GetFont()
760 flags = rightTextTable [8] or CoolTip.OptionsTable.TextShadow or nil
761 size = rightTextTable [6] or CoolTip.OptionsTable.TextSize or size
762 menuButton.rightText:SetFont (face, size, flags)
763 end
764
765 else
766 menuButton.rightText:SetFont (CoolTip._default_font, rightTextTable [6] or CoolTip.OptionsTable.TextSize or 10, rightTextTable [8] or CoolTip.OptionsTable.TextShadow)
767 end
768
769
770 else
771 menuButton.rightText:SetText ("")
772 end
773
774 --> left icon
775 if (leftIconTable and leftIconTable [1]) then
776 menuButton.leftIcon:SetTexture (leftIconTable [1])
777 menuButton.leftIcon:SetWidth (leftIconTable [2])
778 menuButton.leftIcon:SetHeight (leftIconTable [3])
779 menuButton.leftIcon:SetTexCoord (leftIconTable [4], leftIconTable [5], leftIconTable [6], leftIconTable [7])
780
781 local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (leftIconTable [8])
782 menuButton.leftIcon:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
783
784 if (CoolTip.OptionsTable.IconBlendMode) then
785 menuButton.leftIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode)
786 else
787 menuButton.leftIcon:SetBlendMode ("BLEND")
788 end
789
790 menuButton.leftIcon:SetDesaturated (leftIconTable [9])
791 else
792 menuButton.leftIcon:SetTexture (nil)
793 menuButton.leftIcon:SetWidth (1)
794 menuButton.leftIcon:SetHeight (1)
795 end
796
797 --> right icon
798 if (rightIconTable and rightIconTable [1]) then
799 menuButton.rightIcon:SetTexture (rightIconTable [1])
800 menuButton.rightIcon:SetWidth (rightIconTable [2])
801 menuButton.rightIcon:SetHeight (rightIconTable [3])
802 menuButton.rightIcon:SetTexCoord (rightIconTable [4], rightIconTable [5], rightIconTable [6], rightIconTable [7])
803
804 local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (rightIconTable [8])
805 menuButton.rightIcon:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
806
807 if (CoolTip.OptionsTable.IconBlendMode) then
808 menuButton.rightIcon:SetBlendMode (CoolTip.OptionsTable.IconBlendMode)
809 else
810 menuButton.rightIcon:SetBlendMode ("BLEND")
811 end
812
813 menuButton.rightIcon:SetDesaturated (rightIconTable [9])
814 else
815 menuButton.rightIcon:SetTexture (nil)
816 menuButton.rightIcon:SetWidth (1)
817 menuButton.rightIcon:SetHeight (1)
818 end
819
820 --> overwrite icon size
821 if (CoolTip.OptionsTable.IconSize) then
822 menuButton.leftIcon:SetWidth (CoolTip.OptionsTable.IconSize)
823 menuButton.leftIcon:SetHeight (CoolTip.OptionsTable.IconSize)
824 menuButton.rightIcon:SetWidth (CoolTip.OptionsTable.IconSize)
825 menuButton.rightIcon:SetHeight (CoolTip.OptionsTable.IconSize)
826 end
827
828 if (CoolTip.Type == 2) then
829 CoolTip:LeftTextSpace (menuButton)
830 end
831
832 --> string length
833 if (not isSub) then --> main frame
834 if (not CoolTip.OptionsTable.FixedWidth) then
835 if (CoolTip.Type == 1 or CoolTip.Type == 2) then
836 local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth() + 10
837 if (stringWidth > frame.w) then
838 frame.w = stringWidth
839 end
840 end
841 else
842 menuButton.leftText:SetWidth (CoolTip.OptionsTable.FixedWidth - menuButton.leftIcon:GetWidth() - menuButton.rightText:GetStringWidth() - menuButton.rightIcon:GetWidth() - 30)
843 end
844 else
845 if (not CoolTip.OptionsTable.FixedWidthSub) then
846 if (CoolTip.Type == 1 or CoolTip.Type == 2) then
847 local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth()
848 if (stringWidth > frame.w) then
849 frame.w = stringWidth
850 end
851 end
852 else
853 menuButton.leftText:SetWidth (CoolTip.OptionsTable.FixedWidthSub - menuButton.leftIcon:GetWidth() - 20)
854 end
855 end
856
857 local height = _math_max ( menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight(), menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight() )
858 if (height > frame.hHeight) then
859 frame.hHeight = height
860 end
861
862 end
863
864 function CoolTip:RefreshSpark (menuButton)
865 menuButton.spark:ClearAllPoints()
866 menuButton.spark:SetPoint ("LEFT", menuButton.statusbar, "LEFT", (menuButton.statusbar:GetValue() * (menuButton.statusbar:GetWidth() / 100)) - 3, 0)
867 menuButton.spark2:ClearAllPoints()
868 menuButton.spark2:SetPoint ("left", menuButton.statusbar, "left", menuButton.statusbar:GetValue() * (menuButton.statusbar:GetWidth()/100) - 16, 0)
869 end
870
871 function CoolTip:StatusBar (menuButton, StatusBar)
872
873 if (StatusBar) then
874
875 menuButton.statusbar:SetValue (StatusBar [1])
876 menuButton.statusbar:SetStatusBarColor (StatusBar [2], StatusBar [3], StatusBar [4], StatusBar [5])
877 menuButton.statusbar:SetHeight (20 + (CoolTip.OptionsTable.StatusBarHeightMod or 0))
878
879 menuButton.spark2:Hide()
880 if (StatusBar [6]) then
881 menuButton.spark:Show()
882 --menuButton.spark:ClearAllPoints()
883 --menuButton.spark:SetPoint ("LEFT", menuButton.statusbar, "LEFT", (StatusBar [1] * (menuButton.statusbar:GetWidth() / 100)) - 3, 0)
884 else
885 menuButton.spark:Hide()
886 end
887
888 if (StatusBar [7]) then
889 menuButton.statusbar2:SetValue (StatusBar[7].value)
890 menuButton.statusbar2.texture:SetTexture (StatusBar[7].texture or [[Interface\RaidFrame\Raid-Bar-Hp-Fill]])
891 if (StatusBar[7].specialSpark) then
892 menuButton.spark2:Show()
893 end
894 if (StatusBar[7].color) then
895 local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (StatusBar[7].color)
896 menuButton.statusbar2:SetStatusBarColor (ColorR, ColorG, ColorB, ColorA)
897 else
898 menuButton.statusbar2:SetStatusBarColor (1, 1, 1, 1)
899 end
900 else
901 menuButton.statusbar2:SetValue (0)
902 menuButton.spark2:Hide()
903 end
904
905 if (CoolTip.OptionsTable.StatusBarTexture) then
906 menuButton.statusbar.texture:SetTexture (CoolTip.OptionsTable.StatusBarTexture)
907 else
908 menuButton.statusbar.texture:SetTexture ("Interface\\PaperDollInfoFrame\\UI-Character-Skills-Bar")
909 end
910
911 else
912 menuButton.statusbar:SetValue (0)
913 menuButton.statusbar2:SetValue (0)
914 menuButton.spark:Hide()
915 menuButton.spark2:Hide()
916 end
917
918 if (CoolTip.OptionsTable.LeftBorderSize) then
919 menuButton.statusbar:SetPoint ("left", menuButton, "left", 10 + CoolTip.OptionsTable.LeftBorderSize, 0)
920 else
921 menuButton.statusbar:SetPoint ("left", menuButton, "left", 10, 0)
922 end
923
924 if (CoolTip.OptionsTable.RightBorderSize) then
925 menuButton.statusbar:SetPoint ("right", menuButton, "right", CoolTip.OptionsTable.RightBorderSize + (- 10), 0)
926 else
927 menuButton.statusbar:SetPoint ("right", menuButton, "right", -10, 0)
928 end
929 end
930
931 function CoolTip:SetupMainButton (menuButton, index)
932 menuButton.index = index
933
934 --> setup texts and icons
935 CoolTip:TextAndIcon (index, frame1, menuButton, CoolTip.LeftTextTable [index], CoolTip.RightTextTable [index], CoolTip.LeftIconTable [index], CoolTip.RightIconTable [index])
936 --> setup statusbar
937 CoolTip:StatusBar (menuButton, CoolTip.StatusBarTable [index])
938
939 --> click
940 menuButton:RegisterForClicks ("LeftButtonDown")
941
942 --> string length
943 if (not CoolTip.OptionsTable.FixedWidth) then
944 local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth()
945 if (stringWidth > frame1.w) then
946 frame1.w = stringWidth
947 end
948 end
949
950 --> register click function
951 menuButton:SetScript ("OnClick", OnClickFunctionButtonPrincipal)
952 menuButton:Show()
953 end
954
955 function CoolTip:SetupSecondaryButton (menuButton, index, mainMenuIndex)
956
957 menuButton.index = index
958 menuButton.mainIndex = mainMenuIndex
959
960 --> setup texts and icons
961 CoolTip:TextAndIcon (index, frame2, menuButton, CoolTip.LeftTextTableSub [mainMenuIndex] and CoolTip.LeftTextTableSub [mainMenuIndex] [index],
962 CoolTip.RightTextTableSub [mainMenuIndex] and CoolTip.RightTextTableSub [mainMenuIndex] [index],
963 CoolTip.LeftIconTableSub [mainMenuIndex] and CoolTip.LeftIconTableSub [mainMenuIndex] [index],
964 CoolTip.RightIconTableSub [mainMenuIndex] and CoolTip.RightIconTableSub [mainMenuIndex] [index], true)
965 --> setup statusbar
966 CoolTip:StatusBar (menuButton, CoolTip.StatusBarTableSub [mainMenuIndex] and CoolTip.StatusBarTableSub [mainMenuIndex] [index])
967
968
969 --> click
970 menuButton:RegisterForClicks ("LeftButtonDown")
971
972 menuButton:ClearAllPoints()
973 menuButton:SetPoint ("center", frame2, "center")
974 menuButton:SetPoint ("top", frame2, "top", 0, (((index-1)*20)*-1)-3)
975 menuButton:SetPoint ("left", frame2, "left")
976 menuButton:SetPoint ("right", frame2, "right")
977
978 DF:Fade (menuButton, 0)
979
980 --> string length
981 local stringWidth = menuButton.leftText:GetStringWidth() + menuButton.rightText:GetStringWidth() + menuButton.leftIcon:GetWidth() + menuButton.rightIcon:GetWidth()
982 if (stringWidth > frame2.w) then
983 frame2.w = stringWidth
984 end
985
986 menuButton:SetScript ("OnClick", OnClickFunctionButtonSecundario)
987 menuButton:Show()
988
989 return true
990 end
991
992 -- -- --------------------------------------------------------------------------------------------------------------
993
994 function CoolTip:SetupWallpaper (wallpaperTable, wallpaper)
995 local texture = wallpaperTable [1]
996 if (DF:IsHtmlColor (texture) or type (texture) == "table") then
997 local r, g, b, a = DF:ParseColors (texture)
998 wallpaper:SetTexture (r, g, b, a)
999 else
1000 wallpaper:SetTexture (texture)
1001 end
1002
1003 wallpaper:SetTexCoord (wallpaperTable[2], wallpaperTable[3], wallpaperTable[4], wallpaperTable[5])
1004
1005 local color = wallpaperTable[6]
1006 if (color) then
1007 local r, g, b, a = DF:ParseColors (color)
1008 wallpaper:SetVertexColor (r, g, b, a)
1009 else
1010 wallpaper:SetVertexColor (1, 1, 1, 1)
1011 end
1012
1013 if (wallpaperTable[7]) then
1014 wallpaper:SetDesaturated (true)
1015 else
1016 wallpaper:SetDesaturated (false)
1017 end
1018
1019 wallpaper:Show()
1020 end
1021
1022 -- -- --------------------------------------------------------------------------------------------------------------
1023
1024 function CoolTip:ShowSub (index)
1025
1026 if (CoolTip.OptionsTable.IgnoreSubMenu) then
1027 DF:Fade (frame2, 1)
1028 return
1029 end
1030
1031 frame2:SetHeight (6)
1032
1033 local amtIndexes = CoolTip.IndexesSub [index]
1034 if (not amtIndexes) then
1035 --print ("Sub menu called but sub menu indexes is nil")
1036 return
1037 end
1038
1039 if (CoolTip.OptionsTable.FixedWidthSub) then
1040 frame2:SetWidth (CoolTip.OptionsTable.FixedWidthSub)
1041 end
1042
1043 frame2.h = CoolTip.IndexesSub [index] * 20
1044 frame2.hHeight = 0
1045 frame2.w = 0
1046
1047 --> pegar a fontsize da label principal
1048 local mainButton = frame1.Lines [index]
1049 local fontSize = DF:GetFontSize (mainButton.leftText)
1050
1051 local GotChecked = false
1052
1053 local IsTooltip = CoolTip.OptionsTable.SubMenuIsTooltip
1054 if (IsTooltip) then
1055 frame2:EnableMouse (false)
1056 else
1057 frame2:EnableMouse (true)
1058 end
1059
1060 for i = 1, CoolTip.IndexesSub [index] do
1061
1062 local button = frame2.Lines [i]
1063
1064 if (not button) then
1065 button = CoolTip:NewSecondaryButton (i)
1066 end
1067
1068 local checked = CoolTip:SetupSecondaryButton (button, i, index)
1069 if (checked) then
1070 GotChecked = true
1071 end
1072
1073 if (IsTooltip) then
1074 button:EnableMouse (false)
1075 else
1076 button:EnableMouse (true)
1077 end
1078 end
1079
1080 local selected = CoolTip.SelectedIndexSec [index]
1081 if (selected) then
1082
1083 CoolTip:SetSelectedAnchor (frame2, frame2.Lines [selected])
1084
1085 if (not CoolTip.OptionsTable.NoLastSelectedBar) then
1086 CoolTip:ShowSelectedTexture (frame2)
1087 end
1088 else
1089 CoolTip:HideSelectedTexture (frame2)
1090 end
1091
1092 for i = CoolTip.IndexesSub [index] + 1, #frame2.Lines do
1093 DF:Fade (frame2.Lines[i], 1)
1094 end
1095
1096 local spacing = 0
1097 if (CoolTip.OptionsTable.YSpacingModSub) then
1098 spacing = CoolTip.OptionsTable.YSpacingModSub
1099 end
1100
1101 --> normalize height of all rows
1102 for i = 1, CoolTip.IndexesSub [index] do
1103
1104 local menuButton = frame2.Lines [i]
1105
1106 -- CoolTipFrame2.Lines [2].divbar
1107
1108 if (menuButton.leftText:GetText() == "$div") then
1109
1110 --> height
1111 menuButton:SetHeight (4)
1112
1113 --> points
1114 menuButton:ClearAllPoints()
1115
1116 menuButton:SetPoint ("center", frame2, "center")
1117 menuButton:SetPoint ("left", frame2, "left")
1118 menuButton:SetPoint ("right", frame2, "right")
1119
1120 menuButton.rightText:SetText ("")
1121
1122 local div_size_up = tonumber (CoolTip.RightTextTableSub [index] [i] [2])
1123 if (not div_size_up) then
1124 div_size_up = 0
1125 end
1126 local div_size_down = tonumber (CoolTip.RightTextTableSub [index] [i] [3])
1127 if (not div_size_down) then
1128 div_size_down = 0
1129 end
1130
1131 menuButton:SetPoint ("top", frame2, "top", 0, ( ( (i-1) * frame2.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYModSub or 0) + spacing + (2 + (div_size_up or 0)))
1132
1133 if (CoolTip.OptionsTable.YSpacingModSub) then
1134 spacing = spacing + CoolTip.OptionsTable.YSpacingModSub
1135 end
1136
1137 spacing = spacing + 17 + (div_size_down or 0)
1138
1139 menuButton.leftText:SetText ("")
1140 menuButton.isDiv = true
1141
1142 if (not menuButton.divbar) then
1143 CoolTip:CreateDivBar (menuButton)
1144 else
1145 menuButton.divbar:Show()
1146 end
1147
1148 menuButton.divbar:SetPoint ("left", menuButton, "left", frame1:GetWidth()*0.10, 0)
1149 menuButton.divbar:SetPoint ("right", menuButton, "right", -frame1:GetWidth()*0.10, 0)
1150
1151 else
1152 --> height
1153 menuButton:SetHeight (frame2.hHeight + (CoolTip.OptionsTable.ButtonHeightModSub or 0))
1154 --> points
1155 menuButton:ClearAllPoints()
1156 menuButton:SetPoint ("center", frame2, "center")
1157 menuButton:SetPoint ("top", frame2, "top", 0, ( ( (i-1) * frame2.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYModSub or 0) + spacing)
1158 if (CoolTip.OptionsTable.YSpacingModSub) then
1159 spacing = spacing + CoolTip.OptionsTable.YSpacingModSub
1160 end
1161 menuButton:SetPoint ("left", frame2, "left")
1162 menuButton:SetPoint ("right", frame2, "right")
1163
1164 if (menuButton.divbar) then
1165 menuButton.divbar:Hide()
1166 menuButton.isDiv = false
1167 end
1168 end
1169
1170 end
1171
1172 local mod = CoolTip.OptionsTable.HeighModSub or 0
1173 frame2:SetHeight ( (frame2.hHeight * CoolTip.IndexesSub [index]) + 12 + (-spacing) + mod)
1174
1175 if (CoolTip.TopIconTableSub [index]) then
1176 local upperImageTable = CoolTip.TopIconTableSub [index]
1177 frame2.upperImage:SetTexture (upperImageTable [1])
1178 frame2.upperImage:SetWidth (upperImageTable [2])
1179 frame2.upperImage:SetHeight (upperImageTable [3])
1180 frame2.upperImage:SetTexCoord (upperImageTable[4], upperImageTable[5], upperImageTable[6], upperImageTable[7])
1181 frame2.upperImage:Show()
1182 else
1183 frame2.upperImage:Hide()
1184 end
1185
1186 if (CoolTip.WallpaperTableSub [index]) then
1187 CoolTip:SetupWallpaper (CoolTip.WallpaperTableSub [index], frame2.frameWallpaper)
1188 else
1189 frame2.frameWallpaper:Hide()
1190 end
1191
1192 if (not CoolTip.OptionsTable.FixedWidthSub) then
1193 frame2:SetWidth (frame2.w + 44)
1194 end
1195
1196 DF:Fade (frame2, 0)
1197
1198 CoolTip:CheckOverlap()
1199
1200 if (CoolTip.OptionsTable.SubFollowButton and not CoolTip.frame2_leftside) then
1201
1202 local button = frame1.Lines [index]
1203
1204 frame2:ClearAllPoints()
1205 frame2:SetPoint ("left", button, "right")
1206
1207 elseif (CoolTip.OptionsTable.SubFollowButton and CoolTip.frame2_leftside) then
1208
1209 local button = frame1.Lines [index]
1210
1211 frame2:ClearAllPoints()
1212 frame2:SetPoint ("right", button, "left")
1213
1214 elseif (CoolTip.frame2_leftside) then
1215 frame2:ClearAllPoints()
1216 frame2:SetPoint ("bottomright", frame1, "bottomleft")
1217 else
1218 frame2:ClearAllPoints()
1219 frame2:SetPoint ("bottomleft", frame1, "bottomright")
1220 end
1221
1222 end
1223
1224 function CoolTip:HideSub()
1225 DF:Fade (frame2, 1)
1226 end
1227
1228
1229 function CoolTip:LeftTextSpace (row)
1230 row.leftText:SetWidth (row:GetWidth() - 30 - row.leftIcon:GetWidth() - row.rightIcon:GetWidth() - row.rightText:GetStringWidth())
1231 row.leftText:SetHeight (10)
1232 end
1233
1234 --> ~inicio ~start
1235 function CoolTip:monta_tooltip()
1236
1237 --> hide sub frame
1238 DF:Fade (frame2, 1)
1239 --> hide select bar
1240 CoolTip:HideSelectedTexture (frame1)
1241
1242 frame1:EnableMouse (false)
1243
1244 --> elevator
1245 local yDown = 5
1246 --> width
1247 if (CoolTip.OptionsTable.FixedWidth) then
1248 frame1:SetWidth (CoolTip.OptionsTable.FixedWidth)
1249 end
1250
1251 frame1.w = CoolTip.OptionsTable.FixedWidth or 0
1252 frame1.hHeight = 0
1253 frame2.hHeight = 0
1254
1255 CoolTip.active = true
1256
1257 for i = 1, CoolTip.Indexes do
1258
1259 local button = frame1.Lines [i]
1260 if (not button) then
1261 button = CoolTip:NewMainButton (i)
1262 end
1263
1264 button.index = i
1265
1266 --> basic stuff
1267 button:Show()
1268 button.background:Hide()
1269 button:SetHeight (CoolTip.OptionsTable.ButtonHeightMod or CoolTip.default_height)
1270 button:RegisterForClicks()
1271
1272 --> setup texts and icons
1273 CoolTip:TextAndIcon (i, frame1, button, CoolTip.LeftTextTable [i], CoolTip.RightTextTable [i], CoolTip.LeftIconTable [i], CoolTip.RightIconTable [i])
1274 --> setup statusbar
1275 CoolTip:StatusBar (button, CoolTip.StatusBarTable [i])
1276 end
1277
1278 --> hide unused lines
1279 for i = CoolTip.Indexes+1, #frame1.Lines do
1280 frame1.Lines[i]:Hide()
1281 end
1282 CoolTip.NumLines = CoolTip.Indexes
1283
1284 local spacing = 0
1285 if (CoolTip.OptionsTable.YSpacingMod) then
1286 spacing = CoolTip.OptionsTable.YSpacingMod
1287 end
1288
1289 --> normalize height of all rows
1290 local temp = -6 + spacing + (CoolTip.OptionsTable.ButtonsYMod or 0)
1291 for i = 1, CoolTip.Indexes do
1292 local menuButton = frame1.Lines [i]
1293
1294 menuButton:ClearAllPoints()
1295 menuButton:SetPoint ("center", frame1, "center")
1296 menuButton:SetPoint ("left", frame1, "left")
1297 menuButton:SetPoint ("right", frame1, "right")
1298
1299 --> height
1300 if (CoolTip.OptionsTable.AlignAsBlizzTooltip) then
1301 local height = _math_max (8, menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight(), menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight())
1302 menuButton:SetHeight (height)
1303 menuButton:SetPoint ("top", frame1, "top", 0, temp)
1304 temp = temp + ( height * -1)
1305
1306 elseif (CoolTip.OptionsTable.IgnoreButtonAutoHeight) then
1307
1308 local height = _math_max (menuButton.leftText:GetStringHeight(), menuButton.rightText:GetStringHeight(), menuButton.leftIcon:GetHeight(), menuButton.rightIcon:GetHeight())
1309 menuButton:SetHeight (height)
1310 menuButton:SetPoint ("top", frame1, "top", 0, temp)
1311
1312 temp = temp + ( height * -1) + spacing + (CoolTip.OptionsTable.ButtonsYMod or 0)
1313
1314 else
1315 menuButton:SetHeight (frame1.hHeight + (CoolTip.OptionsTable.ButtonHeightMod or 0))
1316 menuButton:SetPoint ("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 6 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing)
1317 end
1318
1319 --> points
1320
1321 if (CoolTip.OptionsTable.YSpacingMod and not CoolTip.OptionsTable.IgnoreButtonAutoHeight) then
1322 spacing = spacing + CoolTip.OptionsTable.YSpacingMod
1323 end
1324
1325 menuButton:EnableMouse (false)
1326 end
1327
1328 if (not CoolTip.OptionsTable.FixedWidth) then
1329 if (CoolTip.Type == 2) then --> with bars
1330 if (CoolTip.OptionsTable.MinWidth) then
1331 local w = frame1.w + 34
1332 frame1:SetWidth (math.max (w, CoolTip.OptionsTable.MinWidth))
1333 else
1334 frame1:SetWidth (frame1.w + 34)
1335 end
1336 else
1337 --> width stability check
1338 local width = frame1.w + 24
1339 if (width > CoolTip.LastSize-5 and width < CoolTip.LastSize+5) then
1340 width = CoolTip.LastSize
1341 else
1342 CoolTip.LastSize = width
1343 end
1344
1345 if (CoolTip.OptionsTable.MinWidth) then
1346 frame1:SetWidth (math.max (width, CoolTip.OptionsTable.MinWidth))
1347 else
1348 frame1:SetWidth (width)
1349 end
1350 end
1351 end
1352
1353 if (CoolTip.OptionsTable.FixedHeight) then
1354 frame1:SetHeight (CoolTip.OptionsTable.FixedHeight)
1355 else
1356 if (CoolTip.OptionsTable.AlignAsBlizzTooltip) then
1357 frame1:SetHeight ( (temp-10) * -1)
1358 elseif (CoolTip.OptionsTable.IgnoreButtonAutoHeight) then
1359 frame1:SetHeight ( (temp+spacing) * -1)
1360 else
1361 frame1:SetHeight ( _math_max ( (frame1.hHeight * CoolTip.Indexes) + 12, 22 ))
1362 end
1363 end
1364
1365 if (CoolTip.WallpaperTable [1]) then
1366 CoolTip:SetupWallpaper (CoolTip.WallpaperTable, frame1.frameWallpaper)
1367 else
1368 frame1.frameWallpaper:Hide()
1369 end
1370
1371 --> unhide frame
1372 DF:Fade (frame1, 0)
1373 CoolTip:SetMyPoint (host)
1374
1375 --> fix sparks
1376 for i = 1, CoolTip.Indexes do
1377 local menuButton = frame1.Lines [i]
1378 if (menuButton.spark:IsShown() or menuButton.spark2:IsShown()) then
1379 CoolTip:RefreshSpark (menuButton)
1380 end
1381 end
1382 end
1383
1384 function CoolTip:CreateDivBar (button)
1385 button.divbar = button:CreateTexture (nil, "overlay")
1386
1387 button.divbar:SetTexture ([[Interface\QUESTFRAME\AutoQuest-Parts]])
1388 button.divbar:SetTexCoord (238/512, 445/512, 0/64, 4/64)
1389
1390 button.divbar:SetHeight (3)
1391 button.divbar:SetAlpha (0.1)
1392
1393 button.divbar:SetDesaturated (true)
1394 end
1395
1396 --> ~inicio ~start
1397 function CoolTip:monta_cooltip (host, instancia, options, sub_menus, icones, tamanho1, tamanho2, font, fontsize)
1398
1399 if (CoolTip.Indexes == 0) then
1400 CoolTip:Reset()
1401 CoolTip:SetType ("tooltip")
1402 CoolTip:AddLine ("There is no options.")
1403 CoolTip:ShowCooltip()
1404 return
1405 end
1406
1407 if (CoolTip.OptionsTable.FixedWidth) then
1408 frame1:SetWidth (CoolTip.OptionsTable.FixedWidth)
1409 end
1410
1411 frame1.w = CoolTip.OptionsTable.FixedWidth or 0
1412 frame1.hHeight = 0
1413 frame2.hHeight = 0
1414
1415 frame1:EnableMouse (true)
1416
1417 if (CoolTip.HaveSubMenu) then --> zera o segundo frame
1418 frame2.w = 0
1419 frame2:SetHeight (6)
1420 if (CoolTip.SelectedIndexMain and CoolTip.IndexesSub [CoolTip.SelectedIndexMain] and CoolTip.IndexesSub [CoolTip.SelectedIndexMain] > 0) then
1421 DF:Fade (frame2, 0)
1422 else
1423 DF:Fade (frame2, 1)
1424 end
1425 else
1426 DF:Fade (frame2, 1)
1427 end
1428
1429 CoolTip.active = true
1430
1431 for i = 1, CoolTip.Indexes do
1432 local menuButton = frame1.Lines [i]
1433 if (not menuButton) then
1434 menuButton = CoolTip:NewMainButton (i)
1435 end
1436
1437 CoolTip:SetupMainButton (menuButton, i)
1438
1439 menuButton.background:Hide()
1440 end
1441
1442 --> selected texture
1443 if (CoolTip.SelectedIndexMain) then
1444 CoolTip:SetSelectedAnchor (frame1, frame1.Lines [CoolTip.SelectedIndexMain])
1445
1446 if (CoolTip.OptionsTable.NoLastSelectedBar) then
1447 CoolTip:HideSelectedTexture (frame1)
1448 else
1449 CoolTip:ShowSelectedTexture (frame1)
1450 end
1451 else
1452 CoolTip:HideSelectedTexture (frame1)
1453 end
1454
1455 if (CoolTip.Indexes < #frame1.Lines) then
1456 for i = CoolTip.Indexes+1, #frame1.Lines do
1457 frame1.Lines[i]:Hide()
1458 end
1459 end
1460
1461 CoolTip.NumLines = CoolTip.Indexes
1462
1463 local spacing = 0
1464 if (CoolTip.OptionsTable.YSpacingMod) then
1465 spacing = CoolTip.OptionsTable.YSpacingMod
1466 end
1467
1468 if (not CoolTip.OptionsTable.FixedWidth) then
1469 if (CoolTip.OptionsTable.MinWidth) then
1470 local w = frame1.w + 24
1471 frame1:SetWidth (math.max (w, CoolTip.OptionsTable.MinWidth))
1472 else
1473 frame1:SetWidth (frame1.w + 24)
1474 end
1475 end
1476
1477 --> normalize height of all rows
1478 for i = 1, CoolTip.Indexes do
1479 local menuButton = frame1.Lines [i]
1480 menuButton:EnableMouse (true)
1481
1482 if (menuButton.leftText:GetText() == "$div") then
1483
1484 --> height
1485 menuButton:SetHeight (4)
1486 --> points
1487 menuButton:ClearAllPoints()
1488 menuButton:SetPoint ("left", frame1, "left")
1489 menuButton:SetPoint ("right", frame1, "right")
1490 menuButton:SetPoint ("center", frame1, "center")
1491
1492 local div_size_up = tonumber (CoolTip.LeftTextTable [i] [2])
1493 if (not div_size_up) then
1494 div_size_up = 0
1495 end
1496 local div_size_down = tonumber (CoolTip.LeftTextTable [i] [3])
1497 if (not div_size_down) then
1498 div_size_down = 0
1499 end
1500
1501 menuButton:SetPoint ("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing - 4 + div_size_up)
1502 if (CoolTip.OptionsTable.YSpacingMod) then
1503 spacing = spacing + CoolTip.OptionsTable.YSpacingMod
1504 end
1505
1506 spacing = spacing + 4 + div_size_down
1507
1508 menuButton.leftText:SetText ("")
1509 menuButton.isDiv = true
1510
1511 if (not menuButton.divbar) then
1512 CoolTip:CreateDivBar (menuButton)
1513 else
1514 menuButton.divbar:Show()
1515 end
1516
1517 menuButton.divbar:SetPoint ("left", menuButton, "left", frame1:GetWidth()*0.10, 0)
1518 menuButton.divbar:SetPoint ("right", menuButton, "right", -frame1:GetWidth()*0.10, 0)
1519
1520 else
1521
1522 --> height
1523 menuButton:SetHeight (frame1.hHeight + (CoolTip.OptionsTable.ButtonHeightMod or 0))
1524 --> points
1525 menuButton:ClearAllPoints()
1526 menuButton:SetPoint ("center", frame1, "center")
1527 menuButton:SetPoint ("top", frame1, "top", 0, ( ( (i-1) * frame1.hHeight) * -1) - 4 + (CoolTip.OptionsTable.ButtonsYMod or 0) + spacing)
1528 if (CoolTip.OptionsTable.YSpacingMod) then
1529 spacing = spacing + CoolTip.OptionsTable.YSpacingMod
1530 end
1531 menuButton:SetPoint ("left", frame1, "left")
1532 menuButton:SetPoint ("right", frame1, "right")
1533
1534 if (menuButton.divbar) then
1535 menuButton.divbar:Hide()
1536 menuButton.isDiv = false
1537 end
1538 end
1539
1540 end
1541
1542 if (CoolTip.OptionsTable.FixedHeight) then
1543 frame1:SetHeight (CoolTip.OptionsTable.FixedHeight)
1544 else
1545 local mod = CoolTip.OptionsTable.HeighMod or 0
1546 frame1:SetHeight (_math_max ( (frame1.hHeight * CoolTip.Indexes) + 12 + (-spacing) + mod, 22 ))
1547 end
1548
1549 --> sub menu arrows
1550 if (CoolTip.HaveSubMenu and not CoolTip.OptionsTable.IgnoreArrows and not CoolTip.OptionsTable.SubMenuIsTooltip) then
1551 for i = 1, CoolTip.Indexes do
1552 if (CoolTip.IndexesSub [i] and CoolTip.IndexesSub [i] > 0) then
1553 frame1.Lines [i].statusbar.subMenuArrow:Show()
1554 else
1555 frame1.Lines [i].statusbar.subMenuArrow:Hide()
1556 end
1557 end
1558
1559 frame1:SetWidth (frame1:GetWidth() + 16)
1560 end
1561
1562 frame1:ClearAllPoints()
1563 CoolTip:SetMyPoint (host)
1564
1565 if (CoolTip.title1) then
1566 CoolTip.frame1.titleText:Show()
1567 CoolTip.frame1.titleIcon:Show()
1568 CoolTip.frame1.titleText:SetText (CoolTip.title_text)
1569 CoolTip.frame1.titleIcon:SetWidth (frame1:GetWidth())
1570 CoolTip.frame1.titleIcon:SetHeight (40)
1571 end
1572
1573 if (CoolTip.WallpaperTable [1]) then
1574 CoolTip:SetupWallpaper (CoolTip.WallpaperTable, frame1.frameWallpaper)
1575 else
1576 frame1.frameWallpaper:Hide()
1577 end
1578
1579 DF:Fade (frame1, 0)
1580
1581 for i = 1, CoolTip.Indexes do
1582 if (CoolTip.SelectedIndexMain and CoolTip.SelectedIndexMain == i) then
1583 if (CoolTip.HaveSubMenu and CoolTip.IndexesSub [i] and CoolTip.IndexesSub [i] > 0) then
1584 CoolTip:ShowSub (i)
1585 end
1586 end
1587 end
1588
1589 return true
1590 end
1591
1592 function CoolTip:SetMyPoint (host, x_mod, y_mod)
1593
1594 local moveX = x_mod or 0
1595 local moveY = y_mod or 0
1596
1597 --> clear all points
1598 frame1:ClearAllPoints()
1599
1600 local anchor = CoolTip.OptionsTable.Anchor or CoolTip.Host
1601 frame1:SetPoint (CoolTip.OptionsTable.MyAnchor, anchor, CoolTip.OptionsTable.RelativeAnchor, 0 + moveX + CoolTip.OptionsTable.WidthAnchorMod, 10 + CoolTip.OptionsTable.HeightAnchorMod + moveY)
1602
1603 if (not x_mod) then
1604 --> check if cooltip is out of screen bounds
1605 local center_x = frame1:GetCenter()
1606
1607 if (center_x) then
1608 local screen_x_res = GetScreenWidth()
1609 local half_x = frame1:GetWidth() / 2
1610
1611 if (center_x+half_x > screen_x_res) then
1612 --> out of right side
1613 local move_to_left = (center_x + half_x) - screen_x_res
1614 CoolTip.internal_x_mod = -move_to_left
1615 return CoolTip:SetMyPoint (host, -move_to_left, 0)
1616
1617 elseif (center_x-half_x < 0) then
1618 --> out of left side
1619 local move_to_right = center_x - half_x
1620 CoolTip.internal_x_mod = move_to_right*-1
1621 return CoolTip:SetMyPoint (host, move_to_right*-1, 0)
1622 end
1623 end
1624 end
1625
1626 if (not y_mod) then
1627 --> check if cooltip is out of screen bounds
1628 local _, center_y = frame1:GetCenter()
1629 local screen_y_res = GetScreenHeight()
1630 local half_y = frame1:GetHeight() / 2
1631
1632 if (center_y) then
1633 if (center_y+half_y > screen_y_res) then
1634 --> out of top side
1635 local move_to_down = (center_y + half_y) - screen_y_res
1636 CoolTip.internal_y_mod = -move_to_down
1637 return CoolTip:SetMyPoint (host, 0, -move_to_down)
1638
1639 elseif (center_y-half_y < 0) then
1640 --> out of bottom side
1641 local move_to_up = center_y - half_y
1642 CoolTip.internal_y_mod = move_to_up*-1
1643 return CoolTip:SetMyPoint (host, 0, move_to_up*-1)
1644
1645 end
1646 end
1647 end
1648
1649 if (frame2:IsShown() and not CoolTip.overlap_checked) then
1650
1651 local frame_2_center_x = frame2:GetCenter()
1652 if (frame_2_center_x) then
1653 local frame_2_half_x = frame2:GetWidth() / 2
1654
1655 local frame_1_center_x = frame1:GetCenter()
1656 if (frame_1_center_x) then
1657
1658 local frame_1_half_x = frame1:GetWidth() / 2
1659
1660 local f1_end_point = frame_1_center_x + frame_1_half_x - 3
1661 local f2_start_point = frame_2_center_x - frame_2_half_x
1662
1663 if (f2_start_point < f1_end_point) then
1664 local diff = f2_start_point - f1_end_point
1665 CoolTip.overlap_checked = true
1666
1667 frame2:ClearAllPoints()
1668 frame2:SetPoint ("bottomright", frame1, "bottomleft")
1669 CoolTip.frame2_leftside = true
1670 --> diff
1671 return CoolTip:SetMyPoint (host, CoolTip.internal_x_mod , CoolTip.internal_y_mod)
1672 end
1673
1674 end
1675 end
1676
1677 end
1678
1679 end
1680
1681 function CoolTip:CheckOverlap()
1682 if (frame2:IsShown()) then
1683
1684 local frame_2_center_x = frame2:GetCenter()
1685 if (frame_2_center_x) then
1686 local frame_2_half_x = frame2:GetWidth() / 2
1687
1688 local frame_1_center_x = frame1:GetCenter()
1689 if (frame_1_center_x) then
1690
1691 local frame_1_half_x = frame1:GetWidth() / 2
1692
1693 local f1_end_point = frame_1_center_x + frame_1_half_x - 3
1694 local f2_start_point = frame_2_center_x - frame_2_half_x
1695
1696 if (f2_start_point < f1_end_point) then
1697 local diff = f2_start_point - f1_end_point
1698
1699 frame2:ClearAllPoints()
1700 frame2:SetPoint ("bottomright", frame1, "bottomleft")
1701 CoolTip.frame2_leftside = true
1702 end
1703
1704 end
1705 end
1706
1707 end
1708 end
1709
1710 function CoolTip:GetText (buttonIndex)
1711 local button1 = frame1.Lines [buttonIndex]
1712 if (not button1) then
1713 return "", ""
1714 else
1715 return button1.leftText:GetText() or "", button1.rightText:GetText() or ""
1716 end
1717 end
1718
1719 ----------------------------------------------------------------------
1720 --> Get the number of lines current shown on cooltip
1721
1722 function CoolTip:GetNumLines()
1723 return CoolTip.NumLines or 0
1724 end
1725
1726 ----------------------------------------------------------------------
1727 --> Remove all options actived
1728 --> Set a option on current cooltip
1729
1730 function CoolTip:ClearAllOptions()
1731 for option, _ in pairs (CoolTip.OptionsTable) do
1732 CoolTip.OptionsTable [option] = nil
1733 end
1734
1735 CoolTip:SetOption ("MyAnchor", "bottom")
1736 CoolTip:SetOption ("RelativeAnchor", "top")
1737 CoolTip:SetOption ("WidthAnchorMod", 0)
1738 CoolTip:SetOption ("HeightAnchorMod", 0)
1739 end
1740
1741 function CoolTip:SetOption (option, value)
1742 --> check if this options exists
1743 if (not CoolTip.OptionsList [option]) then
1744 return --> error
1745 end
1746
1747 --> set options
1748 CoolTip.OptionsTable [option] = value
1749 end
1750
1751 ----------------------------------------------------------------------
1752 --> set the anchor of cooltip
1753 --> parameters: frame [, cooltip anchor point, frame anchor point [, x mod, y mod]]
1754 --> frame [, x mod, y mod]
1755
1756 --> alias
1757 function CoolTip:GetOwner()
1758 return CoolTip.Host
1759 end
1760
1761 function CoolTip:SetOwner (frame, myPoint, hisPoint, x, y)
1762 return CoolTip:SetHost (frame, myPoint, hisPoint, x, y)
1763 end
1764
1765 function CoolTip:SetHost (frame, myPoint, hisPoint, x, y)
1766 --> check data integrity
1767 if (type (frame) ~= "table" or not frame.GetObjectType) then
1768 print ("host need to be a frame")
1769 return --> error
1770 end
1771
1772 CoolTip.Host = frame
1773
1774 CoolTip.frame1:SetFrameLevel (frame:GetFrameLevel()+1)
1775
1776 --> defaults
1777 myPoint = myPoint or CoolTip.OptionsTable.MyAnchor or "bottom"
1778 hisPoint = hisPoint or CoolTip.OptionsTable.hisPoint or "top"
1779
1780 x = x or CoolTip.OptionsTable.WidthAnchorMod or 0
1781 y = y or CoolTip.OptionsTable.HeightAnchorMod or 0
1782
1783 --> check options
1784 if (type (myPoint) == "string") then
1785 CoolTip:SetOption ("MyAnchor", myPoint)
1786 CoolTip:SetOption ("WidthAnchorMod", x)
1787 elseif (type (myPoint) == "number") then
1788 CoolTip:SetOption ("HeightAnchorMod", myPoint)
1789 end
1790
1791 if (type (hisPoint) == "string") then
1792 CoolTip:SetOption ("RelativeAnchor", hisPoint)
1793 CoolTip:SetOption ("HeightAnchorMod", y)
1794 elseif (type (hisPoint) == "number") then
1795 CoolTip:SetOption ("WidthAnchorMod", hisPoint)
1796 end
1797 end
1798
1799 ----------------------------------------------------------------------
1800 --> set cooltip type
1801 --> parameters: type (1 = tooltip | 2 = tooltip with bars | 3 = menu)
1802
1803 function CoolTip:IsMenu()
1804 return CoolTip.frame1:IsShown() and CoolTip.Type == 3
1805 end
1806
1807 function CoolTip:IsTooltip()
1808 return CoolTip.frame1:IsShown() and (CoolTip.Type == 1 or CoolTip.Type == 2)
1809 end
1810
1811 function CoolTip:GetType()
1812 if (CoolTip.Type == 1 or CoolTip.Type == 2) then
1813 return "tooltip"
1814 elseif (CoolTip.Type == 3) then
1815 return "menu"
1816 else
1817 return "none"
1818 end
1819 end
1820
1821 function CoolTip:SetType (newType)
1822 if (type (newType) == "string") then
1823 if (newType == "tooltip") then
1824 CoolTip.Type = 1
1825 elseif (newType == "tooltipbar") then
1826 CoolTip.Type = 2
1827 elseif (newType == "menu") then
1828 CoolTip.Type = 3
1829 else
1830 --> error
1831 end
1832 elseif (type (newType) == "number") then
1833 if (newType == 1) then
1834 CoolTip.Type = 1
1835 elseif (newType == 2) then
1836 CoolTip.Type = 2
1837 elseif (newType == 3) then
1838 CoolTip.Type = 3
1839 else
1840 --> error
1841 end
1842 else
1843 --> error
1844 end
1845 end
1846
1847 --> Set a fixed value for menu
1848 function CoolTip:SetFixedParameter (value, injected)
1849 if (injected ~= nil) then
1850 local frame = value
1851 if (frame.dframework) then
1852 frame = frame.widget
1853 end
1854 if (frame.CoolTip) then
1855 frame.CoolTip.FixedValue = injected
1856 else
1857 --debug
1858 end
1859 end
1860 CoolTip.FixedValue = value
1861 end
1862
1863 function CoolTip:SetColor (menuType, ...)
1864 local ColorR, ColorG, ColorB, ColorA = DF:ParseColors (...)
1865 if ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1)) then
1866 frame1.framebackgroundLeft:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
1867 frame1.framebackgroundRight:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
1868 frame1.framebackgroundCenter:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
1869
1870 elseif ((type (menuType) == "string" and menuType == "sec") or (type (menuType) == "number" and menuType == 2)) then
1871 frame2.framebackgroundLeft:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
1872 frame2.framebackgroundRight:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
1873 frame2.framebackgroundCenter:SetVertexColor (ColorR, ColorG, ColorB, ColorA)
1874
1875 else
1876 return --> error
1877 end
1878 end
1879
1880 --> Set last selected option
1881 function CoolTip:SetLastSelected (menuType, index, index2)
1882
1883 if (CoolTip.Type == 3) then
1884 if ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1)) then
1885 CoolTip.SelectedIndexMain = index
1886 elseif ((type (menuType) == "string" and menuType == "sec") or (type (menuType) == "number" and menuType == 2)) then
1887 CoolTip.SelectedIndexSec [index] = index2
1888 else
1889 return --> error
1890 end
1891 else
1892 return --> error
1893 end
1894 end
1895
1896 --> serack key: ~select
1897 function CoolTip:Select (menuType, option, mainIndex)
1898 if (menuType == 1) then --main menu
1899 local botao = frame1.Lines [option]
1900 CoolTip.buttonClicked = true
1901 CoolTip:SetSelectedAnchor (frame1, botao)
1902
1903 --UIFrameFlash (frame1.selected, 0.05, 0.05, 0.2, true, 0, 0)
1904
1905 elseif (menuType == 2) then --sub menu
1906 CoolTip:ShowSub (mainIndex)
1907 local botao = frame2.Lines [option]
1908 CoolTip.buttonClicked = true
1909
1910 CoolTip:SetSelectedAnchor (frame2, botao)
1911 end
1912 end
1913
1914 ----------------------------------------------------------------------
1915 --> Reset cooltip
1916
1917 local default_backdrop = {bgFile=[[Interface\DialogFrame\UI-DialogBox-Background-Dark]], edgeFile=[[Interface\Tooltips\UI-Tooltip-Border]], tile=true,
1918 edgeSize=16, tileSize=16, insets = {left=3, right=3, top=4, bottom=4}}
1919 local default_backdrop_color = {0.09019, 0.09019, 0.18823, 1}
1920 local default_backdropborder_color = {1, 1, 1, 1}
1921
1922 --borda preta sem usar unpack
1923
1924 --> wipe all data ~reset
1925 function CoolTip:Reset()
1926
1927 frame2:ClearAllPoints()
1928 frame2:SetPoint ("bottomleft", frame1, "bottomright")
1929
1930 CoolTip:HideSelectedTexture (frame1)
1931 CoolTip:HideSelectedTexture (frame2)
1932
1933 CoolTip.FixedValue = nil
1934 CoolTip.HaveSubMenu = false
1935
1936 CoolTip.SelectedIndexMain = nil
1937 _table_wipe (CoolTip.SelectedIndexSec)
1938
1939 CoolTip.Indexes = 0
1940 CoolTip.SubIndexes = 0
1941 _table_wipe (CoolTip.IndexesSub)
1942
1943 CoolTip.internal_x_mod = 0
1944 CoolTip.internal_y_mod = 0
1945 CoolTip.current_anchor = nil
1946 CoolTip.overlap_checked = false
1947
1948 CoolTip.frame2_leftside = nil
1949
1950 frame1:SetBackdrop (default_backdrop)
1951 frame1:SetBackdropColor (unpack (default_backdrop_color))
1952 frame1:SetBackdropBorderColor (unpack (default_backdropborder_color))
1953
1954 frame2:SetBackdrop (default_backdrop)
1955 frame2:SetBackdropColor (unpack (default_backdrop_color))
1956 frame2:SetBackdropBorderColor (unpack (default_backdropborder_color))
1957
1958 --[
1959 _table_wipe (CoolTip.LeftTextTable)
1960 _table_wipe (CoolTip.LeftTextTableSub)
1961 _table_wipe (CoolTip.RightTextTable)
1962 _table_wipe (CoolTip.RightTextTableSub)
1963
1964 _table_wipe (CoolTip.LeftIconTable)
1965 _table_wipe (CoolTip.LeftIconTableSub)
1966 _table_wipe (CoolTip.RightIconTable)
1967 _table_wipe (CoolTip.RightIconTableSub)
1968
1969 _table_wipe (CoolTip.StatusBarTable)
1970 _table_wipe (CoolTip.StatusBarTableSub)
1971
1972 _table_wipe (CoolTip.FunctionsTableMain)
1973 _table_wipe (CoolTip.FunctionsTableSub)
1974
1975 _table_wipe (CoolTip.ParametersTableMain)
1976 _table_wipe (CoolTip.ParametersTableSub)
1977
1978 _table_wipe (CoolTip.WallpaperTable)
1979 _table_wipe (CoolTip.WallpaperTableSub)
1980 --]]
1981
1982 _table_wipe (CoolTip.TopIconTableSub)
1983 CoolTip.Banner [1] = false
1984 CoolTip.Banner [2] = false
1985 CoolTip.Banner [3] = false
1986
1987 frame1.upperImage:Hide()
1988 frame1.upperImage2:Hide()
1989 frame1.upperImageText:Hide()
1990 frame1.upperImageText2:Hide()
1991
1992 frame1.frameWallpaper:Hide()
1993 frame2.frameWallpaper:Hide()
1994
1995 frame2.upperImage:Hide()
1996
1997 CoolTip.title1 = nil
1998 CoolTip.title_text = nil
1999
2000 CoolTip.frame1.titleText:Hide()
2001 CoolTip.frame1.titleIcon:Hide()
2002
2003 CoolTip:ClearAllOptions()
2004 CoolTip:SetColor (1, "transparent")
2005 CoolTip:SetColor (2, "transparent")
2006
2007 local f1Lines = frame1.Lines
2008 for i = 1, #f1Lines do
2009 f1Lines [i].statusbar.subMenuArrow:Hide()
2010 end
2011 end
2012
2013 ----------------------------------------------------------------------
2014 --> Menu functions
2015
2016 local _default_color = {1, 1, 1}
2017 local _default_point = {"center", "center", 0, -3}
2018
2019 function CoolTip:AddMenu (menuType, func, param1, param2, param3, leftText, leftIcon, indexUp)
2020
2021 if (leftText and indexUp and ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1))) then
2022 CoolTip.Indexes = CoolTip.Indexes + 1
2023
2024 if (not CoolTip.IndexesSub [CoolTip.Indexes]) then
2025 CoolTip.IndexesSub [CoolTip.Indexes] = 0
2026 end
2027
2028 CoolTip.SubIndexes = 0
2029 end
2030
2031 --> need a previous line
2032 if (CoolTip.Indexes == 0) then
2033 print ("Indexes are 0")
2034 return --> return error
2035 end
2036
2037 --> check data integrity
2038 if (type (func) ~= "function") then
2039 print ("No function")
2040 return --> erroe
2041 end
2042
2043 --> add
2044
2045 if ((type (menuType) == "string" and menuType == "main") or (type (menuType) == "number" and menuType == 1)) then
2046
2047 local parameterTable
2048 if (CoolTip.isSpecial) then
2049 parameterTable = {}
2050 _table_insert (CoolTip.FunctionsTableMain, CoolTip.Indexes, func)
2051 _table_insert (CoolTip.ParametersTableMain, CoolTip.Indexes, parameterTable)
2052 else
2053
2054 CoolTip.FunctionsTableMain [CoolTip.Indexes] = func
2055
2056 parameterTable = CoolTip.ParametersTableMain [CoolTip.Indexes]
2057 if (not parameterTable) then
2058 parameterTable = {}
2059 CoolTip.ParametersTableMain [CoolTip.Indexes] = parameterTable
2060 end
2061 end
2062
2063 parameterTable [1] = param1
2064 parameterTable [2] = param2
2065 parameterTable [3] = param3
2066
2067 if (leftIcon) then
2068 local iconTable = CoolTip.LeftIconTable [CoolTip.Indexes]
2069
2070 if (not iconTable or CoolTip.isSpecial) then
2071 iconTable = {}
2072 CoolTip.LeftIconTable [CoolTip.Indexes] = iconTable
2073 end
2074
2075 iconTable [1] = leftIcon
2076 iconTable [2] = 16 --> default 16
2077 iconTable [3] = 16 --> default 16
2078 iconTable [4] = 0 --> default 0
2079 iconTable [5] = 1 --> default 1
2080 iconTable [6] = 0 --> default 0
2081 iconTable [7] = 1 --> default 1
2082 iconTable [8] = _default_color
2083 end
2084
2085 if (leftText) then
2086 local lineTable_left = CoolTip.LeftTextTable [CoolTip.Indexes]
2087
2088 if (not lineTable_left or CoolTip.isSpecial) then
2089 lineTable_left = {}
2090 CoolTip.LeftTextTable [CoolTip.Indexes] = lineTable_left
2091 end
2092
2093 lineTable_left [1] = leftText --> line text
2094 lineTable_left [2] = 0
2095 lineTable_left [3] = 0
2096 lineTable_left [4] = 0
2097 lineTable_left [5] = 0
2098 lineTable_left [6] = false
2099 lineTable_left [7] = false
2100 lineTable_left [8] = false
2101
2102 end
2103
2104 elseif ((type (menuType) == "string" and menuType == "sec") or (type (menuType) == "number" and menuType == 2)) then
2105
2106 if (CoolTip.SubIndexes == 0) then
2107 if (not indexUp or not leftText) then
2108 print ("not indexUp or not leftText")
2109 return --> error
2110 end
2111 end
2112
2113 if (indexUp and leftText) then
2114 CoolTip.SubIndexes = CoolTip.SubIndexes + 1
2115 CoolTip.IndexesSub [CoolTip.Indexes] = CoolTip.IndexesSub [CoolTip.Indexes] + 1
2116 elseif (indexUp and not leftText) then
2117 print ("indexUp and not leftText")
2118 return --> error [leftText can't be nil if indexUp are true]
2119 end
2120
2121 --> menu container
2122 local subMenuContainerParameters = CoolTip.ParametersTableSub [CoolTip.Indexes]
2123 if (not subMenuContainerParameters) then
2124 subMenuContainerParameters = {}
2125 CoolTip.ParametersTableSub [CoolTip.Indexes] = subMenuContainerParameters
2126 end
2127
2128 local subMenuContainerFunctions = CoolTip.FunctionsTableSub [CoolTip.Indexes]
2129 if (not subMenuContainerFunctions or CoolTip.isSpecial) then
2130 subMenuContainerFunctions = {}
2131 CoolTip.FunctionsTableSub [CoolTip.Indexes] = subMenuContainerFunctions
2132 end
2133
2134 --> menu table
2135 local subMenuTablesParameters = subMenuContainerParameters [CoolTip.SubIndexes]
2136 if (not subMenuTablesParameters or CoolTip.isSpecial) then
2137 subMenuTablesParameters = {}
2138 subMenuContainerParameters [CoolTip.SubIndexes] = subMenuTablesParameters
2139 end
2140
2141 --> add
2142 subMenuContainerFunctions [CoolTip.SubIndexes] = func
2143
2144 subMenuTablesParameters [1] = param1
2145 subMenuTablesParameters [2] = param2
2146 subMenuTablesParameters [3] = param3
2147
2148 --> text and icon
2149 if (leftIcon) then
2150
2151 local subMenuContainerIcons = CoolTip.LeftIconTableSub [CoolTip.Indexes]
2152 if (not subMenuContainerIcons) then
2153 subMenuContainerIcons = {}
2154 CoolTip.LeftIconTableSub [CoolTip.Indexes] = subMenuContainerIcons
2155 end
2156 local subMenuTablesIcons = subMenuContainerIcons [CoolTip.SubIndexes]
2157 if (not subMenuTablesIcons or CoolTip.isSpecial) then
2158 subMenuTablesIcons = {}
2159 subMenuContainerIcons [CoolTip.SubIndexes] = subMenuTablesIcons
2160 end
2161
2162 subMenuTablesIcons [1] = leftIcon
2163 subMenuTablesIcons [2] = 16 --> default 16
2164 subMenuTablesIcons [3] = 16 --> default 16
2165 subMenuTablesIcons [4] = 0 --> default 0
2166 subMenuTablesIcons [5] = 1 --> default 1
2167 subMenuTablesIcons [6] = 0 --> default 0
2168 subMenuTablesIcons [7] = 1 --> default 1
2169 subMenuTablesIcons [8] = _default_color
2170 end
2171
2172 if (leftText) then
2173
2174 local subMenuContainerTexts = CoolTip.LeftTextTableSub [CoolTip.Indexes]
2175 if (not subMenuContainerTexts) then
2176 subMenuContainerTexts = {}
2177 CoolTip.LeftTextTableSub [CoolTip.Indexes] = subMenuContainerTexts
2178 end
2179 local subMenuTablesTexts = subMenuContainerTexts [CoolTip.SubIndexes]
2180 if (not subMenuTablesTexts or CoolTip.isSpecial) then
2181 subMenuTablesTexts = {}
2182 subMenuContainerTexts [CoolTip.SubIndexes] = subMenuTablesTexts
2183 end
2184
2185 subMenuTablesTexts [1] = leftText --> line text
2186 subMenuTablesTexts [2] = 0
2187 subMenuTablesTexts [3] = 0
2188 subMenuTablesTexts [4] = 0
2189 subMenuTablesTexts [5] = 0
2190 subMenuTablesTexts [6] = false
2191 subMenuTablesTexts [7] = false
2192 subMenuTablesTexts [8] = false
2193
2194 end
2195
2196 CoolTip.HaveSubMenu = true
2197
2198 else
2199 return --> error
2200 end
2201 end
2202
2203 ----------------------------------------------------------------------
2204 --> adds a statusbar to the last line added.
2205 --> only works with cooltip type 2 (tooltip with bars)
2206 --> parameters: value [, color red, color green, color blue, color alpha [, glow]]
2207 --> can also use a table or html color name in color red and send glow in color green
2208
2209 function CoolTip:AddStatusBar (statusbarValue, frame, ColorR, ColorG, ColorB, ColorA, statusbarGlow, backgroundBar)
2210
2211 --> need a previous line
2212 if (CoolTip.Indexes == 0) then
2213 return --> return error
2214 end
2215
2216 --> check data integrity
2217 if (type (statusbarValue) ~= "number") then
2218 return --> error
2219 end
2220
2221 if (type (ColorR) == "table" or type (ColorR) == "string") then
2222 statusbarGlow, backgroundBar, ColorR, ColorG, ColorB, ColorA = ColorG, ColorB, DF:ParseColors (ColorR)
2223 elseif (type (ColorR) == "boolean") then
2224 backgroundBar = ColorG
2225 statusbarGlow = ColorR
2226 ColorR, ColorG, ColorB, ColorA = 1, 1, 1, 1
2227 else
2228 --> error
2229 end
2230
2231 --> add
2232 local frameTable
2233 local statusbarTable
2234
2235 if (not frame or (type (frame) == "string" and frame == "main") or (type (frame) == "number" and frame == 1)) then
2236 frameTable = CoolTip.StatusBarTable
2237
2238 if (CoolTip.isSpecial) then
2239 statusbarTable = {}
2240 _table_insert (frameTable, CoolTip.Indexes, statusbarTable)
2241 else
2242 statusbarTable = frameTable [CoolTip.Indexes]
2243 if (not statusbarTable) then
2244 statusbarTable = {}
2245 _table_insert (frameTable, CoolTip.Indexes, statusbarTable)
2246 --frameTable [CoolTip.Indexes] = statusbarTable
2247 end
2248 end
2249
2250 elseif ((type (frame) == "string" and frame == "sub") or (type (frame) == "number" and frame == 2)) then
2251
2252 frameTable = CoolTip.StatusBarTableSub
2253
2254 local subMenuContainerStatusBar = frameTable [CoolTip.Indexes]
2255 if (not subMenuContainerStatusBar) then
2256 subMenuContainerStatusBar = {}
2257 frameTable [CoolTip.Indexes] = subMenuContainerStatusBar
2258 end
2259
2260 if (CoolTip.isSpecial) then
2261 statusbarTable = {}
2262 _table_insert (subMenuContainerStatusBar, CoolTip.SubIndexes, statusbarTable)
2263 else
2264 statusbarTable = subMenuContainerStatusBar [CoolTip.SubIndexes]
2265 if (not statusbarTable) then
2266 statusbarTable = {}
2267 _table_insert (subMenuContainerStatusBar, CoolTip.SubIndexes, statusbarTable)
2268 end
2269 end
2270 else
2271 print ("unknow frame")
2272 return --> error
2273 end
2274
2275 statusbarTable [1] = statusbarValue
2276 statusbarTable [2] = ColorR
2277 statusbarTable [3] = ColorG
2278 statusbarTable [4] = ColorB
2279 statusbarTable [5] = ColorA
2280 statusbarTable [6] = statusbarGlow
2281 statusbarTable [7] = backgroundBar
2282
2283 end
2284
2285 frame1.frameWallpaper:Hide()
2286 frame2.frameWallpaper:Hide()
2287
2288 function CoolTip:SetWallpaper (index, texture, texcoord, color, desaturate)
2289
2290 if (CoolTip.Indexes == 0) then
2291 return --> return error
2292 end
2293
2294 local frameTable
2295 local wallpaperTable
2296
2297 if ( (type (index) == "number" and index == 1) or (type (index) == "string" and index == "main") ) then
2298 wallpaperTable = CoolTip.WallpaperTable
2299
2300 elseif ( (type (index) == "number" and index == 2) or (type (index) == "string" and index == "sub") ) then
2301 frameTable = CoolTip.WallpaperTableSub
2302
2303 local subMenuContainerWallpapers = frameTable [CoolTip.Indexes]
2304 if (not subMenuContainerWallpapers) then
2305 subMenuContainerWallpapers = {}
2306 frameTable [CoolTip.Indexes] = subMenuContainerWallpapers
2307 end
2308
2309 wallpaperTable = subMenuContainerWallpapers
2310 end
2311
2312 wallpaperTable [1] = texture
2313 if (texcoord) then
2314 wallpaperTable [2] = texcoord [1]
2315 wallpaperTable [3] = texcoord [2]
2316 wallpaperTable [4] = texcoord [3]
2317 wallpaperTable [5] = texcoord [4]
2318 else
2319 wallpaperTable [2] = 0
2320 wallpaperTable [3] = 1
2321 wallpaperTable [4] = 0
2322 wallpaperTable [5] = 1
2323 end
2324 wallpaperTable [6] = color
2325 wallpaperTable [7] = desaturate
2326 end
2327
2328 function CoolTip:SetBannerText (index, text, anchor, color, fontsize, fontface, fontflag)
2329 local fontstring
2330
2331 if (index == 1) then
2332 fontstring = frame1.upperImageText
2333 elseif (index == 2) then
2334 fontstring = frame1.upperImageText2
2335 end
2336
2337 fontstring:SetText (text or "")
2338
2339 if (anchor and index == 1) then
2340 local myAnchor, hisAnchor, x, y = unpack (anchor)
2341 fontstring:SetPoint (myAnchor, frame1.upperImage, hisAnchor or myAnchor, x or 0, y or 0)
2342 elseif (anchor and index == 2) then
2343 local myAnchor, hisAnchor, x, y = unpack (anchor)
2344 fontstring:SetPoint (myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0)
2345 end
2346
2347 if (color) then
2348 local r, g, b, a = DF:ParseColors (color)
2349 fontstring:SetTextColor (r, g, b, a)
2350 end
2351
2352 local face, size, flags = fontstring:GetFont()
2353 face = fontface or [[Fonts\FRIZQT__.TTF]]
2354 size = fontsize or 13
2355 flags = fontflag or nil
2356 fontstring:SetFont (face, size, flags)
2357 fontstring:Show()
2358 end
2359
2360 function CoolTip:SetBackdrop (index, backdrop, backdropcolor, bordercolor)
2361
2362 local f
2363 if (index == 1) then
2364 f = frame1
2365 elseif (index == 2) then
2366 f = frame2
2367 end
2368
2369 if (backdrop) then
2370 f:SetBackdrop (backdrop)
2371 end
2372 if (backdropcolor) then
2373 local r, g, b, a = DF:ParseColors (backdropcolor)
2374 f:SetBackdropColor (r, g, b, a)
2375 end
2376 if (bordercolor) then
2377 local r, g, b, a = DF:ParseColors (bordercolor)
2378 f:SetBackdropBorderColor (r, g, b, a)
2379 end
2380
2381 end
2382
2383 function CoolTip:SetBannerImage (index, texturepath, width, height, anchor, texcoord, overlay)
2384
2385 local texture
2386
2387 if (index == 1) then
2388 texture = frame1.upperImage
2389 elseif (index == 2) then
2390 texture = frame1.upperImage2
2391 end
2392
2393 if (texturepath) then
2394 texture:SetTexture (texturepath)
2395 end
2396
2397 if (width) then
2398 texture:SetWidth (width)
2399 end
2400 if (height) then
2401 texture:SetHeight (height)
2402 end
2403
2404 if (anchor) then
2405 if (type (anchor[1]) == "table") then
2406 for _, t in _ipairs (anchor) do
2407 local myAnchor, hisAnchor, x, y = unpack (t)
2408 texture:SetPoint (myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0)
2409 end
2410 else
2411 local myAnchor, hisAnchor, x, y = unpack (anchor)
2412 texture:SetPoint (myAnchor, frame1, hisAnchor or myAnchor, x or 0, y or 0)
2413 end
2414 end
2415
2416 if (texcoord) then
2417 local L, R, T, B = unpack (texcoord)
2418 texture:SetTexCoord (L, R, T, B)
2419 end
2420
2421 if (overlay) then
2422 texture:SetVertexColor (unpack (overlay))
2423 end
2424
2425 CoolTip.Banner [index] = true
2426 texture:Show()
2427
2428 end
2429
2430 ----------------------------------------------------------------------
2431 --> adds a icon to the last line added.
2432 --> only works with cooltip type 1 and 2 (tooltip and tooltip with bars)
2433 --> parameters: icon [, width [, height [, TexCoords L R T B ]]]
2434 --> texture support string path or texture object
2435
2436 function CoolTip:AddTexture (iconTexture, frame, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated)
2437 return CoolTip:AddIcon (iconTexture, frame, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated)
2438 end
2439 function CoolTip:AddIcon (iconTexture, frame, side, iconWidth, iconHeight, L, R, T, B, overlayColor, point, desaturated)
2440
2441 --> need a previous line
2442 if (CoolTip.Indexes == 0) then
2443 return --> return error
2444 end
2445
2446 --> check data integrity
2447 if (type (iconTexture) ~= "string" and (type (iconTexture) ~= "table" or not iconTexture.GetObjectType or iconTexture:GetObjectType() ~= "Texture") ) then
2448 return --> return error
2449 end
2450
2451 side = side or 1
2452
2453 local frameTable
2454 local iconTable
2455
2456 if (not frame or (type (frame) == "string" and frame == "main") or (type (frame) == "number" and frame == 1)) then
2457
2458 if (not side or (type (side) == "string" and side == "left") or (type (side) == "number" and side == 1)) then
2459 frameTable = CoolTip.LeftIconTable
2460
2461 elseif ((type (side) == "string" and side == "right") or (type (side) == "number" and side == 2)) then
2462 frameTable = CoolTip.RightIconTable
2463
2464 end
2465
2466 if (CoolTip.isSpecial) then
2467 iconTable = {}
2468 _table_insert (frameTable, CoolTip.Indexes, iconTable)
2469 else
2470 iconTable = frameTable [CoolTip.Indexes]
2471 if (not iconTable) then
2472 iconTable = {}
2473 _table_insert (frameTable, CoolTip.Indexes, iconTable)
2474 --frameTable [CoolTip.Indexes] = iconTable
2475 end
2476 end
2477
2478 elseif ((type (frame) == "string" and frame == "sub") or (type (frame) == "number" and frame == 2)) then
2479
2480 if ((type (side) == "string" and side == "left") or (type (side) == "number" and side == 1)) then
2481 frameTable = CoolTip.LeftIconTableSub
2482 elseif ((type (side) == "string" and side == "right") or (type (side) == "number" and side == 2)) then
2483 frameTable = CoolTip.RightIconTableSub
2484 elseif ((type (side) == "string" and side == "top") or (type (side) == "number" and side == 3)) then
2485 CoolTip.TopIconTableSub [CoolTip.Indexes] = CoolTip.TopIconTableSub [CoolTip.Indexes] or {}
2486 CoolTip.TopIconTableSub [CoolTip.Indexes] [1] = iconTexture
2487 CoolTip.TopIconTableSub [CoolTip.Indexes] [2] = iconWidth or 16
2488 CoolTip.TopIconTableSub [CoolTip.Indexes] [3] = iconHeight or 16
2489 CoolTip.TopIconTableSub [CoolTip.Indexes] [4] = L or 0
2490 CoolTip.TopIconTableSub [CoolTip.Indexes] [5] = R or 1
2491 CoolTip.TopIconTableSub [CoolTip.Indexes] [6] = T or 0
2492 CoolTip.TopIconTableSub [CoolTip.Indexes] [7] = B or 1
2493 CoolTip.TopIconTableSub [CoolTip.Indexes] [8] = overlayColor or _default_color
2494 CoolTip.TopIconTableSub [CoolTip.Indexes] [9] = desaturated
2495 return
2496 end
2497
2498 local subMenuContainerIcons = frameTable [CoolTip.Indexes]
2499 if (not subMenuContainerIcons) then
2500 subMenuContainerIcons = {}
2501 frameTable [CoolTip.Indexes] = subMenuContainerIcons
2502 end
2503
2504 if (CoolTip.isSpecial) then
2505 iconTable = {}
2506 subMenuContainerIcons [CoolTip.SubIndexes] = iconTable
2507 else
2508 iconTable = subMenuContainerIcons [CoolTip.SubIndexes]
2509 if (not iconTable) then
2510 iconTable = {}
2511 subMenuContainerIcons [CoolTip.SubIndexes] = iconTable
2512 end
2513 end
2514
2515 else
2516 return --> error
2517 end
2518
2519 iconTable [1] = iconTexture
2520 iconTable [2] = iconWidth or 16 --> default 16
2521 iconTable [3] = iconHeight or 16 --> default 16
2522 iconTable [4] = L or 0 --> default 0
2523 iconTable [5] = R or 1 --> default 1
2524 iconTable [6] = T or 0 --> default 0
2525 iconTable [7] = B or 1 --> default 1
2526 iconTable [8] = overlayColor or _default_color --> default 1, 1, 1
2527 iconTable [9] = desaturated
2528
2529 return true
2530 end
2531
2532 ----------------------------------------------------------------------
2533 --> adds a line.
2534 --> only works with cooltip type 1 and 2 (tooltip and tooltip with bars)
2535 --> parameters: left text, right text [, L color R, L color G, L color B, L color A [, R color R, R color G, R color B, R color A [, wrap]]]
2536
2537 --> alias
2538 function CoolTip:AddDoubleLine (leftText, rightText, frame, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag)
2539 return CoolTip:AddLine (leftText, rightText, frame, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag)
2540 end
2541
2542 --> adds a line for tooltips
2543 function CoolTip:AddLine (leftText, rightText, frame, ColorR1, ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag)
2544
2545 --> check data integrity
2546 local t = type (leftText)
2547 if (t ~= "string") then
2548 if (t == "number") then
2549 leftText = tostring (leftText)
2550 else
2551 leftText = ""
2552 end
2553 end
2554
2555 local t = type (rightText)
2556 if (t ~= "string") then
2557 if (t == "number") then
2558 rightText = tostring (rightText)
2559 else
2560 rightText = ""
2561 end
2562 end
2563
2564 if (type (ColorR1) ~= "number") then
2565 ColorR2, ColorG2, ColorB2, ColorA2, fontSize, fontFace, fontFlag = ColorG1, ColorB1, ColorA1, ColorR2, ColorG2, ColorB2, ColorA2
2566
2567 if (type (ColorR1) == "boolean" or not ColorR1) then
2568 ColorR1, ColorG1, ColorB1, ColorA1 = 0, 0, 0, 0
2569 else
2570 ColorR1, ColorG1, ColorB1, ColorA1 = DF:ParseColors (ColorR1)
2571 end
2572 end
2573
2574 if (type (ColorR2) ~= "number") then
2575 fontSize, fontFace, fontFlag = ColorG2, ColorB2, ColorA2
2576
2577 if (type (ColorR2) == "boolean" or not ColorR2) then
2578 ColorR2, ColorG2, ColorB2, ColorA2 = 0, 0, 0, 0
2579 else
2580 ColorR2, ColorG2, ColorB2, ColorA2 = DF:ParseColors (ColorR2)
2581 end
2582 end
2583
2584 local frameTableLeft
2585 local frameTableRight
2586 local lineTable_left
2587 local lineTable_right
2588
2589 if (not frame or (type (frame) == "string" and frame == "main") or (type (frame) == "number" and frame == 1)) then
2590
2591 CoolTip.Indexes = CoolTip.Indexes + 1
2592
2593 if (not CoolTip.IndexesSub [CoolTip.Indexes]) then
2594 CoolTip.IndexesSub [CoolTip.Indexes] = 0
2595 end
2596
2597 CoolTip.SubIndexes = 0
2598
2599 frameTableLeft = CoolTip.LeftTextTable
2600 frameTableRight = CoolTip.RightTextTable
2601
2602 if (CoolTip.isSpecial) then
2603 lineTable_left = {}
2604 _table_insert (frameTableLeft, CoolTip.Indexes, lineTable_left)
2605 lineTable_right = {}
2606 _table_insert (frameTableRight, CoolTip.Indexes, lineTable_right)
2607 else
2608 lineTable_left = frameTableLeft [CoolTip.Indexes]
2609 lineTable_right = frameTableRight [CoolTip.Indexes]
2610
2611 if (not lineTable_left) then
2612 lineTable_left = {}
2613 _table_insert (frameTableLeft, CoolTip.Indexes, lineTable_left)
2614 end
2615 if (not lineTable_right) then
2616 lineTable_right = {}
2617 _table_insert (frameTableRight, CoolTip.Indexes, lineTable_right)
2618 end
2619 end
2620
2621 elseif ((type (frame) == "string" and frame == "sub") or (type (frame) == "number" and frame == 2)) then
2622
2623 CoolTip.SubIndexes = CoolTip.SubIndexes + 1
2624 CoolTip.IndexesSub [CoolTip.Indexes] = CoolTip.IndexesSub [CoolTip.Indexes] + 1
2625 CoolTip.HaveSubMenu = true
2626
2627 frameTableLeft = CoolTip.LeftTextTableSub
2628 frameTableRight = CoolTip.RightTextTableSub
2629
2630 local subMenuContainerTexts = frameTableLeft [CoolTip.Indexes]
2631 if (not subMenuContainerTexts) then
2632 subMenuContainerTexts = {}
2633 _table_insert (frameTableLeft, CoolTip.Indexes, subMenuContainerTexts)
2634 end
2635
2636 if (CoolTip.isSpecial) then
2637 lineTable_left = {}
2638 _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_left)
2639 else
2640 lineTable_left = subMenuContainerTexts [CoolTip.SubIndexes]
2641 if (not lineTable_left) then
2642 lineTable_left = {}
2643 --subMenuContainerTexts [CoolTip.SubIndexes] = lineTable_left
2644 _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_left)
2645 end
2646 end
2647
2648 local subMenuContainerTexts = frameTableRight [CoolTip.Indexes]
2649 if (not subMenuContainerTexts) then
2650 subMenuContainerTexts = {}
2651 _table_insert (frameTableRight, CoolTip.Indexes, subMenuContainerTexts)
2652 --frameTableRight [CoolTip.Indexes] = subMenuContainerTexts
2653 end
2654
2655 if (CoolTip.isSpecial) then
2656 lineTable_right = {}
2657 _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_right)
2658 else
2659 lineTable_right = subMenuContainerTexts [CoolTip.SubIndexes]
2660 if (not lineTable_right) then
2661 lineTable_right = {}
2662 _table_insert (subMenuContainerTexts, CoolTip.SubIndexes, lineTable_right)
2663 --subMenuContainerTexts [CoolTip.SubIndexes] = lineTable_right
2664 end
2665 end
2666 else
2667 return --> error
2668 end
2669
2670 lineTable_left [1] = leftText --> line text
2671 lineTable_left [2] = ColorR1
2672 lineTable_left [3] = ColorG1
2673 lineTable_left [4] = ColorB1
2674 lineTable_left [5] = ColorA1
2675 lineTable_left [6] = fontSize
2676 lineTable_left [7] = fontFace
2677 lineTable_left [8] = fontFlag
2678
2679 lineTable_right [1] = rightText --> line text
2680 lineTable_right [2] = ColorR2
2681 lineTable_right [3] = ColorG2
2682 lineTable_right [4] = ColorB2
2683 lineTable_right [5] = ColorA2
2684 lineTable_right [6] = fontSize
2685 lineTable_right [7] = fontFace
2686 lineTable_right [8] = fontFlag
2687 end
2688
2689 function CoolTip:AddSpecial (widgetType, index, subIndex, ...)
2690
2691 local currentIndex = CoolTip.Indexes
2692 local currentSubIndex = CoolTip.SubIndexes
2693 CoolTip.isSpecial = true
2694
2695 widgetType = string.lower (widgetType)
2696
2697 if (widgetType == "line") then
2698
2699 if (subIndex) then
2700 CoolTip.Indexes = index
2701 CoolTip.SubIndexes = subIndex-1
2702 else
2703 CoolTip.Indexes = index-1
2704 end
2705
2706 CoolTip:AddLine (...)
2707
2708 if (subIndex) then
2709 CoolTip.Indexes = currentIndex
2710 CoolTip.SubIndexes = currentSubIndex+1
2711 else
2712 CoolTip.Indexes = currentIndex+1
2713 end
2714
2715 elseif (widgetType == "icon") then
2716
2717 CoolTip.Indexes = index
2718 if (subIndex) then
2719 CoolTip.SubIndexes = subIndex
2720 end
2721
2722 CoolTip:AddIcon (...)
2723
2724 CoolTip.Indexes = currentIndex
2725 if (subIndex) then
2726 CoolTip.SubIndexes = currentSubIndex
2727 end
2728
2729 elseif (widgetType == "statusbar") then
2730
2731 CoolTip.Indexes = index
2732 if (subIndex) then
2733 CoolTip.SubIndexes = subIndex
2734 end
2735
2736 CoolTip:AddStatusBar (...)
2737
2738 CoolTip.Indexes = currentIndex
2739 if (subIndex) then
2740 CoolTip.SubIndexes = currentSubIndex
2741 end
2742
2743 elseif (widgetType == "menu") then
2744
2745 CoolTip.Indexes = index
2746 if (subIndex) then
2747 CoolTip.SubIndexes = subIndex
2748 end
2749
2750 CoolTip:AddMenu (...)
2751
2752 CoolTip.Indexes = currentIndex
2753 if (subIndex) then
2754 CoolTip.SubIndexes = currentSubIndex
2755 end
2756
2757 end
2758
2759 CoolTip.isSpecial = false
2760
2761 end
2762
2763 --> search key: ~fromline
2764 function CoolTip:AddFromTable (_table)
2765 for index, menu in _ipairs (_table) do
2766 if (menu.func) then
2767 CoolTip:AddMenu (menu.type or 1, menu.func, menu.param1, menu.param2, menu.param3, nil, menu.icon)
2768 elseif (menu.statusbar) then
2769 CoolTip:AddStatusBar (menu.value, menu.type or 1, menu.color, true)
2770 elseif (menu.icon) then
2771 CoolTip:AddIcon (menu.icon, menu.type or 1, menu.side or 1, menu.width, menu.height, menu.l, menu.r, menu.t, menu.b, menu.color)
2772 elseif (menu.textleft or menu.textright or menu.text) then
2773 CoolTip:AddLine (menu.text, "", menu.type, menu.color, menu.color)
2774 end
2775 end
2776 end
2777
2778 ----------------------------------------------------------------------
2779 --> show cooltip
2780
2781 --> serach key: ~start
2782 function CoolTip:Show (frame, menuType, color)
2783 return CoolTip:ShowCooltip (frame, menuType, color)
2784 end
2785
2786 function CoolTip:ShowCooltip (frame, menuType, color)
2787
2788 if (frame) then
2789 --> details framework
2790 if (frame.dframework) then
2791 frame = frame.widget
2792 end
2793 CoolTip:SetHost (frame)
2794 end
2795 if (menuType) then
2796 CoolTip:SetType (menuType)
2797 end
2798 if (color) then
2799 CoolTip:SetColor (1, color)
2800 CoolTip:SetColor (2, color)
2801 end
2802
2803 if (CoolTip.Type == 1 or CoolTip.Type == 2) then
2804 return CoolTip:monta_tooltip()
2805
2806 elseif (CoolTip.Type == 3) then
2807 return CoolTip:monta_cooltip()
2808
2809 end
2810 end
2811
2812 local emptyOptions = {}
2813
2814 function CoolTip:Hide()
2815 return CoolTip:Close()
2816 end
2817
2818 function CoolTip:Close()
2819 CoolTip.active = false
2820 CoolTip.Host = nil
2821 DF:Fade (frame1, 1)
2822 DF:Fade (frame2, 1)
2823
2824 end
2825
2826 --> old function call
2827 function CoolTip:ShowMe (host, arg2)
2828 --> ignore if mouse is up me
2829 if (CoolTip.mouseOver) then
2830 return
2831 end
2832
2833 if (not host or not arg2) then --> hideme
2834 CoolTip:Close()
2835 end
2836 end
2837
2838 --> search key: ~inject
2839 function CoolTip:ExecFunc (host, fromClick)
2840
2841 if (host.dframework) then
2842 if (not host.widget.CoolTip) then
2843 host.widget.CoolTip = host.CoolTip
2844 end
2845 host = host.widget
2846 end
2847
2848 CoolTip:Reset()
2849 CoolTip:SetType (host.CoolTip.Type)
2850 CoolTip:SetFixedParameter (host.CoolTip.FixedValue)
2851 CoolTip:SetColor ("main", host.CoolTip.MainColor or "transparent")
2852 CoolTip:SetColor ("sec", host.CoolTip.SubColor or "transparent")
2853
2854 CoolTip:SetOwner (host, host.CoolTip.MyAnchor, host.CoolTip.HisAnchor, host.CoolTip.X, host.CoolTip.Y)
2855
2856 local options = host.CoolTip.Options
2857 if (type (options) == "function") then
2858 options = options()
2859 end
2860 if (options) then
2861 for optionName, optionValue in pairs (options) do
2862 CoolTip:SetOption (optionName, optionValue)
2863 end
2864 end
2865
2866 host.CoolTip.BuildFunc()
2867
2868 if (CoolTip.Indexes == 0) then
2869 if (host.CoolTip.Default) then
2870 CoolTip:SetType ("tooltip")
2871 CoolTip:AddLine (host.CoolTip.Default, nil, 1, "white")
2872 end
2873 end
2874
2875 CoolTip:ShowCooltip()
2876
2877 if (fromClick) then
2878 --UIFrameFlash (frame1, )
2879 frame1:Flash (0.05, 0.05, 0.2, true, 0, 0)
2880 end
2881 end
2882
2883 local wait = 0.2
2884
2885 local InjectOnUpdateEnter = function (self, elapsed)
2886 elapsedTime = elapsedTime+elapsed
2887 if (elapsedTime > wait) then
2888 self:SetScript ("OnUpdate", nil)
2889 CoolTip:ExecFunc (self)
2890 end
2891 end
2892
2893 local InjectOnUpdateLeave = function (self, elapsed)
2894 elapsedTime = elapsedTime+elapsed
2895 if (elapsedTime > 0.2) then
2896 if (not CoolTip.mouseOver and not CoolTip.buttonOver and self == CoolTip.Host) then
2897 CoolTip:ShowMe (false)
2898 end
2899 self:SetScript ("OnUpdate", nil)
2900 end
2901 end
2902
2903 local InjectOnLeave = function (self)
2904 CoolTip.buttonOver = false
2905
2906 if (CoolTip.active) then
2907 elapsedTime = 0
2908 self:SetScript ("OnUpdate", InjectOnUpdateLeave)
2909 else
2910 self:SetScript ("OnUpdate", nil)
2911 end
2912
2913 if (self.CoolTip.OnLeaveFunc) then
2914 self.CoolTip.OnLeaveFunc (self)
2915 end
2916
2917 if (self.OldOnLeaveScript) then
2918 self:OldOnLeaveScript()
2919 end
2920 end
2921
2922 local InjectOnEnter = function (self)
2923 CoolTip.buttonOver = true
2924 if (CoolTip.active) then
2925 CoolTip:ExecFunc (self)
2926 else
2927 elapsedTime = 0
2928 wait = self.CoolTip.ShowSpeed or 0.2
2929 self:SetScript ("OnUpdate", InjectOnUpdateEnter)
2930 end
2931
2932 if (self.CoolTip.OnEnterFunc) then
2933 self.CoolTip.OnEnterFunc (self)
2934 end
2935
2936 if (self.OldOnEnterScript) then
2937 self:OldOnEnterScript()
2938 end
2939 end
2940
2941 function CoolTip:CoolTipInject (host, openOnClick)
2942 if (host.dframework) then
2943 if (not host.widget.CoolTip) then
2944 host.widget.CoolTip = host.CoolTip
2945 end
2946 host = host.widget
2947 end
2948
2949 local coolTable = host.CoolTip
2950 if (not coolTable) then
2951 print ("Host nao tem uma CoolTable.")
2952 return false
2953 end
2954
2955 host.OldOnEnterScript = host:GetScript ("OnEnter")
2956 host.OldOnLeaveScript = host:GetScript ("OnLeave")
2957
2958 host:SetScript ("OnEnter", InjectOnEnter)
2959 host:SetScript ("OnLeave", InjectOnLeave)
2960
2961 if (openOnClick) then
2962 if (host:GetObjectType() == "Button") then
2963 host:SetScript ("OnClick", function() CoolTip:ExecFunc (host, true) end)
2964 end
2965 end
2966
2967 return ture
2968 end
2969
2970 --> all done
2971 CoolTip:ClearAllOptions()
2972
2973 local preset2_backdrop = {bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]], edgeFile = DF.folder .. "border_3", tile=true,
2974 edgeSize = 16, tileSize = 64, insets = {left = 3, right = 3, top = 4, bottom = 4}}
2975
2976 local white_table = {1, 1, 1, 1}
2977
2978 function CoolTip:Preset (number)
2979 self:Reset()
2980
2981 if (number == 1) then
2982 self:SetOption ("TextFont", "Friz Quadrata TT")
2983 self:SetOption ("TextColor", "orange")
2984 self:SetOption ("TextSize", 12)
2985 self:SetOption ("ButtonsYMod", -4)
2986 self:SetOption ("YSpacingMod", -4)
2987 self:SetOption ("IgnoreButtonAutoHeight", true)
2988 self:SetColor (1, 0.5, 0.5, 0.5, 0.5)
2989
2990 elseif (number == 2) then
2991 self:SetOption ("TextFont", "Friz Quadrata TT")
2992 self:SetOption ("TextColor", "orange")
2993 self:SetOption ("TextSize", 12)
2994 self:SetOption ("FixedWidth", 220)
2995 self:SetOption ("ButtonsYMod", -4)
2996 self:SetOption ("YSpacingMod", -4)
2997 self:SetOption ("IgnoreButtonAutoHeight", true)
2998 self:SetColor (1, 0.5, 0.5, 0.5, 0.5)
2999
3000 self:SetBackdrop (1, preset2_backdrop, nil, white_table)
3001 end
3002 end
3003
3004 return CoolTip
3005
3006 end
3007
3008 DF:CreateCoolTip()