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