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