flickerstreak@175: local addonName, addonTable = ... flickerstreak@175: local ReAction = addonTable.ReAction flickerstreak@122: local L = ReAction.L flickerstreak@183: local LKB = ReAction.LKB flickerstreak@122: local CreateFrame = CreateFrame flickerstreak@122: local InCombatLockdown = InCombatLockdown flickerstreak@122: local floor = math.floor flickerstreak@122: local min = math.min flickerstreak@122: local format = string.format flickerstreak@122: local GameTooltip = GameTooltip flickerstreak@122: local Bar = ReAction.Bar flickerstreak@122: local GetSize = Bar.GetSize flickerstreak@122: local SetSize = Bar.SetSize flickerstreak@122: local GetButtonSize = Bar.GetButtonSize flickerstreak@122: local GetButtonGrid = Bar.GetButtonGrid flickerstreak@122: local SetButtonSize = Bar.SetButtonSize flickerstreak@122: local SetButtonGrid = Bar.SetButtonGrid flickerstreak@122: local ApplyAnchor = Bar.ApplyAnchor flickerstreak@122: local GameTooltipTextRight1 = GameTooltipTextRight1 flickerstreak@122: local GameTooltipTextRight2 = GameTooltipTextRight2 flickerstreak@122: local GameTooltipTextRight3 = GameTooltipTextRight3 flickerstreak@122: flickerstreak@122: -- flickerstreak@122: -- Wrap some of the bar manipulators to make them state-aware flickerstreak@122: -- flickerstreak@122: local function SetAnchor( bar, point, frame, relPoint, x, y ) flickerstreak@155: local state = bar:GetSecureState() flickerstreak@122: if state then flickerstreak@122: local anchorstate = bar:GetStateProperty(state, "anchorEnable") flickerstreak@122: if anchorstate then flickerstreak@122: bar:SetStateProperty(state, "anchorFrame", frame) flickerstreak@122: bar:SetStateProperty(state, "anchorPoint", point) flickerstreak@122: bar:SetStateProperty(state, "anchorRelPoint", relPoint) flickerstreak@122: bar:SetStateProperty(state, "anchorX", x or 0) flickerstreak@122: bar:SetStateProperty(state, "anchorY", y or 0) flickerstreak@122: bar:SetAnchor(bar:GetAnchor()) flickerstreak@122: return flickerstreak@122: end flickerstreak@122: end flickerstreak@122: bar:SetAnchor(point, frame, relPoint, x, y) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetStateScale( bar ) flickerstreak@155: local state = bar:GetSecureState() flickerstreak@122: if state and bar:GetStateProperty(state, "enableScale") then flickerstreak@122: return bar:GetStateProperty(state, "scale") flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function SetStateScale( bar, scale ) flickerstreak@155: local state = bar:GetSecureState() flickerstreak@122: if state and bar:GetStateProperty(state, "enableScale") then flickerstreak@122: bar:SetStateProperty(state, "scale", scale) flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: flickerstreak@122: -- flickerstreak@122: -- Bar config overlay flickerstreak@122: -- flickerstreak@122: flickerstreak@122: local function GetNormalTextColor() flickerstreak@122: return 1.0, 1.0, 1.0, 1.0 flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetAnchoredTextColor() flickerstreak@122: return 1.0, 1.0, 1.0, 1.0 flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetNormalBgColor() flickerstreak@122: return 0.7, 0.7, 1.0, 0.3 flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetAnchoredBgColor() flickerstreak@122: return 0.9, 0.2, 0.7, 0.3 flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function StoreSize(bar) flickerstreak@122: local f = bar:GetFrame() flickerstreak@122: SetSize( bar, f:GetWidth(), f:GetHeight() ) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function StoreExtents(bar) flickerstreak@122: local f = bar:GetFrame() flickerstreak@122: local p, fr, rp, x, y = f:GetPoint(1) flickerstreak@122: fr = fr and fr:GetName() or "UIParent" flickerstreak@122: SetAnchor( bar, p, fr, rp, x, y ) flickerstreak@122: SetSize( bar, f:GetWidth(), f:GetHeight() ) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function RecomputeButtonSize(bar) flickerstreak@122: local w, h = GetSize(bar) flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = GetButtonGrid(bar) flickerstreak@122: flickerstreak@122: local scaleW = (floor(w/c) - s) / bw flickerstreak@122: local scaleH = (floor(h/r) - s) / bh flickerstreak@122: local scale = min(scaleW, scaleH) flickerstreak@122: flickerstreak@122: SetButtonSize(bar, scale * bw, scale * bh, s) flickerstreak@122: end flickerstreak@122: flickerstreak@154: local function ComputeBarScale(bar, overlay) flickerstreak@154: local w, h = overlay:GetWidth() - 8, overlay:GetHeight() - 8 flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = GetButtonGrid(bar) flickerstreak@122: flickerstreak@122: local scaleW = w / (c*(bw+s)) flickerstreak@122: local scaleH = h / (r*(bh+s)) flickerstreak@122: local scale = min(scaleW, scaleH) flickerstreak@122: flickerstreak@122: if scale > 2.5 then flickerstreak@122: scale = 2.5 flickerstreak@122: elseif scale < 0.25 then flickerstreak@122: scale = 0.25 flickerstreak@122: end flickerstreak@122: flickerstreak@122: return scale flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function RecomputeButtonSpacing(bar) flickerstreak@122: local w, h = GetSize(bar) flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = GetButtonGrid(bar) flickerstreak@122: flickerstreak@122: SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh)) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function RecomputeGrid(bar) flickerstreak@122: local w, h = GetSize(bar) flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = GetButtonGrid(bar) flickerstreak@122: flickerstreak@122: SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function ClampToButtons(bar) flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = GetButtonGrid(bar) flickerstreak@122: SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function HideGameTooltip() flickerstreak@122: GameTooltip:Hide() flickerstreak@122: end flickerstreak@122: flickerstreak@122: local anchorInside = { inside = true } flickerstreak@122: local anchorOutside = { outside = true } flickerstreak@122: local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" } flickerstreak@122: local oppositeEdges = { flickerstreak@122: TOP = "BOTTOM", flickerstreak@122: BOTTOM = "TOP", flickerstreak@122: LEFT = "RIGHT", flickerstreak@122: RIGHT = "LEFT" flickerstreak@122: } flickerstreak@122: local pointsOnEdge = { flickerstreak@122: BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", }, flickerstreak@122: TOP = { "TOP", "TOPLEFT", "TOPRIGHT", }, flickerstreak@122: RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", }, flickerstreak@122: LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", }, flickerstreak@122: } flickerstreak@122: local edgeSelector = { flickerstreak@122: BOTTOM = 1, -- select x of x,y flickerstreak@122: TOP = 1, -- select x of x,y flickerstreak@122: LEFT = 2, -- select y of x,y flickerstreak@122: RIGHT = 2, -- select y of x,y flickerstreak@122: } flickerstreak@122: local snapPoints = { flickerstreak@122: [anchorOutside] = { flickerstreak@122: BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"}, flickerstreak@122: BOTTOM = {"TOP"}, flickerstreak@122: BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"}, flickerstreak@122: RIGHT = {"LEFT"}, flickerstreak@122: TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"}, flickerstreak@122: TOP = {"BOTTOM"}, flickerstreak@122: TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"}, flickerstreak@122: LEFT = {"RIGHT"}, flickerstreak@122: CENTER = {"CENTER"} flickerstreak@122: }, flickerstreak@122: [anchorInside] = { flickerstreak@122: BOTTOMLEFT = {"BOTTOMLEFT"}, flickerstreak@122: BOTTOM = {"BOTTOM"}, flickerstreak@122: BOTTOMRIGHT = {"BOTTOMRIGHT"}, flickerstreak@122: RIGHT = {"RIGHT"}, flickerstreak@122: TOPRIGHT = {"TOPRIGHT"}, flickerstreak@122: TOP = {"TOP"}, flickerstreak@122: TOPLEFT = {"TOPLEFT"}, flickerstreak@122: LEFT = {"LEFT"}, flickerstreak@122: CENTER = {"CENTER"} flickerstreak@122: } flickerstreak@122: } flickerstreak@122: local insidePointOffsetFuncs = { flickerstreak@122: BOTTOMLEFT = function(x, y) return x, y end, flickerstreak@122: BOTTOM = function(x, y) return 0, y end, flickerstreak@122: BOTTOMRIGHT = function(x, y) return -x, y end, flickerstreak@122: RIGHT = function(x, y) return -x, 0 end, flickerstreak@122: TOPRIGHT = function(x, y) return -x, -y end, flickerstreak@122: TOP = function(x, y) return 0, -y end, flickerstreak@122: TOPLEFT = function(x, y) return x, -y end, flickerstreak@122: LEFT = function(x, y) return x, 0 end, flickerstreak@122: CENTER = function(x, y) return x, y end, flickerstreak@122: } flickerstreak@122: local pointCoordFuncs = { flickerstreak@122: BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end, flickerstreak@122: BOTTOM = function(f) return nil, f:GetBottom() end, flickerstreak@122: BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end, flickerstreak@122: RIGHT = function(f) return f:GetRight(), nil end, flickerstreak@122: TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end, flickerstreak@122: TOP = function(f) return nil, f:GetTop() end, flickerstreak@122: TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end, flickerstreak@122: LEFT = function(f) return f:GetLeft(), nil end, flickerstreak@122: CENTER = function(f) return f:GetCenter() end, flickerstreak@122: } flickerstreak@122: local edgeBoundsFuncs = { flickerstreak@122: BOTTOM = function(f) return f:GetLeft(), f:GetRight() end, flickerstreak@122: LEFT = function(f) return f:GetBottom(), f:GetTop() end flickerstreak@122: } flickerstreak@122: edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM flickerstreak@122: edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT flickerstreak@122: local cornerTexCoords = { flickerstreak@122: -- ULx, ULy, LLx, LLy, URx, URy, LRx, LRy flickerstreak@122: TOPLEFT = { 1, 1, 1, 0, 0, 1, 0, 0 }, flickerstreak@122: TOPRIGHT = { 1, 0, 0, 0, 1, 1, 0, 1 }, flickerstreak@122: BOTTOMLEFT = { 0, 1, 1, 1, 0, 0, 1, 0 }, flickerstreak@122: BOTTOMRIGHT = { 0, 0, 0, 1, 1, 0, 1, 1 }, flickerstreak@122: } flickerstreak@122: flickerstreak@122: -- Returns absolute coordinates x,y of the named point 'p' of frame 'f' flickerstreak@122: local function GetPointCoords( f, p ) flickerstreak@122: local x, y = pointCoordFuncs[p](f) flickerstreak@122: if not(x and y) then flickerstreak@122: local cx, cy = f:GetCenter() flickerstreak@122: x = x or cx flickerstreak@122: y = y or cy flickerstreak@122: end flickerstreak@122: return x, y flickerstreak@122: end flickerstreak@122: flickerstreak@122: flickerstreak@122: -- Returns true if frame 'f1' can be anchored to frame 'f2' flickerstreak@122: local function CheckAnchorable( f1, f2 ) flickerstreak@122: -- can't anchor a frame to itself or to nil flickerstreak@122: if f1 == f2 or f2 == nil then flickerstreak@122: return false flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- can always anchor to UIParent flickerstreak@122: if f2 == UIParent then flickerstreak@122: return true flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- also can't do circular anchoring of frames flickerstreak@122: -- walk the anchor chain, which generally shouldn't be that expensive flickerstreak@122: -- (who nests draggables that deep anyway?) flickerstreak@122: for i = 1, f2:GetNumPoints() do flickerstreak@122: local _, f = f2:GetPoint(i) flickerstreak@122: if not f then f = f2:GetParent() end flickerstreak@122: return CheckAnchorable(f1,f) flickerstreak@122: end flickerstreak@122: flickerstreak@122: return true flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- Returns true if frames f1 and f2 specified edges overlap flickerstreak@122: local function CheckEdgeOverlap( f1, f2, e ) flickerstreak@122: local l1, u1 = edgeBoundsFuncs[e](f1) flickerstreak@122: local l2, u2 = edgeBoundsFuncs[e](f2) flickerstreak@122: return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2 flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2 flickerstreak@122: local function CheckPointEdgeOverlap( f1, p1, f2, e2 ) flickerstreak@122: local l, u = edgeBoundsFuncs[e2](f2) flickerstreak@122: local x, y = GetPointCoords(f1,p1) flickerstreak@122: x = select(edgeSelector[e2], x, y) flickerstreak@122: return l <= x and x <= u flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- Returns the distance between corresponding edges. It is flickerstreak@122: -- assumed that the passed in edges e1 and e2 are the same or opposites flickerstreak@122: local function GetEdgeDistance( f1, f2, e1, e2 ) flickerstreak@122: local x1, y1 = pointCoordFuncs[e1](f1) flickerstreak@122: local x2, y2 = pointCoordFuncs[e2](f2) flickerstreak@122: return math.abs((x1 or y1) - (x2 or y2)) flickerstreak@122: end flickerstreak@122: flickerstreak@122: local globalSnapTargets = { [UIParent] = anchorInside } flickerstreak@122: flickerstreak@122: local function GetClosestFrameEdge(f1,f2,a) flickerstreak@122: local dist, edge, opp flickerstreak@122: if f2:IsVisible() and CheckAnchorable(f1,f2) then flickerstreak@122: for _, e in pairs(edges) do flickerstreak@122: local o = a.inside and e or oppositeEdges[e] flickerstreak@122: if CheckEdgeOverlap(f1,f2,e) then flickerstreak@122: local d = GetEdgeDistance(f1, f2, e, o) flickerstreak@122: if not dist or (d < dist) then flickerstreak@122: dist, edge, opp = d, e, o flickerstreak@122: end flickerstreak@122: end flickerstreak@122: end flickerstreak@122: end flickerstreak@122: return dist, edge, opp flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetClosestVisibleEdge( f ) flickerstreak@122: local r, o, e1, e2 flickerstreak@122: local a = anchorOutside flickerstreak@122: for _, b in ReAction:IterateBars() do flickerstreak@122: local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a) flickerstreak@122: if d and (not r or d < r) then flickerstreak@122: r, o, e1, e2 = d, b:GetFrame(), e, opp flickerstreak@122: end flickerstreak@122: end flickerstreak@122: for f2, a2 in pairs(globalSnapTargets) do flickerstreak@122: local d, e, opp = GetClosestFrameEdge(f,f2,a2) flickerstreak@122: if d and (not r or d < r) then flickerstreak@122: r, o, e1, e2, a = d, f2, e, opp, a2 flickerstreak@122: end flickerstreak@122: end flickerstreak@122: return o, e1, e2, a flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetClosestVisiblePoint(f1) flickerstreak@122: local f2, e1, e2, a = GetClosestVisibleEdge(f1) flickerstreak@122: if f2 then flickerstreak@122: local rsq, p, rp, x, y flickerstreak@122: -- iterate pointsOnEdge in order and use < to prefer edge centers to corners flickerstreak@122: for _, p1 in ipairs(pointsOnEdge[e1]) do flickerstreak@122: if CheckPointEdgeOverlap(f1,p1,f2,e2) then flickerstreak@122: for _, p2 in pairs(snapPoints[a][p1]) do flickerstreak@122: local x1, y1 = GetPointCoords(f1,p1) flickerstreak@122: local x2, y2 = GetPointCoords(f2,p2) flickerstreak@122: local dx = x1 - x2 flickerstreak@122: local dy = y1 - y2 flickerstreak@122: local rsq2 = dx*dx + dy*dy flickerstreak@122: if not rsq or rsq2 < rsq then flickerstreak@122: rsq, p, rp, x, y = rsq2, p1, p2, dx, dy flickerstreak@122: end flickerstreak@122: end flickerstreak@122: end flickerstreak@122: end flickerstreak@122: return f2, p, rp, x, y flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff) flickerstreak@122: local o, p, rp, x, y = GetClosestVisiblePoint(f1) flickerstreak@122: local s = false flickerstreak@122: flickerstreak@122: local insideOffsetFunc = p and insidePointOffsetFuncs[p] flickerstreak@122: local coordFunc = p and pointCoordFuncs[p] flickerstreak@122: if not insideOffsetFunc or not coordFunc then flickerstreak@122: return flickerstreak@122: end flickerstreak@122: flickerstreak@122: local sx, sy = insideOffsetFunc(xOff or 0, yOff or 0) flickerstreak@122: local xx, yy = coordFunc(f1) flickerstreak@122: if xx and yy then flickerstreak@122: if math.abs(x) <= rx then flickerstreak@122: if math.abs(y) <= ry then flickerstreak@122: x = sx flickerstreak@122: y = sy flickerstreak@122: s = true flickerstreak@122: elseif CheckEdgeOverlap(f1,o,"LEFT") then flickerstreak@122: x = sx flickerstreak@122: s = true flickerstreak@122: end flickerstreak@122: elseif math.abs(y) <= ry and CheckEdgeOverlap(f1,o,"TOP") then flickerstreak@122: y = sy flickerstreak@122: s = true flickerstreak@122: end flickerstreak@122: elseif xx then flickerstreak@122: if math.abs(x) <= rx then flickerstreak@122: x = sx flickerstreak@122: s = true flickerstreak@122: if math.abs(y) <= ry then flickerstreak@122: y = sy flickerstreak@122: end flickerstreak@122: end flickerstreak@122: elseif yy then flickerstreak@122: if math.abs(y) <= ry then flickerstreak@122: y = sy flickerstreak@122: s = true flickerstreak@122: if math.abs(x) <= rx then flickerstreak@122: x = sx flickerstreak@122: end flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- correct for some Lua oddities with doubles flickerstreak@122: if x == -0 then x = 0 end flickerstreak@122: if y == -0 then y = 0 end flickerstreak@122: flickerstreak@122: if s then flickerstreak@122: return o, p, rp, math.floor(x), math.floor(y) flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function CreateSnapIndicator() flickerstreak@122: local si = CreateFrame("Frame",nil,UIParent) flickerstreak@122: si:SetFrameStrata("HIGH") flickerstreak@122: si:SetHeight(16) flickerstreak@122: si:SetWidth(16) flickerstreak@122: local tex = si:CreateTexture() flickerstreak@122: tex:SetAllPoints() flickerstreak@122: tex:SetTexture("Interface\\AddOns\\ReAction\\img\\lock") flickerstreak@122: tex:SetBlendMode("ADD") flickerstreak@122: tex:SetDrawLayer("OVERLAY") flickerstreak@122: return si flickerstreak@122: end flickerstreak@122: flickerstreak@122: local si1 = CreateSnapIndicator() flickerstreak@122: local si2 = CreateSnapIndicator() flickerstreak@122: flickerstreak@122: local function DisplaySnapIndicator( f, rx, ry, xOff, yOff ) flickerstreak@122: local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff) flickerstreak@122: if o then flickerstreak@122: si1:ClearAllPoints() flickerstreak@122: si2:ClearAllPoints() flickerstreak@122: si1:SetPoint("CENTER", f, p, 0, 0) flickerstreak@122: local xx, yy = pointCoordFuncs[rp](o) flickerstreak@122: x = math.abs(x) <=rx and xx and 0 or x flickerstreak@122: y = math.abs(y) <=ry and yy and 0 or y flickerstreak@122: si2:SetPoint("CENTER", o, rp, x, y) flickerstreak@122: si1:Show() flickerstreak@122: si2:Show() flickerstreak@122: else flickerstreak@122: if si1:IsVisible() then flickerstreak@122: si1:Hide() flickerstreak@122: si2:Hide() flickerstreak@122: end flickerstreak@122: end flickerstreak@122: return o, p flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function HideSnapIndicator() flickerstreak@122: if si1:IsVisible() then flickerstreak@122: si1:Hide() flickerstreak@122: si2:Hide() flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@154: local function UpdateLabelString(overlay) flickerstreak@154: local label = overlay.labelString flickerstreak@122: if label then flickerstreak@154: local name = overlay.labelName flickerstreak@154: if name and overlay.labelSubtext then flickerstreak@154: name = format("%s (%s)", name, overlay.labelSubtext) flickerstreak@122: end flickerstreak@122: label:SetText(name or "") flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function CreateControls(bar) flickerstreak@122: local f = bar:GetFrame() flickerstreak@122: flickerstreak@122: f:SetMovable(true) flickerstreak@122: f:SetResizable(true) flickerstreak@122: flickerstreak@122: -- child of UIParent so that alpha and scale doesn't propagate to it flickerstreak@122: local overlay = CreateFrame("Button", nil, UIParent) flickerstreak@122: overlay:EnableMouse(true) flickerstreak@135: overlay:SetFrameLevel(10) -- set it above the buttons flickerstreak@122: overlay:SetPoint("TOPLEFT", f, "TOPLEFT", -4, 4) flickerstreak@122: overlay:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 4, -4) flickerstreak@122: overlay:SetBackdrop({ flickerstreak@122: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", flickerstreak@122: tile = true, flickerstreak@122: tileSize = 16, flickerstreak@122: edgeSize = 16, flickerstreak@122: insets = { left = 0, right = 0, top = 0, bottom = 0 }, flickerstreak@122: }) flickerstreak@122: flickerstreak@122: -- textures flickerstreak@122: local bgTex = overlay:CreateTexture(nil,"BACKGROUND") flickerstreak@122: bgTex:SetTexture(0.7,0.7,1.0,0.2) flickerstreak@122: bgTex:SetPoint("TOPLEFT",4,-4) flickerstreak@122: bgTex:SetPoint("BOTTOMRIGHT",-4,4) flickerstreak@122: local hTex = overlay:CreateTexture(nil,"HIGHLIGHT") flickerstreak@122: hTex:SetTexture(0.7,0.7,1.0,0.2) flickerstreak@122: hTex:SetPoint("TOPLEFT",4,-4) flickerstreak@122: hTex:SetPoint("BOTTOMRIGHT",-4,4) flickerstreak@122: hTex:SetBlendMode("ADD") flickerstreak@122: local aTex = overlay:CreateTexture(nil,"ARTWORK") flickerstreak@122: aTex:SetTexture("Interface\\AddOns\\ReAction\\img\\lock") flickerstreak@122: aTex:SetWidth(16) flickerstreak@122: aTex:SetHeight(16) flickerstreak@122: aTex:Hide() flickerstreak@122: flickerstreak@122: -- label flickerstreak@122: local label = overlay:CreateFontString(nil,"OVERLAY","GameFontNormalLarge") flickerstreak@122: label:SetAllPoints() flickerstreak@122: label:SetJustifyH("CENTER") flickerstreak@122: label:SetShadowColor(0,0,0,1) flickerstreak@122: label:SetShadowOffset(3,-3) flickerstreak@122: label:SetTextColor(GetNormalTextColor()) flickerstreak@122: label:SetText(bar:GetName()) flickerstreak@122: label:Show() flickerstreak@154: overlay.labelString = label flickerstreak@154: overlay.labelName = bar:GetName() flickerstreak@122: flickerstreak@122: local function UpdateAnchorDecoration() flickerstreak@122: local point, anchor, relPoint, x, y = f:GetPoint(1) flickerstreak@122: if point then flickerstreak@122: local ofsx, ofsy = insidePointOffsetFuncs[point](x,y) flickerstreak@122: if (anchor and anchor ~= UIParent) or (ofsx == 0 and ofsy == 0) then flickerstreak@122: bgTex:SetTexture( GetAnchoredBgColor() ) flickerstreak@122: hTex:SetTexture( GetAnchoredBgColor() ) flickerstreak@122: label:SetTextColor( GetAnchoredTextColor() ) flickerstreak@122: aTex:ClearAllPoints() flickerstreak@122: aTex:SetPoint(point) flickerstreak@122: aTex:Show() flickerstreak@122: return flickerstreak@122: end flickerstreak@122: end flickerstreak@122: bgTex:SetTexture( GetNormalBgColor() ) flickerstreak@122: hTex:SetTexture( GetNormalBgColor() ) flickerstreak@122: label:SetTextColor( GetNormalTextColor() ) flickerstreak@122: aTex:Hide() flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function StopResize() flickerstreak@122: f:StopMovingOrSizing() flickerstreak@122: f.isMoving = false flickerstreak@122: f:SetScript("OnUpdate",nil) flickerstreak@122: StoreSize(bar) flickerstreak@122: ClampToButtons(bar) flickerstreak@122: ReAction:RefreshOptions() flickerstreak@122: end flickerstreak@122: flickerstreak@122: local function CornerUpdate() flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = GetButtonGrid(bar) flickerstreak@122: local ss = GetStateScale(bar) flickerstreak@122: if IsShiftKeyDown() then flickerstreak@122: if ss then flickerstreak@122: f:SetMinResize( ((s+bw)*c*0.25)/ss, ((s+bh)*r*0.25)/ss ) flickerstreak@122: f:SetMaxResize( ((s+bw)*c*2.5 + 1)/ss, ((s+bh)*r*2.5 + 1)/ss ) flickerstreak@154: scale = ComputeBarScale(bar, overlay) flickerstreak@122: else flickerstreak@122: f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) flickerstreak@122: f:SetMaxResize( (s+128)*c+1, (s+128)*r+1 ) flickerstreak@122: RecomputeButtonSize(bar) flickerstreak@122: end flickerstreak@122: elseif not ss and IsAltKeyDown() then flickerstreak@122: f:SetMinResize( bw*c, bh*r ) flickerstreak@122: f:SetMaxResize( 2*bw*c, 2*bh*r ) flickerstreak@122: RecomputeButtonSpacing(bar) flickerstreak@122: else flickerstreak@122: f:SetMinResize( bw+s+1, bh+s+1 ) flickerstreak@122: f:SetMaxResize( 50*(bw+s)+1, 50*(bh+s)+1 ) flickerstreak@122: RecomputeGrid(bar) flickerstreak@122: end flickerstreak@122: GameTooltipTextRight2:SetText(format("%d x %d",r,c)) flickerstreak@122: flickerstreak@122: local ss = GetStateScale(bar) flickerstreak@122: if ss then flickerstreak@122: GameTooltipTextRight4:SetText(format("%d%%", scale*100)) flickerstreak@122: else flickerstreak@122: local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) flickerstreak@122: GameTooltipTextRight3:SetText(size) flickerstreak@122: GameTooltipTextRight4:SetText(tostring(s)) flickerstreak@122: end flickerstreak@122: end flickerstreak@122: flickerstreak@122: -- corner drag handles flickerstreak@122: for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do flickerstreak@122: local corner = CreateFrame("Frame",nil,overlay) flickerstreak@122: corner:EnableMouse(true) flickerstreak@122: corner:SetWidth(16) flickerstreak@122: corner:SetHeight(16) flickerstreak@122: corner:SetPoint(point) flickerstreak@122: flickerstreak@122: local tex = corner:CreateTexture(nil,"HIGHLIGHT") flickerstreak@122: tex:SetTexture("Interface\\AddOns\\ReAction\\img\\corner") flickerstreak@122: tex:SetTexCoord(unpack(cornerTexCoords[point])) flickerstreak@122: tex:SetBlendMode("ADD") flickerstreak@122: tex:SetAlpha(0.6) flickerstreak@122: tex:SetAllPoints() flickerstreak@122: flickerstreak@122: corner:SetScript("OnMouseDown", flickerstreak@122: function(_,btn) flickerstreak@122: f:SetScript("OnUpdate", CornerUpdate) flickerstreak@122: f:StartSizing(point) flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: corner:SetScript("OnMouseUp", flickerstreak@122: function() flickerstreak@122: local ss = GetStateScale(bar) flickerstreak@122: if ss then flickerstreak@154: SetStateScale(bar, ComputeBarScale(bar, overlay)) flickerstreak@122: end flickerstreak@122: StopResize() flickerstreak@122: end) flickerstreak@122: corner:SetScript("OnEnter", flickerstreak@122: function() flickerstreak@122: local bw, bh = GetButtonSize(bar) flickerstreak@122: local r, c, s = bar:GetButtonGrid() flickerstreak@122: local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) flickerstreak@122: local ss = GetStateScale(bar) flickerstreak@155: local state = bar:GetSecureState() flickerstreak@122: GameTooltip:SetOwner(f, "ANCHOR_"..point) flickerstreak@122: if ss then flickerstreak@122: GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state)) flickerstreak@122: else flickerstreak@122: GameTooltip:AddLine(bar:GetName()) flickerstreak@122: end flickerstreak@122: GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c)) flickerstreak@122: if ss then flickerstreak@122: GameTooltip:AddLine(L["State Scale Override"]) flickerstreak@122: GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to change scale:"]), format("%d%%", bar:GetStateProperty(state,"scale")*100)) flickerstreak@122: else flickerstreak@122: GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), tostring(floor(size))) flickerstreak@122: GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"], L["to change spacing:"]), tostring(floor(s))) flickerstreak@122: end flickerstreak@122: GameTooltip:Show() flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: corner:SetScript("OnLeave", flickerstreak@122: function() flickerstreak@122: GameTooltip:Hide() flickerstreak@122: f:SetScript("OnUpdate",nil) flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: end flickerstreak@122: flickerstreak@122: overlay:RegisterForDrag("LeftButton") flickerstreak@122: overlay:RegisterForClicks("RightButtonUp") flickerstreak@122: flickerstreak@122: overlay:SetScript("OnDragStart", flickerstreak@122: function() flickerstreak@122: f:StartMoving() flickerstreak@122: f.isMoving = true flickerstreak@122: local w,h = bar:GetButtonSize() flickerstreak@122: f:ClearAllPoints() flickerstreak@122: UpdateAnchorDecoration() flickerstreak@122: f:SetScript("OnUpdate", function() flickerstreak@122: if IsShiftKeyDown() then flickerstreak@122: local f, p = DisplaySnapIndicator(f,w,h) flickerstreak@122: else flickerstreak@122: HideSnapIndicator() flickerstreak@122: end flickerstreak@122: end) flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: flickerstreak@122: local function UpdateDragTooltip() flickerstreak@122: GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") flickerstreak@122: local ss = GetStateScale(bar) flickerstreak@155: local state = bar:GetSecureState() flickerstreak@122: if ss then flickerstreak@122: GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state)) flickerstreak@122: else flickerstreak@122: GameTooltip:AddLine(bar:GetName()) flickerstreak@122: end flickerstreak@122: GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"])) flickerstreak@122: GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"])) flickerstreak@122: GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."])) flickerstreak@122: local point, frame, relpoint, x, y = bar:GetFrame():GetPoint(1) flickerstreak@122: if point then flickerstreak@122: local ofsx, ofsy = insidePointOffsetFuncs[point](x,y) flickerstreak@122: if (frame and frame ~= UIParent) or (ofsx == 0 and ofsy == 0) then flickerstreak@122: frame = frame or UIParent flickerstreak@122: GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],frame:GetName())) flickerstreak@122: end flickerstreak@122: end flickerstreak@122: GameTooltip:Show() flickerstreak@122: end flickerstreak@122: flickerstreak@122: overlay:SetScript("OnDragStop", flickerstreak@122: function() flickerstreak@122: f:StopMovingOrSizing() flickerstreak@122: f.isMoving = false flickerstreak@122: f:SetScript("OnUpdate",nil) flickerstreak@122: flickerstreak@122: if IsShiftKeyDown() then flickerstreak@122: local w, h = bar:GetButtonSize() flickerstreak@122: local a, p, rp, x, y = GetClosestPointSnapped(f,w,h) flickerstreak@122: if a then flickerstreak@122: f:ClearAllPoints() flickerstreak@122: f:SetPoint(p,a,rp,x,y) flickerstreak@122: end flickerstreak@122: HideSnapIndicator() flickerstreak@122: end flickerstreak@122: flickerstreak@122: StoreExtents(bar) flickerstreak@122: ReAction:RefreshOptions() flickerstreak@122: UpdateDragTooltip() flickerstreak@122: UpdateAnchorDecoration() flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: flickerstreak@122: overlay:SetScript("OnEnter", flickerstreak@122: function() flickerstreak@122: UpdateDragTooltip() flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: flickerstreak@122: overlay:SetScript("OnLeave", HideGameTooltip) flickerstreak@122: flickerstreak@122: overlay:SetScript("OnClick", flickerstreak@122: function() flickerstreak@122: ReAction:ShowEditor(bar) flickerstreak@122: end flickerstreak@122: ) flickerstreak@122: flickerstreak@122: function overlay:LIBKEYBOUND_ENABLED(evt) flickerstreak@122: self:SetFrameLevel(1) flickerstreak@122: end flickerstreak@122: flickerstreak@122: function overlay:LIBKEYBOUND_DISABLED(evt) flickerstreak@135: self:SetFrameLevel(10) flickerstreak@122: end flickerstreak@122: flickerstreak@122: function overlay:RefreshControls() flickerstreak@122: UpdateAnchorDecoration() flickerstreak@122: end flickerstreak@122: flickerstreak@122: overlay:SetScript("OnShow", overlay.RefreshControls) flickerstreak@122: flickerstreak@183: LKB.RegisterCallback(overlay,"LIBKEYBOUND_ENABLED") flickerstreak@183: LKB.RegisterCallback(overlay,"LIBKEYBOUND_DISABLED") flickerstreak@122: flickerstreak@122: if ReAction:GetKeybindMode() then flickerstreak@122: overlay:SetFrameLevel(1) flickerstreak@122: end flickerstreak@122: flickerstreak@154: UpdateLabelString(overlay) flickerstreak@122: UpdateAnchorDecoration() flickerstreak@122: flickerstreak@122: return overlay flickerstreak@122: end flickerstreak@122: flickerstreak@122: flickerstreak@122: -- export methods to the Bar prototype flickerstreak@154: Bar.Overlay = { } flickerstreak@154: function Bar.Overlay:New( bar ) flickerstreak@154: return setmetatable( {frame = CreateControls(bar)}, {__index=self} ) flickerstreak@122: end flickerstreak@122: flickerstreak@154: function Bar.Overlay:SetLabel(name) flickerstreak@154: self.frame.labelName = name flickerstreak@154: UpdateLabelString(self.frame) flickerstreak@122: end flickerstreak@122: flickerstreak@154: function Bar.Overlay:SetLabelSubtext(text) flickerstreak@154: self.frame.labelSubtext = text flickerstreak@154: UpdateLabelString(self.frame) flickerstreak@122: end flickerstreak@122: flickerstreak@154: function Bar.Overlay:Show() flickerstreak@154: self.frame:Show() flickerstreak@122: end flickerstreak@154: flickerstreak@154: function Bar.Overlay:Hide() flickerstreak@154: self.frame:Hide() flickerstreak@154: end flickerstreak@155: flickerstreak@155: function Bar.Overlay:IsShown() flickerstreak@155: return self.frame:IsShown() flickerstreak@155: end flickerstreak@155: flickerstreak@155: function Bar.Overlay:RefreshControls() flickerstreak@155: self.frame:RefreshControls() flickerstreak@155: end