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