comparison Overlay.lua @ 103:890e4c4ab143

- added alpha settings (base and stateful) - added scale settings (stateful only) - updated overlay to work with stateful anchor/scale (though when in a state with scale, the button size/spacing can't be manipulated)
author Flick <flickerstreak@gmail.com>
date Thu, 06 Nov 2008 01:28:07 +0000
parents f200bcb193d6
children
comparison
equal deleted inserted replaced
102:ad49739d110d 103:890e4c4ab143
6 local min = math.min 6 local min = math.min
7 local format = string.format 7 local format = string.format
8 local GameTooltip = GameTooltip 8 local GameTooltip = GameTooltip
9 local Bar = ReAction.Bar 9 local Bar = ReAction.Bar
10 local GetSize = Bar.GetSize 10 local GetSize = Bar.GetSize
11 local SetSize = Bar.SetSize
11 local GetButtonSize = Bar.GetButtonSize 12 local GetButtonSize = Bar.GetButtonSize
12 local GetButtonGrid = Bar.GetButtonGrid 13 local GetButtonGrid = Bar.GetButtonGrid
13 local SetSize = Bar.SetSize
14 local SetAnchor = Bar.SetAnchor
15 local SetButtonSize = Bar.SetButtonSize 14 local SetButtonSize = Bar.SetButtonSize
16 local SetButtonGrid = Bar.SetButtonGrid 15 local SetButtonGrid = Bar.SetButtonGrid
17 local ApplyAnchor = Bar.ApplyAnchor 16 local ApplyAnchor = Bar.ApplyAnchor
18 local GameTooltipTextRight1 = GameTooltipTextRight1 17 local GameTooltipTextRight1 = GameTooltipTextRight1
19 local GameTooltipTextRight2 = GameTooltipTextRight2 18 local GameTooltipTextRight2 = GameTooltipTextRight2
21 20
22 local KB = LibStub("LibKeyBound-1.0") 21 local KB = LibStub("LibKeyBound-1.0")
23 22
24 ReAction:UpdateRevision("$Revision$") 23 ReAction:UpdateRevision("$Revision$")
25 24
25
26 --
27 -- Wrap some of the bar manipulators to make them state-aware
28 --
29 local function SetAnchor( bar, point, frame, relPoint, x, y )
30 local state = bar:GetState()
31 if state then
32 local anchorstate = bar:GetStateProperty(state, "anchorEnable")
33 if anchorstate then
34 bar:SetStateProperty(state, "anchorFrame", frame)
35 bar:SetStateProperty(state, "anchorPoint", point)
36 bar:SetStateProperty(state, "anchorRelPoint", relPoint)
37 bar:SetStateProperty(state, "anchorX", x or 0)
38 bar:SetStateProperty(state, "anchorY", y or 0)
39 bar:SetAnchor(bar:GetAnchor())
40 return
41 end
42 end
43 bar:SetAnchor(point, frame, relPoint, x, y)
44 end
45
46 local function GetStateScale( bar )
47 local state = bar:GetState()
48 if state and bar:GetStateProperty(state, "enableScale") then
49 return bar:GetStateProperty(state, "scale")
50 end
51 end
52
53 local function SetStateScale( bar, scale )
54 local state = bar:GetState()
55 if state and bar:GetStateProperty(state, "enableScale") then
56 bar:SetStateProperty(state, "scale", scale)
57 end
58 end
59
60
26 -- 61 --
27 -- Bar config overlay 62 -- Bar config overlay
28 -- 63 --
29 64
30 local function GetNormalTextColor() 65 local function GetNormalTextColor()
49 end 84 end
50 85
51 local function StoreExtents(bar) 86 local function StoreExtents(bar)
52 local f = bar:GetFrame() 87 local f = bar:GetFrame()
53 local p, fr, rp, x, y = f:GetPoint(1) 88 local p, fr, rp, x, y = f:GetPoint(1)
54 fr = fr or UIParent 89 fr = fr and fr:GetName() or "UIParent"
55 SetAnchor( bar, p, fr, rp, x, y ) 90 SetAnchor( bar, p, fr, rp, x, y )
56 SetSize( bar, f:GetWidth(), f:GetHeight() ) 91 SetSize( bar, f:GetWidth(), f:GetHeight() )
57 end 92 end
58 93
59 local function RecomputeButtonSize(bar) 94 local function RecomputeButtonSize(bar)
64 local scaleW = (floor(w/c) - s) / bw 99 local scaleW = (floor(w/c) - s) / bw
65 local scaleH = (floor(h/r) - s) / bh 100 local scaleH = (floor(h/r) - s) / bh
66 local scale = min(scaleW, scaleH) 101 local scale = min(scaleW, scaleH)
67 102
68 SetButtonSize(bar, scale * bw, scale * bh, s) 103 SetButtonSize(bar, scale * bw, scale * bh, s)
104 end
105
106 local function ComputeBarScale(bar)
107 local w, h = bar.controlFrame:GetWidth() - 8, bar.controlFrame:GetHeight() - 8
108 local bw, bh = GetButtonSize(bar)
109 local r, c, s = GetButtonGrid(bar)
110
111 local scaleW = w / (c*(bw+s))
112 local scaleH = h / (r*(bh+s))
113 local scale = min(scaleW, scaleH)
114
115 if scale > 2.5 then
116 scale = 2.5
117 elseif scale < 0.25 then
118 scale = 0.25
119 end
120
121 return scale
69 end 122 end
70 123
71 local function RecomputeButtonSpacing(bar) 124 local function RecomputeButtonSpacing(bar)
72 local w, h = GetSize(bar) 125 local w, h = GetSize(bar)
73 local bw, bh = GetButtonSize(bar) 126 local bw, bh = GetButtonSize(bar)
405 local f = bar:GetFrame() 458 local f = bar:GetFrame()
406 459
407 f:SetMovable(true) 460 f:SetMovable(true)
408 f:SetResizable(true) 461 f:SetResizable(true)
409 462
410 local overlay = CreateFrame("Button", nil, f) 463 -- child of UIParent so that alpha and scale doesn't propagate to it
464 local overlay = CreateFrame("Button", nil, UIParent)
411 overlay:EnableMouse(true) 465 overlay:EnableMouse(true)
412 overlay:SetFrameLevel(3) -- set it above the buttons 466 overlay:SetFrameLevel(3) -- set it above the buttons
413 overlay:SetPoint("TOPLEFT", -4, 4) 467 overlay:SetPoint("TOPLEFT", f, "TOPLEFT", -4, 4)
414 overlay:SetPoint("BOTTOMRIGHT", 4, -4) 468 overlay:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 4, -4)
415 overlay:SetBackdrop({ 469 overlay:SetBackdrop({
416 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", 470 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
417 tile = true, 471 tile = true,
418 tileSize = 16, 472 tileSize = 16,
419 edgeSize = 16, 473 edgeSize = 16,
471 f:StopMovingOrSizing() 525 f:StopMovingOrSizing()
472 f.isMoving = false 526 f.isMoving = false
473 f:SetScript("OnUpdate",nil) 527 f:SetScript("OnUpdate",nil)
474 StoreSize(bar) 528 StoreSize(bar)
475 ClampToButtons(bar) 529 ClampToButtons(bar)
476 --ApplyAnchor(bar)
477 ReAction:RefreshOptions() 530 ReAction:RefreshOptions()
478 end 531 end
479 532
480 local function CornerUpdate() 533 local function CornerUpdate()
481 local bw, bh = GetButtonSize(bar) 534 local bw, bh = GetButtonSize(bar)
482 local r, c, s = GetButtonGrid(bar) 535 local r, c, s = GetButtonGrid(bar)
536 local ss = GetStateScale(bar)
483 if IsShiftKeyDown() then 537 if IsShiftKeyDown() then
484 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) 538 if ss then
485 RecomputeButtonSize(bar) 539 f:SetMinResize( ((s+bw)*c*0.25)/ss, ((s+bh)*r*0.25)/ss )
486 elseif IsAltKeyDown() then 540 f:SetMaxResize( ((s+bw)*c*2.5 + 1)/ss, ((s+bh)*r*2.5 + 1)/ss )
541 scale = ComputeBarScale(bar)
542 else
543 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
544 f:SetMaxResize( (s+128)*c+1, (s+128)*r+1 )
545 RecomputeButtonSize(bar)
546 end
547 elseif not ss and IsAltKeyDown() then
487 f:SetMinResize( bw*c, bh*r ) 548 f:SetMinResize( bw*c, bh*r )
549 f:SetMaxResize( 2*bw*c, 2*bh*r )
488 RecomputeButtonSpacing(bar) 550 RecomputeButtonSpacing(bar)
489 else 551 else
490 f:SetMinResize( bw+s+1, bh+s+1 ) 552 f:SetMinResize( bw+s+1, bh+s+1 )
553 f:SetMaxResize( 50*(bw+s)+1, 50*(bh+s)+1 )
491 RecomputeGrid(bar) 554 RecomputeGrid(bar)
492 end 555 end
493 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) 556 GameTooltipTextRight2:SetText(format("%d x %d",r,c))
494 GameTooltipTextRight1:SetText(format("%d x %d",r,c)) 557
495 GameTooltipTextRight2:SetText(size) 558 local ss = GetStateScale(bar)
496 GameTooltipTextRight3:SetText(tostring(s)) 559 local state = bar:GetState()
560 if ss then
561 GameTooltipTextRight4:SetText(format("%d%%", scale*100))
562 else
563 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
564 GameTooltipTextRight3:SetText(size)
565 GameTooltipTextRight4:SetText(tostring(s))
566 end
497 end 567 end
498 568
499 -- corner drag handles 569 -- corner drag handles
500 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do 570 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
501 local corner = CreateFrame("Frame",nil,overlay) 571 local corner = CreateFrame("Frame",nil,overlay)
509 tex:SetTexCoord(unpack(cornerTexCoords[point])) 579 tex:SetTexCoord(unpack(cornerTexCoords[point]))
510 tex:SetBlendMode("ADD") 580 tex:SetBlendMode("ADD")
511 tex:SetAlpha(0.6) 581 tex:SetAlpha(0.6)
512 tex:SetAllPoints() 582 tex:SetAllPoints()
513 583
514 --corner:RegisterForDrag("LeftButton")
515
516 corner:SetScript("OnMouseDown", 584 corner:SetScript("OnMouseDown",
517 function(_,btn) 585 function(_,btn)
518 f:SetScript("OnUpdate", CornerUpdate) 586 f:SetScript("OnUpdate", CornerUpdate)
519 f:StartSizing(point) 587 f:StartSizing(point)
520 end 588 end
521 ) 589 )
522 corner:SetScript("OnMouseUp",StopResize) 590 corner:SetScript("OnMouseUp",
591 function()
592 local ss = GetStateScale(bar)
593 if ss then
594 local state = bar:GetState()
595 SetStateScale(bar, ComputeBarScale(bar))
596 end
597 StopResize()
598 end)
523 corner:SetScript("OnEnter", 599 corner:SetScript("OnEnter",
524 function() 600 function()
525 local bw, bh = GetButtonSize(bar) 601 local bw, bh = GetButtonSize(bar)
526 local r, c, s = bar:GetButtonGrid() 602 local r, c, s = bar:GetButtonGrid()
527 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) 603 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
604 local ss = GetStateScale(bar)
605 local state = bar:GetState()
528 GameTooltip:SetOwner(f, "ANCHOR_"..point) 606 GameTooltip:SetOwner(f, "ANCHOR_"..point)
607 if ss then
608 GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state))
609 else
610 GameTooltip:AddLine(bar:GetName())
611 end
529 GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c)) 612 GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c))
530 GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), size) 613 if ss then
531 GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"],L["to change spacing:"]), tostring(s)) 614 GameTooltip:AddLine(L["State Scale Override"])
615 GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to change scale:"]), format("%d%%", bar:GetStateProperty(state,"scale")*100))
616 else
617 GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), tostring(floor(size)))
618 GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"], L["to change spacing:"]), tostring(floor(s)))
619 end
532 GameTooltip:Show() 620 GameTooltip:Show()
533 end 621 end
534 ) 622 )
535 corner:SetScript("OnLeave", 623 corner:SetScript("OnLeave",
536 function() 624 function()
560 end 648 end
561 ) 649 )
562 650
563 local function UpdateDragTooltip() 651 local function UpdateDragTooltip()
564 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") 652 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
565 GameTooltip:AddLine(bar.name) 653 local ss = GetStateScale(bar)
654 local state = bar:GetState()
655 if ss then
656 GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state))
657 else
658 GameTooltip:AddLine(bar:GetName())
659 end
566 GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"])) 660 GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"]))
567 GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"])) 661 GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"]))
568 GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."])) 662 GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."]))
569 local point, anchor, relpoint, x, y = bar:GetAnchor() 663 local point, frame, relpoint, x, y = bar:GetFrame():GetPoint(1)
570 if point then 664 if point then
571 local ofsx, ofsy = insidePointOffsetFuncs[point](x,y) 665 local ofsx, ofsy = insidePointOffsetFuncs[point](x,y)
572 if (anchor and anchor ~= "UIParent") or (ofsx == 0 and ofsy == 0) then 666 if (frame and frame ~= UIParent) or (ofsx == 0 and ofsy == 0) then
573 --anchor = anchor or "UIParent" 667 frame = frame or UIParent
574 GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],anchor)) 668 GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],frame:GetName()))
575 end 669 end
576 end 670 end
577 GameTooltip:Show() 671 GameTooltip:Show()
578 end 672 end
579 673
620 714
621 function overlay:LIBKEYBOUND_DISABLED(evt) 715 function overlay:LIBKEYBOUND_DISABLED(evt)
622 self:SetFrameLevel(3) 716 self:SetFrameLevel(3)
623 end 717 end
624 718
719 function overlay:RefreshControls()
720 UpdateAnchorDecoration()
721 end
722
723 overlay:SetScript("OnShow", overlay.RefreshControls)
724
625 KB.RegisterCallback(overlay,"LIBKEYBOUND_ENABLED") 725 KB.RegisterCallback(overlay,"LIBKEYBOUND_ENABLED")
626 KB.RegisterCallback(overlay,"LIBKEYBOUND_DISABLED") 726 KB.RegisterCallback(overlay,"LIBKEYBOUND_DISABLED")
627 727
628 if ReAction:GetKeybindMode() then 728 if ReAction:GetKeybindMode() then
629 overlay:SetFrameLevel(1) 729 overlay:SetFrameLevel(1)
650 elseif f then 750 elseif f then
651 f:Hide() 751 f:Hide()
652 end 752 end
653 end 753 end
654 754
755 function Bar:RefreshControls()
756 if self.controlFrame and self.controlFrame:IsShown() then
757 self.controlFrame:RefreshControls()
758 end
759 end
760
655 function Bar:SetLabel(name) 761 function Bar:SetLabel(name)
656 self.labelName = name 762 self.labelName = name
657 UpdateLabelString(self) 763 UpdateLabelString(self)
658 end 764 end
659 765