annotate modules/Overlay.lua @ 114:d39cfbdde301

localized 'default' profile name
author Flick <flickerstreak@gmail.com>
date Fri, 09 Jan 2009 18:35:54 +0000
parents 410d036c43b2
children
rev   line source
flickerstreak@109 1 local ReAction = ReAction
flickerstreak@109 2 local L = ReAction.L
flickerstreak@109 3 local CreateFrame = CreateFrame
flickerstreak@109 4 local InCombatLockdown = InCombatLockdown
flickerstreak@109 5 local floor = math.floor
flickerstreak@109 6 local min = math.min
flickerstreak@109 7 local format = string.format
flickerstreak@109 8 local GameTooltip = GameTooltip
flickerstreak@109 9 local Bar = ReAction.Bar
flickerstreak@109 10 local GetSize = Bar.GetSize
flickerstreak@109 11 local SetSize = Bar.SetSize
flickerstreak@109 12 local GetButtonSize = Bar.GetButtonSize
flickerstreak@109 13 local GetButtonGrid = Bar.GetButtonGrid
flickerstreak@109 14 local SetButtonSize = Bar.SetButtonSize
flickerstreak@109 15 local SetButtonGrid = Bar.SetButtonGrid
flickerstreak@109 16 local ApplyAnchor = Bar.ApplyAnchor
flickerstreak@109 17 local GameTooltipTextRight1 = GameTooltipTextRight1
flickerstreak@109 18 local GameTooltipTextRight2 = GameTooltipTextRight2
flickerstreak@109 19 local GameTooltipTextRight3 = GameTooltipTextRight3
flickerstreak@109 20
flickerstreak@109 21 local KB = LibStub("LibKeyBound-1.0")
flickerstreak@109 22
flickerstreak@109 23 ReAction:UpdateRevision("$Revision$")
flickerstreak@109 24
flickerstreak@109 25
flickerstreak@109 26 --
flickerstreak@109 27 -- Wrap some of the bar manipulators to make them state-aware
flickerstreak@109 28 --
flickerstreak@109 29 local function SetAnchor( bar, point, frame, relPoint, x, y )
flickerstreak@109 30 local state = bar:GetState()
flickerstreak@109 31 if state then
flickerstreak@109 32 local anchorstate = bar:GetStateProperty(state, "anchorEnable")
flickerstreak@109 33 if anchorstate then
flickerstreak@109 34 bar:SetStateProperty(state, "anchorFrame", frame)
flickerstreak@109 35 bar:SetStateProperty(state, "anchorPoint", point)
flickerstreak@109 36 bar:SetStateProperty(state, "anchorRelPoint", relPoint)
flickerstreak@109 37 bar:SetStateProperty(state, "anchorX", x or 0)
flickerstreak@109 38 bar:SetStateProperty(state, "anchorY", y or 0)
flickerstreak@109 39 bar:SetAnchor(bar:GetAnchor())
flickerstreak@109 40 return
flickerstreak@109 41 end
flickerstreak@109 42 end
flickerstreak@109 43 bar:SetAnchor(point, frame, relPoint, x, y)
flickerstreak@109 44 end
flickerstreak@109 45
flickerstreak@109 46 local function GetStateScale( bar )
flickerstreak@109 47 local state = bar:GetState()
flickerstreak@109 48 if state and bar:GetStateProperty(state, "enableScale") then
flickerstreak@109 49 return bar:GetStateProperty(state, "scale")
flickerstreak@109 50 end
flickerstreak@109 51 end
flickerstreak@109 52
flickerstreak@109 53 local function SetStateScale( bar, scale )
flickerstreak@109 54 local state = bar:GetState()
flickerstreak@109 55 if state and bar:GetStateProperty(state, "enableScale") then
flickerstreak@109 56 bar:SetStateProperty(state, "scale", scale)
flickerstreak@109 57 end
flickerstreak@109 58 end
flickerstreak@109 59
flickerstreak@109 60
flickerstreak@109 61 --
flickerstreak@109 62 -- Bar config overlay
flickerstreak@109 63 --
flickerstreak@109 64
flickerstreak@109 65 local function GetNormalTextColor()
flickerstreak@109 66 return 1.0, 1.0, 1.0, 1.0
flickerstreak@109 67 end
flickerstreak@109 68
flickerstreak@109 69 local function GetAnchoredTextColor()
flickerstreak@109 70 return 1.0, 1.0, 1.0, 1.0
flickerstreak@109 71 end
flickerstreak@109 72
flickerstreak@109 73 local function GetNormalBgColor()
flickerstreak@109 74 return 0.7, 0.7, 1.0, 0.3
flickerstreak@109 75 end
flickerstreak@109 76
flickerstreak@109 77 local function GetAnchoredBgColor()
flickerstreak@109 78 return 0.9, 0.2, 0.7, 0.3
flickerstreak@109 79 end
flickerstreak@109 80
flickerstreak@109 81 local function StoreSize(bar)
flickerstreak@109 82 local f = bar:GetFrame()
flickerstreak@109 83 SetSize( bar, f:GetWidth(), f:GetHeight() )
flickerstreak@109 84 end
flickerstreak@109 85
flickerstreak@109 86 local function StoreExtents(bar)
flickerstreak@109 87 local f = bar:GetFrame()
flickerstreak@109 88 local p, fr, rp, x, y = f:GetPoint(1)
flickerstreak@109 89 fr = fr and fr:GetName() or "UIParent"
flickerstreak@109 90 SetAnchor( bar, p, fr, rp, x, y )
flickerstreak@109 91 SetSize( bar, f:GetWidth(), f:GetHeight() )
flickerstreak@109 92 end
flickerstreak@109 93
flickerstreak@109 94 local function RecomputeButtonSize(bar)
flickerstreak@109 95 local w, h = GetSize(bar)
flickerstreak@109 96 local bw, bh = GetButtonSize(bar)
flickerstreak@109 97 local r, c, s = GetButtonGrid(bar)
flickerstreak@109 98
flickerstreak@109 99 local scaleW = (floor(w/c) - s) / bw
flickerstreak@109 100 local scaleH = (floor(h/r) - s) / bh
flickerstreak@109 101 local scale = min(scaleW, scaleH)
flickerstreak@109 102
flickerstreak@109 103 SetButtonSize(bar, scale * bw, scale * bh, s)
flickerstreak@109 104 end
flickerstreak@109 105
flickerstreak@109 106 local function ComputeBarScale(bar)
flickerstreak@109 107 local w, h = bar.controlFrame:GetWidth() - 8, bar.controlFrame:GetHeight() - 8
flickerstreak@109 108 local bw, bh = GetButtonSize(bar)
flickerstreak@109 109 local r, c, s = GetButtonGrid(bar)
flickerstreak@109 110
flickerstreak@109 111 local scaleW = w / (c*(bw+s))
flickerstreak@109 112 local scaleH = h / (r*(bh+s))
flickerstreak@109 113 local scale = min(scaleW, scaleH)
flickerstreak@109 114
flickerstreak@109 115 if scale > 2.5 then
flickerstreak@109 116 scale = 2.5
flickerstreak@109 117 elseif scale < 0.25 then
flickerstreak@109 118 scale = 0.25
flickerstreak@109 119 end
flickerstreak@109 120
flickerstreak@109 121 return scale
flickerstreak@109 122 end
flickerstreak@109 123
flickerstreak@109 124 local function RecomputeButtonSpacing(bar)
flickerstreak@109 125 local w, h = GetSize(bar)
flickerstreak@109 126 local bw, bh = GetButtonSize(bar)
flickerstreak@109 127 local r, c, s = GetButtonGrid(bar)
flickerstreak@109 128
flickerstreak@109 129 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
flickerstreak@109 130 end
flickerstreak@109 131
flickerstreak@109 132 local function RecomputeGrid(bar)
flickerstreak@109 133 local w, h = GetSize(bar)
flickerstreak@109 134 local bw, bh = GetButtonSize(bar)
flickerstreak@109 135 local r, c, s = GetButtonGrid(bar)
flickerstreak@109 136
flickerstreak@109 137 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
flickerstreak@109 138 end
flickerstreak@109 139
flickerstreak@109 140 local function ClampToButtons(bar)
flickerstreak@109 141 local bw, bh = GetButtonSize(bar)
flickerstreak@109 142 local r, c, s = GetButtonGrid(bar)
flickerstreak@109 143 SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1)
flickerstreak@109 144 end
flickerstreak@109 145
flickerstreak@109 146 local function HideGameTooltip()
flickerstreak@109 147 GameTooltip:Hide()
flickerstreak@109 148 end
flickerstreak@109 149
flickerstreak@109 150 local anchorInside = { inside = true }
flickerstreak@109 151 local anchorOutside = { outside = true }
flickerstreak@109 152 local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" }
flickerstreak@109 153 local oppositeEdges = {
flickerstreak@109 154 TOP = "BOTTOM",
flickerstreak@109 155 BOTTOM = "TOP",
flickerstreak@109 156 LEFT = "RIGHT",
flickerstreak@109 157 RIGHT = "LEFT"
flickerstreak@109 158 }
flickerstreak@109 159 local pointsOnEdge = {
flickerstreak@109 160 BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", },
flickerstreak@109 161 TOP = { "TOP", "TOPLEFT", "TOPRIGHT", },
flickerstreak@109 162 RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", },
flickerstreak@109 163 LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", },
flickerstreak@109 164 }
flickerstreak@109 165 local edgeSelector = {
flickerstreak@109 166 BOTTOM = 1, -- select x of x,y
flickerstreak@109 167 TOP = 1, -- select x of x,y
flickerstreak@109 168 LEFT = 2, -- select y of x,y
flickerstreak@109 169 RIGHT = 2, -- select y of x,y
flickerstreak@109 170 }
flickerstreak@109 171 local snapPoints = {
flickerstreak@109 172 [anchorOutside] = {
flickerstreak@109 173 BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"},
flickerstreak@109 174 BOTTOM = {"TOP"},
flickerstreak@109 175 BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"},
flickerstreak@109 176 RIGHT = {"LEFT"},
flickerstreak@109 177 TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"},
flickerstreak@109 178 TOP = {"BOTTOM"},
flickerstreak@109 179 TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"},
flickerstreak@109 180 LEFT = {"RIGHT"},
flickerstreak@109 181 CENTER = {"CENTER"}
flickerstreak@109 182 },
flickerstreak@109 183 [anchorInside] = {
flickerstreak@109 184 BOTTOMLEFT = {"BOTTOMLEFT"},
flickerstreak@109 185 BOTTOM = {"BOTTOM"},
flickerstreak@109 186 BOTTOMRIGHT = {"BOTTOMRIGHT"},
flickerstreak@109 187 RIGHT = {"RIGHT"},
flickerstreak@109 188 TOPRIGHT = {"TOPRIGHT"},
flickerstreak@109 189 TOP = {"TOP"},
flickerstreak@109 190 TOPLEFT = {"TOPLEFT"},
flickerstreak@109 191 LEFT = {"LEFT"},
flickerstreak@109 192 CENTER = {"CENTER"}
flickerstreak@109 193 }
flickerstreak@109 194 }
flickerstreak@109 195 local insidePointOffsetFuncs = {
flickerstreak@109 196 BOTTOMLEFT = function(x, y) return x, y end,
flickerstreak@109 197 BOTTOM = function(x, y) return 0, y end,
flickerstreak@109 198 BOTTOMRIGHT = function(x, y) return -x, y end,
flickerstreak@109 199 RIGHT = function(x, y) return -x, 0 end,
flickerstreak@109 200 TOPRIGHT = function(x, y) return -x, -y end,
flickerstreak@109 201 TOP = function(x, y) return 0, -y end,
flickerstreak@109 202 TOPLEFT = function(x, y) return x, -y end,
flickerstreak@109 203 LEFT = function(x, y) return x, 0 end,
flickerstreak@109 204 CENTER = function(x, y) return x, y end,
flickerstreak@109 205 }
flickerstreak@109 206 local pointCoordFuncs = {
flickerstreak@109 207 BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end,
flickerstreak@109 208 BOTTOM = function(f) return nil, f:GetBottom() end,
flickerstreak@109 209 BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end,
flickerstreak@109 210 RIGHT = function(f) return f:GetRight(), nil end,
flickerstreak@109 211 TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end,
flickerstreak@109 212 TOP = function(f) return nil, f:GetTop() end,
flickerstreak@109 213 TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end,
flickerstreak@109 214 LEFT = function(f) return f:GetLeft(), nil end,
flickerstreak@109 215 CENTER = function(f) return f:GetCenter() end,
flickerstreak@109 216 }
flickerstreak@109 217 local edgeBoundsFuncs = {
flickerstreak@109 218 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end,
flickerstreak@109 219 LEFT = function(f) return f:GetBottom(), f:GetTop() end
flickerstreak@109 220 }
flickerstreak@109 221 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM
flickerstreak@109 222 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
flickerstreak@109 223 local cornerTexCoords = {
flickerstreak@109 224 -- ULx, ULy, LLx, LLy, URx, URy, LRx, LRy
flickerstreak@109 225 TOPLEFT = { 1, 1, 1, 0, 0, 1, 0, 0 },
flickerstreak@109 226 TOPRIGHT = { 1, 0, 0, 0, 1, 1, 0, 1 },
flickerstreak@109 227 BOTTOMLEFT = { 0, 1, 1, 1, 0, 0, 1, 0 },
flickerstreak@109 228 BOTTOMRIGHT = { 0, 0, 0, 1, 1, 0, 1, 1 },
flickerstreak@109 229 }
flickerstreak@109 230
flickerstreak@109 231 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
flickerstreak@109 232 local function GetPointCoords( f, p )
flickerstreak@109 233 local x, y = pointCoordFuncs[p](f)
flickerstreak@109 234 if not(x and y) then
flickerstreak@109 235 local cx, cy = f:GetCenter()
flickerstreak@109 236 x = x or cx
flickerstreak@109 237 y = y or cy
flickerstreak@109 238 end
flickerstreak@109 239 return x, y
flickerstreak@109 240 end
flickerstreak@109 241
flickerstreak@109 242
flickerstreak@109 243 -- Returns true if frame 'f1' can be anchored to frame 'f2'
flickerstreak@109 244 local function CheckAnchorable( f1, f2 )
flickerstreak@109 245 -- can't anchor a frame to itself or to nil
flickerstreak@109 246 if f1 == f2 or f2 == nil then
flickerstreak@109 247 return false
flickerstreak@109 248 end
flickerstreak@109 249
flickerstreak@109 250 -- can always anchor to UIParent
flickerstreak@109 251 if f2 == UIParent then
flickerstreak@109 252 return true
flickerstreak@109 253 end
flickerstreak@109 254
flickerstreak@109 255 -- also can't do circular anchoring of frames
flickerstreak@109 256 -- walk the anchor chain, which generally shouldn't be that expensive
flickerstreak@109 257 -- (who nests draggables that deep anyway?)
flickerstreak@109 258 for i = 1, f2:GetNumPoints() do
flickerstreak@109 259 local _, f = f2:GetPoint(i)
flickerstreak@109 260 if not f then f = f2:GetParent() end
flickerstreak@109 261 return CheckAnchorable(f1,f)
flickerstreak@109 262 end
flickerstreak@109 263
flickerstreak@109 264 return true
flickerstreak@109 265 end
flickerstreak@109 266
flickerstreak@109 267 -- Returns true if frames f1 and f2 specified edges overlap
flickerstreak@109 268 local function CheckEdgeOverlap( f1, f2, e )
flickerstreak@109 269 local l1, u1 = edgeBoundsFuncs[e](f1)
flickerstreak@109 270 local l2, u2 = edgeBoundsFuncs[e](f2)
flickerstreak@109 271 return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2
flickerstreak@109 272 end
flickerstreak@109 273
flickerstreak@109 274 -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2
flickerstreak@109 275 local function CheckPointEdgeOverlap( f1, p1, f2, e2 )
flickerstreak@109 276 local l, u = edgeBoundsFuncs[e2](f2)
flickerstreak@109 277 local x, y = GetPointCoords(f1,p1)
flickerstreak@109 278 x = select(edgeSelector[e2], x, y)
flickerstreak@109 279 return l <= x and x <= u
flickerstreak@109 280 end
flickerstreak@109 281
flickerstreak@109 282 -- Returns the distance between corresponding edges. It is
flickerstreak@109 283 -- assumed that the passed in edges e1 and e2 are the same or opposites
flickerstreak@109 284 local function GetEdgeDistance( f1, f2, e1, e2 )
flickerstreak@109 285 local x1, y1 = pointCoordFuncs[e1](f1)
flickerstreak@109 286 local x2, y2 = pointCoordFuncs[e2](f2)
flickerstreak@109 287 return math.abs((x1 or y1) - (x2 or y2))
flickerstreak@109 288 end
flickerstreak@109 289
flickerstreak@109 290 local globalSnapTargets = { [UIParent] = anchorInside }
flickerstreak@109 291
flickerstreak@109 292 local function GetClosestFrameEdge(f1,f2,a)
flickerstreak@109 293 local dist, edge, opp
flickerstreak@109 294 if f2:IsVisible() and CheckAnchorable(f1,f2) then
flickerstreak@109 295 for _, e in pairs(edges) do
flickerstreak@109 296 local o = a.inside and e or oppositeEdges[e]
flickerstreak@109 297 if CheckEdgeOverlap(f1,f2,e) then
flickerstreak@109 298 local d = GetEdgeDistance(f1, f2, e, o)
flickerstreak@109 299 if not dist or (d < dist) then
flickerstreak@109 300 dist, edge, opp = d, e, o
flickerstreak@109 301 end
flickerstreak@109 302 end
flickerstreak@109 303 end
flickerstreak@109 304 end
flickerstreak@109 305 return dist, edge, opp
flickerstreak@109 306 end
flickerstreak@109 307
flickerstreak@109 308 local function GetClosestVisibleEdge( f )
flickerstreak@109 309 local r, o, e1, e2
flickerstreak@109 310 local a = anchorOutside
flickerstreak@109 311 for _, b in ReAction:IterateBars() do
flickerstreak@109 312 local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a)
flickerstreak@109 313 if d and (not r or d < r) then
flickerstreak@109 314 r, o, e1, e2 = d, b:GetFrame(), e, opp
flickerstreak@109 315 end
flickerstreak@109 316 end
flickerstreak@109 317 for f2, a2 in pairs(globalSnapTargets) do
flickerstreak@109 318 local d, e, opp = GetClosestFrameEdge(f,f2,a2)
flickerstreak@109 319 if d and (not r or d < r) then
flickerstreak@109 320 r, o, e1, e2, a = d, f2, e, opp, a2
flickerstreak@109 321 end
flickerstreak@109 322 end
flickerstreak@109 323 return o, e1, e2, a
flickerstreak@109 324 end
flickerstreak@109 325
flickerstreak@109 326 local function GetClosestVisiblePoint(f1)
flickerstreak@109 327 local f2, e1, e2, a = GetClosestVisibleEdge(f1)
flickerstreak@109 328 if f2 then
flickerstreak@109 329 local rsq, p, rp, x, y
flickerstreak@109 330 -- iterate pointsOnEdge in order and use < to prefer edge centers to corners
flickerstreak@109 331 for _, p1 in ipairs(pointsOnEdge[e1]) do
flickerstreak@109 332 if CheckPointEdgeOverlap(f1,p1,f2,e2) then
flickerstreak@109 333 for _, p2 in pairs(snapPoints[a][p1]) do
flickerstreak@109 334 local x1, y1 = GetPointCoords(f1,p1)
flickerstreak@109 335 local x2, y2 = GetPointCoords(f2,p2)
flickerstreak@109 336 local dx = x1 - x2
flickerstreak@109 337 local dy = y1 - y2
flickerstreak@109 338 local rsq2 = dx*dx + dy*dy
flickerstreak@109 339 if not rsq or rsq2 < rsq then
flickerstreak@109 340 rsq, p, rp, x, y = rsq2, p1, p2, dx, dy
flickerstreak@109 341 end
flickerstreak@109 342 end
flickerstreak@109 343 end
flickerstreak@109 344 end
flickerstreak@109 345 return f2, p, rp, x, y
flickerstreak@109 346 end
flickerstreak@109 347 end
flickerstreak@109 348
flickerstreak@109 349 local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff)
flickerstreak@109 350 local o, p, rp, x, y = GetClosestVisiblePoint(f1)
flickerstreak@109 351 local s = false
flickerstreak@109 352
flickerstreak@109 353 local insideOffsetFunc = p and insidePointOffsetFuncs[p]
flickerstreak@109 354 local coordFunc = p and pointCoordFuncs[p]
flickerstreak@109 355 if not insideOffsetFunc or not coordFunc then
flickerstreak@109 356 return
flickerstreak@109 357 end
flickerstreak@109 358
flickerstreak@109 359 local sx, sy = insideOffsetFunc(xOff or 0, yOff or 0)
flickerstreak@109 360 local xx, yy = coordFunc(f1)
flickerstreak@109 361 if xx and yy then
flickerstreak@109 362 if math.abs(x) <= rx then
flickerstreak@109 363 if math.abs(y) <= ry then
flickerstreak@109 364 x = sx
flickerstreak@109 365 y = sy
flickerstreak@109 366 s = true
flickerstreak@109 367 elseif CheckEdgeOverlap(f1,o,"LEFT") then
flickerstreak@109 368 x = sx
flickerstreak@109 369 s = true
flickerstreak@109 370 end
flickerstreak@109 371 elseif math.abs(y) <= ry and CheckEdgeOverlap(f1,o,"TOP") then
flickerstreak@109 372 y = sy
flickerstreak@109 373 s = true
flickerstreak@109 374 end
flickerstreak@109 375 elseif xx then
flickerstreak@109 376 if math.abs(x) <= rx then
flickerstreak@109 377 x = sx
flickerstreak@109 378 s = true
flickerstreak@109 379 if math.abs(y) <= ry then
flickerstreak@109 380 y = sy
flickerstreak@109 381 end
flickerstreak@109 382 end
flickerstreak@109 383 elseif yy then
flickerstreak@109 384 if math.abs(y) <= ry then
flickerstreak@109 385 y = sy
flickerstreak@109 386 s = true
flickerstreak@109 387 if math.abs(x) <= rx then
flickerstreak@109 388 x = sx
flickerstreak@109 389 end
flickerstreak@109 390 end
flickerstreak@109 391 end
flickerstreak@109 392
flickerstreak@109 393 -- correct for some Lua oddities with doubles
flickerstreak@109 394 if x == -0 then x = 0 end
flickerstreak@109 395 if y == -0 then y = 0 end
flickerstreak@109 396
flickerstreak@109 397 if s then
flickerstreak@109 398 return o, p, rp, math.floor(x), math.floor(y)
flickerstreak@109 399 end
flickerstreak@109 400 end
flickerstreak@109 401
flickerstreak@109 402 local function CreateSnapIndicator()
flickerstreak@109 403 local si = CreateFrame("Frame",nil,UIParent)
flickerstreak@109 404 si:SetFrameStrata("HIGH")
flickerstreak@109 405 si:SetHeight(16)
flickerstreak@109 406 si:SetWidth(16)
flickerstreak@109 407 local tex = si:CreateTexture()
flickerstreak@109 408 tex:SetAllPoints()
flickerstreak@109 409 tex:SetTexture("Interface\\AddOns\\ReAction\\img\\lock")
flickerstreak@109 410 tex:SetBlendMode("ADD")
flickerstreak@109 411 tex:SetDrawLayer("OVERLAY")
flickerstreak@109 412 return si
flickerstreak@109 413 end
flickerstreak@109 414
flickerstreak@109 415 local si1 = CreateSnapIndicator()
flickerstreak@109 416 local si2 = CreateSnapIndicator()
flickerstreak@109 417
flickerstreak@109 418 local function DisplaySnapIndicator( f, rx, ry, xOff, yOff )
flickerstreak@109 419 local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff)
flickerstreak@109 420 if o then
flickerstreak@109 421 si1:ClearAllPoints()
flickerstreak@109 422 si2:ClearAllPoints()
flickerstreak@109 423 si1:SetPoint("CENTER", f, p, 0, 0)
flickerstreak@109 424 local xx, yy = pointCoordFuncs[rp](o)
flickerstreak@109 425 x = math.abs(x) <=rx and xx and 0 or x
flickerstreak@109 426 y = math.abs(y) <=ry and yy and 0 or y
flickerstreak@109 427 si2:SetPoint("CENTER", o, rp, x, y)
flickerstreak@109 428 si1:Show()
flickerstreak@109 429 si2:Show()
flickerstreak@109 430 else
flickerstreak@109 431 if si1:IsVisible() then
flickerstreak@109 432 si1:Hide()
flickerstreak@109 433 si2:Hide()
flickerstreak@109 434 end
flickerstreak@109 435 end
flickerstreak@109 436 return o, p
flickerstreak@109 437 end
flickerstreak@109 438
flickerstreak@109 439 local function HideSnapIndicator()
flickerstreak@109 440 if si1:IsVisible() then
flickerstreak@109 441 si1:Hide()
flickerstreak@109 442 si2:Hide()
flickerstreak@109 443 end
flickerstreak@109 444 end
flickerstreak@109 445
flickerstreak@109 446 local function UpdateLabelString(bar)
flickerstreak@109 447 local label = bar.controlLabelString
flickerstreak@109 448 if label then
flickerstreak@109 449 local name = bar.labelName
flickerstreak@109 450 if name and bar.labelSubtext then
flickerstreak@109 451 name = format("%s (%s)", name, bar.labelSubtext)
flickerstreak@109 452 end
flickerstreak@109 453 label:SetText(name or "")
flickerstreak@109 454 end
flickerstreak@109 455 end
flickerstreak@109 456
flickerstreak@109 457 local function CreateControls(bar)
flickerstreak@109 458 local f = bar:GetFrame()
flickerstreak@109 459
flickerstreak@109 460 f:SetMovable(true)
flickerstreak@109 461 f:SetResizable(true)
flickerstreak@109 462
flickerstreak@109 463 -- child of UIParent so that alpha and scale doesn't propagate to it
flickerstreak@109 464 local overlay = CreateFrame("Button", nil, UIParent)
flickerstreak@109 465 overlay:EnableMouse(true)
flickerstreak@109 466 overlay:SetFrameLevel(3) -- set it above the buttons
flickerstreak@109 467 overlay:SetPoint("TOPLEFT", f, "TOPLEFT", -4, 4)
flickerstreak@109 468 overlay:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 4, -4)
flickerstreak@109 469 overlay:SetBackdrop({
flickerstreak@109 470 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
flickerstreak@109 471 tile = true,
flickerstreak@109 472 tileSize = 16,
flickerstreak@109 473 edgeSize = 16,
flickerstreak@109 474 insets = { left = 0, right = 0, top = 0, bottom = 0 },
flickerstreak@109 475 })
flickerstreak@109 476
flickerstreak@109 477 -- textures
flickerstreak@109 478 local bgTex = overlay:CreateTexture(nil,"BACKGROUND")
flickerstreak@109 479 bgTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@109 480 bgTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@109 481 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@109 482 local hTex = overlay:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@109 483 hTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@109 484 hTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@109 485 hTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@109 486 hTex:SetBlendMode("ADD")
flickerstreak@109 487 local aTex = overlay:CreateTexture(nil,"ARTWORK")
flickerstreak@109 488 aTex:SetTexture("Interface\\AddOns\\ReAction\\img\\lock")
flickerstreak@109 489 aTex:SetWidth(16)
flickerstreak@109 490 aTex:SetHeight(16)
flickerstreak@109 491 aTex:Hide()
flickerstreak@109 492
flickerstreak@109 493 -- label
flickerstreak@109 494 local label = overlay:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
flickerstreak@109 495 label:SetAllPoints()
flickerstreak@109 496 label:SetJustifyH("CENTER")
flickerstreak@109 497 label:SetShadowColor(0,0,0,1)
flickerstreak@109 498 label:SetShadowOffset(3,-3)
flickerstreak@109 499 label:SetTextColor(GetNormalTextColor())
flickerstreak@109 500 label:SetText(bar:GetName())
flickerstreak@109 501 label:Show()
flickerstreak@109 502 bar.controlLabelString = label -- so that bar:SetLabel() can update it
flickerstreak@109 503
flickerstreak@109 504 local function UpdateAnchorDecoration()
flickerstreak@109 505 local point, anchor, relPoint, x, y = f:GetPoint(1)
flickerstreak@109 506 if point then
flickerstreak@109 507 local ofsx, ofsy = insidePointOffsetFuncs[point](x,y)
flickerstreak@109 508 if (anchor and anchor ~= UIParent) or (ofsx == 0 and ofsy == 0) then
flickerstreak@109 509 bgTex:SetTexture( GetAnchoredBgColor() )
flickerstreak@109 510 hTex:SetTexture( GetAnchoredBgColor() )
flickerstreak@109 511 label:SetTextColor( GetAnchoredTextColor() )
flickerstreak@109 512 aTex:ClearAllPoints()
flickerstreak@109 513 aTex:SetPoint(point)
flickerstreak@109 514 aTex:Show()
flickerstreak@109 515 return
flickerstreak@109 516 end
flickerstreak@109 517 end
flickerstreak@109 518 bgTex:SetTexture( GetNormalBgColor() )
flickerstreak@109 519 hTex:SetTexture( GetNormalBgColor() )
flickerstreak@109 520 label:SetTextColor( GetNormalTextColor() )
flickerstreak@109 521 aTex:Hide()
flickerstreak@109 522 end
flickerstreak@109 523
flickerstreak@109 524 local function StopResize()
flickerstreak@109 525 f:StopMovingOrSizing()
flickerstreak@109 526 f.isMoving = false
flickerstreak@109 527 f:SetScript("OnUpdate",nil)
flickerstreak@109 528 StoreSize(bar)
flickerstreak@109 529 ClampToButtons(bar)
flickerstreak@109 530 ReAction:RefreshOptions()
flickerstreak@109 531 end
flickerstreak@109 532
flickerstreak@109 533 local function CornerUpdate()
flickerstreak@109 534 local bw, bh = GetButtonSize(bar)
flickerstreak@109 535 local r, c, s = GetButtonGrid(bar)
flickerstreak@109 536 local ss = GetStateScale(bar)
flickerstreak@109 537 if IsShiftKeyDown() then
flickerstreak@109 538 if ss then
flickerstreak@109 539 f:SetMinResize( ((s+bw)*c*0.25)/ss, ((s+bh)*r*0.25)/ss )
flickerstreak@109 540 f:SetMaxResize( ((s+bw)*c*2.5 + 1)/ss, ((s+bh)*r*2.5 + 1)/ss )
flickerstreak@109 541 scale = ComputeBarScale(bar)
flickerstreak@109 542 else
flickerstreak@109 543 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
flickerstreak@109 544 f:SetMaxResize( (s+128)*c+1, (s+128)*r+1 )
flickerstreak@109 545 RecomputeButtonSize(bar)
flickerstreak@109 546 end
flickerstreak@109 547 elseif not ss and IsAltKeyDown() then
flickerstreak@109 548 f:SetMinResize( bw*c, bh*r )
flickerstreak@109 549 f:SetMaxResize( 2*bw*c, 2*bh*r )
flickerstreak@109 550 RecomputeButtonSpacing(bar)
flickerstreak@109 551 else
flickerstreak@109 552 f:SetMinResize( bw+s+1, bh+s+1 )
flickerstreak@109 553 f:SetMaxResize( 50*(bw+s)+1, 50*(bh+s)+1 )
flickerstreak@109 554 RecomputeGrid(bar)
flickerstreak@109 555 end
flickerstreak@109 556 GameTooltipTextRight2:SetText(format("%d x %d",r,c))
flickerstreak@109 557
flickerstreak@109 558 local ss = GetStateScale(bar)
flickerstreak@109 559 local state = bar:GetState()
flickerstreak@109 560 if ss then
flickerstreak@109 561 GameTooltipTextRight4:SetText(format("%d%%", scale*100))
flickerstreak@109 562 else
flickerstreak@109 563 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
flickerstreak@109 564 GameTooltipTextRight3:SetText(size)
flickerstreak@109 565 GameTooltipTextRight4:SetText(tostring(s))
flickerstreak@109 566 end
flickerstreak@109 567 end
flickerstreak@109 568
flickerstreak@109 569 -- corner drag handles
flickerstreak@109 570 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
flickerstreak@109 571 local corner = CreateFrame("Frame",nil,overlay)
flickerstreak@109 572 corner:EnableMouse(true)
flickerstreak@109 573 corner:SetWidth(16)
flickerstreak@109 574 corner:SetHeight(16)
flickerstreak@109 575 corner:SetPoint(point)
flickerstreak@109 576
flickerstreak@109 577 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@109 578 tex:SetTexture("Interface\\AddOns\\ReAction\\img\\corner")
flickerstreak@109 579 tex:SetTexCoord(unpack(cornerTexCoords[point]))
flickerstreak@109 580 tex:SetBlendMode("ADD")
flickerstreak@109 581 tex:SetAlpha(0.6)
flickerstreak@109 582 tex:SetAllPoints()
flickerstreak@109 583
flickerstreak@109 584 corner:SetScript("OnMouseDown",
flickerstreak@109 585 function(_,btn)
flickerstreak@109 586 f:SetScript("OnUpdate", CornerUpdate)
flickerstreak@109 587 f:StartSizing(point)
flickerstreak@109 588 end
flickerstreak@109 589 )
flickerstreak@109 590 corner:SetScript("OnMouseUp",
flickerstreak@109 591 function()
flickerstreak@109 592 local ss = GetStateScale(bar)
flickerstreak@109 593 if ss then
flickerstreak@109 594 local state = bar:GetState()
flickerstreak@109 595 SetStateScale(bar, ComputeBarScale(bar))
flickerstreak@109 596 end
flickerstreak@109 597 StopResize()
flickerstreak@109 598 end)
flickerstreak@109 599 corner:SetScript("OnEnter",
flickerstreak@109 600 function()
flickerstreak@109 601 local bw, bh = GetButtonSize(bar)
flickerstreak@109 602 local r, c, s = bar:GetButtonGrid()
flickerstreak@109 603 local size = (bw == bh) and tostring(bw) or format("%d x %d",bw,bh)
flickerstreak@109 604 local ss = GetStateScale(bar)
flickerstreak@109 605 local state = bar:GetState()
flickerstreak@109 606 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@109 607 if ss then
flickerstreak@109 608 GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state))
flickerstreak@109 609 else
flickerstreak@109 610 GameTooltip:AddLine(bar:GetName())
flickerstreak@109 611 end
flickerstreak@109 612 GameTooltip:AddDoubleLine(format("|cffcccccc%s|r %s",L["Drag"],L["to add/remove buttons:"]), format("%d x %d",r,c))
flickerstreak@109 613 if ss then
flickerstreak@109 614 GameTooltip:AddLine(L["State Scale Override"])
flickerstreak@109 615 GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to change scale:"]), format("%d%%", bar:GetStateProperty(state,"scale")*100))
flickerstreak@109 616 else
flickerstreak@109 617 GameTooltip:AddDoubleLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to resize buttons:"]), tostring(floor(size)))
flickerstreak@109 618 GameTooltip:AddDoubleLine(format("|cff0033cc%s|r %s",L["Hold Alt"], L["to change spacing:"]), tostring(floor(s)))
flickerstreak@109 619 end
flickerstreak@109 620 GameTooltip:Show()
flickerstreak@109 621 end
flickerstreak@109 622 )
flickerstreak@109 623 corner:SetScript("OnLeave",
flickerstreak@109 624 function()
flickerstreak@109 625 GameTooltip:Hide()
flickerstreak@109 626 f:SetScript("OnUpdate",nil)
flickerstreak@109 627 end
flickerstreak@109 628 )
flickerstreak@109 629 end
flickerstreak@109 630
flickerstreak@109 631 overlay:RegisterForDrag("LeftButton")
flickerstreak@109 632 overlay:RegisterForClicks("RightButtonUp")
flickerstreak@109 633
flickerstreak@109 634 overlay:SetScript("OnDragStart",
flickerstreak@109 635 function()
flickerstreak@109 636 f:StartMoving()
flickerstreak@109 637 f.isMoving = true
flickerstreak@109 638 local w,h = bar:GetButtonSize()
flickerstreak@109 639 f:ClearAllPoints()
flickerstreak@109 640 UpdateAnchorDecoration()
flickerstreak@109 641 f:SetScript("OnUpdate", function()
flickerstreak@109 642 if IsShiftKeyDown() then
flickerstreak@109 643 local f, p = DisplaySnapIndicator(f,w,h)
flickerstreak@109 644 else
flickerstreak@109 645 HideSnapIndicator()
flickerstreak@109 646 end
flickerstreak@109 647 end)
flickerstreak@109 648 end
flickerstreak@109 649 )
flickerstreak@109 650
flickerstreak@109 651 local function UpdateDragTooltip()
flickerstreak@109 652 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
flickerstreak@109 653 local ss = GetStateScale(bar)
flickerstreak@109 654 local state = bar:GetState()
flickerstreak@109 655 if ss then
flickerstreak@109 656 GameTooltip:AddLine(format("%s (%s: %s)", bar:GetName(), L["State"], state))
flickerstreak@109 657 else
flickerstreak@109 658 GameTooltip:AddLine(bar:GetName())
flickerstreak@109 659 end
flickerstreak@109 660 GameTooltip:AddLine(format("|cffcccccc%s|r %s",L["Drag"],L["to move"]))
flickerstreak@109 661 GameTooltip:AddLine(format("|cff00ff00%s|r %s",L["Hold Shift"],L["to anchor to nearby frames"]))
flickerstreak@109 662 GameTooltip:AddLine(format("|cff00cccc%s|r %s",L["Right-click"],L["for options..."]))
flickerstreak@109 663 local point, frame, relpoint, x, y = bar:GetFrame():GetPoint(1)
flickerstreak@109 664 if point then
flickerstreak@109 665 local ofsx, ofsy = insidePointOffsetFuncs[point](x,y)
flickerstreak@109 666 if (frame and frame ~= UIParent) or (ofsx == 0 and ofsy == 0) then
flickerstreak@109 667 frame = frame or UIParent
flickerstreak@109 668 GameTooltip:AddLine(format("%s <%s>",L["Currently anchored to"],frame:GetName()))
flickerstreak@109 669 end
flickerstreak@109 670 end
flickerstreak@109 671 GameTooltip:Show()
flickerstreak@109 672 end
flickerstreak@109 673
flickerstreak@109 674 overlay:SetScript("OnDragStop",
flickerstreak@109 675 function()
flickerstreak@109 676 f:StopMovingOrSizing()
flickerstreak@109 677 f.isMoving = false
flickerstreak@109 678 f:SetScript("OnUpdate",nil)
flickerstreak@109 679
flickerstreak@109 680 if IsShiftKeyDown() then
flickerstreak@109 681 local w, h = bar:GetButtonSize()
flickerstreak@109 682 local a, p, rp, x, y = GetClosestPointSnapped(f,w,h)
flickerstreak@109 683 if a then
flickerstreak@109 684 f:ClearAllPoints()
flickerstreak@109 685 f:SetPoint(p,a,rp,x,y)
flickerstreak@109 686 end
flickerstreak@109 687 HideSnapIndicator()
flickerstreak@109 688 end
flickerstreak@109 689
flickerstreak@109 690 StoreExtents(bar)
flickerstreak@109 691 ReAction:RefreshOptions()
flickerstreak@109 692 UpdateDragTooltip()
flickerstreak@109 693 UpdateAnchorDecoration()
flickerstreak@109 694 end
flickerstreak@109 695 )
flickerstreak@109 696
flickerstreak@109 697 overlay:SetScript("OnEnter",
flickerstreak@109 698 function()
flickerstreak@109 699 UpdateDragTooltip()
flickerstreak@109 700 end
flickerstreak@109 701 )
flickerstreak@109 702
flickerstreak@109 703 overlay:SetScript("OnLeave", HideGameTooltip)
flickerstreak@109 704
flickerstreak@109 705 overlay:SetScript("OnClick",
flickerstreak@109 706 function()
flickerstreak@109 707 ReAction:ShowEditor(bar)
flickerstreak@109 708 end
flickerstreak@109 709 )
flickerstreak@109 710
flickerstreak@109 711 function overlay:LIBKEYBOUND_ENABLED(evt)
flickerstreak@109 712 self:SetFrameLevel(1)
flickerstreak@109 713 end
flickerstreak@109 714
flickerstreak@109 715 function overlay:LIBKEYBOUND_DISABLED(evt)
flickerstreak@109 716 self:SetFrameLevel(3)
flickerstreak@109 717 end
flickerstreak@109 718
flickerstreak@109 719 function overlay:RefreshControls()
flickerstreak@109 720 UpdateAnchorDecoration()
flickerstreak@109 721 end
flickerstreak@109 722
flickerstreak@109 723 overlay:SetScript("OnShow", overlay.RefreshControls)
flickerstreak@109 724
flickerstreak@109 725 KB.RegisterCallback(overlay,"LIBKEYBOUND_ENABLED")
flickerstreak@109 726 KB.RegisterCallback(overlay,"LIBKEYBOUND_DISABLED")
flickerstreak@109 727
flickerstreak@109 728 if ReAction:GetKeybindMode() then
flickerstreak@109 729 overlay:SetFrameLevel(1)
flickerstreak@109 730 end
flickerstreak@109 731
flickerstreak@109 732 bar:SetLabel(bar:GetName())
flickerstreak@109 733 UpdateLabelString(bar)
flickerstreak@109 734 UpdateAnchorDecoration()
flickerstreak@109 735
flickerstreak@109 736 return overlay
flickerstreak@109 737 end
flickerstreak@109 738
flickerstreak@109 739
flickerstreak@109 740 -- export methods to the Bar prototype
flickerstreak@109 741
flickerstreak@109 742 function Bar:ShowControls(show)
flickerstreak@109 743 local f = self.controlFrame
flickerstreak@109 744 if show then
flickerstreak@109 745 if not f then
flickerstreak@109 746 f = CreateControls(self)
flickerstreak@109 747 self.controlFrame = f
flickerstreak@109 748 end
flickerstreak@109 749 f:Show()
flickerstreak@109 750 elseif f then
flickerstreak@109 751 f:Hide()
flickerstreak@109 752 end
flickerstreak@109 753 end
flickerstreak@109 754
flickerstreak@109 755 function Bar:RefreshControls()
flickerstreak@109 756 if self.controlFrame and self.controlFrame:IsShown() then
flickerstreak@109 757 self.controlFrame:RefreshControls()
flickerstreak@109 758 end
flickerstreak@109 759 end
flickerstreak@109 760
flickerstreak@109 761 function Bar:SetLabel(name)
flickerstreak@109 762 self.labelName = name
flickerstreak@109 763 UpdateLabelString(self)
flickerstreak@109 764 end
flickerstreak@109 765
flickerstreak@109 766 function Bar:SetLabelSubtext(text)
flickerstreak@109 767 self.labelSubtext = text
flickerstreak@109 768 UpdateLabelString(self)
flickerstreak@109 769 end