annotate Overlay.lua @ 78:502cdb5666e2

Removed OnAttributeChanged handler for action buttons (which was already installed by the Blizzard frame)
author Flick <flickerstreak@gmail.com>
date Tue, 24 Jun 2008 00:10:33 +0000
parents da8ba8783924
children 42ec2938d65a
rev   line source
flickerstreak@73 1 local ReAction = ReAction
flickerstreak@73 2 local L = ReAction.L
flickerstreak@73 3 local CreateFrame = CreateFrame
flickerstreak@73 4 local InCombatLockdown = InCombatLockdown
flickerstreak@73 5 local floor = math.floor
flickerstreak@73 6 local min = math.min
flickerstreak@73 7 local format = string.format
flickerstreak@73 8 local GameTooltip = GameTooltip
flickerstreak@73 9
flickerstreak@77 10 ReAction:UpdateRevision("$Revision: 103 $")
flickerstreak@77 11
flickerstreak@73 12 -- Looking for a lightweight AceConfig3-struct-compatible
flickerstreak@73 13 -- replacement for Dewdrop (e.g. forthcoming AceConfigDropdown-3.0?).
flickerstreak@73 14 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's
flickerstreak@73 15 -- a bit tricky to convert from AceConfig3-struct
flickerstreak@73 16 local Dewdrop = AceLibrary("Dewdrop-2.0")
flickerstreak@73 17
flickerstreak@73 18 local function OpenMenu (frame, opts)
flickerstreak@73 19 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true)
flickerstreak@73 20 end
flickerstreak@73 21
flickerstreak@73 22 local function CloseMenu(frame)
flickerstreak@73 23 if Dewdrop:GetOpenedParent() == frame then
flickerstreak@73 24 Dewdrop:Close()
flickerstreak@73 25 end
flickerstreak@73 26 end
flickerstreak@73 27
flickerstreak@73 28 local function ShowMenu(bar)
flickerstreak@73 29 if not bar.menuOpts then
flickerstreak@73 30 bar.menuOpts = {
flickerstreak@73 31 type = "group",
flickerstreak@73 32 args = {
flickerstreak@73 33 openConfig = {
flickerstreak@73 34 type = "execute",
flickerstreak@73 35 name = L["Settings..."],
flickerstreak@73 36 desc = L["Open the editor for this bar"],
flickerstreak@73 37 func = function() CloseMenu(bar.controlFrame); ReAction:ShowEditor(bar) end,
flickerstreak@73 38 disabled = InCombatLockdown,
flickerstreak@73 39 order = 1
flickerstreak@73 40 },
flickerstreak@73 41 delete = {
flickerstreak@73 42 type = "execute",
flickerstreak@73 43 name = L["Delete Bar"],
flickerstreak@73 44 desc = L["Remove the bar from the current profile"],
flickerstreak@73 45 confirm = L["Are you sure you want to remove this bar?"],
flickerstreak@73 46 func = function() ReAction:EraseBar(bar) end,
flickerstreak@73 47 order = 2
flickerstreak@73 48 },
flickerstreak@73 49 }
flickerstreak@73 50 }
flickerstreak@73 51 end
flickerstreak@73 52 OpenMenu(bar.controlFrame, bar.menuOpts)
flickerstreak@73 53 end
flickerstreak@73 54
flickerstreak@73 55
flickerstreak@73 56 --
flickerstreak@73 57 -- Bar config overlay
flickerstreak@73 58 --
flickerstreak@73 59 -- localize some of these for small OnUpdate performance boost
flickerstreak@77 60 local Bar = ReAction.Bar
flickerstreak@73 61 local GetSize = Bar.GetSize
flickerstreak@73 62 local GetButtonSize = Bar.GetButtonSize
flickerstreak@73 63 local GetButtonGrid = Bar.GetButtonGrid
flickerstreak@73 64 local SetSize = Bar.SetSize
flickerstreak@73 65 local SetButtonSize = Bar.SetButtonSize
flickerstreak@73 66 local SetButtonGrid = Bar.SetButtonGrid
flickerstreak@73 67 local ApplyAnchor = Bar.ApplyAnchor
flickerstreak@73 68
flickerstreak@73 69 local function StoreExtents(bar)
flickerstreak@75 70 local f = bar:GetFrame()
flickerstreak@73 71 local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
flickerstreak@73 72 relativeTo = relativeTo or f:GetParent()
flickerstreak@73 73 local anchorTo
flickerstreak@73 74 for name, b in ReAction:IterateBars() do
flickerstreak@73 75 if b and b:GetFrame() == relativeTo then
flickerstreak@73 76 anchorTo = name
flickerstreak@73 77 break
flickerstreak@73 78 end
flickerstreak@73 79 end
flickerstreak@73 80 anchorTo = anchorTo or relativeTo:GetName()
flickerstreak@73 81 local c = bar.config
flickerstreak@73 82 c.anchor = point
flickerstreak@73 83 c.anchorTo = anchorTo
flickerstreak@73 84 c.relativePoint = relativePoint
flickerstreak@73 85 c.x = x
flickerstreak@73 86 c.y = y
flickerstreak@73 87 c.width, c.height = f:GetWidth(), f:GetHeight()
flickerstreak@73 88 end
flickerstreak@73 89
flickerstreak@73 90 local function StoreSize(bar)
flickerstreak@75 91 local f = bar:GetFrame()
flickerstreak@73 92 local c = bar.config
flickerstreak@73 93 c.width, c.height = f:GetWidth(), f:GetHeight()
flickerstreak@73 94 end
flickerstreak@73 95
flickerstreak@73 96 local function RecomputeButtonSize(bar)
flickerstreak@73 97 local w, h = GetSize(bar)
flickerstreak@73 98 local bw, bh = GetButtonSize(bar)
flickerstreak@73 99 local r, c, s = GetButtonGrid(bar)
flickerstreak@73 100
flickerstreak@73 101 local scaleW = (floor(w/c) - s) / bw
flickerstreak@73 102 local scaleH = (floor(h/r) - s) / bh
flickerstreak@73 103 local scale = min(scaleW, scaleH)
flickerstreak@73 104
flickerstreak@73 105 SetButtonSize(bar, scale * bw, scale * bh, s)
flickerstreak@73 106 end
flickerstreak@73 107
flickerstreak@73 108 local function RecomputeButtonSpacing(bar)
flickerstreak@73 109 local w, h = GetSize(bar)
flickerstreak@73 110 local bw, bh = GetButtonSize(bar)
flickerstreak@73 111 local r, c, s = GetButtonGrid(bar)
flickerstreak@73 112
flickerstreak@73 113 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
flickerstreak@73 114 end
flickerstreak@73 115
flickerstreak@73 116 local function RecomputeGrid(bar)
flickerstreak@73 117 local w, h = GetSize(bar)
flickerstreak@73 118 local bw, bh = GetButtonSize(bar)
flickerstreak@73 119 local r, c, s = GetButtonGrid(bar)
flickerstreak@73 120
flickerstreak@73 121 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
flickerstreak@73 122 end
flickerstreak@73 123
flickerstreak@73 124 local function ClampToButtons(bar)
flickerstreak@73 125 local bw, bh = GetButtonSize(bar)
flickerstreak@73 126 local r, c, s = GetButtonGrid(bar)
flickerstreak@73 127 SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1)
flickerstreak@73 128 end
flickerstreak@73 129
flickerstreak@73 130 local function HideGameTooltip()
flickerstreak@73 131 GameTooltip:Hide()
flickerstreak@73 132 end
flickerstreak@73 133
flickerstreak@73 134 local anchorInside = { inside = true }
flickerstreak@73 135 local anchorOutside = { outside = true }
flickerstreak@73 136 local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" }
flickerstreak@73 137 local oppositeEdges = {
flickerstreak@73 138 TOP = "BOTTOM",
flickerstreak@73 139 BOTTOM = "TOP",
flickerstreak@73 140 LEFT = "RIGHT",
flickerstreak@73 141 RIGHT = "LEFT"
flickerstreak@73 142 }
flickerstreak@73 143 local pointsOnEdge = {
flickerstreak@73 144 BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", },
flickerstreak@73 145 TOP = { "TOP", "TOPLEFT", "TOPRIGHT", },
flickerstreak@73 146 RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", },
flickerstreak@73 147 LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", },
flickerstreak@73 148 }
flickerstreak@73 149 local edgeSelector = {
flickerstreak@73 150 BOTTOM = 1, -- select x of x,y
flickerstreak@73 151 TOP = 1, -- select x of x,y
flickerstreak@73 152 LEFT = 2, -- select y of x,y
flickerstreak@73 153 RIGHT = 2, -- select y of x,y
flickerstreak@73 154 }
flickerstreak@73 155 local snapPoints = {
flickerstreak@73 156 [anchorOutside] = {
flickerstreak@73 157 BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"},
flickerstreak@73 158 BOTTOM = {"TOP"},
flickerstreak@73 159 BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"},
flickerstreak@73 160 RIGHT = {"LEFT"},
flickerstreak@73 161 TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"},
flickerstreak@73 162 TOP = {"BOTTOM"},
flickerstreak@73 163 TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"},
flickerstreak@73 164 LEFT = {"RIGHT"},
flickerstreak@73 165 CENTER = {"CENTER"}
flickerstreak@73 166 },
flickerstreak@73 167 [anchorInside] = {
flickerstreak@73 168 BOTTOMLEFT = {"BOTTOMLEFT"},
flickerstreak@73 169 BOTTOM = {"BOTTOM"},
flickerstreak@73 170 BOTTOMRIGHT = {"BOTTOMRIGHT"},
flickerstreak@73 171 RIGHT = {"RIGHT"},
flickerstreak@73 172 TOPRIGHT = {"TOPRIGHT"},
flickerstreak@73 173 TOP = {"TOP"},
flickerstreak@73 174 TOPLEFT = {"TOPLEFT"},
flickerstreak@73 175 LEFT = {"LEFT"},
flickerstreak@73 176 CENTER = {"CENTER"}
flickerstreak@73 177 }
flickerstreak@73 178 }
flickerstreak@73 179 local insidePointOffsetFuncs = {
flickerstreak@73 180 BOTTOMLEFT = function(x, y) return x, y end,
flickerstreak@73 181 BOTTOM = function(x, y) return 0, y end,
flickerstreak@73 182 BOTTOMRIGHT = function(x, y) return -x, y end,
flickerstreak@73 183 RIGHT = function(x, y) return -x, 0 end,
flickerstreak@73 184 TOPRIGHT = function(x, y) return -x, -y end,
flickerstreak@73 185 TOP = function(x, y) return 0, -y end,
flickerstreak@73 186 TOPLEFT = function(x, y) return x, -y end,
flickerstreak@73 187 LEFT = function(x, y) return x, 0 end,
flickerstreak@73 188 CENTER = function(x, y) return 0, 0 end,
flickerstreak@73 189 }
flickerstreak@73 190 local pointCoordFuncs = {
flickerstreak@73 191 BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end,
flickerstreak@73 192 BOTTOM = function(f) return nil, f:GetBottom() end,
flickerstreak@73 193 BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end,
flickerstreak@73 194 RIGHT = function(f) return f:GetRight(), nil end,
flickerstreak@73 195 TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end,
flickerstreak@73 196 TOP = function(f) return nil, f:GetTop() end,
flickerstreak@73 197 TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end,
flickerstreak@73 198 LEFT = function(f) return f:GetLeft(), nil end,
flickerstreak@73 199 CENTER = function(f) return f:GetCenter() end,
flickerstreak@73 200 }
flickerstreak@73 201 local edgeBoundsFuncs = {
flickerstreak@73 202 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end,
flickerstreak@73 203 LEFT = function(f) return f:GetBottom(), f:GetTop() end
flickerstreak@73 204 }
flickerstreak@73 205 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM
flickerstreak@73 206 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
flickerstreak@73 207
flickerstreak@73 208
flickerstreak@73 209 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
flickerstreak@73 210 local function GetPointCoords( f, p )
flickerstreak@73 211 local x, y = pointCoordFuncs[p](f)
flickerstreak@73 212 if not(x and y) then
flickerstreak@73 213 local cx, cy = f:GetCenter()
flickerstreak@73 214 x = x or cx
flickerstreak@73 215 y = y or cy
flickerstreak@73 216 end
flickerstreak@73 217 return x, y
flickerstreak@73 218 end
flickerstreak@73 219
flickerstreak@73 220
flickerstreak@73 221 -- Returns true if frame 'f1' can be anchored to frame 'f2'
flickerstreak@73 222 local function CheckAnchorable( f1, f2 )
flickerstreak@73 223 -- can't anchor a frame to itself or to nil
flickerstreak@73 224 if f1 == f2 or f2 == nil then
flickerstreak@73 225 return false
flickerstreak@73 226 end
flickerstreak@73 227
flickerstreak@73 228 -- can always anchor to UIParent
flickerstreak@73 229 if f2 == UIParent then
flickerstreak@73 230 return true
flickerstreak@73 231 end
flickerstreak@73 232
flickerstreak@73 233 -- also can't do circular anchoring of frames
flickerstreak@73 234 -- walk the anchor chain, which generally shouldn't be that expensive
flickerstreak@73 235 -- (who nests draggables that deep anyway?)
flickerstreak@73 236 for i = 1, f2:GetNumPoints() do
flickerstreak@73 237 local _, f = f2:GetPoint(i)
flickerstreak@73 238 if not f then f = f2:GetParent() end
flickerstreak@73 239 return CheckAnchorable(f1,f)
flickerstreak@73 240 end
flickerstreak@73 241
flickerstreak@73 242 return true
flickerstreak@73 243 end
flickerstreak@73 244
flickerstreak@73 245 -- Returns true if frames f1 and f2 specified edges overlap
flickerstreak@73 246 local function CheckEdgeOverlap( f1, f2, e )
flickerstreak@73 247 local l1, u1 = edgeBoundsFuncs[e](f1)
flickerstreak@73 248 local l2, u2 = edgeBoundsFuncs[e](f2)
flickerstreak@73 249 return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2
flickerstreak@73 250 end
flickerstreak@73 251
flickerstreak@73 252 -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2
flickerstreak@73 253 local function CheckPointEdgeOverlap( f1, p1, f2, e2 )
flickerstreak@73 254 local l, u = edgeBoundsFuncs[e2](f2)
flickerstreak@73 255 local x, y = GetPointCoords(f1,p1)
flickerstreak@73 256 x = select(edgeSelector[e2], x, y)
flickerstreak@73 257 return l <= x and x <= u
flickerstreak@73 258 end
flickerstreak@73 259
flickerstreak@73 260 -- Returns the distance between corresponding edges. It is
flickerstreak@73 261 -- assumed that the passed in edges e1 and e2 are the same or opposites
flickerstreak@73 262 local function GetEdgeDistance( f1, f2, e1, e2 )
flickerstreak@73 263 local x1, y1 = pointCoordFuncs[e1](f1)
flickerstreak@73 264 local x2, y2 = pointCoordFuncs[e2](f2)
flickerstreak@73 265 return math.abs((x1 or y1) - (x2 or y2))
flickerstreak@73 266 end
flickerstreak@73 267
flickerstreak@73 268 local globalSnapTargets = { [UIParent] = anchorInside }
flickerstreak@73 269
flickerstreak@73 270 local function GetClosestFrameEdge(f1,f2,a)
flickerstreak@73 271 local dist, edge, opp
flickerstreak@73 272 if f2:IsVisible() and CheckAnchorable(f1,f2) then
flickerstreak@73 273 for _, e in pairs(edges) do
flickerstreak@73 274 local o = a.inside and e or oppositeEdges[e]
flickerstreak@73 275 if CheckEdgeOverlap(f1,f2,e) then
flickerstreak@73 276 local d = GetEdgeDistance(f1, f2, e, o)
flickerstreak@73 277 if not dist or (d < dist) then
flickerstreak@73 278 dist, edge, opp = d, e, o
flickerstreak@73 279 end
flickerstreak@73 280 end
flickerstreak@73 281 end
flickerstreak@73 282 end
flickerstreak@73 283 return dist, edge, opp
flickerstreak@73 284 end
flickerstreak@73 285
flickerstreak@73 286 local function GetClosestVisibleEdge( f )
flickerstreak@73 287 local r, o, e1, e2
flickerstreak@73 288 local a = anchorOutside
flickerstreak@73 289 for _, b in ReAction:IterateBars() do
flickerstreak@73 290 local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a)
flickerstreak@73 291 if d and (not r or d < r) then
flickerstreak@73 292 r, o, e1, e2 = d, b:GetFrame(), e, opp
flickerstreak@73 293 end
flickerstreak@73 294 end
flickerstreak@73 295 for f2, a2 in pairs(globalSnapTargets) do
flickerstreak@73 296 local d, e, opp = GetClosestFrameEdge(f,f2,a2)
flickerstreak@73 297 if d and (not r or d < r) then
flickerstreak@73 298 r, o, e1, e2, a = d, f2, e, opp, a2
flickerstreak@73 299 end
flickerstreak@73 300 end
flickerstreak@73 301 return o, e1, e2, a
flickerstreak@73 302 end
flickerstreak@73 303
flickerstreak@73 304 local function GetClosestVisiblePoint(f1)
flickerstreak@73 305 local f2, e1, e2, a = GetClosestVisibleEdge(f1)
flickerstreak@73 306 if f2 then
flickerstreak@73 307 local rsq, p, rp, x, y
flickerstreak@73 308 -- iterate pointsOnEdge in order and use < to prefer edge centers to corners
flickerstreak@73 309 for _, p1 in ipairs(pointsOnEdge[e1]) do
flickerstreak@73 310 if CheckPointEdgeOverlap(f1,p1,f2,e2) then
flickerstreak@73 311 for _, p2 in pairs(snapPoints[a][p1]) do
flickerstreak@73 312 local x1, y1 = GetPointCoords(f1,p1)
flickerstreak@73 313 local x2, y2 = GetPointCoords(f2,p2)
flickerstreak@73 314 local dx = x1 - x2
flickerstreak@73 315 local dy = y1 - y2
flickerstreak@73 316 local rsq2 = dx*dx + dy*dy
flickerstreak@73 317 if not rsq or rsq2 < rsq then
flickerstreak@73 318 rsq, p, rp, x, y = rsq2, p1, p2, dx, dy
flickerstreak@73 319 end
flickerstreak@73 320 end
flickerstreak@73 321 end
flickerstreak@73 322 end
flickerstreak@73 323 return f2, p, rp, x, y
flickerstreak@73 324 end
flickerstreak@73 325 end
flickerstreak@73 326
flickerstreak@73 327 local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff)
flickerstreak@73 328 local o, p, rp, x, y = GetClosestVisiblePoint(f1)
flickerstreak@73 329 local s = false
flickerstreak@73 330
flickerstreak@73 331 local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0)
flickerstreak@73 332 local xx, yy = pointCoordFuncs[p](f1)
flickerstreak@73 333 if xx and yy then
flickerstreak@73 334 if math.abs(x) <= rx then
flickerstreak@73 335 x = sx
flickerstreak@73 336 s = true
flickerstreak@73 337 end
flickerstreak@73 338 if math.abs(y) <= ry then
flickerstreak@73 339 y = sy
flickerstreak@73 340 s = true
flickerstreak@73 341 end
flickerstreak@73 342 elseif xx then
flickerstreak@73 343 if math.abs(x) <= rx then
flickerstreak@73 344 x = sx
flickerstreak@73 345 s = true
flickerstreak@73 346 if math.abs(y) <= ry then
flickerstreak@73 347 y = sy
flickerstreak@73 348 end
flickerstreak@73 349 end
flickerstreak@73 350 elseif yy then
flickerstreak@73 351 if math.abs(y) <= ry then
flickerstreak@73 352 y = sy
flickerstreak@73 353 s = true
flickerstreak@73 354 if math.abs(x) <= rx then
flickerstreak@73 355 x = sx
flickerstreak@73 356 end
flickerstreak@73 357 end
flickerstreak@73 358 end
flickerstreak@73 359
flickerstreak@73 360 if x == -0 then x = 0 end
flickerstreak@73 361 if y == -0 then y = 0 end
flickerstreak@73 362
flickerstreak@73 363 if s then
flickerstreak@73 364 return o, p, rp, math.floor(x), math.floor(y)
flickerstreak@73 365 end
flickerstreak@73 366 end
flickerstreak@73 367
flickerstreak@73 368 local function CreateSnapIndicator()
flickerstreak@73 369 local si = CreateFrame("Frame",nil,UIParent)
flickerstreak@73 370 si:SetFrameStrata("HIGH")
flickerstreak@73 371 si:SetHeight(8)
flickerstreak@73 372 si:SetWidth(8)
flickerstreak@73 373 local tex = si:CreateTexture()
flickerstreak@73 374 tex:SetAllPoints()
flickerstreak@73 375 tex:SetTexture(1.0, 0.82, 0, 0.8)
flickerstreak@73 376 tex:SetBlendMode("ADD")
flickerstreak@73 377 tex:SetDrawLayer("OVERLAY")
flickerstreak@73 378 return si
flickerstreak@73 379 end
flickerstreak@73 380
flickerstreak@73 381 local si1 = CreateSnapIndicator()
flickerstreak@73 382 local si2 = CreateSnapIndicator()
flickerstreak@73 383
flickerstreak@73 384 local function DisplaySnapIndicator( f, rx, ry, xOff, yOff )
flickerstreak@73 385 local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff)
flickerstreak@73 386 if o then
flickerstreak@73 387 si1:ClearAllPoints()
flickerstreak@73 388 si2:ClearAllPoints()
flickerstreak@73 389 si1:SetPoint("CENTER", f, p, 0, 0)
flickerstreak@73 390 local xx, yy = pointCoordFuncs[rp](o)
flickerstreak@73 391 x = math.abs(x) <=rx and xx and 0 or x
flickerstreak@73 392 y = math.abs(y) <=ry and yy and 0 or y
flickerstreak@73 393 si2:SetPoint("CENTER", o, rp, x, y)
flickerstreak@73 394 si1:Show()
flickerstreak@73 395 si2:Show()
flickerstreak@73 396 else
flickerstreak@73 397 if si1:IsVisible() then
flickerstreak@73 398 si1:Hide()
flickerstreak@73 399 si2:Hide()
flickerstreak@73 400 end
flickerstreak@73 401 end
flickerstreak@73 402 end
flickerstreak@73 403
flickerstreak@73 404 local function HideSnapIndicator()
flickerstreak@73 405 if si1:IsVisible() then
flickerstreak@73 406 si1:Hide()
flickerstreak@73 407 si2:Hide()
flickerstreak@73 408 end
flickerstreak@73 409 end
flickerstreak@73 410
flickerstreak@73 411 local function CreateControls(bar)
flickerstreak@75 412 local f = bar:GetFrame()
flickerstreak@73 413
flickerstreak@73 414 f:SetMovable(true)
flickerstreak@73 415 f:SetResizable(true)
flickerstreak@73 416 f:SetClampedToScreen(true)
flickerstreak@73 417
flickerstreak@77 418 local control = CreateFrame("Button", nil, f)
flickerstreak@73 419 control:EnableMouse(true)
flickerstreak@73 420 control:SetToplevel(true)
flickerstreak@73 421 control:SetPoint("TOPLEFT", -4, 4)
flickerstreak@73 422 control:SetPoint("BOTTOMRIGHT", 4, -4)
flickerstreak@73 423 control:SetBackdrop({
flickerstreak@73 424 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
flickerstreak@73 425 tile = true,
flickerstreak@73 426 tileSize = 16,
flickerstreak@73 427 edgeSize = 16,
flickerstreak@73 428 insets = { left = 0, right = 0, top = 0, bottom = 0 },
flickerstreak@73 429 })
flickerstreak@77 430 control:SetClampedToScreen(true)
flickerstreak@73 431
flickerstreak@73 432 -- textures
flickerstreak@73 433 local bgTex = control:CreateTexture(nil,"BACKGROUND")
flickerstreak@73 434 bgTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@73 435 bgTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@73 436 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@73 437 local hTex = control:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@73 438 hTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@73 439 hTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@73 440 hTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@73 441 hTex:SetBlendMode("ADD")
flickerstreak@73 442
flickerstreak@73 443 -- label
flickerstreak@73 444 local label = control:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
flickerstreak@73 445 label:SetAllPoints()
flickerstreak@73 446 label:SetJustifyH("CENTER")
flickerstreak@73 447 label:SetShadowColor(0,0,0,1)
flickerstreak@73 448 label:SetShadowOffset(2,-2)
flickerstreak@73 449 label:SetTextColor(1,1,1,1)
flickerstreak@73 450 label:SetText(bar:GetName())
flickerstreak@73 451 label:Show()
flickerstreak@73 452 bar.controlLabelString = label -- so that bar:SetName() can update it
flickerstreak@73 453
flickerstreak@73 454 local function StopResize()
flickerstreak@73 455 f:StopMovingOrSizing()
flickerstreak@73 456 f.isMoving = false
flickerstreak@73 457 f:SetScript("OnUpdate",nil)
flickerstreak@73 458 StoreSize(bar)
flickerstreak@73 459 ClampToButtons(bar)
flickerstreak@73 460 ApplyAnchor(bar)
flickerstreak@73 461 ReAction:RefreshOptions()
flickerstreak@73 462 end
flickerstreak@73 463
flickerstreak@73 464 -- edge drag handles
flickerstreak@73 465 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
flickerstreak@73 466 local edge = CreateFrame("Frame",nil,control)
flickerstreak@73 467 edge:EnableMouse(true)
flickerstreak@73 468 edge:SetWidth(8)
flickerstreak@73 469 edge:SetHeight(8)
flickerstreak@73 470 if point == "TOP" or point == "BOTTOM" then
flickerstreak@73 471 edge:SetPoint(point.."LEFT")
flickerstreak@73 472 edge:SetPoint(point.."RIGHT")
flickerstreak@73 473 else
flickerstreak@73 474 edge:SetPoint("TOP"..point)
flickerstreak@73 475 edge:SetPoint("BOTTOM"..point)
flickerstreak@73 476 end
flickerstreak@73 477 local tex = edge:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@73 478 tex:SetTexture(1.0,0.82,0,0.7)
flickerstreak@73 479 tex:SetBlendMode("ADD")
flickerstreak@73 480 tex:SetAllPoints()
flickerstreak@73 481 edge:RegisterForDrag("LeftButton")
flickerstreak@73 482 edge:SetScript("OnMouseDown",
flickerstreak@73 483 function()
flickerstreak@73 484 local bw, bh = GetButtonSize(bar)
flickerstreak@73 485 local r, c, s = GetButtonGrid(bar)
flickerstreak@73 486 f:SetMinResize( bw+s+1, bh+s+1 )
flickerstreak@73 487 f:StartSizing(point)
flickerstreak@73 488 f:SetScript("OnUpdate",
flickerstreak@73 489 function()
flickerstreak@73 490 RecomputeGrid(bar)
flickerstreak@73 491 end
flickerstreak@73 492 )
flickerstreak@73 493 end
flickerstreak@73 494 )
flickerstreak@73 495 edge:SetScript("OnMouseUp", StopResize)
flickerstreak@73 496 edge:SetScript("OnEnter",
flickerstreak@73 497 function()
flickerstreak@73 498 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@73 499 GameTooltip:AddLine(L["Drag to add/remove buttons"])
flickerstreak@73 500 GameTooltip:Show()
flickerstreak@73 501 end
flickerstreak@73 502 )
flickerstreak@73 503 edge:SetScript("OnLeave", HideGameTooltip)
flickerstreak@73 504 edge:Show()
flickerstreak@73 505 end
flickerstreak@73 506
flickerstreak@77 507 -- corner drag handles, nested in an anonymous frame so that they are on top
flickerstreak@77 508 local foo = CreateFrame("Frame",nil,control)
flickerstreak@77 509 foo:SetAllPoints(true)
flickerstreak@73 510 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
flickerstreak@77 511 local corner = CreateFrame("Frame",nil,foo)
flickerstreak@73 512 corner:EnableMouse(true)
flickerstreak@73 513 corner:SetWidth(12)
flickerstreak@73 514 corner:SetHeight(12)
flickerstreak@73 515 corner:SetPoint(point)
flickerstreak@73 516 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@73 517 tex:SetTexture(1.0,0.82,0,0.7)
flickerstreak@73 518 tex:SetBlendMode("ADD")
flickerstreak@73 519 tex:SetAllPoints()
flickerstreak@73 520 corner:RegisterForDrag("LeftButton","RightButton")
flickerstreak@73 521 local function updateTooltip()
flickerstreak@73 522 local size, size2 = bar:GetButtonSize()
flickerstreak@73 523 local rows, cols, spacing = bar:GetButtonGrid()
flickerstreak@73 524 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
flickerstreak@73 525 GameTooltipTextRight4:SetText(size)
flickerstreak@73 526 GameTooltipTextRight5:SetText(tostring(spacing))
flickerstreak@73 527 end
flickerstreak@73 528 corner:SetScript("OnMouseDown",
flickerstreak@73 529 function(_,btn)
flickerstreak@73 530 local bw, bh = GetButtonSize(bar)
flickerstreak@73 531 local r, c, s = GetButtonGrid(bar)
flickerstreak@73 532 if btn == "LeftButton" then -- button resize
flickerstreak@73 533 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
flickerstreak@73 534 f:SetScript("OnUpdate",
flickerstreak@73 535 function()
flickerstreak@73 536 RecomputeButtonSize(bar)
flickerstreak@73 537 updateTooltip()
flickerstreak@73 538 end
flickerstreak@73 539 )
flickerstreak@73 540 elseif btn == "RightButton" then -- spacing resize
flickerstreak@73 541 f:SetMinResize( bw*c, bh*r )
flickerstreak@73 542 f:SetScript("OnUpdate",
flickerstreak@73 543 function()
flickerstreak@73 544 RecomputeButtonSpacing(bar)
flickerstreak@73 545 updateTooltip()
flickerstreak@73 546 end
flickerstreak@73 547 )
flickerstreak@73 548 end
flickerstreak@73 549 f:StartSizing(point)
flickerstreak@73 550 end
flickerstreak@73 551 )
flickerstreak@73 552 corner:SetScript("OnMouseUp",StopResize)
flickerstreak@73 553 corner:SetScript("OnEnter",
flickerstreak@73 554 function()
flickerstreak@73 555 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@73 556 GameTooltip:AddLine(L["Drag to resize buttons"])
flickerstreak@73 557 GameTooltip:AddLine(L["Right-click-drag"])
flickerstreak@73 558 GameTooltip:AddLine(L["to change spacing"])
flickerstreak@73 559 local size, size2 = bar:GetButtonSize()
flickerstreak@73 560 local rows, cols, spacing = bar:GetButtonGrid()
flickerstreak@73 561 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
flickerstreak@73 562 GameTooltip:AddDoubleLine(L["Size:"], size)
flickerstreak@73 563 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
flickerstreak@73 564 GameTooltip:Show()
flickerstreak@73 565 end
flickerstreak@73 566 )
flickerstreak@73 567 corner:SetScript("OnLeave",
flickerstreak@73 568 function()
flickerstreak@73 569 GameTooltip:Hide()
flickerstreak@73 570 f:SetScript("OnUpdate",nil)
flickerstreak@73 571 end
flickerstreak@73 572 )
flickerstreak@73 573
flickerstreak@73 574 end
flickerstreak@73 575
flickerstreak@73 576 control:RegisterForDrag("LeftButton")
flickerstreak@73 577 control:RegisterForClicks("RightButtonUp")
flickerstreak@73 578
flickerstreak@73 579 control:SetScript("OnDragStart",
flickerstreak@73 580 function()
flickerstreak@73 581 f:StartMoving()
flickerstreak@73 582 f.isMoving = true
flickerstreak@73 583 local w,h = bar:GetButtonSize()
flickerstreak@73 584 f:ClearAllPoints()
flickerstreak@73 585 f:SetScript("OnUpdate", function()
flickerstreak@73 586 if IsShiftKeyDown() then
flickerstreak@73 587 DisplaySnapIndicator(f,w,h)
flickerstreak@73 588 else
flickerstreak@73 589 HideSnapIndicator()
flickerstreak@73 590 end
flickerstreak@73 591 end)
flickerstreak@73 592 end
flickerstreak@73 593 )
flickerstreak@73 594
flickerstreak@73 595 local function updateDragTooltip()
flickerstreak@73 596 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
flickerstreak@73 597 GameTooltip:AddLine(bar.name)
flickerstreak@73 598 GameTooltip:AddLine(L["Drag to move"])
flickerstreak@73 599 GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"]))
flickerstreak@73 600 GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"]))
flickerstreak@73 601 local _, a = bar:GetAnchor()
flickerstreak@73 602 if a and a ~= "UIParent" then
flickerstreak@73 603 GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a))
flickerstreak@73 604 end
flickerstreak@73 605 GameTooltip:Show()
flickerstreak@73 606 end
flickerstreak@73 607
flickerstreak@73 608 control:SetScript("OnDragStop",
flickerstreak@73 609 function()
flickerstreak@73 610 f:StopMovingOrSizing()
flickerstreak@73 611 f.isMoving = false
flickerstreak@73 612 f:SetScript("OnUpdate",nil)
flickerstreak@73 613
flickerstreak@73 614 if IsShiftKeyDown() then
flickerstreak@73 615 local w, h = bar:GetButtonSize()
flickerstreak@73 616 local a, p, rp, x, y = GetClosestPointSnapped(f,w,h)
flickerstreak@73 617 if a then
flickerstreak@73 618 f:ClearAllPoints()
flickerstreak@73 619 f:SetPoint(p,a,rp,x,y)
flickerstreak@73 620 end
flickerstreak@73 621 HideSnapIndicator()
flickerstreak@73 622 end
flickerstreak@73 623
flickerstreak@73 624 StoreExtents(bar)
flickerstreak@73 625 ReAction:RefreshOptions()
flickerstreak@73 626 updateDragTooltip()
flickerstreak@73 627 end
flickerstreak@73 628 )
flickerstreak@73 629
flickerstreak@73 630 control:SetScript("OnEnter",
flickerstreak@73 631 function()
flickerstreak@73 632 -- TODO: add bar type and status information to name
flickerstreak@73 633 --[[
flickerstreak@73 634 local name = bar.name
flickerstreak@73 635 for _, m in ReAction:IterateModules() do
flickerstreak@73 636 local suffix = safecall(m,"GetBarNameModifier",bar)
flickerstreak@73 637 if suffix then
flickerstreak@73 638 name = ("%s %s"):format(name,suffix)
flickerstreak@73 639 end
flickerstreak@73 640 end
flickerstreak@73 641 ]]--
flickerstreak@73 642
flickerstreak@73 643 updateDragTooltip()
flickerstreak@73 644 end
flickerstreak@73 645 )
flickerstreak@73 646
flickerstreak@73 647 control:SetScript("OnLeave", HideGameTooltip)
flickerstreak@73 648
flickerstreak@73 649 control:SetScript("OnClick",
flickerstreak@73 650 function()
flickerstreak@73 651 ShowMenu(bar)
flickerstreak@73 652 end
flickerstreak@73 653 )
flickerstreak@73 654
flickerstreak@73 655 return control
flickerstreak@73 656 end
flickerstreak@73 657
flickerstreak@73 658
flickerstreak@73 659 -- export the ShowControls method to the Bar prototype
flickerstreak@73 660
flickerstreak@73 661 function Bar:ShowControls(show)
flickerstreak@73 662 if show then
flickerstreak@73 663 if not self.controlFrame then
flickerstreak@73 664 self.controlFrame = CreateControls(self)
flickerstreak@73 665 end
flickerstreak@73 666 self.controlFrame:Show()
flickerstreak@77 667 self.controlFrame:Raise()
flickerstreak@73 668 elseif self.controlFrame then
flickerstreak@73 669 CloseMenu(self.controlFrame)
flickerstreak@73 670 self.controlFrame:Hide()
flickerstreak@73 671 end
flickerstreak@73 672 end
flickerstreak@73 673
flickerstreak@73 674