flickerstreak@90: local ReAction = ReAction flickerstreak@90: local L = ReAction.L flickerstreak@90: local CreateFrame = CreateFrame flickerstreak@73: local InCombatLockdown = InCombatLockdown flickerstreak@90: local floor = math.floor flickerstreak@90: local min = math.min flickerstreak@90: local format = string.format flickerstreak@90: local GameTooltip = GameTooltip flickerstreak@90: local Bar = ReAction.Bar flickerstreak@90: local GetSize = Bar.GetSize flickerstreak@90: local GetButtonSize = Bar.GetButtonSize flickerstreak@90: local GetButtonGrid = Bar.GetButtonGrid flickerstreak@90: local SetSize = Bar.SetSize flickerstreak@90: local SetAnchor = Bar.SetAnchor flickerstreak@90: local SetButtonSize = Bar.SetButtonSize flickerstreak@90: local SetButtonGrid = Bar.SetButtonGrid flickerstreak@90: local ApplyAnchor = Bar.ApplyAnchor flickerstreak@73: flickerstreak@92: local KB = LibStub("LibKeyBound-1.0") flickerstreak@92: flickerstreak@80: ReAction:UpdateRevision("$Revision$") flickerstreak@77: flickerstreak@73: -- flickerstreak@73: -- Bar config overlay flickerstreak@73: -- flickerstreak@90: flickerstreak@90: local function StoreSize(bar) flickerstreak@90: local f = bar:GetFrame() flickerstreak@90: SetSize( bar, f:GetWidth(), f:GetHeight() ) flickerstreak@90: end flickerstreak@73: flickerstreak@73: local function StoreExtents(bar) flickerstreak@75: local f = bar:GetFrame() flickerstreak@92: local p, fr, rp, x, y = f:GetPoint(1) flickerstreak@92: fr = fr or UIParent flickerstreak@92: SetAnchor( bar, p, fr, rp, x, y ) flickerstreak@90: SetSize( bar, f:GetWidth(), f:GetHeight() ) flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function RecomputeButtonSize(bar) flickerstreak@73: local w, h = GetSize(bar) flickerstreak@73: local bw, bh = GetButtonSize(bar) flickerstreak@73: local r, c, s = GetButtonGrid(bar) flickerstreak@73: flickerstreak@73: local scaleW = (floor(w/c) - s) / bw flickerstreak@73: local scaleH = (floor(h/r) - s) / bh flickerstreak@73: local scale = min(scaleW, scaleH) flickerstreak@73: flickerstreak@73: SetButtonSize(bar, scale * bw, scale * bh, s) flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function RecomputeButtonSpacing(bar) flickerstreak@73: local w, h = GetSize(bar) flickerstreak@73: local bw, bh = GetButtonSize(bar) flickerstreak@73: local r, c, s = GetButtonGrid(bar) flickerstreak@73: flickerstreak@73: SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh)) flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function RecomputeGrid(bar) flickerstreak@73: local w, h = GetSize(bar) flickerstreak@73: local bw, bh = GetButtonSize(bar) flickerstreak@73: local r, c, s = GetButtonGrid(bar) flickerstreak@73: flickerstreak@73: SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s) flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function ClampToButtons(bar) flickerstreak@73: local bw, bh = GetButtonSize(bar) flickerstreak@73: local r, c, s = GetButtonGrid(bar) flickerstreak@73: SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1) flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function HideGameTooltip() flickerstreak@73: GameTooltip:Hide() flickerstreak@73: end flickerstreak@73: flickerstreak@73: local anchorInside = { inside = true } flickerstreak@73: local anchorOutside = { outside = true } flickerstreak@73: local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" } flickerstreak@73: local oppositeEdges = { flickerstreak@73: TOP = "BOTTOM", flickerstreak@73: BOTTOM = "TOP", flickerstreak@73: LEFT = "RIGHT", flickerstreak@73: RIGHT = "LEFT" flickerstreak@73: } flickerstreak@73: local pointsOnEdge = { flickerstreak@73: BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", }, flickerstreak@73: TOP = { "TOP", "TOPLEFT", "TOPRIGHT", }, flickerstreak@73: RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", }, flickerstreak@73: LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", }, flickerstreak@73: } flickerstreak@73: local edgeSelector = { flickerstreak@73: BOTTOM = 1, -- select x of x,y flickerstreak@73: TOP = 1, -- select x of x,y flickerstreak@73: LEFT = 2, -- select y of x,y flickerstreak@73: RIGHT = 2, -- select y of x,y flickerstreak@73: } flickerstreak@73: local snapPoints = { flickerstreak@73: [anchorOutside] = { flickerstreak@73: BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"}, flickerstreak@73: BOTTOM = {"TOP"}, flickerstreak@73: BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"}, flickerstreak@73: RIGHT = {"LEFT"}, flickerstreak@73: TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"}, flickerstreak@73: TOP = {"BOTTOM"}, flickerstreak@73: TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"}, flickerstreak@73: LEFT = {"RIGHT"}, flickerstreak@73: CENTER = {"CENTER"} flickerstreak@73: }, flickerstreak@73: [anchorInside] = { flickerstreak@73: BOTTOMLEFT = {"BOTTOMLEFT"}, flickerstreak@73: BOTTOM = {"BOTTOM"}, flickerstreak@73: BOTTOMRIGHT = {"BOTTOMRIGHT"}, flickerstreak@73: RIGHT = {"RIGHT"}, flickerstreak@73: TOPRIGHT = {"TOPRIGHT"}, flickerstreak@73: TOP = {"TOP"}, flickerstreak@73: TOPLEFT = {"TOPLEFT"}, flickerstreak@73: LEFT = {"LEFT"}, flickerstreak@73: CENTER = {"CENTER"} flickerstreak@73: } flickerstreak@73: } flickerstreak@73: local insidePointOffsetFuncs = { flickerstreak@73: BOTTOMLEFT = function(x, y) return x, y end, flickerstreak@73: BOTTOM = function(x, y) return 0, y end, flickerstreak@73: BOTTOMRIGHT = function(x, y) return -x, y end, flickerstreak@73: RIGHT = function(x, y) return -x, 0 end, flickerstreak@73: TOPRIGHT = function(x, y) return -x, -y end, flickerstreak@73: TOP = function(x, y) return 0, -y end, flickerstreak@73: TOPLEFT = function(x, y) return x, -y end, flickerstreak@73: LEFT = function(x, y) return x, 0 end, flickerstreak@73: CENTER = function(x, y) return 0, 0 end, flickerstreak@73: } flickerstreak@73: local pointCoordFuncs = { flickerstreak@73: BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end, flickerstreak@73: BOTTOM = function(f) return nil, f:GetBottom() end, flickerstreak@73: BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end, flickerstreak@73: RIGHT = function(f) return f:GetRight(), nil end, flickerstreak@73: TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end, flickerstreak@73: TOP = function(f) return nil, f:GetTop() end, flickerstreak@73: TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end, flickerstreak@73: LEFT = function(f) return f:GetLeft(), nil end, flickerstreak@73: CENTER = function(f) return f:GetCenter() end, flickerstreak@73: } flickerstreak@73: local edgeBoundsFuncs = { flickerstreak@73: BOTTOM = function(f) return f:GetLeft(), f:GetRight() end, flickerstreak@73: LEFT = function(f) return f:GetBottom(), f:GetTop() end flickerstreak@73: } flickerstreak@73: edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM flickerstreak@73: edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT flickerstreak@73: flickerstreak@73: flickerstreak@73: -- Returns absolute coordinates x,y of the named point 'p' of frame 'f' flickerstreak@73: local function GetPointCoords( f, p ) flickerstreak@73: local x, y = pointCoordFuncs[p](f) flickerstreak@73: if not(x and y) then flickerstreak@73: local cx, cy = f:GetCenter() flickerstreak@73: x = x or cx flickerstreak@73: y = y or cy flickerstreak@73: end flickerstreak@73: return x, y flickerstreak@73: end flickerstreak@73: flickerstreak@73: flickerstreak@73: -- Returns true if frame 'f1' can be anchored to frame 'f2' flickerstreak@73: local function CheckAnchorable( f1, f2 ) flickerstreak@73: -- can't anchor a frame to itself or to nil flickerstreak@73: if f1 == f2 or f2 == nil then flickerstreak@73: return false flickerstreak@73: end flickerstreak@73: flickerstreak@73: -- can always anchor to UIParent flickerstreak@73: if f2 == UIParent then flickerstreak@73: return true flickerstreak@73: end flickerstreak@73: flickerstreak@73: -- also can't do circular anchoring of frames flickerstreak@73: -- walk the anchor chain, which generally shouldn't be that expensive flickerstreak@73: -- (who nests draggables that deep anyway?) flickerstreak@73: for i = 1, f2:GetNumPoints() do flickerstreak@73: local _, f = f2:GetPoint(i) flickerstreak@73: if not f then f = f2:GetParent() end flickerstreak@73: return CheckAnchorable(f1,f) flickerstreak@73: end flickerstreak@73: flickerstreak@73: return true flickerstreak@73: end flickerstreak@73: flickerstreak@73: -- Returns true if frames f1 and f2 specified edges overlap flickerstreak@73: local function CheckEdgeOverlap( f1, f2, e ) flickerstreak@73: local l1, u1 = edgeBoundsFuncs[e](f1) flickerstreak@73: local l2, u2 = edgeBoundsFuncs[e](f2) flickerstreak@73: return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2 flickerstreak@73: end flickerstreak@73: flickerstreak@73: -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2 flickerstreak@73: local function CheckPointEdgeOverlap( f1, p1, f2, e2 ) flickerstreak@73: local l, u = edgeBoundsFuncs[e2](f2) flickerstreak@73: local x, y = GetPointCoords(f1,p1) flickerstreak@73: x = select(edgeSelector[e2], x, y) flickerstreak@73: return l <= x and x <= u flickerstreak@73: end flickerstreak@73: flickerstreak@73: -- Returns the distance between corresponding edges. It is flickerstreak@73: -- assumed that the passed in edges e1 and e2 are the same or opposites flickerstreak@73: local function GetEdgeDistance( f1, f2, e1, e2 ) flickerstreak@73: local x1, y1 = pointCoordFuncs[e1](f1) flickerstreak@73: local x2, y2 = pointCoordFuncs[e2](f2) flickerstreak@73: return math.abs((x1 or y1) - (x2 or y2)) flickerstreak@73: end flickerstreak@73: flickerstreak@73: local globalSnapTargets = { [UIParent] = anchorInside } flickerstreak@73: flickerstreak@73: local function GetClosestFrameEdge(f1,f2,a) flickerstreak@73: local dist, edge, opp flickerstreak@73: if f2:IsVisible() and CheckAnchorable(f1,f2) then flickerstreak@73: for _, e in pairs(edges) do flickerstreak@73: local o = a.inside and e or oppositeEdges[e] flickerstreak@73: if CheckEdgeOverlap(f1,f2,e) then flickerstreak@73: local d = GetEdgeDistance(f1, f2, e, o) flickerstreak@73: if not dist or (d < dist) then flickerstreak@73: dist, edge, opp = d, e, o flickerstreak@73: end flickerstreak@73: end flickerstreak@73: end flickerstreak@73: end flickerstreak@73: return dist, edge, opp flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function GetClosestVisibleEdge( f ) flickerstreak@73: local r, o, e1, e2 flickerstreak@73: local a = anchorOutside flickerstreak@73: for _, b in ReAction:IterateBars() do flickerstreak@73: local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a) flickerstreak@73: if d and (not r or d < r) then flickerstreak@73: r, o, e1, e2 = d, b:GetFrame(), e, opp flickerstreak@73: end flickerstreak@73: end flickerstreak@73: for f2, a2 in pairs(globalSnapTargets) do flickerstreak@73: local d, e, opp = GetClosestFrameEdge(f,f2,a2) flickerstreak@73: if d and (not r or d < r) then flickerstreak@73: r, o, e1, e2, a = d, f2, e, opp, a2 flickerstreak@73: end flickerstreak@73: end flickerstreak@73: return o, e1, e2, a flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function GetClosestVisiblePoint(f1) flickerstreak@73: local f2, e1, e2, a = GetClosestVisibleEdge(f1) flickerstreak@73: if f2 then flickerstreak@73: local rsq, p, rp, x, y flickerstreak@73: -- iterate pointsOnEdge in order and use < to prefer edge centers to corners flickerstreak@73: for _, p1 in ipairs(pointsOnEdge[e1]) do flickerstreak@73: if CheckPointEdgeOverlap(f1,p1,f2,e2) then flickerstreak@73: for _, p2 in pairs(snapPoints[a][p1]) do flickerstreak@73: local x1, y1 = GetPointCoords(f1,p1) flickerstreak@73: local x2, y2 = GetPointCoords(f2,p2) flickerstreak@73: local dx = x1 - x2 flickerstreak@73: local dy = y1 - y2 flickerstreak@73: local rsq2 = dx*dx + dy*dy flickerstreak@73: if not rsq or rsq2 < rsq then flickerstreak@73: rsq, p, rp, x, y = rsq2, p1, p2, dx, dy flickerstreak@73: end flickerstreak@73: end flickerstreak@73: end flickerstreak@73: end flickerstreak@73: return f2, p, rp, x, y flickerstreak@73: end flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff) flickerstreak@73: local o, p, rp, x, y = GetClosestVisiblePoint(f1) flickerstreak@73: local s = false flickerstreak@92: flickerstreak@92: local insideOffsetFunc = p and insidePointOffsetFuncs[p] flickerstreak@92: local coordFunc = p and pointCoordFuncs[p] flickerstreak@92: if not insideOffsetFunc or not coordFunc then flickerstreak@92: return flickerstreak@92: end flickerstreak@73: flickerstreak@73: local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0) flickerstreak@73: local xx, yy = pointCoordFuncs[p](f1) flickerstreak@73: if xx and yy then flickerstreak@73: if math.abs(x) <= rx then flickerstreak@73: x = sx flickerstreak@73: s = true flickerstreak@73: end flickerstreak@73: if math.abs(y) <= ry then flickerstreak@73: y = sy flickerstreak@73: s = true flickerstreak@73: end flickerstreak@73: elseif xx then flickerstreak@73: if math.abs(x) <= rx then flickerstreak@73: x = sx flickerstreak@73: s = true flickerstreak@73: if math.abs(y) <= ry then flickerstreak@73: y = sy flickerstreak@73: end flickerstreak@73: end flickerstreak@73: elseif yy then flickerstreak@73: if math.abs(y) <= ry then flickerstreak@73: y = sy flickerstreak@73: s = true flickerstreak@73: if math.abs(x) <= rx then flickerstreak@73: x = sx flickerstreak@73: end flickerstreak@73: end flickerstreak@73: end flickerstreak@73: flickerstreak@73: if x == -0 then x = 0 end flickerstreak@73: if y == -0 then y = 0 end flickerstreak@73: flickerstreak@73: if s then flickerstreak@73: return o, p, rp, math.floor(x), math.floor(y) flickerstreak@73: end flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function CreateSnapIndicator() flickerstreak@73: local si = CreateFrame("Frame",nil,UIParent) flickerstreak@73: si:SetFrameStrata("HIGH") flickerstreak@73: si:SetHeight(8) flickerstreak@73: si:SetWidth(8) flickerstreak@73: local tex = si:CreateTexture() flickerstreak@73: tex:SetAllPoints() flickerstreak@73: tex:SetTexture(1.0, 0.82, 0, 0.8) flickerstreak@73: tex:SetBlendMode("ADD") flickerstreak@73: tex:SetDrawLayer("OVERLAY") flickerstreak@73: return si flickerstreak@73: end flickerstreak@73: flickerstreak@73: local si1 = CreateSnapIndicator() flickerstreak@73: local si2 = CreateSnapIndicator() flickerstreak@73: flickerstreak@73: local function DisplaySnapIndicator( f, rx, ry, xOff, yOff ) flickerstreak@73: local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff) flickerstreak@73: if o then flickerstreak@73: si1:ClearAllPoints() flickerstreak@73: si2:ClearAllPoints() flickerstreak@73: si1:SetPoint("CENTER", f, p, 0, 0) flickerstreak@73: local xx, yy = pointCoordFuncs[rp](o) flickerstreak@73: x = math.abs(x) <=rx and xx and 0 or x flickerstreak@73: y = math.abs(y) <=ry and yy and 0 or y flickerstreak@73: si2:SetPoint("CENTER", o, rp, x, y) flickerstreak@73: si1:Show() flickerstreak@73: si2:Show() flickerstreak@73: else flickerstreak@73: if si1:IsVisible() then flickerstreak@73: si1:Hide() flickerstreak@73: si2:Hide() flickerstreak@73: end flickerstreak@73: end flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function HideSnapIndicator() flickerstreak@73: if si1:IsVisible() then flickerstreak@73: si1:Hide() flickerstreak@73: si2:Hide() flickerstreak@73: end flickerstreak@73: end flickerstreak@73: flickerstreak@73: local function CreateControls(bar) flickerstreak@75: local f = bar:GetFrame() flickerstreak@73: flickerstreak@73: f:SetMovable(true) flickerstreak@73: f:SetResizable(true) flickerstreak@73: flickerstreak@92: local overlay = CreateFrame("Button", nil, f) flickerstreak@92: overlay:EnableMouse(true) flickerstreak@92: overlay:SetFrameLevel(3) -- set it above the buttons flickerstreak@92: overlay:SetPoint("TOPLEFT", -4, 4) flickerstreak@92: overlay:SetPoint("BOTTOMRIGHT", 4, -4) flickerstreak@92: overlay:SetBackdrop({ flickerstreak@73: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", flickerstreak@73: tile = true, flickerstreak@73: tileSize = 16, flickerstreak@73: edgeSize = 16, flickerstreak@73: insets = { left = 0, right = 0, top = 0, bottom = 0 }, flickerstreak@73: }) flickerstreak@73: flickerstreak@73: -- textures flickerstreak@92: local bgTex = overlay:CreateTexture(nil,"BACKGROUND") flickerstreak@73: bgTex:SetTexture(0.7,0.7,1.0,0.2) flickerstreak@73: bgTex:SetPoint("TOPLEFT",4,-4) flickerstreak@73: bgTex:SetPoint("BOTTOMRIGHT",-4,4) flickerstreak@92: local hTex = overlay:CreateTexture(nil,"HIGHLIGHT") flickerstreak@73: hTex:SetTexture(0.7,0.7,1.0,0.2) flickerstreak@73: hTex:SetPoint("TOPLEFT",4,-4) flickerstreak@73: hTex:SetPoint("BOTTOMRIGHT",-4,4) flickerstreak@73: hTex:SetBlendMode("ADD") flickerstreak@73: flickerstreak@73: -- label flickerstreak@92: local label = overlay:CreateFontString(nil,"OVERLAY","GameFontNormalLarge") flickerstreak@73: label:SetAllPoints() flickerstreak@73: label:SetJustifyH("CENTER") flickerstreak@73: label:SetShadowColor(0,0,0,1) flickerstreak@73: label:SetShadowOffset(2,-2) flickerstreak@73: label:SetTextColor(1,1,1,1) flickerstreak@73: label:SetText(bar:GetName()) flickerstreak@73: label:Show() flickerstreak@90: bar.controlLabelString = label -- so that bar:SetLabel() can update it flickerstreak@73: flickerstreak@73: local function StopResize() flickerstreak@73: f:StopMovingOrSizing() flickerstreak@73: f.isMoving = false flickerstreak@73: f:SetScript("OnUpdate",nil) flickerstreak@73: StoreSize(bar) flickerstreak@73: ClampToButtons(bar) flickerstreak@90: --ApplyAnchor(bar) flickerstreak@73: ReAction:RefreshOptions() flickerstreak@73: end flickerstreak@73: flickerstreak@73: -- edge drag handles flickerstreak@73: for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do flickerstreak@92: local edge = CreateFrame("Frame",nil,overlay) flickerstreak@73: edge:EnableMouse(true) flickerstreak@73: edge:SetWidth(8) flickerstreak@73: edge:SetHeight(8) flickerstreak@73: if point == "TOP" or point == "BOTTOM" then flickerstreak@73: edge:SetPoint(point.."LEFT") flickerstreak@73: edge:SetPoint(point.."RIGHT") flickerstreak@73: else flickerstreak@73: edge:SetPoint("TOP"..point) flickerstreak@73: edge:SetPoint("BOTTOM"..point) flickerstreak@73: end flickerstreak@73: local tex = edge:CreateTexture(nil,"HIGHLIGHT") flickerstreak@73: tex:SetTexture(1.0,0.82,0,0.7) flickerstreak@73: tex:SetBlendMode("ADD") flickerstreak@73: tex:SetAllPoints() flickerstreak@73: edge:RegisterForDrag("LeftButton") flickerstreak@73: edge:SetScript("OnMouseDown", flickerstreak@73: function() flickerstreak@73: local bw, bh = GetButtonSize(bar) flickerstreak@73: local r, c, s = GetButtonGrid(bar) flickerstreak@73: f:SetMinResize( bw+s+1, bh+s+1 ) flickerstreak@73: f:StartSizing(point) flickerstreak@73: f:SetScript("OnUpdate", flickerstreak@73: function() flickerstreak@73: RecomputeGrid(bar) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: edge:SetScript("OnMouseUp", StopResize) flickerstreak@73: edge:SetScript("OnEnter", flickerstreak@73: function() flickerstreak@73: GameTooltip:SetOwner(f, "ANCHOR_"..point) flickerstreak@73: GameTooltip:AddLine(L["Drag to add/remove buttons"]) flickerstreak@73: GameTooltip:Show() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: edge:SetScript("OnLeave", HideGameTooltip) flickerstreak@73: edge:Show() flickerstreak@73: end flickerstreak@73: flickerstreak@77: -- corner drag handles, nested in an anonymous frame so that they are on top flickerstreak@92: local foo = CreateFrame("Frame",nil,overlay) flickerstreak@77: foo:SetAllPoints(true) flickerstreak@73: for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do flickerstreak@77: local corner = CreateFrame("Frame",nil,foo) flickerstreak@73: corner:EnableMouse(true) flickerstreak@73: corner:SetWidth(12) flickerstreak@73: corner:SetHeight(12) flickerstreak@73: corner:SetPoint(point) flickerstreak@73: local tex = corner:CreateTexture(nil,"HIGHLIGHT") flickerstreak@73: tex:SetTexture(1.0,0.82,0,0.7) flickerstreak@73: tex:SetBlendMode("ADD") flickerstreak@73: tex:SetAllPoints() flickerstreak@73: corner:RegisterForDrag("LeftButton","RightButton") flickerstreak@73: local function updateTooltip() flickerstreak@73: local size, size2 = bar:GetButtonSize() flickerstreak@73: local rows, cols, spacing = bar:GetButtonGrid() flickerstreak@73: size = (size == size2) and tostring(size) or format("%dx%d",size,size2) flickerstreak@73: GameTooltipTextRight4:SetText(size) flickerstreak@73: GameTooltipTextRight5:SetText(tostring(spacing)) flickerstreak@73: end flickerstreak@73: corner:SetScript("OnMouseDown", flickerstreak@73: function(_,btn) flickerstreak@73: local bw, bh = GetButtonSize(bar) flickerstreak@73: local r, c, s = GetButtonGrid(bar) flickerstreak@73: if btn == "LeftButton" then -- button resize flickerstreak@73: f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) flickerstreak@73: f:SetScript("OnUpdate", flickerstreak@73: function() flickerstreak@73: RecomputeButtonSize(bar) flickerstreak@73: updateTooltip() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: elseif btn == "RightButton" then -- spacing resize flickerstreak@73: f:SetMinResize( bw*c, bh*r ) flickerstreak@73: f:SetScript("OnUpdate", flickerstreak@73: function() flickerstreak@73: RecomputeButtonSpacing(bar) flickerstreak@73: updateTooltip() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: end flickerstreak@73: f:StartSizing(point) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: corner:SetScript("OnMouseUp",StopResize) flickerstreak@73: corner:SetScript("OnEnter", flickerstreak@73: function() flickerstreak@73: GameTooltip:SetOwner(f, "ANCHOR_"..point) flickerstreak@73: GameTooltip:AddLine(L["Drag to resize buttons"]) flickerstreak@73: GameTooltip:AddLine(L["Right-click-drag"]) flickerstreak@73: GameTooltip:AddLine(L["to change spacing"]) flickerstreak@73: local size, size2 = bar:GetButtonSize() flickerstreak@73: local rows, cols, spacing = bar:GetButtonGrid() flickerstreak@73: size = (size == size2) and tostring(size) or format("%dx%d",size,size2) flickerstreak@73: GameTooltip:AddDoubleLine(L["Size:"], size) flickerstreak@73: GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing)) flickerstreak@73: GameTooltip:Show() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: corner:SetScript("OnLeave", flickerstreak@73: function() flickerstreak@73: GameTooltip:Hide() flickerstreak@73: f:SetScript("OnUpdate",nil) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@73: end flickerstreak@73: flickerstreak@92: overlay:RegisterForDrag("LeftButton") flickerstreak@92: overlay:RegisterForClicks("RightButtonUp") flickerstreak@73: flickerstreak@92: overlay:SetScript("OnDragStart", flickerstreak@73: function() flickerstreak@73: f:StartMoving() flickerstreak@73: f.isMoving = true flickerstreak@73: local w,h = bar:GetButtonSize() flickerstreak@73: f:ClearAllPoints() flickerstreak@73: f:SetScript("OnUpdate", function() flickerstreak@73: if IsShiftKeyDown() then flickerstreak@73: DisplaySnapIndicator(f,w,h) flickerstreak@73: else flickerstreak@73: HideSnapIndicator() flickerstreak@73: end flickerstreak@73: end) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@73: local function updateDragTooltip() flickerstreak@73: GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") flickerstreak@73: GameTooltip:AddLine(bar.name) flickerstreak@73: GameTooltip:AddLine(L["Drag to move"]) flickerstreak@73: GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"])) flickerstreak@73: GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"])) flickerstreak@73: local _, a = bar:GetAnchor() flickerstreak@73: if a and a ~= "UIParent" then flickerstreak@73: GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a)) flickerstreak@73: end flickerstreak@73: GameTooltip:Show() flickerstreak@73: end flickerstreak@73: flickerstreak@92: overlay:SetScript("OnDragStop", flickerstreak@73: function() flickerstreak@73: f:StopMovingOrSizing() flickerstreak@73: f.isMoving = false flickerstreak@73: f:SetScript("OnUpdate",nil) flickerstreak@73: flickerstreak@73: if IsShiftKeyDown() then flickerstreak@73: local w, h = bar:GetButtonSize() flickerstreak@73: local a, p, rp, x, y = GetClosestPointSnapped(f,w,h) flickerstreak@73: if a then flickerstreak@73: f:ClearAllPoints() flickerstreak@73: f:SetPoint(p,a,rp,x,y) flickerstreak@73: end flickerstreak@73: HideSnapIndicator() flickerstreak@73: end flickerstreak@73: flickerstreak@73: StoreExtents(bar) flickerstreak@73: ReAction:RefreshOptions() flickerstreak@73: updateDragTooltip() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@92: overlay:SetScript("OnEnter", flickerstreak@73: function() flickerstreak@73: -- TODO: add bar type and status information to name flickerstreak@73: --[[ flickerstreak@73: local name = bar.name flickerstreak@73: for _, m in ReAction:IterateModules() do flickerstreak@73: local suffix = safecall(m,"GetBarNameModifier",bar) flickerstreak@73: if suffix then flickerstreak@73: name = ("%s %s"):format(name,suffix) flickerstreak@73: end flickerstreak@73: end flickerstreak@73: ]]-- flickerstreak@73: flickerstreak@73: updateDragTooltip() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@92: overlay:SetScript("OnLeave", HideGameTooltip) flickerstreak@73: flickerstreak@92: overlay:SetScript("OnClick", flickerstreak@73: function() flickerstreak@90: ReAction:ShowEditor(bar) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@92: function overlay:LIBKEYBOUND_ENABLED(evt) flickerstreak@92: self:SetFrameLevel(1) flickerstreak@92: end flickerstreak@90: flickerstreak@92: function overlay:LIBKEYBOUND_DISABLED(evt) flickerstreak@92: self:SetFrameLevel(3) flickerstreak@92: end flickerstreak@92: flickerstreak@92: KB.RegisterCallback(overlay,"LIBKEYBOUND_ENABLED") flickerstreak@92: KB.RegisterCallback(overlay,"LIBKEYBOUND_DISABLED") flickerstreak@92: flickerstreak@92: if ReAction:GetKeybindMode() then flickerstreak@93: overlay:SetFrameLevel(1) flickerstreak@92: end flickerstreak@92: flickerstreak@92: return overlay flickerstreak@73: end flickerstreak@73: flickerstreak@73: flickerstreak@90: -- export methods to the Bar prototype flickerstreak@73: flickerstreak@73: function Bar:ShowControls(show) flickerstreak@92: local f = self.controlFrame flickerstreak@73: if show then flickerstreak@92: if not f then flickerstreak@92: f = CreateControls(self) flickerstreak@92: self.controlFrame = f flickerstreak@73: end flickerstreak@92: f:Show() flickerstreak@92: elseif f then flickerstreak@92: f:Hide() flickerstreak@73: end flickerstreak@73: end flickerstreak@73: flickerstreak@90: function Bar:SetLabel(name) flickerstreak@92: local label = self.controlLabelString flickerstreak@92: if label then flickerstreak@92: label:SetText(self.name) flickerstreak@90: end flickerstreak@90: end