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