vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local MAJOR_VERSION = "1.0"
2 local MINOR_VERSION = tonumber(string.sub("$Revision: 1868 $", 12, -3))
3 if DewdropLib and DewdropLib.versions[MAJOR_VERSION] and DewdropLib.versions[MAJOR_VERSION].minor >= MINOR_VERSION then
4 return
5 end
6  
7 -------------IRIEL'S-STUB-CODE--------------
8 local stub = {};
9  
10 -- Instance replacement method, replace contents of old with that of new
11 function stub:ReplaceInstance(old, new)
12 for k,v in pairs(old) do old[k]=nil; end
13 for k,v in pairs(new) do old[k]=v; end
14 end
15  
16 -- Get a new copy of the stub
17 function stub:NewStub()
18 local newStub = {};
19 self:ReplaceInstance(newStub, self);
20 newStub.lastVersion = '';
21 newStub.versions = {};
22 return newStub;
23 end
24  
25 -- Get instance version
26 function stub:GetInstance(version)
27 if (not version) then version = self.lastVersion; end
28 local versionData = self.versions[version];
29 if (not versionData) then
30 message("Cannot find library instance with version '"
31 .. version .. "'");
32 return;
33 end
34 return versionData.instance;
35 end
36  
37 -- Register new instance
38 function stub:Register(newInstance)
39 local version,minor = newInstance:GetLibraryVersion();
40 self.lastVersion = version;
41 local versionData = self.versions[version];
42 if (not versionData) then
43 -- This one is new!
44 versionData = { instance = newInstance,
45 minor = minor,
46 old = {}
47 };
48 self.versions[version] = versionData;
49 newInstance:LibActivate(self);
50 return newInstance;
51 end
52 if (minor <= versionData.minor) then
53 -- This one is already obsolete
54 if (newInstance.LibDiscard) then
55 newInstance:LibDiscard();
56 end
57 return versionData.instance;
58 end
59 -- This is an update
60 local oldInstance = versionData.instance;
61 local oldList = versionData.old;
62 versionData.instance = newInstance;
63 versionData.minor = minor;
64 local skipCopy = newInstance:LibActivate(self, oldInstance, oldList);
65 table.insert(oldList, oldInstance);
66 if (not skipCopy) then
67 for i, old in ipairs(oldList) do
68 self:ReplaceInstance(old, newInstance);
69 end
70 end
71 return newInstance;
72 end
73  
74 -- Bind stub to global scope if it's not already there
75 if (not DewdropLib) then
76 DewdropLib = stub:NewStub();
77 end
78  
79 -- Nil stub for garbage collection
80 stub = nil;
81 -----------END-IRIEL'S-STUB-CODE------------
82  
83 local function assert(condition, message)
84 if not condition then
85 local stack = debugstack()
86 local first = string.gsub(stack, "\n.*", "")
87 local file = string.gsub(first, "^(.*\\.*)%.lua:%d+: .*", "%1")
88 if not message then
89 local _,_,second = string.find(stack, "\n(.-)\n")
90 message = "assertion failed! " .. second
91 end
92 message = "DewdropLib: " .. message
93 local i = 1
94 for s in string.gfind(stack, "\n(.-)\n") do
95 i = i + 1
96 if not string.find(s, file .. "%.lua:%d+:") then
97 error(message, i)
98 return
99 end
100 end
101 error(message, 2)
102 return
103 end
104 return condition
105 end
106  
107 local lib = {}
108 local ipairs = ipairs
109 local tinsert = table.insert
110 local tremove = table.remove
111 local tgetn = table.getn
112 local function new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
113 local t = {}
114 if k1 then t[k1] = v1
115 if k2 then t[k2] = v2
116 if k3 then t[k3] = v3
117 if k4 then t[k4] = v4
118 if k5 then t[k5] = v5
119 if k6 then t[k6] = v6
120 if k7 then t[k7] = v7
121 if k8 then t[k8] = v8
122 if k9 then t[k9] = v9
123 if k10 then t[k10] = v10
124 if k11 then t[k11] = v11
125 if k12 then t[k12] = v12
126 if k13 then t[k13] = v13
127 if k14 then t[k14] = v14
128 if k15 then t[k15] = v15
129 if k16 then t[k16] = v16
130 if k17 then t[k17] = v17
131 if k18 then t[k18] = v18
132 if k19 then t[k19] = v19
133 if k20 then t[k20] = v20
134 end end end end end end end end end end end end end end end end end end end end
135 return t
136 end
137 local tmp
138 do
139 local t
140 function tmp(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
141 for k in pairs(t) do
142 t[k] = nil
143 end
144 if k1 then t[k1] = v1
145 if k2 then t[k2] = v2
146 if k3 then t[k3] = v3
147 if k4 then t[k4] = v4
148 if k5 then t[k5] = v5
149 if k6 then t[k6] = v6
150 if k7 then t[k7] = v7
151 if k8 then t[k8] = v8
152 if k9 then t[k9] = v9
153 if k10 then t[k10] = v10
154 if k11 then t[k11] = v11
155 if k12 then t[k12] = v12
156 if k13 then t[k13] = v13
157 if k14 then t[k14] = v14
158 if k15 then t[k15] = v15
159 if k16 then t[k16] = v16
160 if k17 then t[k17] = v17
161 if k18 then t[k18] = v18
162 if k19 then t[k19] = v19
163 if k20 then t[k20] = v20
164 end end end end end end end end end end end end end end end end end end end end
165 return t
166 end
167 local x = tmp
168 function tmp(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
169 t = {}
170 tmp = x
171 x = nil
172 return tmp(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
173 end
174 end
175 local tmp2
176 do
177 local t
178 function tmp2(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
179 for k in pairs(t) do
180 t[k] = nil
181 end
182 if k1 then t[k1] = v1
183 if k2 then t[k2] = v2
184 if k3 then t[k3] = v3
185 if k4 then t[k4] = v4
186 if k5 then t[k5] = v5
187 if k6 then t[k6] = v6
188 if k7 then t[k7] = v7
189 if k8 then t[k8] = v8
190 if k9 then t[k9] = v9
191 if k10 then t[k10] = v10
192 if k11 then t[k11] = v11
193 if k12 then t[k12] = v12
194 if k13 then t[k13] = v13
195 if k14 then t[k14] = v14
196 if k15 then t[k15] = v15
197 if k16 then t[k16] = v16
198 if k17 then t[k17] = v17
199 if k18 then t[k18] = v18
200 if k19 then t[k19] = v19
201 if k20 then t[k20] = v20
202 end end end end end end end end end end end end end end end end end end end end
203 return t
204 end
205 local x = tmp2
206 function tmp2(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
207 t = {}
208 tmp2 = x
209 x = nil
210 return tmp2(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
211 end
212 end
213 --local levels
214 local buttons
215  
216 function lib:GetLibraryVersion()
217 return MAJOR_VERSION, MINOR_VERSION
218 end
219  
220 function lib:LibActivate(stub, oldLib, oldList)
221 if oldLib and oldLib.registry then
222 self.registry = oldLib.registry
223 self.onceRegistered = oldLib.onceRegistered
224 else
225 self.registry = {}
226 self.onceRegistered = {}
227  
228 local WorldFrame_OnMouseDown = WorldFrame:GetScript("OnMouseDown")
229 local WorldFrame_OnMouseUp = WorldFrame:GetScript("OnMouseUp")
230 local oldX, oldY, clickTime
231 WorldFrame:SetScript("OnMouseDown", function()
232 oldX,oldY = GetCursorPosition()
233 clickTime = GetTime()
234 if WorldFrame_OnMouseDown then
235 WorldFrame_OnMouseDown()
236 end
237 end)
238  
239 WorldFrame:SetScript("OnMouseUp", function()
240 local x,y = GetCursorPosition()
241 if not oldX or not oldY or not x or not y or not clickTime then
242 self:Close()
243 if WorldFrame_OnMouseUp then
244 WorldFrame_OnMouseUp()
245 end
246 return
247 end
248 local d = math.abs(x - oldX) + math.abs(y - oldY)
249 if d <= 5 and GetTime() - clickTime < 0.5 then
250 self:Close()
251 end
252 if WorldFrame_OnMouseUp then
253 WorldFrame_OnMouseUp()
254 end
255 end)
256  
257 local DropDownList1_Show = DropDownList1.Show
258 function DropDownList1.Show(DropDownList1)
259 if levels[1] and levels[1]:IsVisible() then
260 self:Close()
261 end
262 DropDownList1_Show(DropDownList1)
263 end
264  
265 local old_HideDropDownMenu = HideDropDownMenu
266 function HideDropDownMenu(num)
267 if levels[1] and levels[1]:IsVisible() then
268 self:Close()
269 end
270 old_HideDropDownMenu(num)
271 end
272  
273 local old_CloseDropDownMenus = CloseDropDownMenus
274 function CloseDropDownMenus(num)
275 if levels[1] and levels[1]:IsVisible() then
276 self:Close()
277 end
278 old_CloseDropDownMenus(num)
279 end
280 end
281 levels = {}
282 buttons = {}
283 end
284  
285 function lib:LibDeactivate(stub)
286 levels = nil
287 buttons = nil
288 end
289  
290 local function StartCounting(self, levelNum)
291 for i = levelNum, tgetn(levels) do
292 if levels[i] then
293 levels[i].count = 3
294 end
295 end
296 end
297  
298 local function StopCounting(self, level)
299 for i = level, 1, -1 do
300 if levels[i] then
301 levels[i].count = nil
302 end
303 end
304 end
305  
306 local function OnUpdate(self, arg1)
307 for _,level in ipairs(levels) do
308 if level.count then
309 level.count = level.count - arg1
310 if level.count < 0 then
311 level.count = nil
312 self:Close(level.num)
313 end
314 end
315 end
316 end
317  
318 local function CheckDualMonitor(self, frame)
319 local ratio = GetScreenWidth() / GetScreenHeight()
320 if ratio >= 2.4 and frame:GetRight() > GetScreenWidth() / 2 and frame:GetLeft() < GetScreenWidth() / 2 then
321 local offsetx
322 if GetCursorPosition() / GetScreenHeight() * 768 < GetScreenWidth() / 2 then
323 offsetx = GetScreenWidth() / 2 - frame:GetRight()
324 else
325 offsetx = GetScreenWidth() / 2 - frame:GetLeft()
326 end
327 local point, parent, relativePoint, x, y = frame:GetPoint(1)
328 frame:SetPoint(point, parent, relativePoint, (x or 0) + offsetx, y or 0)
329 end
330 end
331  
332 local function CheckSize(self, level)
333 if not level.buttons then
334 return
335 end
336 local height = 20
337 for _, button in ipairs(level.buttons) do
338 height = height + button:GetHeight()
339 end
340 level:SetHeight(height)
341 local width = 160
342 for _, button in ipairs(level.buttons) do
343 local extra = 1
344 if button.hasArrow or button.hasColorSwatch then
345 extra = extra + 16
346 end
347 if not button.notCheckable then
348 extra = extra + 24
349 end
350 button.text:SetFont(STANDARD_TEXT_FONT, button.textHeight)
351 if button.text:GetWidth() + extra > width then
352 width = button.text:GetWidth() + extra
353 end
354 end
355 level:SetWidth(width + 20)
356 if level:GetLeft() and level:GetTop() and level:GetLeft() < 0 or level:GetRight() > GetScreenWidth() or level:GetTop() > GetScreenHeight() or level:GetBottom() < 0 then
357 level:ClearAllPoints()
358 if level.lastDirection == "RIGHT" then
359 if level.lastVDirection == "DOWN" then
360 level:SetPoint("TOPLEFT", level.parent or level:GetParent(), "TOPRIGHT", 5, 10)
361 else
362 level:SetPoint("BOTTOMLEFT", level.parent or level:GetParent(), "BOTTOMRIGHT", 5, -10)
363 end
364 else
365 if level.lastVDirection == "DOWN" then
366 level:SetPoint("TOPRIGHT", level.parent or level:GetParent(), "TOPLEFT", -5, 10)
367 else
368 level:SetPoint("BOTTOMRIGHT", level.parent or level:GetParent(), "BOTTOMLEFT", -5, -10)
369 end
370 end
371 end
372 local dirty = false
373 if not level:GetRight() then
374 self:Close()
375 return
376 end
377 if level:GetRight() > GetScreenWidth() and level.lastDirection == "RIGHT" then
378 level.lastDirection = "LEFT"
379 dirty = true
380 elseif level:GetLeft() < 0 and level.lastDirection == "LEFT" then
381 level.lastDirection = "RIGHT"
382 dirty = true
383 end
384 if level:GetTop() > GetScreenHeight() and level.lastVDirection == "UP" then
385 level.lastVDirection = "DOWN"
386 dirty = true
387 elseif level:GetBottom() < 0 and level.lastVDirection == "DOWN" then
388 level.lastVDirection = "UP"
389 dirty = true
390 end
391 if dirty then
392 level:ClearAllPoints()
393 if level.lastDirection == "RIGHT" then
394 if level.lastVDirection == "DOWN" then
395 level:SetPoint("TOPLEFT", level.parent or level:GetParent(), "TOPRIGHT", 5, 10)
396 else
397 level:SetPoint("BOTTOMLEFT", level.parent or level:GetParent(), "BOTTOMRIGHT", 5, -10)
398 end
399 else
400 if level.lastVDirection == "DOWN" then
401 level:SetPoint("TOPRIGHT", level.parent or level:GetParent(), "TOPLEFT", -5, 10)
402 else
403 level:SetPoint("BOTTOMRIGHT", level.parent or level:GetParent(), "BOTTOMLEFT", -5, -10)
404 end
405 end
406 end
407 if level:GetTop() > GetScreenHeight() then
408 local top = level:GetTop()
409 local point, parent, relativePoint, x, y = level:GetPoint(1)
410 level:ClearAllPoints()
411 level:SetPoint(point, parent, relativePoint, x or 0, (y or 0) + GetScreenHeight() - top)
412 elseif level:GetBottom() < 0 then
413 local bottom = level:GetBottom()
414 local point, parent, relativePoint, x, y = level:GetPoint(1)
415 level:ClearAllPoints()
416 level:SetPoint(point, parent, relativePoint, x or 0, (y or 0) - bottom)
417 end
418 CheckDualMonitor(self, level)
419 if mod(level.num, 5) == 0 then
420 local left, bottom = level:GetLeft(), level:GetBottom()
421 level:ClearAllPoints()
422 level:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", left, bottom)
423 end
424 end
425  
426 local Open
427 local OpenSlider
428 local Refresh
429 local Clear
430 local function ReleaseButton(self, level, index)
431 if not level.buttons then
432 return
433 end
434 if not level.buttons[index] then
435 return
436 end
437 local button = level.buttons[index]
438 button:Hide()
439 if button.highlight then
440 button.highlight:Hide()
441 end
442 tremove(level.buttons, index)
443 tinsert(buttons, button)
444 for k in pairs(button) do
445 if k ~= 0 and k ~= "text" and k ~= "check" and k ~= "arrow" and k ~= "colorSwatch" and k ~= "highlight" and k ~= "radioHighlight" then
446 button[k] = nil
447 end
448 end
449 return true
450 end
451  
452 local function Scroll(self, level, down)
453 if down then
454 if level:GetBottom() < 0 then
455 local point, parent, relativePoint, x, y = level:GetPoint(1)
456 level:SetPoint(point, parent, relativePoint, x, y + 50)
457 if level:GetBottom() > 0 then
458 level:SetPoint(point, parent, relativePoint, x, y + 50 - level:GetBottom())
459 end
460 end
461 else
462 if level:GetTop() > GetScreenHeight() then
463 local point, parent, relativePoint, x, y = level:GetPoint(1)
464 level:SetPoint(point, parent, relativePoint, x, y - 50)
465 if level:GetTop() < GetScreenHeight() then
466 level:SetPoint(point, parent, relativePoint, x, y - 50 + GetScreenHeight() - level:GetTop())
467 end
468 end
469 end
470 end
471  
472 local sliderFrame
473  
474 local function AcquireButton(self, level)
475 if not levels[level] then
476 return
477 end
478 level = levels[level]
479 if not level.buttons then
480 level.buttons = {}
481 end
482 local button
483 if tgetn(buttons) == 0 then
484 button = CreateFrame("Button")
485 button:SetFrameStrata("FULLSCREEN_DIALOG")
486 button:SetHeight(16)
487 local highlight = button:CreateTexture(nil, "BACKGROUND")
488 highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
489 button.highlight = highlight
490 highlight:SetBlendMode("ADD")
491 highlight:SetAllPoints(button)
492 highlight:Hide()
493 local check = button:CreateTexture(nil, "ARTWORK")
494 button.check = check
495 check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
496 check:SetPoint("CENTER", button, "LEFT", 12, 0)
497 check:SetWidth(24)
498 check:SetHeight(24)
499 local radioHighlight = button:CreateTexture(nil, "ARTWORK")
500 button.radioHighlight = radioHighlight
501 radioHighlight:SetTexture("Interface\\Buttons\\UI-RadioButton")
502 radioHighlight:SetAllPoints(check)
503 radioHighlight:SetBlendMode("ADD")
504 radioHighlight:SetTexCoord(0.5, 0.75, 0, 1)
505 radioHighlight:Hide()
506 button:SetScript("OnEnter", function()
507 if sliderFrame and sliderFrame:IsShown() and sliderFrame.mouseDown and sliderFrame.level == this.level.num + 1 then
508 Refresh(self, this.level)
509 return
510 end
511 self:Close(this.level.num + 1)
512 if this.hasSlider then
513 OpenSlider(self, this)
514 elseif this.hasArrow then
515 Open(self, this, nil, this.level.num + 1, this.value)
516 end
517 StopCounting(self, this.level.num + 1)
518 if not this.disabled then
519 highlight:Show()
520 if this.isRadio then
521 button.radioHighlight:Show()
522 end
523 end
524 if this.tooltipTitle then
525 GameTooltip_AddNewbieTip(this.tooltipTitle, 1.0, 1.0, 1.0, this.tooltipText, 1)
526 end
527 end)
528 button:SetScript("OnLeave", function()
529 highlight:Hide()
530 button.radioHighlight:Hide()
531 if this.level then
532 StartCounting(self, this.level.num)
533 end
534 GameTooltip:Hide()
535 end)
536 button:SetScript("OnClick", function()
537 if not this.disabled then
538 if this.hasColorSwatch then
539 local func = button.swatchFunc
540 ColorPickerFrame.func = function()
541 if func then
542 func(ColorPickerFrame:GetColorRGB())
543 end
544 end
545 ColorPickerFrame.hasOpacity = this.hasOpacity
546 local func = this.opacityFunc
547 ColorPickerFrame.opacityFunc = function()
548 if func then
549 func(1 - OpacitySliderFrame:GetValue())
550 end
551 end
552 ColorPickerFrame.opacity = 1 - this.opacity
553 ColorPickerFrame:SetColorRGB(this.r, this.g, this.b)
554 if this.cancelFunc then
555 local r, g, b, a = this.r, this.g, this.b, this.opacity
556 local func = this.cancelFunc
557 ColorPickerFrame.cancelFunc = function()
558 func(r, g, b, a)
559 end
560 end
561 self:Close(1)
562 ShowUIPanel(ColorPickerFrame)
563 elseif this.func then
564 local level = button.level
565 if type(this.func) == "string" then
566 assert(type(this.arg1[this.func]) == "function", "Cannot call method " .. this.func)
567 this.arg1[this.func](this.arg1, this.arg2, this.arg3, this.arg4)
568 else
569 this.func(this.arg1, this.arg2, this.arg3, this.arg4)
570 end
571 if this.closeWhenClicked then
572 self:Close()
573 elseif level:IsShown() then
574 Refresh(self, level)
575 end
576 elseif this.closeWhenClicked then
577 self:Close()
578 end
579 end
580 end)
581 local text = button:CreateFontString(nil, "ARTWORK")
582 button.text = text
583 text:SetFontObject(GameFontHighlightSmall)
584 button.text:SetFont(STANDARD_TEXT_FONT, UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT)
585 button:SetScript("OnMouseDown", function()
586 if not this.disabled and (this.func or this.swatchFunc or this.closeWhenClicked) then
587 text:SetPoint("LEFT", button, "LEFT", this.notCheckable and 1 or 25, -1)
588 end
589 end)
590 button:SetScript("OnMouseUp", function()
591 if not this.disabled and (this.func or this.swatchFunc or this.closeWhenClicked) then
592 text:SetPoint("LEFT", button, "LEFT", this.notCheckable and 0 or 24, 0)
593 end
594 end)
595 local arrow = button:CreateTexture(nil, "ARTWORK")
596 button.arrow = arrow
597 arrow:SetPoint("RIGHT", button, "RIGHT", 0, 0)
598 arrow:SetWidth(16)
599 arrow:SetHeight(16)
600 arrow:SetTexture("Interface\\ChatFrame\\ChatFrameExpandArrow")
601 local colorSwatch = button:CreateTexture(nil, "OVERLAY")
602 button.colorSwatch = colorSwatch
603 colorSwatch:SetWidth(20)
604 colorSwatch:SetHeight(20)
605 colorSwatch:SetTexture("Interface\\ChatFrame\\ChatFrameColorSwatch")
606 local texture = button:CreateTexture(nil, "OVERLAY")
607 colorSwatch.texture = texture
608 texture:SetTexture(1, 1, 1)
609 texture:SetWidth(11.5)
610 texture:SetHeight(11.5)
611 texture:Show()
612 texture:SetPoint("CENTER", colorSwatch, "CENTER")
613 colorSwatch:SetPoint("RIGHT", button, "RIGHT", 0, 0)
614 else
615 button = buttons[tgetn(buttons)]
616 tremove(buttons, tgetn(buttons))
617 end
618 button:SetParent(level)
619 button:SetFrameStrata(level:GetFrameStrata())
620 button:SetFrameLevel(level:GetFrameLevel() + 1)
621 button:SetPoint("LEFT", level, "LEFT", 10, 0)
622 button:SetPoint("RIGHT", level, "RIGHT", -10, 0)
623 if tgetn(level.buttons) == 0 then
624 button:SetPoint("TOP", level, "TOP", 0, -10)
625 else
626 button:SetPoint("TOP", level.buttons[tgetn(level.buttons)], "BOTTOM", 0, 0)
627 end
628 button.text:SetPoint("LEFT", button, "LEFT", 24, 0)
629 button:Show()
630 button.level = level
631 tinsert(level.buttons, button)
632 if not level.parented then
633 level.parented = true
634 level:ClearAllPoints()
635 if level.num == 1 then
636 if level.parent ~= UIParent then
637 level:SetPoint("TOPRIGHT", level.parent, "TOPLEFT")
638 else
639 level:SetPoint("CENTER", level.parent, "CENTER")
640 end
641 else
642 if level.lastDirection == "RIGHT" then
643 if level.lastVDirection == "DOWN" then
644 level:SetPoint("TOPLEFT", level.parent, "TOPRIGHT", 5, 10)
645 else
646 level:SetPoint("BOTTOMLEFT", level.parent, "BOTTOMRIGHT", 5, -10)
647 end
648 else
649 if level.lastVDirection == "DOWN" then
650 level:SetPoint("TOPRIGHT", level.parent, "TOPLEFT", -5, 10)
651 else
652 level:SetPoint("BOTTOMRIGHT", level.parent, "BOTTOMLEFT", -5, -10)
653 end
654 end
655 end
656 level:SetFrameStrata("TOOLTIP")
657 end
658 return button
659 end
660  
661 local function AcquireLevel(self, level)
662 if not levels[level] then
663 for i = tgetn(levels) + 1, level, -1 do
664 local i = i
665 local frame = CreateFrame("Button")
666 if i == 1 then
667 local old_CloseWindows = CloseWindows
668 function CloseWindows(ignoreCenter)
669 local found = old_CloseWindows(ignoreCenter)
670 if levels[1]:IsShown() then
671 self:Close()
672 return 1
673 end
674 return found
675 end
676 end
677 levels[i] = frame
678 frame.num = i
679 frame:SetParent(UIParent)
680 frame:SetFrameStrata("TOOLTIP")
681 frame:Hide()
682 frame:SetWidth(180)
683 frame:SetHeight(10)
684 frame:SetFrameLevel(i * 3)
685 frame:SetScript("OnHide", function()
686 self:Close(level + 1)
687 end)
688 frame:SetFrameStrata("FULLSCREEN_DIALOG")
689 if frame.SetTopLevel then
690 frame:SetTopLevel(true)
691 end
692 frame:EnableMouse(true)
693 frame:EnableMouseWheel(true)
694 local backdrop = CreateFrame("Frame", nil, frame)
695 backdrop:SetAllPoints(frame)
696 backdrop:SetBackdrop(tmp(
697 'bgFile', "Interface\\Tooltips\\UI-Tooltip-Background",
698 'edgeFile', "Interface\\Tooltips\\UI-Tooltip-Border",
699 'tile', true,
700 'insets', tmp2(
701 'left', 5,
702 'right', 5,
703 'top', 5,
704 'bottom', 5
705 ),
706 'tileSize', 16,
707 'edgeSize', 16
708 ))
709 backdrop:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b)
710 backdrop:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b)
711 frame:SetScript("OnClick", function()
712 self:Close(i)
713 end)
714 frame:SetScript("OnEnter", function()
715 StopCounting(self, i)
716 end)
717 frame:SetScript("OnLeave", function()
718 StartCounting(self, i)
719 end)
720 frame:SetScript("OnMouseWheel", function()
721 Scroll(self, frame, arg1 < 0)
722 end)
723 if i == 1 then
724 frame:SetScript("OnUpdate", function()
725 OnUpdate(self, arg1)
726 end)
727 levels[1].lastDirection = "RIGHT"
728 levels[1].lastVDirection = "DOWN"
729 else
730 levels[i].lastDirection = levels[i - 1].lastDirection
731 levels[i].lastVDirection = levels[i - 1].lastVDirection
732 end
733 end
734 end
735 return levels[level]
736 end
737  
738 local baseFunc, currentLevel
739 function Refresh(self, level)
740 if type(level) == "number" then
741 level = levels[level]
742 end
743 if not level then
744 return
745 end
746 if baseFunc then
747 currentLevel = level.num
748 Clear(self, level)
749 baseFunc(currentLevel, level.value, levels[level.num - 1] and levels[level.num - 1].value, levels[level.num - 2] and levels[level.num - 2].value, levels[level.num - 3] and levels[level.num - 3].value, levels[level.num - 4] and levels[level.num - 4].value)
750 CheckSize(self, level)
751 end
752 end
753  
754 function lib:Refresh(level)
755 Refresh(self, levels[level])
756 end
757  
758 function OpenSlider(self, parent)
759 if not sliderFrame then
760 sliderFrame = CreateFrame("Frame", nil, UIParent)
761 sliderFrame:SetWidth(80)
762 sliderFrame:SetHeight(170)
763 sliderFrame:SetBackdrop(tmp(
764 'bgFile', "Interface\\Tooltips\\UI-Tooltip-Background",
765 'edgeFile', "Interface\\Tooltips\\UI-Tooltip-Border",
766 'tile', true,
767 'insets', tmp2(
768 'left', 5,
769 'right', 5,
770 'top', 5,
771 'bottom', 5
772 ),
773 'tileSize', 16,
774 'edgeSize', 16
775 ))
776 sliderFrame:SetFrameStrata("TOOLTIP")
777 if sliderFrame.SetTopLevel then
778 sliderFrame:SetTopLevel(true)
779 end
780 sliderFrame:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r, TOOLTIP_DEFAULT_COLOR.g, TOOLTIP_DEFAULT_COLOR.b)
781 sliderFrame:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b)
782 sliderFrame:EnableMouse(TRUE)
783 sliderFrame:Hide()
784 sliderFrame:SetPoint("CENTER", UIParent, "CENTER")
785 local slider = CreateFrame("Slider", nil, sliderFrame)
786 sliderFrame.slider = slider
787 slider:SetOrientation("VERTICAL")
788 slider:SetMinMaxValues(0, 1)
789 slider:SetValueStep(0.01)
790 slider:SetValue(0.5)
791 slider:SetWidth(16)
792 slider:SetHeight(128)
793 slider:SetPoint("LEFT", sliderFrame, "LEFT", 15, 0)
794 slider:SetBackdrop(tmp(
795 'bgFile', "Interface\\Buttons\\UI-SliderBar-Background",
796 'edgeFile', "Interface\\Buttons\\UI-SliderBar-Border",
797 'tile', true,
798 'edgeSize', 8,
799 'tileSize', 8,
800 'insets', tmp2(
801 'left', 3,
802 'right', 3,
803 'top', 3,
804 'bottom', 3
805 )
806 ))
807 local texture = slider:CreateTexture()
808 slider:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Vertical")
809 local text = slider:CreateFontString(nil, "ARTWORK")
810 sliderFrame.topText = text
811 text:SetFontObject(GameFontGreenSmall)
812 text:SetText("100%")
813 text:SetPoint("BOTTOM", slider, "TOP")
814 local text = slider:CreateFontString(nil, "ARTWORK")
815 sliderFrame.bottomText = text
816 text:SetFontObject(GameFontGreenSmall)
817 text:SetText("0%")
818 text:SetPoint("TOP", slider, "BOTTOM")
819 local text = slider:CreateFontString(nil, "ARTWORK")
820 sliderFrame.currentText = text
821 text:SetFontObject(GameFontHighlightSmall)
822 text:SetText("50%")
823 text:SetPoint("LEFT", slider, "RIGHT")
824 text:SetPoint("RIGHT", sliderFrame, "RIGHT", -6, 0)
825 text:SetJustifyH("CENTER")
826 local changed = false
827 local inside = false
828 slider:SetScript("OnValueChanged", function()
829 if sliderFrame.changing then
830 return
831 end
832 changed = true
833 local done = false
834 if sliderFrame.parent then
835 if sliderFrame.parent.sliderFunc then
836 local text = sliderFrame.parent.sliderFunc(1 - slider:GetValue())
837 if text then
838 sliderFrame.currentText:SetText(text)
839 done = true
840 end
841 end
842 end
843 if not done then
844 sliderFrame.currentText:SetText(format("%.0f%%", (1 - slider:GetValue()) * 100))
845 end
846 end)
847 sliderFrame:SetScript("OnEnter", function()
848 StopCounting(self, sliderFrame.level)
849 end)
850 sliderFrame:SetScript("OnLeave", function()
851 StartCounting(self, sliderFrame.level)
852 end)
853 slider:SetScript("OnMouseDown", function()
854 sliderFrame.mouseDown = true
855 end)
856 slider:SetScript("OnMouseUp", function()
857 sliderFrame.mouseDown = false
858 if changed and not inside then
859 local parent = sliderFrame.parent
860 Refresh(self, levels[sliderFrame.level - 1])
861 OpenSlider(self, parent)
862 end
863 end)
864 slider:SetScript("OnEnter", function()
865 inside = true
866 StopCounting(self, sliderFrame.level)
867 end)
868 slider:SetScript("OnLeave", function()
869 inside = false
870 StartCounting(self, sliderFrame.level)
871 if changed and not sliderFrame.mouseDown then
872 local parent = sliderFrame.parent
873 Refresh(self, levels[sliderFrame.level - 1])
874 OpenSlider(self, parent)
875 end
876 end)
877 end
878 sliderFrame.parent = parent
879 sliderFrame.level = parent.level.num + 1
880 sliderFrame.parentValue = parent.level.value
881 sliderFrame:SetFrameLevel(parent.level:GetFrameLevel() + 3)
882 sliderFrame.slider:SetFrameLevel(sliderFrame:GetFrameLevel() + 1)
883 sliderFrame.changing = true
884 if not parent.sliderValue then
885 parent.sliderValue = 0.5
886 end
887 sliderFrame.slider:SetValue(1 - parent.sliderValue)
888 sliderFrame.changing = false
889 sliderFrame.bottomText:SetText(parent.sliderBottom or "0%")
890 sliderFrame.topText:SetText(parent.sliderTop or "100%")
891 local text
892 if parent.sliderFunc then
893 text = parent.sliderFunc(parent.sliderValue)
894 end
895 sliderFrame.currentText:SetText(text or format("%.0f%%", parent.sliderValue * 100))
896  
897 local level = parent.level
898 sliderFrame:Show()
899 sliderFrame:ClearAllPoints()
900 if level.lastDirection == "RIGHT" then
901 if level.lastVDirection == "DOWN" then
902 sliderFrame:SetPoint("TOPLEFT", parent, "TOPRIGHT", 5, 10)
903 else
904 sliderFrame:SetPoint("BOTTOMLEFT", parent, "BOTTOMRIGHT", 5, -10)
905 end
906 else
907 if level.lastVDirection == "DOWN" then
908 sliderFrame:SetPoint("TOPRIGHT", parent, "TOPLEFT", -5, 10)
909 else
910 sliderFrame:SetPoint("BOTTOMRIGHT", parent, "BOTTOMLEFT", -5, -10)
911 end
912 end
913 local dirty
914 if level.lastDirection == "RIGHT" then
915 if sliderFrame:GetRight() > GetScreenWidth() then
916 level.lastDirection = "LEFT"
917 dirty = true
918 end
919 elseif sliderFrame:GetLeft() < 0 then
920 level.lastDirection = "RIGHT"
921 dirty = true
922 end
923 if level.lastVDirection == "DOWN" then
924 if sliderFrame:GetBottom() < 0 then
925 level.lastVDirection = "UP"
926 dirty = true
927 end
928 elseif sliderFrame:GetTop() > GetScreenWidth() then
929 level.lastVDirection = "DOWN"
930 dirty = true
931 end
932 if dirty then
933 sliderFrame:ClearAllPoints()
934 if level.lastDirection == "RIGHT" then
935 if level.lastVDirection == "DOWN" then
936 sliderFrame:SetPoint("TOPLEFT", parent, "TOPRIGHT", 5, 10)
937 else
938 sliderFrame:SetPoint("BOTTOMLEFT", parent, "BOTTOMRIGHT", 5, -10)
939 end
940 else
941 if level.lastVDirection == "DOWN" then
942 sliderFrame:SetPoint("TOPRIGHT", parent, "TOPLEFT", -5, 10)
943 else
944 sliderFrame:SetPoint("BOTTOMRIGHT", parent, "BOTTOMLEFT", -5, -10)
945 end
946 end
947 end
948 local left, bottom = sliderFrame:GetLeft(), sliderFrame:GetBottom()
949 sliderFrame:ClearAllPoints()
950 sliderFrame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", left, bottom)
951 if mod(level.num, 5) == 0 then
952 local left, bottom = level:GetLeft(), level:GetBottom()
953 level:ClearAllPoints()
954 level:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", left, bottom)
955 end
956 end
957  
958 function lib:IsOpen(parent)
959 return levels[1] and levels[1]:IsShown() and (parent == levels[1].parent or parent == levels[1]:GetParent())
960 end
961  
962 function Open(self, parent, func, level, value, point, relativePoint, cursorX, cursorY)
963 self:Close(level)
964 local frame = AcquireLevel(self, level)
965 if level == 1 then
966 frame.lastDirection = "RIGHT"
967 frame.lastVDirection = "DOWN"
968 else
969 frame.lastDirection = levels[level - 1].lastDirection
970 frame.lastVDirection = levels[level - 1].lastVDirection
971 end
972 frame:SetFrameStrata("TOOLTIP")
973 frame:ClearAllPoints()
974 frame.parent = parent
975 frame:SetPoint("LEFT", UIParent, "RIGHT", 10000, 0)
976 frame:Show()
977 if level == 1 then
978 baseFunc = func
979 end
980 levels[level].value = value
981 relativePoint = relativePoint or point
982 Refresh(self, levels[level])
983 if point then
984 frame:ClearAllPoints()
985 frame:SetPoint(point, parent, relativePoint)
986 if cursorX then
987 local left = frame:GetLeft()
988 local width = frame:GetWidth()
989 local curX, curY = GetCursorPosition()
990 frame:ClearAllPoints()
991 relativePoint = relativePoint or point
992 if point == "BOTTOM" or point == "TOP" then
993 if curX < GetScreenWidth() / 2 then
994 point = point .. "LEFT"
995 else
996 point = point .. "RIGHT"
997 end
998 elseif point == "CENTER" then
999 if curX < GetScreenWidth() / 2 then
1000 point = "LEFT"
1001 else
1002 point = "RIGHT"
1003 end
1004 end
1005 frame:SetPoint(point, parent, relativePoint, curX - left - width / 2, 0)
1006 if level == 1 then
1007 frame.lastDirection = "RIGHT"
1008 end
1009 elseif cursorY then
1010 local bottom = frame:GetBottom()
1011 local height = frame:GetHeight()
1012 local curX, curY = GetCursorPosition()
1013 frame:ClearAllPoints()
1014 relativePoint = relativePoint or point
1015 if point == "LEFT" or point == "RIGHT" then
1016 if curX < GetScreenHeight() / 2 then
1017 point = point .. "BOTTOM"
1018 else
1019 point = point .. "TOP"
1020 end
1021 elseif point == "CENTER" then
1022 if curX < GetScreenHeight() / 2 then
1023 point = "BOTTOM"
1024 else
1025 point = "TOP"
1026 end
1027 end
1028 frame:SetPoint(point, parent, relativePoint, 0, curY - bottom - height / 2)
1029 if level == 1 then
1030 frame.lastDirection = "DOWN"
1031 end
1032 end
1033 if (strsub(point, 1, 3) ~= strsub(relativePoint, 1, 3)) then
1034 if frame:GetBottom() < 0 then
1035 local point, parent, relativePoint, x, y = frame:GetPoint(1)
1036 local change = GetScreenHeight() - frame:GetTop()
1037 local otherChange = -frame:GetBottom()
1038 if otherChange < change then
1039 change = otherChange
1040 end
1041 frame:SetPoint(point, parent, relativePoint, x, y + change)
1042 elseif frame:GetTop() > GetScreenHeight() then
1043 local point, parent, relativePoint, x, y = frame:GetPoint(1)
1044 local change = GetScreenHeight() - frame:GetTop()
1045 local otherChange = -frame:GetBottom()
1046 if otherChange < change then
1047 change = otherChange
1048 end
1049 frame:SetPoint(point, parent, relativePoint, x, y + change)
1050 end
1051 end
1052 end
1053 CheckDualMonitor(self, frame)
1054 StartCounting(self, level)
1055 end
1056  
1057 function lib:IsRegistered(parent)
1058 assert(parent, "You must provide a parent frame to check")
1059 return not not self.registry[parent]
1060 end
1061  
1062 function lib:Register(parent, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
1063 assert(parent, "You must provide a parent frame to register with")
1064 if self.registry[parent] then
1065 self:Unregister(parent)
1066 end
1067 local info = new(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
1068 self.registry[parent] = info
1069 if not info.dontHook and not self.onceRegistered[parent] then
1070 if parent:HasScript("OnMouseUp") then
1071 local script = parent:GetScript("OnMouseUp")
1072 parent:SetScript("OnMouseUp", function()
1073 if script then
1074 script()
1075 end
1076 if arg1 == "RightButton" and self.registry[parent] then
1077 if self:IsOpen(parent) then
1078 self:Close()
1079 else
1080 self:Open(parent)
1081 end
1082 end
1083 end)
1084 end
1085 if parent:HasScript("OnMouseDown") then
1086 local script = parent:GetScript("OnMouseDown")
1087 parent:SetScript("OnMouseDown", function()
1088 if script then
1089 script()
1090 end
1091 if self.registry[parent] then
1092 self:Close()
1093 end
1094 end)
1095 end
1096 end
1097 self.onceRegistered[parent] = true
1098 end
1099  
1100 function lib:Unregister(parent)
1101 assert(self.registry[parent], "You cannot unregister a parent frame if it has not been registered already.")
1102 self.registry[parent] = nil
1103 end
1104  
1105 function lib:Open(parent, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
1106 local info
1107 if type(k1) == "table" and k1[0] and k1.IsFrameType and self.registry[k1] then
1108 info = tmp()
1109 for k,v in pairs(self.registry[k1]) do
1110 info[k] = v
1111 end
1112 else
1113 info = tmp(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
1114 if self.registry[parent] then
1115 for k,v in pairs(self.registry[parent]) do
1116 if info[k] == nil then
1117 info[k] = v
1118 end
1119 end
1120 end
1121 end
1122 local point = info.point
1123 local relativePoint = info.relativePoint
1124 local cursorX = info.cursorX
1125 local cursorY = info.cursorY
1126 if type(point) == "function" then
1127 local b
1128 point, b = point(parent)
1129 if b then
1130 relativePoint = b
1131 end
1132 end
1133 if type(relativePoint) == "function" then
1134 relativePoint = relativePoint(parent)
1135 end
1136 Open(self, parent, info.children, 1, nil, point, relativePoint, cursorX, cursorY)
1137 end
1138  
1139 function Clear(self, level)
1140 if level then
1141 if level.buttons then
1142 for i = tgetn(level.buttons), 1, -1 do
1143 ReleaseButton(self, level, i)
1144 end
1145 end
1146 end
1147 end
1148  
1149 function lib:Close(level)
1150 if DropDownList1:IsShown() then
1151 DropDownList1:Hide()
1152 end
1153 if not level then
1154 level = 1
1155 end
1156 if level == 1 and levels[level] then
1157 levels[level].parented = false
1158 end
1159 if sliderFrame and sliderFrame.level == level then
1160 sliderFrame:Hide()
1161 end
1162 if levels[level] and levels[level]:IsShown() then
1163 Clear(self, levels[level])
1164 levels[level]:Hide()
1165 end
1166 end
1167  
1168 function lib:AddLine(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
1169 local info = tmp(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10, k11, v11, k12, v12, k13, v13, k14, v14, k15, v15, k16, v16, k17, v17, k18, v18, k19, v19, k20, v20)
1170 local level = info.level or currentLevel
1171 info.level = nil
1172 local button = AcquireButton(self, level)
1173 if not next(info) then
1174 info.disabled = true
1175 end
1176 button.disabled = info.isTitle or info.notClickable or info.disabled
1177 button.isTitle = info.isTitle
1178 button.notClickable = info.notClickable
1179 if button.isTitle then
1180 button.text:SetFontObject(GameFontNormalSmall)
1181 elseif button.notClickable then
1182 button.text:SetFontObject(GameFontHighlightSmall)
1183 elseif button.disabled then
1184 button.text:SetFontObject(GameFontDisableSmall)
1185 else
1186 button.text:SetFontObject(GameFontHighlightSmall)
1187 end
1188 if info.textR and info.textG and info.textB then
1189 button.textR = info.textR
1190 button.textG = info.textG
1191 button.textB = info.textB
1192 button.text:SetTextColor(button.textR, button.textG, button.textB)
1193 else
1194 button.text:SetTextColor(button.text:GetFontObject():GetTextColor())
1195 end
1196 button.notCheckable = info.notCheckable
1197 button.text:SetPoint("LEFT", button, "LEFT", button.notCheckable and 0 or 24, 0)
1198 button.checked = not info.notCheckable and info.checked
1199 button.isRadio = not info.notCheckable and info.isRadio
1200 if info.isRadio then
1201 button.check:Show()
1202 button.check:SetTexture(info.checkIcon or "Interface\\Buttons\\UI-RadioButton")
1203 if button.checked then
1204 button.check:SetTexCoord(0.25, 0.5, 0, 1)
1205 button.check:SetVertexColor(1, 1, 1, 1)
1206 else
1207 button.check:SetTexCoord(0, 0.25, 0, 1)
1208 button.check:SetVertexColor(1, 1, 1, 0.5)
1209 end
1210 button.radioHighlight:SetTexture(info.checkIcon or "Interface\\Buttons\\UI-RadioButton")
1211 button.check:SetWidth(16)
1212 button.check:SetHeight(16)
1213 else
1214 if button.checked then
1215 button.check:SetTexCoord(0, 1, 0, 1)
1216 if info.checkIcon then
1217 button.check:SetWidth(16)
1218 button.check:SetHeight(16)
1219 button.check:SetTexture(info.checkIcon)
1220 else
1221 button.check:SetWidth(24)
1222 button.check:SetHeight(24)
1223 button.check:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
1224 end
1225 button.check:SetVertexColor(1, 1, 1, 1)
1226 else
1227 button.check:SetVertexColor(1, 1, 1, 0)
1228 end
1229 end
1230 if not button.disabled then
1231 button.func = info.func
1232 end
1233 button.hasColorSwatch = info.hasColorSwatch
1234 if button.hasColorSwatch then
1235 button.colorSwatch:Show()
1236 button.colorSwatch.texture:Show()
1237 button.r = info.r or 1
1238 button.g = info.g or 1
1239 button.b = info.b or 1
1240 button.colorSwatch.texture:SetTexture(button.r, button.g, button.b)
1241 button.checked = false
1242 button.func = nil
1243 button.swatchFunc = info.swatchFunc
1244 button.hasOpacity = info.hasOpacity
1245 button.opacityFunc = info.opacityFunc
1246 button.opacity = info.opacity or 1
1247 button.cancelFunc = info.cancelFunc
1248 else
1249 button.colorSwatch:Hide()
1250 button.colorSwatch.texture:Hide()
1251 end
1252 button.hasArrow = not button.hasColorSwatch and (info.value or info.hasSlider) and info.hasArrow
1253 if button.hasArrow then
1254 button.arrow:SetAlpha(1)
1255 if info.hasSlider then
1256 button.hasSlider = info.hasSlider
1257 button.sliderTop = info.sliderTop or "100%"
1258 button.sliderBottom = info.sliderBottom or "0%"
1259 button.sliderFunc = info.sliderFunc
1260 button.sliderValue = info.sliderValue
1261 else
1262 button.value = info.value
1263 end
1264 else
1265 button.arrow:SetAlpha(0)
1266 end
1267 button.arg1 = info.arg1
1268 button.arg2 = info.arg2
1269 button.arg3 = info.arg3
1270 button.arg4 = info.arg4
1271 button.closeWhenClicked = info.closeWhenClicked
1272 button.textHeight = info.textHeight or UIDROPDOWNMENU_DEFAULT_TEXT_HEIGHT
1273 local font,_ = button.text:GetFont()
1274 button.text:SetFont(STANDARD_TEXT_FONT, button.textHeight)
1275 button:SetHeight(button.textHeight + 6)
1276 button.text:SetPoint("RIGHT", button.arrow, (button.hasColorSwatch or button.hasArrow) and "LEFT" or "RIGHT")
1277 button.text:SetJustifyH(info.justifyH or "LEFT")
1278 button.text:SetText(info.text)
1279 button.tooltipTitle = info.tooltipTitle
1280 button.tooltipText = info.tooltipText
1281 if type(button.func) == "string" then
1282 assert(type(button.arg1) == "table", "Cannot call method " .. button.func .. " on a non-table")
1283 assert(type(button.arg1[button.func]) == "function", "Method " .. button.func .. " nonexistant.")
1284 end
1285 end
1286  
1287 DewdropLib:Register(lib)
1288 lib = nil