comparison Bar.lua @ 73:dd01feae0d89

Split the bar overlay out into its own file
author Flick <flickerstreak@gmail.com>
date Thu, 05 Jun 2008 18:52:53 +0000
parents aa88aed52124
children 06cd74bdc7da
comparison
equal deleted inserted replaced
72:aa88aed52124 73:dd01feae0d89
1 local ReAction = ReAction 1 local ReAction = ReAction
2 local L = ReAction.L 2 local L = ReAction.L
3 local _G = _G 3 local _G = _G
4 local CreateFrame = CreateFrame 4 local CreateFrame = CreateFrame
5 local InCombatLockdown = InCombatLockdown
6 local floor = math.floor 5 local floor = math.floor
7 local min = math.min
8 local format = string.format
9 local GameTooltip = GameTooltip
10 local SecureStateHeader_Refresh = SecureStateHeader_Refresh 6 local SecureStateHeader_Refresh = SecureStateHeader_Refresh
11 7
12 8
13 9
14 -- update ReAction revision if this file is newer 10 -- update ReAction revision if this file is newer
59 self.frame = nil 55 self.frame = nil
60 self.config = nil 56 self.config = nil
61 end 57 end
62 58
63 function Bar:OnConfigModeChanged(event, mode) 59 function Bar:OnConfigModeChanged(event, mode)
64 self:ShowControls(mode) 60 self:ShowControls(mode) -- ShowControls() defined in Overlay.lua
65 end 61 end
66 62
67 function Bar:RefreshLayout() 63 function Bar:RefreshLayout()
68 ReAction:RefreshBar(self) 64 ReAction:RefreshBar(self)
69 end 65 end
322 f:SetAttribute("headscale",table.concat(t,";") or "") 318 f:SetAttribute("headscale",table.concat(t,";") or "")
323 SecureStateHeader_Refresh(f) 319 SecureStateHeader_Refresh(f)
324 end 320 end
325 321
326 322
327 --
328 -- Bar config overlay
329 --
330 local CreateControls
331
332 do
333 -- upvalue some of these for small OnUpdate performance boost
334 local GetSize = Bar.GetSize
335 local GetButtonSize = Bar.GetButtonSize
336 local GetButtonGrid = Bar.GetButtonGrid
337 local SetSize = Bar.SetSize
338 local SetButtonSize = Bar.SetButtonSize
339 local SetButtonGrid = Bar.SetButtonGrid
340 local ApplyAnchor = Bar.ApplyAnchor
341
342 local function StoreExtents(bar)
343 local f = bar.frame
344 local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
345 relativeTo = relativeTo or f:GetParent()
346 local anchorTo
347 for name, b in ReAction:IterateBars() do
348 if b and b:GetFrame() == relativeTo then
349 anchorTo = name
350 break
351 end
352 end
353 anchorTo = anchorTo or relativeTo:GetName()
354 local c = bar.config
355 c.anchor = point
356 c.anchorTo = anchorTo
357 c.relativePoint = relativePoint
358 c.x = x
359 c.y = y
360 c.width, c.height = f:GetWidth(), f:GetHeight()
361 end
362
363 local function StoreSize(bar)
364 local f = bar.frame
365 local c = bar.config
366 c.width, c.height = f:GetWidth(), f:GetHeight()
367 end
368
369 local function RecomputeButtonSize(bar)
370 local w, h = GetSize(bar)
371 local bw, bh = GetButtonSize(bar)
372 local r, c, s = GetButtonGrid(bar)
373
374 local scaleW = (floor(w/c) - s) / bw
375 local scaleH = (floor(h/r) - s) / bh
376 local scale = min(scaleW, scaleH)
377
378 SetButtonSize(bar, scale * bw, scale * bh, s)
379 end
380
381 local function RecomputeButtonSpacing(bar)
382 local w, h = GetSize(bar)
383 local bw, bh = GetButtonSize(bar)
384 local r, c, s = GetButtonGrid(bar)
385
386 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
387 end
388
389 local function RecomputeGrid(bar)
390 local w, h = GetSize(bar)
391 local bw, bh = GetButtonSize(bar)
392 local r, c, s = GetButtonGrid(bar)
393
394 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
395 end
396
397 local function ClampToButtons(bar)
398 local bw, bh = GetButtonSize(bar)
399 local r, c, s = GetButtonGrid(bar)
400 SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1)
401 end
402
403 local function HideGameTooltip()
404 GameTooltip:Hide()
405 end
406
407 local anchorInside = { inside = true }
408 local anchorOutside = { outside = true }
409 local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" }
410 local oppositeEdges = {
411 TOP = "BOTTOM",
412 BOTTOM = "TOP",
413 LEFT = "RIGHT",
414 RIGHT = "LEFT"
415 }
416 local pointsOnEdge = {
417 BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", },
418 TOP = { "TOP", "TOPLEFT", "TOPRIGHT", },
419 RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", },
420 LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", },
421 }
422 local edgeSelector = {
423 BOTTOM = 1, -- select x of x,y
424 TOP = 1, -- select x of x,y
425 LEFT = 2, -- select y of x,y
426 RIGHT = 2, -- select y of x,y
427 }
428 local snapPoints = {
429 [anchorOutside] = {
430 BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"},
431 BOTTOM = {"TOP"},
432 BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"},
433 RIGHT = {"LEFT"},
434 TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"},
435 TOP = {"BOTTOM"},
436 TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"},
437 LEFT = {"RIGHT"},
438 CENTER = {"CENTER"}
439 },
440 [anchorInside] = {
441 BOTTOMLEFT = {"BOTTOMLEFT"},
442 BOTTOM = {"BOTTOM"},
443 BOTTOMRIGHT = {"BOTTOMRIGHT"},
444 RIGHT = {"RIGHT"},
445 TOPRIGHT = {"TOPRIGHT"},
446 TOP = {"TOP"},
447 TOPLEFT = {"TOPLEFT"},
448 LEFT = {"LEFT"},
449 CENTER = {"CENTER"}
450 }
451 }
452 local insidePointOffsetFuncs = {
453 BOTTOMLEFT = function(x, y) return x, y end,
454 BOTTOM = function(x, y) return 0, y end,
455 BOTTOMRIGHT = function(x, y) return -x, y end,
456 RIGHT = function(x, y) return -x, 0 end,
457 TOPRIGHT = function(x, y) return -x, -y end,
458 TOP = function(x, y) return 0, -y end,
459 TOPLEFT = function(x, y) return x, -y end,
460 LEFT = function(x, y) return x, 0 end,
461 CENTER = function(x, y) return 0, 0 end,
462 }
463 local pointCoordFuncs = {
464 BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end,
465 BOTTOM = function(f) return nil, f:GetBottom() end,
466 BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end,
467 RIGHT = function(f) return f:GetRight(), nil end,
468 TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end,
469 TOP = function(f) return nil, f:GetTop() end,
470 TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end,
471 LEFT = function(f) return f:GetLeft(), nil end,
472 CENTER = function(f) return f:GetCenter() end,
473 }
474 local edgeBoundsFuncs = {
475 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end,
476 LEFT = function(f) return f:GetBottom(), f:GetTop() end
477 }
478 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM
479 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
480
481
482 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
483 local function GetPointCoords( f, p )
484 local x, y = pointCoordFuncs[p](f)
485 if not(x and y) then
486 local cx, cy = f:GetCenter()
487 x = x or cx
488 y = y or cy
489 end
490 return x, y
491 end
492
493
494 -- Returns true if frame 'f1' can be anchored to frame 'f2'
495 local function CheckAnchorable( f1, f2 )
496 -- can't anchor a frame to itself or to nil
497 if f1 == f2 or f2 == nil then
498 return false
499 end
500
501 -- can always anchor to UIParent
502 if f2 == UIParent then
503 return true
504 end
505
506 -- also can't do circular anchoring of frames
507 -- walk the anchor chain, which generally shouldn't be that expensive
508 -- (who nests draggables that deep anyway?)
509 for i = 1, f2:GetNumPoints() do
510 local _, f = f2:GetPoint(i)
511 if not f then f = f2:GetParent() end
512 return CheckAnchorable(f1,f)
513 end
514
515 return true
516 end
517
518 -- Returns true if frames f1 and f2 specified edges overlap
519 local function CheckEdgeOverlap( f1, f2, e )
520 local l1, u1 = edgeBoundsFuncs[e](f1)
521 local l2, u2 = edgeBoundsFuncs[e](f2)
522 return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2
523 end
524
525 -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2
526 local function CheckPointEdgeOverlap( f1, p1, f2, e2 )
527 local l, u = edgeBoundsFuncs[e2](f2)
528 local x, y = GetPointCoords(f1,p1)
529 x = select(edgeSelector[e2], x, y)
530 return l <= x and x <= u
531 end
532
533 -- Returns the distance between corresponding edges. It is
534 -- assumed that the passed in edges e1 and e2 are the same or opposites
535 local function GetEdgeDistance( f1, f2, e1, e2 )
536 local x1, y1 = pointCoordFuncs[e1](f1)
537 local x2, y2 = pointCoordFuncs[e2](f2)
538 return math.abs((x1 or y1) - (x2 or y2))
539 end
540
541 local globalSnapTargets = { [UIParent] = anchorInside }
542
543 local function GetClosestFrameEdge(f1,f2,a)
544 local dist, edge, opp
545 if f2:IsVisible() and CheckAnchorable(f1,f2) then
546 for _, e in pairs(edges) do
547 local o = a.inside and e or oppositeEdges[e]
548 if CheckEdgeOverlap(f1,f2,e) then
549 local d = GetEdgeDistance(f1, f2, e, o)
550 if not dist or (d < dist) then
551 dist, edge, opp = d, e, o
552 end
553 end
554 end
555 end
556 return dist, edge, opp
557 end
558
559 local function GetClosestVisibleEdge( f )
560 local r, o, e1, e2
561 local a = anchorOutside
562 for _, b in ReAction:IterateBars() do
563 local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a)
564 if d and (not r or d < r) then
565 r, o, e1, e2 = d, b:GetFrame(), e, opp
566 end
567 end
568 for f2, a2 in pairs(globalSnapTargets) do
569 local d, e, opp = GetClosestFrameEdge(f,f2,a2)
570 if d and (not r or d < r) then
571 r, o, e1, e2, a = d, f2, e, opp, a2
572 end
573 end
574 return o, e1, e2, a
575 end
576
577 local function GetClosestVisiblePoint(f1)
578 local f2, e1, e2, a = GetClosestVisibleEdge(f1)
579 if f2 then
580 local rsq, p, rp, x, y
581 -- iterate pointsOnEdge in order and use < to prefer edge centers to corners
582 for _, p1 in ipairs(pointsOnEdge[e1]) do
583 if CheckPointEdgeOverlap(f1,p1,f2,e2) then
584 for _, p2 in pairs(snapPoints[a][p1]) do
585 local x1, y1 = GetPointCoords(f1,p1)
586 local x2, y2 = GetPointCoords(f2,p2)
587 local dx = x1 - x2
588 local dy = y1 - y2
589 local rsq2 = dx*dx + dy*dy
590 if not rsq or rsq2 < rsq then
591 rsq, p, rp, x, y = rsq2, p1, p2, dx, dy
592 end
593 end
594 end
595 end
596 return f2, p, rp, x, y
597 end
598 end
599
600 local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff)
601 local o, p, rp, x, y = GetClosestVisiblePoint(f1)
602 local s = false
603
604 local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0)
605 local xx, yy = pointCoordFuncs[p](f1)
606 if xx and yy then
607 if math.abs(x) <= rx then
608 x = sx
609 s = true
610 end
611 if math.abs(y) <= ry then
612 y = sy
613 s = true
614 end
615 elseif xx then
616 if math.abs(x) <= rx then
617 x = sx
618 s = true
619 if math.abs(y) <= ry then
620 y = sy
621 end
622 end
623 elseif yy then
624 if math.abs(y) <= ry then
625 y = sy
626 s = true
627 if math.abs(x) <= rx then
628 x = sx
629 end
630 end
631 end
632
633 if x == -0 then x = 0 end
634 if y == -0 then y = 0 end
635
636 if s then
637 return o, p, rp, math.floor(x), math.floor(y)
638 end
639 end
640
641 local function CreateSnapIndicator()
642 local si = CreateFrame("Frame",nil,UIParent)
643 si:SetFrameStrata("HIGH")
644 si:SetHeight(8)
645 si:SetWidth(8)
646 local tex = si:CreateTexture()
647 tex:SetAllPoints()
648 tex:SetTexture(1.0, 0.82, 0, 0.8)
649 tex:SetBlendMode("ADD")
650 tex:SetDrawLayer("OVERLAY")
651 return si
652 end
653
654 local si1 = CreateSnapIndicator()
655 local si2 = CreateSnapIndicator()
656
657 local function DisplaySnapIndicator( f, rx, ry, xOff, yOff )
658 local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff)
659 if o then
660 si1:ClearAllPoints()
661 si2:ClearAllPoints()
662 si1:SetPoint("CENTER", f, p, 0, 0)
663 local xx, yy = pointCoordFuncs[rp](o)
664 x = math.abs(x) <=rx and xx and 0 or x
665 y = math.abs(y) <=ry and yy and 0 or y
666 si2:SetPoint("CENTER", o, rp, x, y)
667 si1:Show()
668 si2:Show()
669 else
670 if si1:IsVisible() then
671 si1:Hide()
672 si2:Hide()
673 end
674 end
675 end
676
677 local function HideSnapIndicator()
678 if si1:IsVisible() then
679 si1:Hide()
680 si2:Hide()
681 end
682 end
683
684 function CreateControls(bar)
685 local f = bar.frame
686
687 f:SetMovable(true)
688 f:SetResizable(true)
689 f:SetClampedToScreen(true)
690
691 -- buttons on the bar should be direct children of the bar frame.
692 -- The control elements need to float on top of this, which we could
693 -- do with SetFrameLevel() or Raise(), but it's more reliable to do it
694 -- via frame nesting, hence good old foo's appearance here.
695 local foo = CreateFrame("Frame",nil,f)
696 foo:SetAllPoints()
697 foo:SetClampedToScreen(true)
698
699 local control = CreateFrame("Button", nil, foo)
700 control:EnableMouse(true)
701 control:SetToplevel(true)
702 control:SetPoint("TOPLEFT", -4, 4)
703 control:SetPoint("BOTTOMRIGHT", 4, -4)
704 control:SetBackdrop({
705 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
706 tile = true,
707 tileSize = 16,
708 edgeSize = 16,
709 insets = { left = 0, right = 0, top = 0, bottom = 0 },
710 })
711
712 -- textures
713 local bgTex = control:CreateTexture(nil,"BACKGROUND")
714 bgTex:SetTexture(0.7,0.7,1.0,0.2)
715 bgTex:SetPoint("TOPLEFT",4,-4)
716 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
717 local hTex = control:CreateTexture(nil,"HIGHLIGHT")
718 hTex:SetTexture(0.7,0.7,1.0,0.2)
719 hTex:SetPoint("TOPLEFT",4,-4)
720 hTex:SetPoint("BOTTOMRIGHT",-4,4)
721 hTex:SetBlendMode("ADD")
722
723 -- label
724 local label = control:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
725 label:SetAllPoints()
726 label:SetJustifyH("CENTER")
727 label:SetShadowColor(0,0,0,1)
728 label:SetShadowOffset(2,-2)
729 label:SetTextColor(1,1,1,1)
730 label:SetText(bar:GetName())
731 label:Show()
732 bar.controlLabelString = label -- so that bar:SetName() can update it
733
734 local function StopResize()
735 f:StopMovingOrSizing()
736 f.isMoving = false
737 f:SetScript("OnUpdate",nil)
738 StoreSize(bar)
739 ClampToButtons(bar)
740 ApplyAnchor(bar)
741 ReAction:RefreshOptions()
742 end
743
744 -- edge drag handles
745 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
746 local edge = CreateFrame("Frame",nil,control)
747 edge:EnableMouse(true)
748 edge:SetWidth(8)
749 edge:SetHeight(8)
750 if point == "TOP" or point == "BOTTOM" then
751 edge:SetPoint(point.."LEFT")
752 edge:SetPoint(point.."RIGHT")
753 else
754 edge:SetPoint("TOP"..point)
755 edge:SetPoint("BOTTOM"..point)
756 end
757 local tex = edge:CreateTexture(nil,"HIGHLIGHT")
758 tex:SetTexture(1.0,0.82,0,0.7)
759 tex:SetBlendMode("ADD")
760 tex:SetAllPoints()
761 edge:RegisterForDrag("LeftButton")
762 edge:SetScript("OnMouseDown",
763 function()
764 local bw, bh = GetButtonSize(bar)
765 local r, c, s = GetButtonGrid(bar)
766 f:SetMinResize( bw+s+1, bh+s+1 )
767 f:StartSizing(point)
768 f:SetScript("OnUpdate",
769 function()
770 RecomputeGrid(bar)
771 bar:RefreshLayout()
772 end
773 )
774 end
775 )
776 edge:SetScript("OnMouseUp", StopResize)
777 edge:SetScript("OnEnter",
778 function()
779 GameTooltip:SetOwner(f, "ANCHOR_"..point)
780 GameTooltip:AddLine(L["Drag to add/remove buttons"])
781 GameTooltip:Show()
782 end
783 )
784 edge:SetScript("OnLeave", HideGameTooltip)
785 edge:Show()
786 end
787
788 -- corner drag handles, again nested in an anonymous frame so that they are on top
789 local foo2 = CreateFrame("Frame",nil,control)
790 foo2:SetAllPoints(true)
791 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
792 local corner = CreateFrame("Frame",nil,foo2)
793 corner:EnableMouse(true)
794 corner:SetWidth(12)
795 corner:SetHeight(12)
796 corner:SetPoint(point)
797 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
798 tex:SetTexture(1.0,0.82,0,0.7)
799 tex:SetBlendMode("ADD")
800 tex:SetAllPoints()
801 corner:RegisterForDrag("LeftButton","RightButton")
802 local function updateTooltip()
803 local size, size2 = bar:GetButtonSize()
804 local rows, cols, spacing = bar:GetButtonGrid()
805 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
806 GameTooltipTextRight4:SetText(size)
807 GameTooltipTextRight5:SetText(tostring(spacing))
808 end
809 corner:SetScript("OnMouseDown",
810 function(_,btn)
811 local bw, bh = GetButtonSize(bar)
812 local r, c, s = GetButtonGrid(bar)
813 if btn == "LeftButton" then -- button resize
814 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
815 f:SetScript("OnUpdate",
816 function()
817 RecomputeButtonSize(bar)
818 bar:RefreshLayout()
819 updateTooltip()
820 end
821 )
822 elseif btn == "RightButton" then -- spacing resize
823 f:SetMinResize( bw*c, bh*r )
824 f:SetScript("OnUpdate",
825 function()
826 RecomputeButtonSpacing(bar)
827 bar:RefreshLayout()
828 updateTooltip()
829 end
830 )
831 end
832 f:StartSizing(point)
833 end
834 )
835 corner:SetScript("OnMouseUp",StopResize)
836 corner:SetScript("OnEnter",
837 function()
838 GameTooltip:SetOwner(f, "ANCHOR_"..point)
839 GameTooltip:AddLine(L["Drag to resize buttons"])
840 GameTooltip:AddLine(L["Right-click-drag"])
841 GameTooltip:AddLine(L["to change spacing"])
842 local size, size2 = bar:GetButtonSize()
843 local rows, cols, spacing = bar:GetButtonGrid()
844 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
845 GameTooltip:AddDoubleLine(L["Size:"], size)
846 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
847 GameTooltip:Show()
848 end
849 )
850 corner:SetScript("OnLeave",
851 function()
852 GameTooltip:Hide()
853 f:SetScript("OnUpdate",nil)
854 end
855 )
856
857 end
858
859 control:RegisterForDrag("LeftButton")
860 control:RegisterForClicks("RightButtonDown")
861
862 control:SetScript("OnDragStart",
863 function()
864 f:StartMoving()
865 f.isMoving = true
866 local w,h = bar:GetButtonSize()
867 f:ClearAllPoints()
868 f:SetScript("OnUpdate", function()
869 if IsShiftKeyDown() then
870 DisplaySnapIndicator(f,w,h)
871 else
872 HideSnapIndicator()
873 end
874 end)
875 end
876 )
877
878 local function updateDragTooltip()
879 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
880 GameTooltip:AddLine(bar.name)
881 GameTooltip:AddLine(L["Drag to move"])
882 GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"]))
883 GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"]))
884 local _, a = bar:GetAnchor()
885 if a and a ~= "UIParent" then
886 GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a))
887 end
888 GameTooltip:Show()
889 end
890
891 control:SetScript("OnDragStop",
892 function()
893 f:StopMovingOrSizing()
894 f.isMoving = false
895 f:SetScript("OnUpdate",nil)
896
897 if IsShiftKeyDown() then
898 local w, h = bar:GetButtonSize()
899 local a, p, rp, x, y = GetClosestPointSnapped(f,w,h)
900 if a then
901 f:ClearAllPoints()
902 f:SetPoint(p,a,rp,x,y)
903 end
904 HideSnapIndicator()
905 end
906
907 StoreExtents(bar)
908 ReAction:RefreshOptions()
909 updateDragTooltip()
910 end
911 )
912
913 control:SetScript("OnEnter",
914 function()
915 -- TODO: add bar type and status information to name
916 --[[
917 local name = bar.name
918 for _, m in ReAction:IterateModules() do
919 local suffix = safecall(m,"GetBarNameModifier",bar)
920 if suffix then
921 name = ("%s %s"):format(name,suffix)
922 end
923 end
924 ]]--
925
926 updateDragTooltip()
927 end
928 )
929
930 control:SetScript("OnLeave", HideGameTooltip)
931
932 control:SetScript("OnClick",
933 function()
934 bar:ShowMenu()
935 end
936 )
937
938 return control
939 end
940 end
941
942
943 local OpenMenu, CloseMenu
944 do
945 -- Looking for a lightweight AceConfig3-struct-compatible
946 -- replacement for Dewdrop, encapsulate here
947 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's
948 -- a bit tricky to convert from AceConfig3-struct
949 local Dewdrop = AceLibrary("Dewdrop-2.0")
950 function OpenMenu (frame, opts)
951 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true)
952 end
953 function CloseMenu(frame)
954 if Dewdrop:GetOpenedParent() == frame then
955 Dewdrop:Close()
956 end
957 end
958 end
959
960
961 function Bar:ShowControls(show)
962 if show then
963 if not self.controlFrame then
964 self.controlFrame = CreateControls(self)
965 end
966 self.controlFrame:Show()
967 elseif self.controlFrame then
968 CloseMenu(self.controlFrame)
969 self.controlFrame:Hide()
970 end
971 end
972
973 function Bar:ShowMenu()
974 if not self.menuOpts then
975 self.menuOpts = {
976 type = "group",
977 args = {
978 openConfig = {
979 type = "execute",
980 name = L["Settings..."],
981 desc = L["Open the editor for this bar"],
982 func = function() CloseMenu(self.controlFrame); ReAction:ShowEditor(self) end,
983 disabled = InCombatLockdown,
984 order = 1
985 },
986 delete = {
987 type = "execute",
988 name = L["Delete Bar"],
989 desc = L["Remove the bar from the current profile"],
990 confirm = L["Are you sure you want to remove this bar?"],
991 func = function() ReAction:EraseBar(self) end,
992 order = 2
993 },
994 }
995 }
996 end
997 OpenMenu(self.controlFrame, self.menuOpts)
998 end
999
1000
1001 323
1002 ------ Export as a class-factory ------ 324 ------ Export as a class-factory ------
1003 ReAction.Bar = { 325 ReAction.Bar = {
326 prototype = Bar,
1004 new = function(self, ...) 327 new = function(self, ...)
1005 local x = { } 328 local x = { }
1006 for k,v in pairs(Bar) do 329 for k,v in pairs(Bar) do
1007 x[k] = v 330 x[k] = v
1008 end 331 end