annotate Bar.lua @ 71:3d2cef5dc459

Implemented state anchoring and scaling
author Flick <flickerstreak@gmail.com>
date Wed, 04 Jun 2008 21:46:51 +0000
parents 2c12e2b1752e
children aa88aed52124
rev   line source
flickerstreak@25 1 local ReAction = ReAction
flickerstreak@25 2 local L = ReAction.L
flickerstreak@25 3 local _G = _G
flickerstreak@25 4 local CreateFrame = CreateFrame
flickerstreak@33 5 local InCombatLockdown = InCombatLockdown
flickerstreak@33 6 local floor = math.floor
flickerstreak@33 7 local min = math.min
flickerstreak@33 8 local format = string.format
flickerstreak@33 9 local GameTooltip = GameTooltip
flickerstreak@71 10 local SecureStateHeader_Refresh = SecureStateHeader_Refresh
flickerstreak@33 11
flickerstreak@33 12
flickerstreak@25 13
flickerstreak@25 14 -- update ReAction revision if this file is newer
flickerstreak@33 15 local revision = tonumber(("$Revision$"):match("%d+"))
flickerstreak@25 16 if revision > ReAction.revision then
flickerstreak@52 17 ReAction.revision = revision
flickerstreak@25 18 end
flickerstreak@25 19
flickerstreak@28 20 ------ BAR CLASS ------
flickerstreak@28 21 local Bar = { _classID = {} }
flickerstreak@25 22
flickerstreak@28 23 local function Constructor( self, name, config )
flickerstreak@25 24 self.name, self.config = name, config
flickerstreak@68 25 self.buttons = setmetatable({},{__mode="k"})
flickerstreak@25 26
flickerstreak@25 27 if type(config) ~= "table" then
flickerstreak@28 28 error("ReAction.Bar: config table required")
flickerstreak@25 29 end
flickerstreak@25 30
flickerstreak@54 31 local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent
flickerstreak@68 32 local f = CreateFrame("Frame",nil,parent,"SecureStateHeaderTemplate")
flickerstreak@25 33 f:SetFrameStrata("MEDIUM")
flickerstreak@30 34 config.width = config.width or 480
flickerstreak@30 35 config.height = config.height or 40
flickerstreak@25 36 f:SetWidth(config.width)
flickerstreak@25 37 f:SetWidth(config.height)
flickerstreak@25 38
flickerstreak@63 39 ReAction.RegisterCallback(self, "OnConfigModeChanged")
flickerstreak@63 40
flickerstreak@25 41 self.frame = f
flickerstreak@25 42 self:ApplyAnchor()
flickerstreak@25 43 f:Show()
flickerstreak@68 44 self:RefreshLayout()
flickerstreak@25 45 end
flickerstreak@25 46
flickerstreak@25 47 function Bar:Destroy()
flickerstreak@25 48 local f = self.frame
flickerstreak@25 49 f:UnregisterAllEvents()
flickerstreak@25 50 f:Hide()
flickerstreak@25 51 f:SetParent(UIParent)
flickerstreak@25 52 f:ClearAllPoints()
flickerstreak@63 53 ReAction.UnregisterAllCallbacks(self)
flickerstreak@25 54 self.labelString = nil
flickerstreak@25 55 self.controlFrame = nil
flickerstreak@25 56 self.frame = nil
flickerstreak@25 57 self.config = nil
flickerstreak@25 58 end
flickerstreak@25 59
flickerstreak@63 60 function Bar:OnConfigModeChanged(event, mode)
flickerstreak@63 61 self:ShowControls(mode)
flickerstreak@63 62 end
flickerstreak@63 63
flickerstreak@25 64 function Bar:RefreshLayout()
flickerstreak@63 65 ReAction:RefreshBar(self)
flickerstreak@25 66 end
flickerstreak@25 67
flickerstreak@25 68 function Bar:ApplyAnchor()
flickerstreak@25 69 local f, config = self.frame, self.config
flickerstreak@25 70 f:SetWidth(config.width)
flickerstreak@25 71 f:SetHeight(config.height)
flickerstreak@25 72 local anchor = config.anchor
flickerstreak@51 73 f:ClearAllPoints()
flickerstreak@25 74 if anchor then
flickerstreak@52 75 local anchorTo = f:GetParent()
flickerstreak@25 76 if config.anchorTo then
flickerstreak@52 77 local bar = ReAction:GetBar(config.anchorTo)
flickerstreak@52 78 if bar then
flickerstreak@52 79 anchorTo = bar:GetFrame()
flickerstreak@52 80 else
flickerstreak@52 81 anchorTo = _G[config.anchorTo]
flickerstreak@52 82 end
flickerstreak@25 83 end
flickerstreak@52 84 f:SetPoint(anchor, anchorTo or f:GetParent(), config.relativePoint, config.x or 0, config.y or 0)
flickerstreak@25 85 else
flickerstreak@25 86 f:SetPoint("CENTER")
flickerstreak@25 87 end
flickerstreak@25 88 end
flickerstreak@25 89
flickerstreak@51 90 function Bar:SetAnchor(point, frame, relativePoint, x, y)
flickerstreak@51 91 local c = self.config
flickerstreak@51 92 c.anchor = point or c.anchor
flickerstreak@51 93 c.anchorTo = frame and frame:GetName() or c.anchorTo
flickerstreak@51 94 c.relativePoint = relativePoint or c.relativePoint
flickerstreak@51 95 c.x = x or c.x
flickerstreak@51 96 c.y = y or c.y
flickerstreak@51 97 self:ApplyAnchor()
flickerstreak@51 98 end
flickerstreak@51 99
flickerstreak@51 100 function Bar:GetAnchor()
flickerstreak@51 101 local c = self.config
flickerstreak@51 102 return (c.anchor or "CENTER"), (c.anchorTo or self.frame:GetParent():GetName()), (c.relativePoint or c.anchor or "CENTER"), (c.x or 0), (c.y or 0)
flickerstreak@51 103 end
flickerstreak@51 104
flickerstreak@25 105 function Bar:GetFrame()
flickerstreak@25 106 return self.frame
flickerstreak@25 107 end
flickerstreak@25 108
flickerstreak@25 109 function Bar:GetSize()
flickerstreak@25 110 return self.frame:GetWidth() or 200, self.frame:GetHeight() or 200
flickerstreak@25 111 end
flickerstreak@25 112
flickerstreak@25 113 function Bar:SetSize(w,h)
flickerstreak@25 114 self.config.width = w
flickerstreak@25 115 self.config.height = h
flickerstreak@25 116 end
flickerstreak@25 117
flickerstreak@25 118 function Bar:GetButtonSize()
flickerstreak@25 119 local w = self.config.btnWidth or 32
flickerstreak@25 120 local h = self.config.btnHeight or 32
flickerstreak@25 121 -- TODO: get from modules?
flickerstreak@25 122 return w,h
flickerstreak@25 123 end
flickerstreak@25 124
flickerstreak@25 125 function Bar:SetButtonSize(w,h)
flickerstreak@25 126 if w > 0 and h > 0 then
flickerstreak@25 127 self.config.btnWidth = w
flickerstreak@25 128 self.config.btnHeight = h
flickerstreak@25 129 end
flickerstreak@25 130 end
flickerstreak@25 131
flickerstreak@25 132 function Bar:GetButtonGrid()
flickerstreak@25 133 local cfg = self.config
flickerstreak@25 134 local r = cfg.btnRows or 1
flickerstreak@25 135 local c = cfg.btnColumns or 1
flickerstreak@25 136 local s = cfg.spacing or 4
flickerstreak@25 137 return r,c,s
flickerstreak@25 138 end
flickerstreak@25 139
flickerstreak@25 140 function Bar:SetButtonGrid(r,c,s)
flickerstreak@25 141 if r > 0 and c > 0 and s > 0 then
flickerstreak@25 142 local cfg = self.config
flickerstreak@25 143 cfg.btnRows = r
flickerstreak@25 144 cfg.btnColumns = c
flickerstreak@25 145 cfg.spacing = s
flickerstreak@25 146 end
flickerstreak@25 147 end
flickerstreak@25 148
flickerstreak@25 149 function Bar:GetName()
flickerstreak@25 150 return self.name
flickerstreak@25 151 end
flickerstreak@25 152
flickerstreak@33 153 function Bar:SetName(name)
flickerstreak@33 154 self.name = name
flickerstreak@33 155 if self.controlLabelString then
flickerstreak@33 156 self.controlLabelString:SetText(self.name)
flickerstreak@33 157 end
flickerstreak@33 158 end
flickerstreak@33 159
flickerstreak@25 160 function Bar:PlaceButton(f, idx, baseW, baseH)
flickerstreak@25 161 local r, c, s = self:GetButtonGrid()
flickerstreak@25 162 local bh, bw = self:GetButtonSize()
flickerstreak@25 163 local row, col = floor((idx-1)/c), mod((idx-1),c) -- zero-based
flickerstreak@25 164 local x, y = col*bw + (col+0.5)*s, row*bh + (row+0.5)*s
flickerstreak@25 165 local scale = bw/baseW
flickerstreak@25 166
flickerstreak@25 167 f:ClearAllPoints()
flickerstreak@25 168 f:SetPoint("TOPLEFT",x/scale,-y/scale)
flickerstreak@25 169 f:SetScale(scale)
flickerstreak@68 170 self.buttons[f] = true
flickerstreak@25 171 end
flickerstreak@25 172
flickerstreak@71 173
flickerstreak@71 174 -- multi-state functions --
flickerstreak@68 175 function Bar:GetNumPages()
flickerstreak@68 176 return self.config.nPages or 1
flickerstreak@68 177 end
flickerstreak@28 178
flickerstreak@68 179 function Bar:SetHideStates(s)
flickerstreak@68 180 for f in pairs(self.buttons) do
flickerstreak@68 181 if f:GetParent() == self.frame then
flickerstreak@68 182 f:SetAttribute("hidestates",s)
flickerstreak@68 183 end
flickerstreak@68 184 end
flickerstreak@68 185 SecureStateHeader_Refresh(self.frame)
flickerstreak@68 186 end
flickerstreak@28 187
flickerstreak@70 188 function Bar:SetStateKeybind(key, state, defaultstate)
flickerstreak@71 189 -- set a keybind to toggle transitioning unconditionally to a state
flickerstreak@68 190 -- use a tiny offscreen button to get around making the bar itself a clickable button
flickerstreak@68 191 local f = self.statebuttonframe
flickerstreak@68 192 local off = ("%s_off"):format(state)
flickerstreak@70 193 if key then
flickerstreak@68 194 if not f then
flickerstreak@68 195 f = CreateFrame("Button",self:GetName().."_statebutton",UIParent,"SecureActionButtonTemplate")
flickerstreak@68 196 f:SetPoint("BOTTOMRIGHT",UIParent,"TOPLEFT")
flickerstreak@68 197 f:SetWidth(1)
flickerstreak@68 198 f:SetHeight(1)
flickerstreak@68 199 f:SetAttribute("attribute-name", "state")
flickerstreak@68 200 f:SetAttribute("attribute-frame",self.frame)
flickerstreak@68 201 f:SetAttribute("stateheader",self.frame)
flickerstreak@68 202 f:Show()
flickerstreak@68 203 self.statebuttonframe = f
flickerstreak@68 204 end
flickerstreak@68 205 -- map two virtual buttons to toggle between the state and the default
flickerstreak@68 206 f:SetAttribute(("statebutton-%s"):format(state),("%s:%s;%s"):format(state,off,state))
flickerstreak@68 207 f:SetAttribute(("type-%s"):format(state),"attribute")
flickerstreak@68 208 f:SetAttribute(("type-%s"):format(off),"attribute")
flickerstreak@68 209 f:SetAttribute(("attribute-value-%s"):format(state), state)
flickerstreak@68 210 f:SetAttribute(("attribute-value-%s"):format(off), defaultstate)
flickerstreak@70 211 SetBindingClick(key, f:GetName(), state)
flickerstreak@68 212 elseif f then
flickerstreak@68 213 f:SetAttribute(("type-%s"):format(state),ATTRIBUTE_NOOP)
flickerstreak@68 214 f:SetAttribute(("type-%s"):format(off),ATTRIBUTE_NOOP)
flickerstreak@70 215 local action = ("CLICK %s:%s"):format(f:GetName(),state)
flickerstreak@70 216 key = GetBindingKey(action)
flickerstreak@70 217 if key then
flickerstreak@70 218 SetBinding(key,nil)
flickerstreak@70 219 end
flickerstreak@68 220 end
flickerstreak@68 221 end
flickerstreak@33 222
flickerstreak@68 223 function Bar:SetStatePageMap(state, map) -- map is a { ["statename"] = pagenumber } table
flickerstreak@68 224 local f = self.frame
flickerstreak@68 225 local tmp = { }
flickerstreak@68 226 for s, p in pairs(map) do
flickerstreak@71 227 table.insert(tmp, ("%s:page%d"):format(s,p))
flickerstreak@68 228 end
flickerstreak@68 229 local spec = table.concat(tmp,";")
flickerstreak@68 230 f:SetAttribute("statebutton",spec)
flickerstreak@71 231 SecureStateHeader_Refresh(f)
flickerstreak@68 232 end
flickerstreak@33 233
flickerstreak@68 234 function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled
flickerstreak@68 235 local f = self.frame
flickerstreak@68 236 for i = 1, #states do
flickerstreak@68 237 local s = states[i]
flickerstreak@68 238 states[i] = ("%s:%s"):format(s,s)
flickerstreak@68 239 end
flickerstreak@71 240 table.insert(states,"_defaultbindings")
flickerstreak@68 241 f:SetAttribute("statebindings",table.concat(states,";"))
flickerstreak@71 242 SecureStateHeader_Refresh(f)
flickerstreak@68 243 for b in pairs(self.buttons) do
flickerstreak@71 244 -- TODO: signal child frames that they should maintain multiple bindings
flickerstreak@68 245 end
flickerstreak@68 246 end
flickerstreak@33 247
flickerstreak@71 248 local _ofskeys = { "point", "relpoint", "x", "y" }
flickerstreak@71 249 function Bar:SetStateAnchorMap( map ) -- 'map' is a { ["statename"] = { point=point, relpoint=relpoint, x=x, y=y } } table
flickerstreak@71 250 local f = self.frame
flickerstreak@71 251 local c = self.config
flickerstreak@71 252 local default = { point = c.anchor, relpoint = c.relativePoint, x = c.x, y = c.y }
flickerstreak@71 253 for _, key in pairs(_ofskeys) do
flickerstreak@71 254 local t = { }
flickerstreak@71 255 for state, info in pairs(map) do
flickerstreak@71 256 if info[key] then
flickerstreak@71 257 table.insert(t, ("%s:%s"):format(state, info[key]))
flickerstreak@71 258 end
flickerstreak@71 259 end
flickerstreak@71 260 if #t > 0 and default[key] then table.insert(t, tostring(default[key])) end
flickerstreak@71 261 f:SetAttribute(("headofs%s"):format(key), table.concat(t,";") or "")
flickerstreak@71 262 end
flickerstreak@71 263 SecureStateHeader_Refresh(f)
flickerstreak@71 264 end
flickerstreak@71 265
flickerstreak@71 266 function Bar:SetStateScaleMap( map ) -- 'map' is a { ["statename"] = scalevalue } table
flickerstreak@71 267 local f = self.frame
flickerstreak@71 268 local t = { }
flickerstreak@71 269 for state, scale in pairs(map) do
flickerstreak@71 270 table.insert( t, ("%s:%s"):format(state,scale) )
flickerstreak@71 271 end
flickerstreak@71 272 if #t > 0 then table.insert(t, "1.0") end
flickerstreak@71 273 f:SetAttribute("headscale",table.concat(t,";") or "")
flickerstreak@71 274 SecureStateHeader_Refresh(f)
flickerstreak@71 275 end
flickerstreak@71 276
flickerstreak@71 277
flickerstreak@33 278 --
flickerstreak@33 279 -- Bar config overlay
flickerstreak@33 280 --
flickerstreak@52 281 local CreateControls
flickerstreak@33 282
flickerstreak@33 283 do
flickerstreak@33 284 -- upvalue some of these for small OnUpdate performance boost
flickerstreak@33 285 local GetSize = Bar.GetSize
flickerstreak@33 286 local GetButtonSize = Bar.GetButtonSize
flickerstreak@33 287 local GetButtonGrid = Bar.GetButtonGrid
flickerstreak@33 288 local SetSize = Bar.SetSize
flickerstreak@33 289 local SetButtonSize = Bar.SetButtonSize
flickerstreak@33 290 local SetButtonGrid = Bar.SetButtonGrid
flickerstreak@33 291 local ApplyAnchor = Bar.ApplyAnchor
flickerstreak@33 292
flickerstreak@52 293 local function StoreExtents(bar)
flickerstreak@33 294 local f = bar.frame
flickerstreak@33 295 local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
flickerstreak@33 296 relativeTo = relativeTo or f:GetParent()
flickerstreak@33 297 local anchorTo
flickerstreak@63 298 for name, b in ReAction:IterateBars() do
flickerstreak@52 299 if b and b:GetFrame() == relativeTo then
flickerstreak@52 300 anchorTo = name
flickerstreak@52 301 break
flickerstreak@33 302 end
flickerstreak@33 303 end
flickerstreak@33 304 anchorTo = anchorTo or relativeTo:GetName()
flickerstreak@33 305 local c = bar.config
flickerstreak@33 306 c.anchor = point
flickerstreak@33 307 c.anchorTo = anchorTo
flickerstreak@33 308 c.relativePoint = relativePoint
flickerstreak@33 309 c.x = x
flickerstreak@33 310 c.y = y
flickerstreak@33 311 c.width, c.height = f:GetWidth(), f:GetHeight()
flickerstreak@33 312 end
flickerstreak@33 313
flickerstreak@52 314 local function StoreSize(bar)
flickerstreak@52 315 local f = bar.frame
flickerstreak@52 316 local c = bar.config
flickerstreak@52 317 c.width, c.height = f:GetWidth(), f:GetHeight()
flickerstreak@52 318 end
flickerstreak@52 319
flickerstreak@52 320 local function RecomputeButtonSize(bar)
flickerstreak@33 321 local w, h = GetSize(bar)
flickerstreak@33 322 local bw, bh = GetButtonSize(bar)
flickerstreak@33 323 local r, c, s = GetButtonGrid(bar)
flickerstreak@33 324
flickerstreak@33 325 local scaleW = (floor(w/c) - s) / bw
flickerstreak@33 326 local scaleH = (floor(h/r) - s) / bh
flickerstreak@33 327 local scale = min(scaleW, scaleH)
flickerstreak@33 328
flickerstreak@33 329 SetButtonSize(bar, scale * bw, scale * bh, s)
flickerstreak@33 330 end
flickerstreak@33 331
flickerstreak@52 332 local function RecomputeButtonSpacing(bar)
flickerstreak@33 333 local w, h = GetSize(bar)
flickerstreak@33 334 local bw, bh = GetButtonSize(bar)
flickerstreak@33 335 local r, c, s = GetButtonGrid(bar)
flickerstreak@33 336
flickerstreak@33 337 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
flickerstreak@33 338 end
flickerstreak@33 339
flickerstreak@52 340 local function RecomputeGrid(bar)
flickerstreak@33 341 local w, h = GetSize(bar)
flickerstreak@33 342 local bw, bh = GetButtonSize(bar)
flickerstreak@33 343 local r, c, s = GetButtonGrid(bar)
flickerstreak@33 344
flickerstreak@33 345 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
flickerstreak@33 346 end
flickerstreak@33 347
flickerstreak@52 348 local function ClampToButtons(bar)
flickerstreak@33 349 local bw, bh = GetButtonSize(bar)
flickerstreak@33 350 local r, c, s = GetButtonGrid(bar)
flickerstreak@50 351 SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1)
flickerstreak@33 352 end
flickerstreak@33 353
flickerstreak@52 354 local function HideGameTooltip()
flickerstreak@33 355 GameTooltip:Hide()
flickerstreak@33 356 end
flickerstreak@33 357
flickerstreak@52 358 local anchorInside = { inside = true }
flickerstreak@52 359 local anchorOutside = { outside = true }
flickerstreak@52 360 local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" }
flickerstreak@52 361 local oppositeEdges = {
flickerstreak@52 362 TOP = "BOTTOM",
flickerstreak@52 363 BOTTOM = "TOP",
flickerstreak@52 364 LEFT = "RIGHT",
flickerstreak@52 365 RIGHT = "LEFT"
flickerstreak@52 366 }
flickerstreak@52 367 local pointsOnEdge = {
flickerstreak@52 368 BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", },
flickerstreak@52 369 TOP = { "TOP", "TOPLEFT", "TOPRIGHT", },
flickerstreak@52 370 RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", },
flickerstreak@52 371 LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", },
flickerstreak@52 372 }
flickerstreak@52 373 local edgeSelector = {
flickerstreak@52 374 BOTTOM = 1, -- select x of x,y
flickerstreak@52 375 TOP = 1, -- select x of x,y
flickerstreak@52 376 LEFT = 2, -- select y of x,y
flickerstreak@52 377 RIGHT = 2, -- select y of x,y
flickerstreak@52 378 }
flickerstreak@52 379 local snapPoints = {
flickerstreak@52 380 [anchorOutside] = {
flickerstreak@52 381 BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"},
flickerstreak@52 382 BOTTOM = {"TOP"},
flickerstreak@52 383 BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"},
flickerstreak@52 384 RIGHT = {"LEFT"},
flickerstreak@52 385 TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"},
flickerstreak@52 386 TOP = {"BOTTOM"},
flickerstreak@52 387 TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"},
flickerstreak@52 388 LEFT = {"RIGHT"},
flickerstreak@52 389 CENTER = {"CENTER"}
flickerstreak@52 390 },
flickerstreak@52 391 [anchorInside] = {
flickerstreak@52 392 BOTTOMLEFT = {"BOTTOMLEFT"},
flickerstreak@52 393 BOTTOM = {"BOTTOM"},
flickerstreak@52 394 BOTTOMRIGHT = {"BOTTOMRIGHT"},
flickerstreak@52 395 RIGHT = {"RIGHT"},
flickerstreak@52 396 TOPRIGHT = {"TOPRIGHT"},
flickerstreak@52 397 TOP = {"TOP"},
flickerstreak@52 398 TOPLEFT = {"TOPLEFT"},
flickerstreak@52 399 LEFT = {"LEFT"},
flickerstreak@52 400 CENTER = {"CENTER"}
flickerstreak@52 401 }
flickerstreak@52 402 }
flickerstreak@52 403 local insidePointOffsetFuncs = {
flickerstreak@52 404 BOTTOMLEFT = function(x, y) return x, y end,
flickerstreak@52 405 BOTTOM = function(x, y) return 0, y end,
flickerstreak@52 406 BOTTOMRIGHT = function(x, y) return -x, y end,
flickerstreak@52 407 RIGHT = function(x, y) return -x, 0 end,
flickerstreak@52 408 TOPRIGHT = function(x, y) return -x, -y end,
flickerstreak@52 409 TOP = function(x, y) return 0, -y end,
flickerstreak@52 410 TOPLEFT = function(x, y) return x, -y end,
flickerstreak@52 411 LEFT = function(x, y) return x, 0 end,
flickerstreak@52 412 CENTER = function(x, y) return 0, 0 end,
flickerstreak@52 413 }
flickerstreak@52 414 local pointCoordFuncs = {
flickerstreak@52 415 BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end,
flickerstreak@52 416 BOTTOM = function(f) return nil, f:GetBottom() end,
flickerstreak@52 417 BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end,
flickerstreak@52 418 RIGHT = function(f) return f:GetRight(), nil end,
flickerstreak@52 419 TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end,
flickerstreak@52 420 TOP = function(f) return nil, f:GetTop() end,
flickerstreak@52 421 TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end,
flickerstreak@52 422 LEFT = function(f) return f:GetLeft(), nil end,
flickerstreak@52 423 CENTER = function(f) return f:GetCenter() end,
flickerstreak@52 424 }
flickerstreak@52 425 local edgeBoundsFuncs = {
flickerstreak@52 426 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end,
flickerstreak@52 427 LEFT = function(f) return f:GetBottom(), f:GetTop() end
flickerstreak@52 428 }
flickerstreak@52 429 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM
flickerstreak@52 430 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
flickerstreak@52 431
flickerstreak@52 432
flickerstreak@52 433 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
flickerstreak@52 434 local function GetPointCoords( f, p )
flickerstreak@52 435 local x, y = pointCoordFuncs[p](f)
flickerstreak@52 436 if not(x and y) then
flickerstreak@52 437 local cx, cy = f:GetCenter()
flickerstreak@52 438 x = x or cx
flickerstreak@52 439 y = y or cy
flickerstreak@52 440 end
flickerstreak@52 441 return x, y
flickerstreak@52 442 end
flickerstreak@52 443
flickerstreak@52 444
flickerstreak@52 445 -- Returns true if frame 'f1' can be anchored to frame 'f2'
flickerstreak@52 446 local function CheckAnchorable( f1, f2 )
flickerstreak@52 447 -- can't anchor a frame to itself or to nil
flickerstreak@52 448 if f1 == f2 or f2 == nil then
flickerstreak@52 449 return false
flickerstreak@52 450 end
flickerstreak@52 451
flickerstreak@52 452 -- can always anchor to UIParent
flickerstreak@52 453 if f2 == UIParent then
flickerstreak@52 454 return true
flickerstreak@52 455 end
flickerstreak@52 456
flickerstreak@52 457 -- also can't do circular anchoring of frames
flickerstreak@52 458 -- walk the anchor chain, which generally shouldn't be that expensive
flickerstreak@52 459 -- (who nests draggables that deep anyway?)
flickerstreak@52 460 for i = 1, f2:GetNumPoints() do
flickerstreak@52 461 local _, f = f2:GetPoint(i)
flickerstreak@52 462 if not f then f = f2:GetParent() end
flickerstreak@52 463 return CheckAnchorable(f1,f)
flickerstreak@52 464 end
flickerstreak@52 465
flickerstreak@52 466 return true
flickerstreak@52 467 end
flickerstreak@52 468
flickerstreak@52 469 -- Returns true if frames f1 and f2 specified edges overlap
flickerstreak@52 470 local function CheckEdgeOverlap( f1, f2, e )
flickerstreak@52 471 local l1, u1 = edgeBoundsFuncs[e](f1)
flickerstreak@52 472 local l2, u2 = edgeBoundsFuncs[e](f2)
flickerstreak@52 473 return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2
flickerstreak@52 474 end
flickerstreak@52 475
flickerstreak@52 476 -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2
flickerstreak@52 477 local function CheckPointEdgeOverlap( f1, p1, f2, e2 )
flickerstreak@52 478 local l, u = edgeBoundsFuncs[e2](f2)
flickerstreak@52 479 local x, y = GetPointCoords(f1,p1)
flickerstreak@52 480 x = select(edgeSelector[e2], x, y)
flickerstreak@52 481 return l <= x and x <= u
flickerstreak@52 482 end
flickerstreak@52 483
flickerstreak@52 484 -- Returns the distance between corresponding edges. It is
flickerstreak@52 485 -- assumed that the passed in edges e1 and e2 are the same or opposites
flickerstreak@52 486 local function GetEdgeDistance( f1, f2, e1, e2 )
flickerstreak@52 487 local x1, y1 = pointCoordFuncs[e1](f1)
flickerstreak@52 488 local x2, y2 = pointCoordFuncs[e2](f2)
flickerstreak@52 489 return math.abs((x1 or y1) - (x2 or y2))
flickerstreak@52 490 end
flickerstreak@52 491
flickerstreak@52 492 local globalSnapTargets = { [UIParent] = anchorInside }
flickerstreak@52 493
flickerstreak@52 494 local function GetClosestFrameEdge(f1,f2,a)
flickerstreak@52 495 local dist, edge, opp
flickerstreak@52 496 if f2:IsVisible() and CheckAnchorable(f1,f2) then
flickerstreak@52 497 for _, e in pairs(edges) do
flickerstreak@52 498 local o = a.inside and e or oppositeEdges[e]
flickerstreak@52 499 if CheckEdgeOverlap(f1,f2,e) then
flickerstreak@52 500 local d = GetEdgeDistance(f1, f2, e, o)
flickerstreak@52 501 if not dist or (d < dist) then
flickerstreak@52 502 dist, edge, opp = d, e, o
flickerstreak@52 503 end
flickerstreak@52 504 end
flickerstreak@52 505 end
flickerstreak@52 506 end
flickerstreak@52 507 return dist, edge, opp
flickerstreak@52 508 end
flickerstreak@52 509
flickerstreak@52 510 local function GetClosestVisibleEdge( f )
flickerstreak@52 511 local r, o, e1, e2
flickerstreak@52 512 local a = anchorOutside
flickerstreak@63 513 for _, b in ReAction:IterateBars() do
flickerstreak@52 514 local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a)
flickerstreak@52 515 if d and (not r or d < r) then
flickerstreak@52 516 r, o, e1, e2 = d, b:GetFrame(), e, opp
flickerstreak@52 517 end
flickerstreak@52 518 end
flickerstreak@52 519 for f2, a2 in pairs(globalSnapTargets) do
flickerstreak@52 520 local d, e, opp = GetClosestFrameEdge(f,f2,a2)
flickerstreak@52 521 if d and (not r or d < r) then
flickerstreak@52 522 r, o, e1, e2, a = d, f2, e, opp, a2
flickerstreak@52 523 end
flickerstreak@52 524 end
flickerstreak@52 525 return o, e1, e2, a
flickerstreak@52 526 end
flickerstreak@52 527
flickerstreak@52 528 local function GetClosestVisiblePoint(f1)
flickerstreak@52 529 local f2, e1, e2, a = GetClosestVisibleEdge(f1)
flickerstreak@52 530 if f2 then
flickerstreak@52 531 local rsq, p, rp, x, y
flickerstreak@52 532 -- iterate pointsOnEdge in order and use < to prefer edge centers to corners
flickerstreak@52 533 for _, p1 in ipairs(pointsOnEdge[e1]) do
flickerstreak@52 534 if CheckPointEdgeOverlap(f1,p1,f2,e2) then
flickerstreak@52 535 for _, p2 in pairs(snapPoints[a][p1]) do
flickerstreak@52 536 local x1, y1 = GetPointCoords(f1,p1)
flickerstreak@52 537 local x2, y2 = GetPointCoords(f2,p2)
flickerstreak@52 538 local dx = x1 - x2
flickerstreak@52 539 local dy = y1 - y2
flickerstreak@52 540 local rsq2 = dx*dx + dy*dy
flickerstreak@52 541 if not rsq or rsq2 < rsq then
flickerstreak@52 542 rsq, p, rp, x, y = rsq2, p1, p2, dx, dy
flickerstreak@52 543 end
flickerstreak@52 544 end
flickerstreak@52 545 end
flickerstreak@52 546 end
flickerstreak@52 547 return f2, p, rp, x, y
flickerstreak@52 548 end
flickerstreak@52 549 end
flickerstreak@52 550
flickerstreak@52 551 local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff)
flickerstreak@52 552 local o, p, rp, x, y = GetClosestVisiblePoint(f1)
flickerstreak@52 553 local s = false
flickerstreak@52 554
flickerstreak@52 555 local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0)
flickerstreak@52 556 local xx, yy = pointCoordFuncs[p](f1)
flickerstreak@52 557 if xx and yy then
flickerstreak@52 558 if math.abs(x) <= rx then
flickerstreak@52 559 x = sx
flickerstreak@52 560 s = true
flickerstreak@52 561 end
flickerstreak@52 562 if math.abs(y) <= ry then
flickerstreak@52 563 y = sy
flickerstreak@52 564 s = true
flickerstreak@52 565 end
flickerstreak@52 566 elseif xx then
flickerstreak@52 567 if math.abs(x) <= rx then
flickerstreak@52 568 x = sx
flickerstreak@52 569 s = true
flickerstreak@52 570 if math.abs(y) <= ry then
flickerstreak@52 571 y = sy
flickerstreak@52 572 end
flickerstreak@52 573 end
flickerstreak@52 574 elseif yy then
flickerstreak@52 575 if math.abs(y) <= ry then
flickerstreak@52 576 y = sy
flickerstreak@52 577 s = true
flickerstreak@52 578 if math.abs(x) <= rx then
flickerstreak@52 579 x = sx
flickerstreak@52 580 end
flickerstreak@52 581 end
flickerstreak@52 582 end
flickerstreak@52 583
flickerstreak@52 584 if x == -0 then x = 0 end
flickerstreak@52 585 if y == -0 then y = 0 end
flickerstreak@52 586
flickerstreak@52 587 if s then
flickerstreak@52 588 return o, p, rp, math.floor(x), math.floor(y)
flickerstreak@52 589 end
flickerstreak@52 590 end
flickerstreak@52 591
flickerstreak@52 592 local function CreateSnapIndicator()
flickerstreak@52 593 local si = CreateFrame("Frame",nil,UIParent)
flickerstreak@52 594 si:SetFrameStrata("HIGH")
flickerstreak@52 595 si:SetHeight(8)
flickerstreak@52 596 si:SetWidth(8)
flickerstreak@52 597 local tex = si:CreateTexture()
flickerstreak@52 598 tex:SetAllPoints()
flickerstreak@52 599 tex:SetTexture(1.0, 0.82, 0, 0.8)
flickerstreak@52 600 tex:SetBlendMode("ADD")
flickerstreak@52 601 tex:SetDrawLayer("OVERLAY")
flickerstreak@52 602 return si
flickerstreak@52 603 end
flickerstreak@52 604
flickerstreak@52 605 local si1 = CreateSnapIndicator()
flickerstreak@52 606 local si2 = CreateSnapIndicator()
flickerstreak@52 607
flickerstreak@52 608 local function DisplaySnapIndicator( f, rx, ry, xOff, yOff )
flickerstreak@52 609 local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff)
flickerstreak@52 610 if o then
flickerstreak@52 611 si1:ClearAllPoints()
flickerstreak@52 612 si2:ClearAllPoints()
flickerstreak@52 613 si1:SetPoint("CENTER", f, p, 0, 0)
flickerstreak@52 614 local xx, yy = pointCoordFuncs[rp](o)
flickerstreak@52 615 x = math.abs(x) <=rx and xx and 0 or x
flickerstreak@52 616 y = math.abs(y) <=ry and yy and 0 or y
flickerstreak@52 617 si2:SetPoint("CENTER", o, rp, x, y)
flickerstreak@52 618 si1:Show()
flickerstreak@52 619 si2:Show()
flickerstreak@52 620 else
flickerstreak@52 621 if si1:IsVisible() then
flickerstreak@52 622 si1:Hide()
flickerstreak@52 623 si2:Hide()
flickerstreak@52 624 end
flickerstreak@52 625 end
flickerstreak@52 626 end
flickerstreak@52 627
flickerstreak@52 628 local function HideSnapIndicator()
flickerstreak@52 629 if si1:IsVisible() then
flickerstreak@52 630 si1:Hide()
flickerstreak@52 631 si2:Hide()
flickerstreak@52 632 end
flickerstreak@52 633 end
flickerstreak@52 634
flickerstreak@71 635 function CreateControls(bar)
flickerstreak@33 636 local f = bar.frame
flickerstreak@33 637
flickerstreak@33 638 f:SetMovable(true)
flickerstreak@33 639 f:SetResizable(true)
flickerstreak@33 640 f:SetClampedToScreen(true)
flickerstreak@33 641
flickerstreak@33 642 -- buttons on the bar should be direct children of the bar frame.
flickerstreak@33 643 -- The control elements need to float on top of this, which we could
flickerstreak@33 644 -- do with SetFrameLevel() or Raise(), but it's more reliable to do it
flickerstreak@33 645 -- via frame nesting, hence good old foo's appearance here.
flickerstreak@33 646 local foo = CreateFrame("Frame",nil,f)
flickerstreak@33 647 foo:SetAllPoints()
flickerstreak@51 648 foo:SetClampedToScreen(true)
flickerstreak@33 649
flickerstreak@33 650 local control = CreateFrame("Button", nil, foo)
flickerstreak@33 651 control:EnableMouse(true)
flickerstreak@33 652 control:SetToplevel(true)
flickerstreak@33 653 control:SetPoint("TOPLEFT", -4, 4)
flickerstreak@33 654 control:SetPoint("BOTTOMRIGHT", 4, -4)
flickerstreak@33 655 control:SetBackdrop({
flickerstreak@33 656 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
flickerstreak@33 657 tile = true,
flickerstreak@33 658 tileSize = 16,
flickerstreak@33 659 edgeSize = 16,
flickerstreak@33 660 insets = { left = 0, right = 0, top = 0, bottom = 0 },
flickerstreak@33 661 })
flickerstreak@33 662
flickerstreak@33 663 -- textures
flickerstreak@33 664 local bgTex = control:CreateTexture(nil,"BACKGROUND")
flickerstreak@33 665 bgTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@33 666 bgTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@33 667 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@33 668 local hTex = control:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@33 669 hTex:SetTexture(0.7,0.7,1.0,0.2)
flickerstreak@33 670 hTex:SetPoint("TOPLEFT",4,-4)
flickerstreak@33 671 hTex:SetPoint("BOTTOMRIGHT",-4,4)
flickerstreak@33 672 hTex:SetBlendMode("ADD")
flickerstreak@33 673
flickerstreak@33 674 -- label
flickerstreak@33 675 local label = control:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
flickerstreak@33 676 label:SetAllPoints()
flickerstreak@33 677 label:SetJustifyH("CENTER")
flickerstreak@33 678 label:SetShadowColor(0,0,0,1)
flickerstreak@33 679 label:SetShadowOffset(2,-2)
flickerstreak@33 680 label:SetTextColor(1,1,1,1)
flickerstreak@33 681 label:SetText(bar:GetName())
flickerstreak@33 682 label:Show()
flickerstreak@33 683 bar.controlLabelString = label -- so that bar:SetName() can update it
flickerstreak@33 684
flickerstreak@71 685 local function StopResize()
flickerstreak@33 686 f:StopMovingOrSizing()
flickerstreak@33 687 f.isMoving = false
flickerstreak@33 688 f:SetScript("OnUpdate",nil)
flickerstreak@52 689 StoreSize(bar)
flickerstreak@33 690 ClampToButtons(bar)
flickerstreak@33 691 ApplyAnchor(bar)
flickerstreak@63 692 ReAction:RefreshOptions()
flickerstreak@33 693 end
flickerstreak@33 694
flickerstreak@33 695 -- edge drag handles
flickerstreak@33 696 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
flickerstreak@33 697 local edge = CreateFrame("Frame",nil,control)
flickerstreak@33 698 edge:EnableMouse(true)
flickerstreak@33 699 edge:SetWidth(8)
flickerstreak@33 700 edge:SetHeight(8)
flickerstreak@33 701 if point == "TOP" or point == "BOTTOM" then
flickerstreak@33 702 edge:SetPoint(point.."LEFT")
flickerstreak@33 703 edge:SetPoint(point.."RIGHT")
flickerstreak@33 704 else
flickerstreak@33 705 edge:SetPoint("TOP"..point)
flickerstreak@33 706 edge:SetPoint("BOTTOM"..point)
flickerstreak@33 707 end
flickerstreak@33 708 local tex = edge:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@33 709 tex:SetTexture(1.0,0.82,0,0.7)
flickerstreak@33 710 tex:SetBlendMode("ADD")
flickerstreak@33 711 tex:SetAllPoints()
flickerstreak@33 712 edge:RegisterForDrag("LeftButton")
flickerstreak@33 713 edge:SetScript("OnMouseDown",
flickerstreak@33 714 function()
flickerstreak@33 715 local bw, bh = GetButtonSize(bar)
flickerstreak@33 716 local r, c, s = GetButtonGrid(bar)
flickerstreak@33 717 f:SetMinResize( bw+s+1, bh+s+1 )
flickerstreak@33 718 f:StartSizing(point)
flickerstreak@33 719 f:SetScript("OnUpdate",
flickerstreak@33 720 function()
flickerstreak@33 721 RecomputeGrid(bar)
flickerstreak@33 722 bar:RefreshLayout()
flickerstreak@33 723 end
flickerstreak@33 724 )
flickerstreak@33 725 end
flickerstreak@33 726 )
flickerstreak@33 727 edge:SetScript("OnMouseUp", StopResize)
flickerstreak@33 728 edge:SetScript("OnEnter",
flickerstreak@33 729 function()
flickerstreak@33 730 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@33 731 GameTooltip:AddLine(L["Drag to add/remove buttons"])
flickerstreak@33 732 GameTooltip:Show()
flickerstreak@33 733 end
flickerstreak@33 734 )
flickerstreak@33 735 edge:SetScript("OnLeave", HideGameTooltip)
flickerstreak@33 736 edge:Show()
flickerstreak@33 737 end
flickerstreak@33 738
flickerstreak@33 739 -- corner drag handles, again nested in an anonymous frame so that they are on top
flickerstreak@33 740 local foo2 = CreateFrame("Frame",nil,control)
flickerstreak@33 741 foo2:SetAllPoints(true)
flickerstreak@33 742 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
flickerstreak@33 743 local corner = CreateFrame("Frame",nil,foo2)
flickerstreak@33 744 corner:EnableMouse(true)
flickerstreak@33 745 corner:SetWidth(12)
flickerstreak@33 746 corner:SetHeight(12)
flickerstreak@33 747 corner:SetPoint(point)
flickerstreak@33 748 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
flickerstreak@33 749 tex:SetTexture(1.0,0.82,0,0.7)
flickerstreak@33 750 tex:SetBlendMode("ADD")
flickerstreak@33 751 tex:SetAllPoints()
flickerstreak@33 752 corner:RegisterForDrag("LeftButton","RightButton")
flickerstreak@71 753 local function updateTooltip()
flickerstreak@33 754 local size, size2 = bar:GetButtonSize()
flickerstreak@33 755 local rows, cols, spacing = bar:GetButtonGrid()
flickerstreak@33 756 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
flickerstreak@33 757 GameTooltipTextRight4:SetText(size)
flickerstreak@33 758 GameTooltipTextRight5:SetText(tostring(spacing))
flickerstreak@33 759 end
flickerstreak@33 760 corner:SetScript("OnMouseDown",
flickerstreak@33 761 function(_,btn)
flickerstreak@33 762 local bw, bh = GetButtonSize(bar)
flickerstreak@33 763 local r, c, s = GetButtonGrid(bar)
flickerstreak@33 764 if btn == "LeftButton" then -- button resize
flickerstreak@33 765 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
flickerstreak@33 766 f:SetScript("OnUpdate",
flickerstreak@33 767 function()
flickerstreak@33 768 RecomputeButtonSize(bar)
flickerstreak@33 769 bar:RefreshLayout()
flickerstreak@33 770 updateTooltip()
flickerstreak@33 771 end
flickerstreak@33 772 )
flickerstreak@33 773 elseif btn == "RightButton" then -- spacing resize
flickerstreak@33 774 f:SetMinResize( bw*c, bh*r )
flickerstreak@33 775 f:SetScript("OnUpdate",
flickerstreak@33 776 function()
flickerstreak@33 777 RecomputeButtonSpacing(bar)
flickerstreak@33 778 bar:RefreshLayout()
flickerstreak@33 779 updateTooltip()
flickerstreak@33 780 end
flickerstreak@33 781 )
flickerstreak@33 782 end
flickerstreak@33 783 f:StartSizing(point)
flickerstreak@33 784 end
flickerstreak@33 785 )
flickerstreak@33 786 corner:SetScript("OnMouseUp",StopResize)
flickerstreak@33 787 corner:SetScript("OnEnter",
flickerstreak@33 788 function()
flickerstreak@33 789 GameTooltip:SetOwner(f, "ANCHOR_"..point)
flickerstreak@33 790 GameTooltip:AddLine(L["Drag to resize buttons"])
flickerstreak@33 791 GameTooltip:AddLine(L["Right-click-drag"])
flickerstreak@33 792 GameTooltip:AddLine(L["to change spacing"])
flickerstreak@33 793 local size, size2 = bar:GetButtonSize()
flickerstreak@33 794 local rows, cols, spacing = bar:GetButtonGrid()
flickerstreak@33 795 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
flickerstreak@33 796 GameTooltip:AddDoubleLine(L["Size:"], size)
flickerstreak@33 797 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
flickerstreak@33 798 GameTooltip:Show()
flickerstreak@33 799 end
flickerstreak@33 800 )
flickerstreak@33 801 corner:SetScript("OnLeave",
flickerstreak@33 802 function()
flickerstreak@33 803 GameTooltip:Hide()
flickerstreak@33 804 f:SetScript("OnUpdate",nil)
flickerstreak@33 805 end
flickerstreak@33 806 )
flickerstreak@33 807
flickerstreak@33 808 end
flickerstreak@33 809
flickerstreak@33 810 control:RegisterForDrag("LeftButton")
flickerstreak@33 811 control:RegisterForClicks("RightButtonDown")
flickerstreak@33 812
flickerstreak@33 813 control:SetScript("OnDragStart",
flickerstreak@33 814 function()
flickerstreak@33 815 f:StartMoving()
flickerstreak@33 816 f.isMoving = true
flickerstreak@52 817 local w,h = bar:GetButtonSize()
flickerstreak@52 818 f:ClearAllPoints()
flickerstreak@52 819 f:SetScript("OnUpdate", function()
flickerstreak@52 820 if IsShiftKeyDown() then
flickerstreak@52 821 DisplaySnapIndicator(f,w,h)
flickerstreak@52 822 else
flickerstreak@52 823 HideSnapIndicator()
flickerstreak@52 824 end
flickerstreak@52 825 end)
flickerstreak@33 826 end
flickerstreak@33 827 )
flickerstreak@33 828
flickerstreak@52 829 local function updateDragTooltip()
flickerstreak@52 830 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
flickerstreak@52 831 GameTooltip:AddLine(bar.name)
flickerstreak@52 832 GameTooltip:AddLine(L["Drag to move"])
flickerstreak@52 833 GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"]))
flickerstreak@52 834 GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"]))
flickerstreak@52 835 local _, a = bar:GetAnchor()
flickerstreak@52 836 if a and a ~= "UIParent" then
flickerstreak@52 837 GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a))
flickerstreak@52 838 end
flickerstreak@52 839 GameTooltip:Show()
flickerstreak@52 840 end
flickerstreak@52 841
flickerstreak@33 842 control:SetScript("OnDragStop",
flickerstreak@33 843 function()
flickerstreak@33 844 f:StopMovingOrSizing()
flickerstreak@33 845 f.isMoving = false
flickerstreak@33 846 f:SetScript("OnUpdate",nil)
flickerstreak@52 847
flickerstreak@52 848 if IsShiftKeyDown() then
flickerstreak@52 849 local w, h = bar:GetButtonSize()
flickerstreak@52 850 local a, p, rp, x, y = GetClosestPointSnapped(f,w,h)
flickerstreak@52 851 if a then
flickerstreak@52 852 f:ClearAllPoints()
flickerstreak@52 853 f:SetPoint(p,a,rp,x,y)
flickerstreak@52 854 end
flickerstreak@52 855 HideSnapIndicator()
flickerstreak@52 856 end
flickerstreak@52 857
flickerstreak@33 858 StoreExtents(bar)
flickerstreak@63 859 ReAction:RefreshOptions()
flickerstreak@52 860 updateDragTooltip()
flickerstreak@33 861 end
flickerstreak@33 862 )
flickerstreak@33 863
flickerstreak@33 864 control:SetScript("OnEnter",
flickerstreak@33 865 function()
flickerstreak@63 866 -- TODO: add bar type and status information to name
flickerstreak@63 867 --[[
flickerstreak@33 868 local name = bar.name
flickerstreak@33 869 for _, m in ReAction:IterateModules() do
flickerstreak@33 870 local suffix = safecall(m,"GetBarNameModifier",bar)
flickerstreak@33 871 if suffix then
flickerstreak@33 872 name = ("%s %s"):format(name,suffix)
flickerstreak@33 873 end
flickerstreak@33 874 end
flickerstreak@63 875 ]]--
flickerstreak@52 876
flickerstreak@52 877 updateDragTooltip()
flickerstreak@33 878 end
flickerstreak@33 879 )
flickerstreak@33 880
flickerstreak@33 881 control:SetScript("OnLeave", HideGameTooltip)
flickerstreak@33 882
flickerstreak@33 883 control:SetScript("OnClick",
flickerstreak@33 884 function()
flickerstreak@33 885 bar:ShowMenu()
flickerstreak@33 886 end
flickerstreak@33 887 )
flickerstreak@33 888
flickerstreak@33 889 return control
flickerstreak@33 890 end
flickerstreak@33 891 end
flickerstreak@33 892
flickerstreak@33 893
flickerstreak@33 894 local OpenMenu, CloseMenu
flickerstreak@33 895 do
flickerstreak@33 896 -- Looking for a lightweight AceConfig3-struct-compatible
flickerstreak@33 897 -- replacement for Dewdrop, encapsulate here
flickerstreak@33 898 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's
flickerstreak@33 899 -- a bit tricky to convert from AceConfig3-struct
flickerstreak@33 900 local Dewdrop = AceLibrary("Dewdrop-2.0")
flickerstreak@71 901 function OpenMenu (frame, opts)
flickerstreak@33 902 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true)
flickerstreak@33 903 end
flickerstreak@71 904 function CloseMenu(frame)
flickerstreak@33 905 if Dewdrop:GetOpenedParent() == frame then
flickerstreak@33 906 Dewdrop:Close()
flickerstreak@33 907 end
flickerstreak@33 908 end
flickerstreak@33 909 end
flickerstreak@33 910
flickerstreak@33 911
flickerstreak@33 912 function Bar:ShowControls(show)
flickerstreak@33 913 if show then
flickerstreak@33 914 if not self.controlFrame then
flickerstreak@33 915 self.controlFrame = CreateControls(self)
flickerstreak@33 916 end
flickerstreak@33 917 self.controlFrame:Show()
flickerstreak@33 918 elseif self.controlFrame then
flickerstreak@33 919 CloseMenu(self.controlFrame)
flickerstreak@33 920 self.controlFrame:Hide()
flickerstreak@33 921 end
flickerstreak@33 922 end
flickerstreak@33 923
flickerstreak@33 924 function Bar:ShowMenu()
flickerstreak@33 925 if not self.menuOpts then
flickerstreak@33 926 self.menuOpts = {
flickerstreak@33 927 type = "group",
flickerstreak@33 928 args = {
flickerstreak@33 929 openConfig = {
flickerstreak@33 930 type = "execute",
flickerstreak@58 931 name = L["Settings..."],
flickerstreak@58 932 desc = L["Open the editor for this bar"],
flickerstreak@63 933 func = function() CloseMenu(self.controlFrame); ReAction:ShowEditor(self) end,
flickerstreak@33 934 disabled = InCombatLockdown,
flickerstreak@33 935 order = 1
flickerstreak@33 936 },
flickerstreak@33 937 delete = {
flickerstreak@33 938 type = "execute",
flickerstreak@33 939 name = L["Delete Bar"],
flickerstreak@33 940 desc = L["Remove the bar from the current profile"],
flickerstreak@50 941 confirm = L["Are you sure you want to remove this bar?"],
flickerstreak@33 942 func = function() ReAction:EraseBar(self) end,
flickerstreak@33 943 order = 2
flickerstreak@33 944 },
flickerstreak@33 945 }
flickerstreak@33 946 }
flickerstreak@33 947 end
flickerstreak@33 948 OpenMenu(self.controlFrame, self.menuOpts)
flickerstreak@33 949 end
flickerstreak@33 950
flickerstreak@33 951
flickerstreak@33 952
flickerstreak@28 953 ------ Export as a class-factory ------
flickerstreak@28 954 ReAction.Bar = {
flickerstreak@28 955 new = function(self, ...)
flickerstreak@28 956 local x = { }
flickerstreak@28 957 for k,v in pairs(Bar) do
flickerstreak@28 958 x[k] = v
flickerstreak@28 959 end
flickerstreak@28 960 Constructor(x, ...)
flickerstreak@28 961 return x
flickerstreak@28 962 end
flickerstreak@28 963 }