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