diff 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
line wrap: on
line diff
--- a/Overlay.lua	Fri Oct 24 18:14:07 2008 +0000
+++ b/Overlay.lua	Fri Oct 24 23:23:42 2008 +0000
@@ -1,20 +1,23 @@
-local ReAction         = ReAction
-local L                = ReAction.L
-local CreateFrame      = CreateFrame
-local InCombatLockdown = InCombatLockdown
-local floor            = math.floor
-local min              = math.min
-local format           = string.format
-local GameTooltip      = GameTooltip
-local Bar              = ReAction.Bar
-local GetSize          = Bar.GetSize
-local GetButtonSize    = Bar.GetButtonSize
-local GetButtonGrid    = Bar.GetButtonGrid
-local SetSize          = Bar.SetSize
-local SetAnchor        = Bar.SetAnchor
-local SetButtonSize    = Bar.SetButtonSize
-local SetButtonGrid    = Bar.SetButtonGrid
-local ApplyAnchor      = Bar.ApplyAnchor
+local ReAction               = ReAction
+local L                      = ReAction.L
+local CreateFrame            = CreateFrame
+local InCombatLockdown       = InCombatLockdown
+local floor                  = math.floor
+local min                    = math.min
+local format                 = string.format
+local GameTooltip            = GameTooltip
+local Bar                    = ReAction.Bar
+local GetSize                = Bar.GetSize
+local GetButtonSize          = Bar.GetButtonSize
+local GetButtonGrid          = Bar.GetButtonGrid
+local SetSize                = Bar.SetSize
+local SetAnchor              = Bar.SetAnchor
+local SetButtonSize          = Bar.SetButtonSize
+local SetButtonGrid          = Bar.SetButtonGrid
+local ApplyAnchor            = Bar.ApplyAnchor
+local GameTooltipTextRight1  = GameTooltipTextRight1
+local GameTooltipTextRight2  = GameTooltipTextRight2
+local GameTooltipTextRight3  = GameTooltipTextRight3
 
 local KB = LibStub("LibKeyBound-1.0")
 
@@ -164,7 +167,13 @@
 }
 edgeBoundsFuncs.TOP   = edgeBoundsFuncs.BOTTOM
 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
-
+local cornerTexCoords = {
+              -- ULx, ULy, LLx, LLy, URx, URy, LRx, LRy
+  TOPLEFT     = { 1,   1,   1,   0,   0,   1,   0,   0 },
+  TOPRIGHT    = { 1,   0,   0,   0,   1,   1,   0,   1 },
+  BOTTOMLEFT  = { 0,   1,   1,   1,   0,   0,   1,   0 },
+  BOTTOMRIGHT = { 0,   0,   0,   1,   1,   0,   1,   1 },
+}
 
 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
 local function GetPointCoords( f, p )
@@ -294,14 +303,19 @@
     return
   end
   
-  local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0)
-  local xx, yy = pointCoordFuncs[p](f1)
+  local sx, sy = insideOffsetFunc(xOff or 0, yOff or 0)
+  local xx, yy = coordFunc(f1)
   if xx and yy then
     if math.abs(x) <= rx then
-      x = sx
-      s = true
-    end
-    if math.abs(y) <= ry then
+      if math.abs(y) <= ry then
+        x = sx
+        y = sy
+        s = true
+      elseif CheckEdgeOverlap(f1,o,"LEFT") then
+        x = sx
+        s = true
+      end
+    elseif math.abs(y) <= ry and CheckEdgeOverlap(f1,o,"TOP") then
       y = sy
       s = true
     end
@@ -323,6 +337,7 @@
     end
   end
 
+  -- correct for some Lua oddities with doubles
   if x == -0 then x = 0 end
   if y == -0 then y = 0 end
   
@@ -462,106 +477,58 @@
     ReAction:RefreshOptions()
   end
 
-  -- edge drag handles
-  for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
-    local edge = CreateFrame("Frame",nil,overlay)
-    edge:EnableMouse(true)
-    edge:SetWidth(8)
-    edge:SetHeight(8)
-    if point == "TOP" or point == "BOTTOM" then
-      edge:SetPoint(point.."LEFT")
-      edge:SetPoint(point.."RIGHT")
+  local function CornerUpdate()
+    local bw, bh = GetButtonSize(bar)
+    local r, c, s = GetButtonGrid(bar)
+    if IsShiftKeyDown() then
+      f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
+      RecomputeButtonSize(bar)
+    elseif IsAltKeyDown() then
+      f:SetMinResize( bw*c, bh*r )
+      RecomputeButtonSpacing(bar)
     else
-      edge:SetPoint("TOP"..point)
-      edge:SetPoint("BOTTOM"..point)
+      f:SetMinResize( bw+s+1, bh+s+1 )
+      RecomputeGrid(bar)
     end
-    local tex = edge:CreateTexture(nil,"HIGHLIGHT")
-    tex:SetTexture(1.0,0.82,0,0.7)
-    tex:SetBlendMode("ADD")
-    tex:SetAllPoints()
-    edge:RegisterForDrag("LeftButton")
-    edge:SetScript("OnMouseDown",
-      function()
-        local bw, bh = GetButtonSize(bar)
-        local r, c, s = GetButtonGrid(bar)
-        f:SetMinResize( bw+s+1, bh+s+1 )
-        f:StartSizing(point)
-        f:SetScript("OnUpdate", 
-          function()
-            RecomputeGrid(bar)
-          end
-        )
-      end
-    )
-    edge:SetScript("OnMouseUp", StopResize)
-    edge:SetScript("OnEnter",
-      function()
-        GameTooltip:SetOwner(f, "ANCHOR_"..point)
-        GameTooltip:AddLine(L["Drag to add/remove buttons"])
-        GameTooltip:Show()
-      end
-    )
-    edge:SetScript("OnLeave", HideGameTooltip)
-    edge:Show()
+    local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
+    GameTooltipTextRight1:SetText(format("%d x %d",r,c))
+    GameTooltipTextRight2:SetText(size)
+    GameTooltipTextRight3:SetText(tostring(s))
   end
 
-  -- corner drag handles, nested in an anonymous frame so that they are on top
-  local foo = CreateFrame("Frame",nil,overlay)
-  foo:SetAllPoints(true)
+  -- corner drag handles
   for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
-    local corner = CreateFrame("Frame",nil,foo)
+    local corner = CreateFrame("Frame",nil,overlay)
     corner:EnableMouse(true)
-    corner:SetWidth(12)
-    corner:SetHeight(12)
+    corner:SetWidth(16)
+    corner:SetHeight(16)
     corner:SetPoint(point)
+
     local tex = corner:CreateTexture(nil,"HIGHLIGHT")
-    tex:SetTexture(1.0,0.82,0,0.7)
+    tex:SetTexture("Interface\\AddOns\\ReAction\\img\\corner")
+    tex:SetTexCoord(unpack(cornerTexCoords[point]))
     tex:SetBlendMode("ADD")
+    tex:SetAlpha(0.6)
     tex:SetAllPoints()
-    corner:RegisterForDrag("LeftButton","RightButton")
-    local function UpdateTooltip()
-      local size, size2 = bar:GetButtonSize()
-      local rows, cols, spacing = bar:GetButtonGrid()
-      size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
-      GameTooltipTextRight4:SetText(size)
-      GameTooltipTextRight5:SetText(tostring(spacing))
-    end
+    
+    --corner:RegisterForDrag("LeftButton")
+    
     corner:SetScript("OnMouseDown",
       function(_,btn)
-        local bw, bh = GetButtonSize(bar)
-        local r, c, s = GetButtonGrid(bar)
-        if btn == "LeftButton" then -- button resize
-          f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
-          f:SetScript("OnUpdate", 
-            function()
-              RecomputeButtonSize(bar)
-              UpdateTooltip()
-            end
-          )
-        elseif btn == "RightButton" then -- spacing resize
-          f:SetMinResize( bw*c, bh*r )
-          f:SetScript("OnUpdate", 
-            function()
-              RecomputeButtonSpacing(bar)
-              UpdateTooltip()
-            end
-          )
-        end
+        f:SetScript("OnUpdate", CornerUpdate)
         f:StartSizing(point)
       end
     )
     corner:SetScript("OnMouseUp",StopResize)
     corner:SetScript("OnEnter",
       function()
+        local bw, bh = GetButtonSize(bar)
+        local r, c, s = bar:GetButtonGrid()
+        local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
         GameTooltip:SetOwner(f, "ANCHOR_"..point)
-        GameTooltip:AddLine(L["Drag to resize buttons"])
-        GameTooltip:AddLine(L["Right-click-drag"])
-        GameTooltip:AddLine(L["to change spacing"])
-        local size, size2 = bar:GetButtonSize()
-        local rows, cols, spacing = bar:GetButtonGrid()
-        size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
-        GameTooltip:AddDoubleLine(L["Size:"], size)
-        GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
+        GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c))
+        GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), size)
+        GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"],L["to change spacing:"]), tostring(s))
         GameTooltip:Show()
       end
     )
@@ -571,7 +538,6 @@
         f:SetScript("OnUpdate",nil)
       end
     )
-
   end
 
   overlay:RegisterForDrag("LeftButton")
@@ -597,12 +563,16 @@
   local function UpdateDragTooltip()
     GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
     GameTooltip:AddLine(bar.name)
-    GameTooltip:AddLine(L["Drag to move"])
-    GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"]))
-    GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"]))
-    local _, a = bar:GetAnchor()
-    if a and a ~= "UIParent" then
-      GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a))
+    GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"]))
+    GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"]))
+    GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."]))
+    local point, anchor, relpoint, x, y = bar:GetAnchor()
+    if point then
+      local ofsx, ofsy = insidePointOffsetFuncs[point](x,y)
+      if (anchor and anchor ~= "UIParent") or (ofsx == 0 and ofsy == 0) then
+        --anchor = anchor or "UIParent"
+        GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],anchor))
+      end
     end
     GameTooltip:Show()
   end