comparison Overlay.lua @ 99:f200bcb193d6

- Added corner icon image - removed edge drag handles. Changed corner drag semantics (re-grid, shift:resize, alt:spacing) - updated tooltip displays - fixed bug with anchoring off the edge of a target
author Flick <flickerstreak@gmail.com>
date Fri, 24 Oct 2008 23:23:42 +0000
parents a44173c7a82c
children 890e4c4ab143
comparison
equal deleted inserted replaced
98:a44173c7a82c 99:f200bcb193d6
1 local ReAction = ReAction 1 local ReAction = ReAction
2 local L = ReAction.L 2 local L = ReAction.L
3 local CreateFrame = CreateFrame 3 local CreateFrame = CreateFrame
4 local InCombatLockdown = InCombatLockdown 4 local InCombatLockdown = InCombatLockdown
5 local floor = math.floor 5 local floor = math.floor
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 GetButtonSize = Bar.GetButtonSize 11 local GetButtonSize = Bar.GetButtonSize
12 local GetButtonGrid = Bar.GetButtonGrid 12 local GetButtonGrid = Bar.GetButtonGrid
13 local SetSize = Bar.SetSize 13 local SetSize = Bar.SetSize
14 local SetAnchor = Bar.SetAnchor 14 local SetAnchor = Bar.SetAnchor
15 local SetButtonSize = Bar.SetButtonSize 15 local SetButtonSize = Bar.SetButtonSize
16 local SetButtonGrid = Bar.SetButtonGrid 16 local SetButtonGrid = Bar.SetButtonGrid
17 local ApplyAnchor = Bar.ApplyAnchor 17 local ApplyAnchor = Bar.ApplyAnchor
18 local GameTooltipTextRight1 = GameTooltipTextRight1
19 local GameTooltipTextRight2 = GameTooltipTextRight2
20 local GameTooltipTextRight3 = GameTooltipTextRight3
18 21
19 local KB = LibStub("LibKeyBound-1.0") 22 local KB = LibStub("LibKeyBound-1.0")
20 23
21 ReAction:UpdateRevision("$Revision$") 24 ReAction:UpdateRevision("$Revision$")
22 25
162 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end, 165 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end,
163 LEFT = function(f) return f:GetBottom(), f:GetTop() end 166 LEFT = function(f) return f:GetBottom(), f:GetTop() end
164 } 167 }
165 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM 168 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM
166 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT 169 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
167 170 local cornerTexCoords = {
171 -- ULx, ULy, LLx, LLy, URx, URy, LRx, LRy
172 TOPLEFT = { 1, 1, 1, 0, 0, 1, 0, 0 },
173 TOPRIGHT = { 1, 0, 0, 0, 1, 1, 0, 1 },
174 BOTTOMLEFT = { 0, 1, 1, 1, 0, 0, 1, 0 },
175 BOTTOMRIGHT = { 0, 0, 0, 1, 1, 0, 1, 1 },
176 }
168 177
169 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f' 178 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
170 local function GetPointCoords( f, p ) 179 local function GetPointCoords( f, p )
171 local x, y = pointCoordFuncs[p](f) 180 local x, y = pointCoordFuncs[p](f)
172 if not(x and y) then 181 if not(x and y) then
292 local coordFunc = p and pointCoordFuncs[p] 301 local coordFunc = p and pointCoordFuncs[p]
293 if not insideOffsetFunc or not coordFunc then 302 if not insideOffsetFunc or not coordFunc then
294 return 303 return
295 end 304 end
296 305
297 local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0) 306 local sx, sy = insideOffsetFunc(xOff or 0, yOff or 0)
298 local xx, yy = pointCoordFuncs[p](f1) 307 local xx, yy = coordFunc(f1)
299 if xx and yy then 308 if xx and yy then
300 if math.abs(x) <= rx then 309 if math.abs(x) <= rx then
301 x = sx 310 if math.abs(y) <= ry then
302 s = true 311 x = sx
303 end 312 y = sy
304 if math.abs(y) <= ry then 313 s = true
314 elseif CheckEdgeOverlap(f1,o,"LEFT") then
315 x = sx
316 s = true
317 end
318 elseif math.abs(y) <= ry and CheckEdgeOverlap(f1,o,"TOP") then
305 y = sy 319 y = sy
306 s = true 320 s = true
307 end 321 end
308 elseif xx then 322 elseif xx then
309 if math.abs(x) <= rx then 323 if math.abs(x) <= rx then
321 x = sx 335 x = sx
322 end 336 end
323 end 337 end
324 end 338 end
325 339
340 -- correct for some Lua oddities with doubles
326 if x == -0 then x = 0 end 341 if x == -0 then x = 0 end
327 if y == -0 then y = 0 end 342 if y == -0 then y = 0 end
328 343
329 if s then 344 if s then
330 return o, p, rp, math.floor(x), math.floor(y) 345 return o, p, rp, math.floor(x), math.floor(y)
460 ClampToButtons(bar) 475 ClampToButtons(bar)
461 --ApplyAnchor(bar) 476 --ApplyAnchor(bar)
462 ReAction:RefreshOptions() 477 ReAction:RefreshOptions()
463 end 478 end
464 479
465 -- edge drag handles 480 local function CornerUpdate()
466 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do 481 local bw, bh = GetButtonSize(bar)
467 local edge = CreateFrame("Frame",nil,overlay) 482 local r, c, s = GetButtonGrid(bar)
468 edge:EnableMouse(true) 483 if IsShiftKeyDown() then
469 edge:SetWidth(8) 484 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
470 edge:SetHeight(8) 485 RecomputeButtonSize(bar)
471 if point == "TOP" or point == "BOTTOM" then 486 elseif IsAltKeyDown() then
472 edge:SetPoint(point.."LEFT") 487 f:SetMinResize( bw*c, bh*r )
473 edge:SetPoint(point.."RIGHT") 488 RecomputeButtonSpacing(bar)
474 else 489 else
475 edge:SetPoint("TOP"..point) 490 f:SetMinResize( bw+s+1, bh+s+1 )
476 edge:SetPoint("BOTTOM"..point) 491 RecomputeGrid(bar)
477 end 492 end
478 local tex = edge:CreateTexture(nil,"HIGHLIGHT") 493 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
479 tex:SetTexture(1.0,0.82,0,0.7) 494 GameTooltipTextRight1:SetText(format("%d x %d",r,c))
495 GameTooltipTextRight2:SetText(size)
496 GameTooltipTextRight3:SetText(tostring(s))
497 end
498
499 -- corner drag handles
500 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
501 local corner = CreateFrame("Frame",nil,overlay)
502 corner:EnableMouse(true)
503 corner:SetWidth(16)
504 corner:SetHeight(16)
505 corner:SetPoint(point)
506
507 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
508 tex:SetTexture("Interface\\AddOns\\ReAction\\img\\corner")
509 tex:SetTexCoord(unpack(cornerTexCoords[point]))
480 tex:SetBlendMode("ADD") 510 tex:SetBlendMode("ADD")
511 tex:SetAlpha(0.6)
481 tex:SetAllPoints() 512 tex:SetAllPoints()
482 edge:RegisterForDrag("LeftButton") 513
483 edge:SetScript("OnMouseDown", 514 --corner:RegisterForDrag("LeftButton")
484 function() 515
485 local bw, bh = GetButtonSize(bar)
486 local r, c, s = GetButtonGrid(bar)
487 f:SetMinResize( bw+s+1, bh+s+1 )
488 f:StartSizing(point)
489 f:SetScript("OnUpdate",
490 function()
491 RecomputeGrid(bar)
492 end
493 )
494 end
495 )
496 edge:SetScript("OnMouseUp", StopResize)
497 edge:SetScript("OnEnter",
498 function()
499 GameTooltip:SetOwner(f, "ANCHOR_"..point)
500 GameTooltip:AddLine(L["Drag to add/remove buttons"])
501 GameTooltip:Show()
502 end
503 )
504 edge:SetScript("OnLeave", HideGameTooltip)
505 edge:Show()
506 end
507
508 -- corner drag handles, nested in an anonymous frame so that they are on top
509 local foo = CreateFrame("Frame",nil,overlay)
510 foo:SetAllPoints(true)
511 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
512 local corner = CreateFrame("Frame",nil,foo)
513 corner:EnableMouse(true)
514 corner:SetWidth(12)
515 corner:SetHeight(12)
516 corner:SetPoint(point)
517 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
518 tex:SetTexture(1.0,0.82,0,0.7)
519 tex:SetBlendMode("ADD")
520 tex:SetAllPoints()
521 corner:RegisterForDrag("LeftButton","RightButton")
522 local function UpdateTooltip()
523 local size, size2 = bar:GetButtonSize()
524 local rows, cols, spacing = bar:GetButtonGrid()
525 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
526 GameTooltipTextRight4:SetText(size)
527 GameTooltipTextRight5:SetText(tostring(spacing))
528 end
529 corner:SetScript("OnMouseDown", 516 corner:SetScript("OnMouseDown",
530 function(_,btn) 517 function(_,btn)
531 local bw, bh = GetButtonSize(bar) 518 f:SetScript("OnUpdate", CornerUpdate)
532 local r, c, s = GetButtonGrid(bar)
533 if btn == "LeftButton" then -- button resize
534 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
535 f:SetScript("OnUpdate",
536 function()
537 RecomputeButtonSize(bar)
538 UpdateTooltip()
539 end
540 )
541 elseif btn == "RightButton" then -- spacing resize
542 f:SetMinResize( bw*c, bh*r )
543 f:SetScript("OnUpdate",
544 function()
545 RecomputeButtonSpacing(bar)
546 UpdateTooltip()
547 end
548 )
549 end
550 f:StartSizing(point) 519 f:StartSizing(point)
551 end 520 end
552 ) 521 )
553 corner:SetScript("OnMouseUp",StopResize) 522 corner:SetScript("OnMouseUp",StopResize)
554 corner:SetScript("OnEnter", 523 corner:SetScript("OnEnter",
555 function() 524 function()
525 local bw, bh = GetButtonSize(bar)
526 local r, c, s = bar:GetButtonGrid()
527 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
556 GameTooltip:SetOwner(f, "ANCHOR_"..point) 528 GameTooltip:SetOwner(f, "ANCHOR_"..point)
557 GameTooltip:AddLine(L["Drag to resize buttons"]) 529 GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c))
558 GameTooltip:AddLine(L["Right-click-drag"]) 530 GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), size)
559 GameTooltip:AddLine(L["to change spacing"]) 531 GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"],L["to change spacing:"]), tostring(s))
560 local size, size2 = bar:GetButtonSize()
561 local rows, cols, spacing = bar:GetButtonGrid()
562 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
563 GameTooltip:AddDoubleLine(L["Size:"], size)
564 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
565 GameTooltip:Show() 532 GameTooltip:Show()
566 end 533 end
567 ) 534 )
568 corner:SetScript("OnLeave", 535 corner:SetScript("OnLeave",
569 function() 536 function()
570 GameTooltip:Hide() 537 GameTooltip:Hide()
571 f:SetScript("OnUpdate",nil) 538 f:SetScript("OnUpdate",nil)
572 end 539 end
573 ) 540 )
574
575 end 541 end
576 542
577 overlay:RegisterForDrag("LeftButton") 543 overlay:RegisterForDrag("LeftButton")
578 overlay:RegisterForClicks("RightButtonUp") 544 overlay:RegisterForClicks("RightButtonUp")
579 545
595 ) 561 )
596 562
597 local function UpdateDragTooltip() 563 local function UpdateDragTooltip()
598 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") 564 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
599 GameTooltip:AddLine(bar.name) 565 GameTooltip:AddLine(bar.name)
600 GameTooltip:AddLine(L["Drag to move"]) 566 GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"]))
601 GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"])) 567 GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"]))
602 GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"])) 568 GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."]))
603 local _, a = bar:GetAnchor() 569 local point, anchor, relpoint, x, y = bar:GetAnchor()
604 if a and a ~= "UIParent" then 570 if point then
605 GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a)) 571 local ofsx, ofsy = insidePointOffsetFuncs[point](x,y)
572 if (anchor and anchor ~= "UIParent") or (ofsx == 0 and ofsy == 0) then
573 --anchor = anchor or "UIParent"
574 GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],anchor))
575 end
606 end 576 end
607 GameTooltip:Show() 577 GameTooltip:Show()
608 end 578 end
609 579
610 overlay:SetScript("OnDragStop", 580 overlay:SetScript("OnDragStop",