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