flickerstreak@99: local ReAction = ReAction flickerstreak@99: local L = ReAction.L flickerstreak@99: local CreateFrame = CreateFrame flickerstreak@99: local InCombatLockdown = InCombatLockdown flickerstreak@99: local floor = math.floor flickerstreak@99: local min = math.min flickerstreak@99: local format = string.format flickerstreak@99: local GameTooltip = GameTooltip flickerstreak@99: local Bar = ReAction.Bar flickerstreak@99: local GetSize = Bar.GetSize flickerstreak@103: local SetSize = Bar.SetSize flickerstreak@99: local GetButtonSize = Bar.GetButtonSize flickerstreak@99: local GetButtonGrid = Bar.GetButtonGrid flickerstreak@99: local SetButtonSize = Bar.SetButtonSize flickerstreak@99: local SetButtonGrid = Bar.SetButtonGrid flickerstreak@99: local ApplyAnchor = Bar.ApplyAnchor flickerstreak@99: local GameTooltipTextRight1 = GameTooltipTextRight1 flickerstreak@99: local GameTooltipTextRight2 = GameTooltipTextRight2 flickerstreak@99: local GameTooltipTextRight3 = GameTooltipTextRight3 flickerstreak@73: flickerstreak@92: local KB = LibStub("LibKeyBound-1.0") flickerstreak@92: flickerstreak@80: ReAction:UpdateRevision("$Revision$") flickerstreak@77: flickerstreak@103: flickerstreak@103: -- flickerstreak@103: -- Wrap some of the bar manipulators to make them state-aware flickerstreak@103: -- flickerstreak@103: local function SetAnchor( bar, point, frame, relPoint, x, y ) flickerstreak@103: local state = bar:GetState() flickerstreak@103: if state then flickerstreak@103: local anchorstate = bar:GetStateProperty(state, "anchorEnable") flickerstreak@103: if anchorstate then flickerstreak@103: bar:SetStateProperty(state, "anchorFrame", frame) flickerstreak@103: bar:SetStateProperty(state, "anchorPoint", point) flickerstreak@103: bar:SetStateProperty(state, "anchorRelPoint", relPoint) flickerstreak@103: bar:SetStateProperty(state, "anchorX", x or 0) flickerstreak@103: bar:SetStateProperty(state, "anchorY", y or 0) flickerstreak@103: bar:SetAnchor(bar:GetAnchor()) flickerstreak@103: return flickerstreak@103: end flickerstreak@103: end flickerstreak@103: bar:SetAnchor(point, frame, relPoint, x, y) flickerstreak@103: end flickerstreak@103: flickerstreak@103: local function GetStateScale( bar ) flickerstreak@103: local state = bar:GetState() flickerstreak@103: if state and bar:GetStateProperty(state, "enableScale") then flickerstreak@103: return bar:GetStateProperty(state, "scale") flickerstreak@103: end flickerstreak@103: end flickerstreak@103: flickerstreak@103: local function SetStateScale( bar, scale ) flickerstreak@103: local state = bar:GetState() flickerstreak@103: if state and bar:GetStateProperty(state, "enableScale") then flickerstreak@103: bar:SetStateProperty(state, "scale", scale) flickerstreak@103: end flickerstreak@103: end flickerstreak@103: flickerstreak@103: flickerstreak@73: -- flickerstreak@73: -- Bar config overlay flickerstreak@73: -- flickerstreak@90: flickerstreak@98: local function GetNormalTextColor() flickerstreak@98: return 1.0, 1.0, 1.0, 1.0 flickerstreak@98: end flickerstreak@98: flickerstreak@98: local function GetAnchoredTextColor() flickerstreak@98: return 1.0, 1.0, 1.0, 1.0 flickerstreak@98: end flickerstreak@98: flickerstreak@98: local function GetNormalBgColor() flickerstreak@98: return 0.7, 0.7, 1.0, 0.3 flickerstreak@98: end flickerstreak@98: flickerstreak@98: local function GetAnchoredBgColor() flickerstreak@98: return 0.9, 0.2, 0.7, 0.3 flickerstreak@98: end flickerstreak@98: 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@103: fr = fr and fr:GetName() 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@103: local function ComputeBarScale(bar) flickerstreak@103: local w, h = bar.controlFrame:GetWidth() - 8, bar.controlFrame:GetHeight() - 8 flickerstreak@103: local bw, bh = GetButtonSize(bar) flickerstreak@103: local r, c, s = GetButtonGrid(bar) flickerstreak@103: flickerstreak@103: local scaleW = w / (c*(bw+s)) flickerstreak@103: local scaleH = h / (r*(bh+s)) flickerstreak@103: local scale = min(scaleW, scaleH) flickerstreak@103: flickerstreak@103: if scale > 2.5 then flickerstreak@103: scale = 2.5 flickerstreak@103: elseif scale < 0.25 then flickerstreak@103: scale = 0.25 flickerstreak@103: end flickerstreak@103: flickerstreak@103: return scale flickerstreak@103: end flickerstreak@103: 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@98: CENTER = function(x, y) return x, y 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@99: local cornerTexCoords = { flickerstreak@99: -- ULx, ULy, LLx, LLy, URx, URy, LRx, LRy flickerstreak@99: TOPLEFT = { 1, 1, 1, 0, 0, 1, 0, 0 }, flickerstreak@99: TOPRIGHT = { 1, 0, 0, 0, 1, 1, 0, 1 }, flickerstreak@99: BOTTOMLEFT = { 0, 1, 1, 1, 0, 0, 1, 0 }, flickerstreak@99: BOTTOMRIGHT = { 0, 0, 0, 1, 1, 0, 1, 1 }, flickerstreak@99: } 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@99: local sx, sy = insideOffsetFunc(xOff or 0, yOff or 0) flickerstreak@99: local xx, yy = coordFunc(f1) flickerstreak@73: if xx and yy then flickerstreak@73: if math.abs(x) <= rx then flickerstreak@99: if math.abs(y) <= ry then flickerstreak@99: x = sx flickerstreak@99: y = sy flickerstreak@99: s = true flickerstreak@99: elseif CheckEdgeOverlap(f1,o,"LEFT") then flickerstreak@99: x = sx flickerstreak@99: s = true flickerstreak@99: end flickerstreak@99: elseif math.abs(y) <= ry and CheckEdgeOverlap(f1,o,"TOP") 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@99: -- correct for some Lua oddities with doubles 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@98: si:SetHeight(16) flickerstreak@98: si:SetWidth(16) flickerstreak@73: local tex = si:CreateTexture() flickerstreak@73: tex:SetAllPoints() flickerstreak@98: tex:SetTexture("Interface\\AddOns\\ReAction\\img\\lock") 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@98: return o, p 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@98: local function UpdateLabelString(bar) flickerstreak@98: local label = bar.controlLabelString flickerstreak@98: if label then flickerstreak@98: local name = bar.labelName flickerstreak@98: if name and bar.labelSubtext then flickerstreak@98: name = format("%s (%s)", name, bar.labelSubtext) flickerstreak@98: end flickerstreak@98: label:SetText(name or "") flickerstreak@98: end flickerstreak@98: end flickerstreak@98: 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@103: -- child of UIParent so that alpha and scale doesn't propagate to it flickerstreak@103: local overlay = CreateFrame("Button", nil, UIParent) flickerstreak@92: overlay:EnableMouse(true) flickerstreak@92: overlay:SetFrameLevel(3) -- set it above the buttons flickerstreak@103: overlay:SetPoint("TOPLEFT", f, "TOPLEFT", -4, 4) flickerstreak@103: overlay:SetPoint("BOTTOMRIGHT", f, "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@98: local aTex = overlay:CreateTexture(nil,"ARTWORK") flickerstreak@98: aTex:SetTexture("Interface\\AddOns\\ReAction\\img\\lock") flickerstreak@98: aTex:SetWidth(16) flickerstreak@98: aTex:SetHeight(16) flickerstreak@98: aTex:Hide() 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@98: label:SetShadowOffset(3,-3) flickerstreak@98: label:SetTextColor(GetNormalTextColor()) 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@98: local function UpdateAnchorDecoration() flickerstreak@98: local point, anchor, relPoint, x, y = f:GetPoint(1) flickerstreak@98: if point then flickerstreak@98: local ofsx, ofsy = insidePointOffsetFuncs[point](x,y) flickerstreak@98: if (anchor and anchor ~= UIParent) or (ofsx == 0 and ofsy == 0) then flickerstreak@98: bgTex:SetTexture( GetAnchoredBgColor() ) flickerstreak@98: hTex:SetTexture( GetAnchoredBgColor() ) flickerstreak@98: label:SetTextColor( GetAnchoredTextColor() ) flickerstreak@98: aTex:ClearAllPoints() flickerstreak@98: aTex:SetPoint(point) flickerstreak@98: aTex:Show() flickerstreak@98: return flickerstreak@98: end flickerstreak@98: end flickerstreak@98: bgTex:SetTexture( GetNormalBgColor() ) flickerstreak@98: hTex:SetTexture( GetNormalBgColor() ) flickerstreak@98: label:SetTextColor( GetNormalTextColor() ) flickerstreak@98: aTex:Hide() flickerstreak@98: end flickerstreak@98: 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@73: ReAction:RefreshOptions() flickerstreak@73: end flickerstreak@73: flickerstreak@99: local function CornerUpdate() flickerstreak@99: local bw, bh = GetButtonSize(bar) flickerstreak@99: local r, c, s = GetButtonGrid(bar) flickerstreak@103: local ss = GetStateScale(bar) flickerstreak@99: if IsShiftKeyDown() then flickerstreak@103: if ss then flickerstreak@103: f:SetMinResize( ((s+bw)*c*0.25)/ss, ((s+bh)*r*0.25)/ss ) flickerstreak@103: f:SetMaxResize( ((s+bw)*c*2.5 + 1)/ss, ((s+bh)*r*2.5 + 1)/ss ) flickerstreak@103: scale = ComputeBarScale(bar) flickerstreak@103: else flickerstreak@103: f:SetMinResize( (s+12)*c+1, (s+12)*r+1 ) flickerstreak@103: f:SetMaxResize( (s+128)*c+1, (s+128)*r+1 ) flickerstreak@103: RecomputeButtonSize(bar) flickerstreak@103: end flickerstreak@103: elseif not ss and IsAltKeyDown() then flickerstreak@99: f:SetMinResize( bw*c, bh*r ) flickerstreak@103: f:SetMaxResize( 2*bw*c, 2*bh*r ) flickerstreak@99: RecomputeButtonSpacing(bar) flickerstreak@73: else flickerstreak@99: f:SetMinResize( bw+s+1, bh+s+1 ) flickerstreak@103: f:SetMaxResize( 50*(bw+s)+1, 50*(bh+s)+1 ) flickerstreak@99: RecomputeGrid(bar) flickerstreak@73: end flickerstreak@103: GameTooltipTextRight2:SetText(format("%d x %d",r,c)) flickerstreak@103: flickerstreak@103: local ss = GetStateScale(bar) flickerstreak@103: local state = bar:GetState() flickerstreak@103: if ss then flickerstreak@103: GameTooltipTextRight4:SetText(format("%d%%", scale*100)) flickerstreak@103: else flickerstreak@103: local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) flickerstreak@103: GameTooltipTextRight3:SetText(size) flickerstreak@103: GameTooltipTextRight4:SetText(tostring(s)) flickerstreak@103: end flickerstreak@73: end flickerstreak@73: flickerstreak@99: -- corner drag handles flickerstreak@73: for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do flickerstreak@99: local corner = CreateFrame("Frame",nil,overlay) flickerstreak@73: corner:EnableMouse(true) flickerstreak@99: corner:SetWidth(16) flickerstreak@99: corner:SetHeight(16) flickerstreak@73: corner:SetPoint(point) flickerstreak@99: flickerstreak@73: local tex = corner:CreateTexture(nil,"HIGHLIGHT") flickerstreak@99: tex:SetTexture("Interface\\AddOns\\ReAction\\img\\corner") flickerstreak@99: tex:SetTexCoord(unpack(cornerTexCoords[point])) flickerstreak@73: tex:SetBlendMode("ADD") flickerstreak@99: tex:SetAlpha(0.6) flickerstreak@73: tex:SetAllPoints() flickerstreak@99: flickerstreak@73: corner:SetScript("OnMouseDown", flickerstreak@73: function(_,btn) flickerstreak@99: f:SetScript("OnUpdate", CornerUpdate) flickerstreak@73: f:StartSizing(point) flickerstreak@73: end flickerstreak@73: ) flickerstreak@103: corner:SetScript("OnMouseUp", flickerstreak@103: function() flickerstreak@103: local ss = GetStateScale(bar) flickerstreak@103: if ss then flickerstreak@103: local state = bar:GetState() flickerstreak@103: SetStateScale(bar, ComputeBarScale(bar)) flickerstreak@103: end flickerstreak@103: StopResize() flickerstreak@103: end) flickerstreak@73: corner:SetScript("OnEnter", flickerstreak@73: function() flickerstreak@99: local bw, bh = GetButtonSize(bar) flickerstreak@99: local r, c, s = bar:GetButtonGrid() flickerstreak@99: local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh) flickerstreak@103: local ss = GetStateScale(bar) flickerstreak@103: local state = bar:GetState() flickerstreak@73: GameTooltip:SetOwner(f, "ANCHOR_"..point) flickerstreak@103: if ss then flickerstreak@103: GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state)) flickerstreak@103: else flickerstreak@103: GameTooltip:AddLine(bar:GetName()) flickerstreak@103: end flickerstreak@99: GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c)) flickerstreak@103: if ss then flickerstreak@103: GameTooltip:AddLine(L["State Scale Override"]) flickerstreak@103: GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to change scale:"]), format("%d%%", bar:GetStateProperty(state,"scale")*100)) flickerstreak@103: else flickerstreak@103: GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), tostring(floor(size))) flickerstreak@103: GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"], L["to change spacing:"]), tostring(floor(s))) flickerstreak@103: end 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: 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@98: UpdateAnchorDecoration() flickerstreak@73: f:SetScript("OnUpdate", function() flickerstreak@73: if IsShiftKeyDown() then flickerstreak@98: local f, p = DisplaySnapIndicator(f,w,h) flickerstreak@73: else flickerstreak@73: HideSnapIndicator() flickerstreak@73: end flickerstreak@73: end) flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@98: local function UpdateDragTooltip() flickerstreak@73: GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT") flickerstreak@103: local ss = GetStateScale(bar) flickerstreak@103: local state = bar:GetState() flickerstreak@103: if ss then flickerstreak@103: GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state)) flickerstreak@103: else flickerstreak@103: GameTooltip:AddLine(bar:GetName()) flickerstreak@103: end flickerstreak@99: GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"])) flickerstreak@99: GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"])) flickerstreak@99: GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."])) flickerstreak@103: local point, frame, relpoint, x, y = bar:GetFrame():GetPoint(1) flickerstreak@99: if point then flickerstreak@99: local ofsx, ofsy = insidePointOffsetFuncs[point](x,y) flickerstreak@103: if (frame and frame ~= UIParent) or (ofsx == 0 and ofsy == 0) then flickerstreak@103: frame = frame or UIParent flickerstreak@103: GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],frame:GetName())) flickerstreak@99: end 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@98: UpdateDragTooltip() flickerstreak@98: UpdateAnchorDecoration() flickerstreak@73: end flickerstreak@73: ) flickerstreak@73: flickerstreak@92: overlay:SetScript("OnEnter", flickerstreak@73: function() flickerstreak@98: 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@103: function overlay:RefreshControls() flickerstreak@103: UpdateAnchorDecoration() flickerstreak@103: end flickerstreak@103: flickerstreak@103: overlay:SetScript("OnShow", overlay.RefreshControls) flickerstreak@103: 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@98: bar:SetLabel(bar:GetName()) flickerstreak@98: UpdateLabelString(bar) flickerstreak@98: UpdateAnchorDecoration() flickerstreak@98: 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@103: function Bar:RefreshControls() flickerstreak@103: if self.controlFrame and self.controlFrame:IsShown() then flickerstreak@103: self.controlFrame:RefreshControls() flickerstreak@103: end flickerstreak@103: end flickerstreak@103: flickerstreak@90: function Bar:SetLabel(name) flickerstreak@98: self.labelName = name flickerstreak@98: UpdateLabelString(self) flickerstreak@90: end flickerstreak@98: flickerstreak@98: function Bar:SetLabelSubtext(text) flickerstreak@98: self.labelSubtext = text flickerstreak@98: UpdateLabelString(self) flickerstreak@98: end