flickerstreak@25
|
1 local ReAction = ReAction
|
flickerstreak@25
|
2 local L = ReAction.L
|
flickerstreak@25
|
3 local _G = _G
|
flickerstreak@25
|
4 local CreateFrame = CreateFrame
|
flickerstreak@33
|
5 local InCombatLockdown = InCombatLockdown
|
flickerstreak@33
|
6 local floor = math.floor
|
flickerstreak@33
|
7 local min = math.min
|
flickerstreak@33
|
8 local format = string.format
|
flickerstreak@33
|
9 local GameTooltip = GameTooltip
|
flickerstreak@71
|
10 local SecureStateHeader_Refresh = SecureStateHeader_Refresh
|
flickerstreak@33
|
11
|
flickerstreak@33
|
12
|
flickerstreak@25
|
13
|
flickerstreak@25
|
14 -- update ReAction revision if this file is newer
|
flickerstreak@33
|
15 local revision = tonumber(("$Revision$"):match("%d+"))
|
flickerstreak@25
|
16 if revision > ReAction.revision then
|
flickerstreak@52
|
17 ReAction.revision = revision
|
flickerstreak@25
|
18 end
|
flickerstreak@25
|
19
|
flickerstreak@28
|
20 ------ BAR CLASS ------
|
flickerstreak@28
|
21 local Bar = { _classID = {} }
|
flickerstreak@25
|
22
|
flickerstreak@28
|
23 local function Constructor( self, name, config )
|
flickerstreak@25
|
24 self.name, self.config = name, config
|
flickerstreak@68
|
25 self.buttons = setmetatable({},{__mode="k"})
|
flickerstreak@25
|
26
|
flickerstreak@25
|
27 if type(config) ~= "table" then
|
flickerstreak@28
|
28 error("ReAction.Bar: config table required")
|
flickerstreak@25
|
29 end
|
flickerstreak@25
|
30
|
flickerstreak@54
|
31 local parent = config.parent and (ReAction:GetBar(config.parent) or _G[config.parent]) or UIParent
|
flickerstreak@68
|
32 local f = CreateFrame("Frame",nil,parent,"SecureStateHeaderTemplate")
|
flickerstreak@25
|
33 f:SetFrameStrata("MEDIUM")
|
flickerstreak@30
|
34 config.width = config.width or 480
|
flickerstreak@30
|
35 config.height = config.height or 40
|
flickerstreak@25
|
36 f:SetWidth(config.width)
|
flickerstreak@25
|
37 f:SetWidth(config.height)
|
flickerstreak@25
|
38
|
flickerstreak@63
|
39 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@63
|
40
|
flickerstreak@25
|
41 self.frame = f
|
flickerstreak@25
|
42 self:ApplyAnchor()
|
flickerstreak@25
|
43 f:Show()
|
flickerstreak@68
|
44 self:RefreshLayout()
|
flickerstreak@25
|
45 end
|
flickerstreak@25
|
46
|
flickerstreak@25
|
47 function Bar:Destroy()
|
flickerstreak@25
|
48 local f = self.frame
|
flickerstreak@25
|
49 f:UnregisterAllEvents()
|
flickerstreak@25
|
50 f:Hide()
|
flickerstreak@25
|
51 f:SetParent(UIParent)
|
flickerstreak@25
|
52 f:ClearAllPoints()
|
flickerstreak@63
|
53 ReAction.UnregisterAllCallbacks(self)
|
flickerstreak@72
|
54 if self.statedriver then
|
flickerstreak@72
|
55 UnregisterStateDriver(f, "reaction")
|
flickerstreak@72
|
56 end
|
flickerstreak@25
|
57 self.labelString = nil
|
flickerstreak@25
|
58 self.controlFrame = nil
|
flickerstreak@25
|
59 self.frame = nil
|
flickerstreak@25
|
60 self.config = nil
|
flickerstreak@25
|
61 end
|
flickerstreak@25
|
62
|
flickerstreak@63
|
63 function Bar:OnConfigModeChanged(event, mode)
|
flickerstreak@63
|
64 self:ShowControls(mode)
|
flickerstreak@63
|
65 end
|
flickerstreak@63
|
66
|
flickerstreak@25
|
67 function Bar:RefreshLayout()
|
flickerstreak@63
|
68 ReAction:RefreshBar(self)
|
flickerstreak@25
|
69 end
|
flickerstreak@25
|
70
|
flickerstreak@25
|
71 function Bar:ApplyAnchor()
|
flickerstreak@25
|
72 local f, config = self.frame, self.config
|
flickerstreak@25
|
73 f:SetWidth(config.width)
|
flickerstreak@25
|
74 f:SetHeight(config.height)
|
flickerstreak@25
|
75 local anchor = config.anchor
|
flickerstreak@51
|
76 f:ClearAllPoints()
|
flickerstreak@25
|
77 if anchor then
|
flickerstreak@52
|
78 local anchorTo = f:GetParent()
|
flickerstreak@25
|
79 if config.anchorTo then
|
flickerstreak@52
|
80 local bar = ReAction:GetBar(config.anchorTo)
|
flickerstreak@52
|
81 if bar then
|
flickerstreak@52
|
82 anchorTo = bar:GetFrame()
|
flickerstreak@52
|
83 else
|
flickerstreak@52
|
84 anchorTo = _G[config.anchorTo]
|
flickerstreak@52
|
85 end
|
flickerstreak@25
|
86 end
|
flickerstreak@52
|
87 f:SetPoint(anchor, anchorTo or f:GetParent(), config.relativePoint, config.x or 0, config.y or 0)
|
flickerstreak@25
|
88 else
|
flickerstreak@25
|
89 f:SetPoint("CENTER")
|
flickerstreak@25
|
90 end
|
flickerstreak@25
|
91 end
|
flickerstreak@25
|
92
|
flickerstreak@51
|
93 function Bar:SetAnchor(point, frame, relativePoint, x, y)
|
flickerstreak@51
|
94 local c = self.config
|
flickerstreak@51
|
95 c.anchor = point or c.anchor
|
flickerstreak@51
|
96 c.anchorTo = frame and frame:GetName() or c.anchorTo
|
flickerstreak@51
|
97 c.relativePoint = relativePoint or c.relativePoint
|
flickerstreak@51
|
98 c.x = x or c.x
|
flickerstreak@51
|
99 c.y = y or c.y
|
flickerstreak@51
|
100 self:ApplyAnchor()
|
flickerstreak@51
|
101 end
|
flickerstreak@51
|
102
|
flickerstreak@51
|
103 function Bar:GetAnchor()
|
flickerstreak@51
|
104 local c = self.config
|
flickerstreak@51
|
105 return (c.anchor or "CENTER"), (c.anchorTo or self.frame:GetParent():GetName()), (c.relativePoint or c.anchor or "CENTER"), (c.x or 0), (c.y or 0)
|
flickerstreak@51
|
106 end
|
flickerstreak@51
|
107
|
flickerstreak@25
|
108 function Bar:GetFrame()
|
flickerstreak@25
|
109 return self.frame
|
flickerstreak@25
|
110 end
|
flickerstreak@25
|
111
|
flickerstreak@25
|
112 function Bar:GetSize()
|
flickerstreak@25
|
113 return self.frame:GetWidth() or 200, self.frame:GetHeight() or 200
|
flickerstreak@25
|
114 end
|
flickerstreak@25
|
115
|
flickerstreak@25
|
116 function Bar:SetSize(w,h)
|
flickerstreak@25
|
117 self.config.width = w
|
flickerstreak@25
|
118 self.config.height = h
|
flickerstreak@25
|
119 end
|
flickerstreak@25
|
120
|
flickerstreak@25
|
121 function Bar:GetButtonSize()
|
flickerstreak@25
|
122 local w = self.config.btnWidth or 32
|
flickerstreak@25
|
123 local h = self.config.btnHeight or 32
|
flickerstreak@25
|
124 -- TODO: get from modules?
|
flickerstreak@25
|
125 return w,h
|
flickerstreak@25
|
126 end
|
flickerstreak@25
|
127
|
flickerstreak@25
|
128 function Bar:SetButtonSize(w,h)
|
flickerstreak@25
|
129 if w > 0 and h > 0 then
|
flickerstreak@25
|
130 self.config.btnWidth = w
|
flickerstreak@25
|
131 self.config.btnHeight = h
|
flickerstreak@25
|
132 end
|
flickerstreak@25
|
133 end
|
flickerstreak@25
|
134
|
flickerstreak@25
|
135 function Bar:GetButtonGrid()
|
flickerstreak@25
|
136 local cfg = self.config
|
flickerstreak@25
|
137 local r = cfg.btnRows or 1
|
flickerstreak@25
|
138 local c = cfg.btnColumns or 1
|
flickerstreak@25
|
139 local s = cfg.spacing or 4
|
flickerstreak@25
|
140 return r,c,s
|
flickerstreak@25
|
141 end
|
flickerstreak@25
|
142
|
flickerstreak@25
|
143 function Bar:SetButtonGrid(r,c,s)
|
flickerstreak@25
|
144 if r > 0 and c > 0 and s > 0 then
|
flickerstreak@25
|
145 local cfg = self.config
|
flickerstreak@25
|
146 cfg.btnRows = r
|
flickerstreak@25
|
147 cfg.btnColumns = c
|
flickerstreak@25
|
148 cfg.spacing = s
|
flickerstreak@25
|
149 end
|
flickerstreak@25
|
150 end
|
flickerstreak@25
|
151
|
flickerstreak@25
|
152 function Bar:GetName()
|
flickerstreak@25
|
153 return self.name
|
flickerstreak@25
|
154 end
|
flickerstreak@25
|
155
|
flickerstreak@33
|
156 function Bar:SetName(name)
|
flickerstreak@33
|
157 self.name = name
|
flickerstreak@33
|
158 if self.controlLabelString then
|
flickerstreak@33
|
159 self.controlLabelString:SetText(self.name)
|
flickerstreak@33
|
160 end
|
flickerstreak@33
|
161 end
|
flickerstreak@33
|
162
|
flickerstreak@25
|
163 function Bar:PlaceButton(f, idx, baseW, baseH)
|
flickerstreak@25
|
164 local r, c, s = self:GetButtonGrid()
|
flickerstreak@25
|
165 local bh, bw = self:GetButtonSize()
|
flickerstreak@25
|
166 local row, col = floor((idx-1)/c), mod((idx-1),c) -- zero-based
|
flickerstreak@25
|
167 local x, y = col*bw + (col+0.5)*s, row*bh + (row+0.5)*s
|
flickerstreak@25
|
168 local scale = bw/baseW
|
flickerstreak@25
|
169
|
flickerstreak@25
|
170 f:ClearAllPoints()
|
flickerstreak@25
|
171 f:SetPoint("TOPLEFT",x/scale,-y/scale)
|
flickerstreak@25
|
172 f:SetScale(scale)
|
flickerstreak@68
|
173 self.buttons[f] = true
|
flickerstreak@25
|
174 end
|
flickerstreak@25
|
175
|
flickerstreak@71
|
176
|
flickerstreak@71
|
177 -- multi-state functions --
|
flickerstreak@68
|
178 function Bar:GetNumPages()
|
flickerstreak@68
|
179 return self.config.nPages or 1
|
flickerstreak@68
|
180 end
|
flickerstreak@28
|
181
|
flickerstreak@72
|
182 --
|
flickerstreak@72
|
183 -- 'rule' is a rule-string to pass to RegisterStateDriver
|
flickerstreak@72
|
184 -- 'states' is a { ["statename"] = <don't care> } table of all state names
|
flickerstreak@72
|
185 -- 'keybinds' is a { ["statename"] = keybind } table of all keybound states
|
flickerstreak@72
|
186 --
|
flickerstreak@72
|
187 function Bar:SetStateDriver( rule, states, keybinds )
|
flickerstreak@72
|
188 local f = self.frame
|
flickerstreak@72
|
189 local kbprefix = ""
|
flickerstreak@72
|
190 do
|
flickerstreak@72
|
191 local tmp = { }
|
flickerstreak@72
|
192 for s, k in pairs(keybinds) do
|
flickerstreak@72
|
193 if k and #k > 0 then -- filter out false table entries
|
flickerstreak@72
|
194 -- if in a keybound state, set the stack to the new state but stay in the keybound state.
|
flickerstreak@72
|
195 -- use $s as a placeholder for the current state, it will be gsub()'d in later
|
flickerstreak@72
|
196 table.insert(tmp,("%s:$s set() %s"):format(s,s))
|
flickerstreak@72
|
197 end
|
flickerstreak@72
|
198 end
|
flickerstreak@72
|
199 table.insert(tmp,kbprefix) -- to get a trailing ';' if the table is not empty
|
flickerstreak@72
|
200 kbprefix = table.concat(tmp,";")
|
flickerstreak@72
|
201 end
|
flickerstreak@72
|
202 for state in pairs(states) do
|
flickerstreak@72
|
203 -- For all states: if in a keybound state, stay there (with stack manipulation, see above).
|
flickerstreak@72
|
204 -- Otherwise, go to the state
|
flickerstreak@72
|
205 f:SetAttribute(("statemap-reaction-%s"):format(state),("%s%s"):format(kbprefix:gsub("%$s",state),state))
|
flickerstreak@72
|
206
|
flickerstreak@72
|
207 local binding = keybinds[state]
|
flickerstreak@72
|
208 self:SetStateKeybind(binding, state) -- set the binding even if nil, to clear it unconditionally
|
flickerstreak@72
|
209 if binding then
|
flickerstreak@72
|
210 -- for key bindings, use the state-stack to toggle between the last state and the keybound state
|
flickerstreak@72
|
211 -- use a different 'virtual state' passed to attribute 'reaction-state' for key bindings, "<state>_binding"
|
flickerstreak@72
|
212 f:SetAttribute(("statemap-reaction-%s_binding"):format(state), ("%s:pop();*:set(%s)"):format(state,state))
|
flickerstreak@72
|
213 end
|
flickerstreak@72
|
214 end
|
flickerstreak@72
|
215
|
flickerstreak@72
|
216 if rule and #rule > 0 then
|
flickerstreak@72
|
217 self.stateDriver = true
|
flickerstreak@72
|
218 RegisterStateDriver(f, "reaction", rule)
|
flickerstreak@72
|
219 elseif self.statedriver then
|
flickerstreak@72
|
220 self.statedriver = false
|
flickerstreak@72
|
221 UnregisterStateDriver(f, "reaction")
|
flickerstreak@72
|
222 end
|
flickerstreak@72
|
223 end
|
flickerstreak@72
|
224
|
flickerstreak@68
|
225 function Bar:SetHideStates(s)
|
flickerstreak@68
|
226 for f in pairs(self.buttons) do
|
flickerstreak@68
|
227 if f:GetParent() == self.frame then
|
flickerstreak@68
|
228 f:SetAttribute("hidestates",s)
|
flickerstreak@68
|
229 end
|
flickerstreak@68
|
230 end
|
flickerstreak@68
|
231 SecureStateHeader_Refresh(self.frame)
|
flickerstreak@68
|
232 end
|
flickerstreak@28
|
233
|
flickerstreak@70
|
234 function Bar:SetStateKeybind(key, state, defaultstate)
|
flickerstreak@72
|
235 -- Lazily create a tiny offscreen button which sends "<state>_binding" values to the
|
flickerstreak@72
|
236 -- bar frame's state-reaction attribute, by using an override binding to generate a
|
flickerstreak@72
|
237 -- click on the button with a virtual mouse button "state".
|
flickerstreak@72
|
238 -- This gets around making the bar itself a clickable button, which is not desirable
|
flickerstreak@68
|
239 local f = self.statebuttonframe
|
flickerstreak@70
|
240 if key then
|
flickerstreak@68
|
241 if not f then
|
flickerstreak@72
|
242 f = CreateFrame("Button",self:GetName().."_statebutton",self.frame,"SecureActionButtonTemplate")
|
flickerstreak@68
|
243 f:SetPoint("BOTTOMRIGHT",UIParent,"TOPLEFT")
|
flickerstreak@68
|
244 f:SetWidth(1)
|
flickerstreak@68
|
245 f:SetHeight(1)
|
flickerstreak@72
|
246 f:SetAttribute("type*","attribute")
|
flickerstreak@72
|
247 f:SetAttribute("attribute-name*","state-reaction")
|
flickerstreak@72
|
248 f:SetAttribute("attribute-frame*",self.frame)
|
flickerstreak@68
|
249 f:Show()
|
flickerstreak@72
|
250 f.bindings = { }
|
flickerstreak@68
|
251 self.statebuttonframe = f
|
flickerstreak@68
|
252 end
|
flickerstreak@72
|
253 f:SetAttribute(("attribute-value-%s"):format(state),("%s_binding"):format(state))
|
flickerstreak@72
|
254 -- clear the old binding, if any, for this state
|
flickerstreak@72
|
255 if f.bindings[state] then
|
flickerstreak@72
|
256 SetOverrideBinding(self.frame, false, f.bindings[state], nil)
|
flickerstreak@72
|
257 end
|
flickerstreak@72
|
258 SetOverrideBindingClick(self.frame, false, key, f:GetName(), state) -- the state name is used as the virtual button
|
flickerstreak@72
|
259 f.bindings[state] = key
|
flickerstreak@68
|
260 elseif f then
|
flickerstreak@72
|
261 key = f.bindings[state]
|
flickerstreak@70
|
262 if key then
|
flickerstreak@72
|
263 SetOverrideBinding(self.frame, false, key, nil)
|
flickerstreak@72
|
264 f.bindings[state] = nil
|
flickerstreak@70
|
265 end
|
flickerstreak@68
|
266 end
|
flickerstreak@68
|
267 end
|
flickerstreak@33
|
268
|
flickerstreak@68
|
269 function Bar:SetStatePageMap(state, map) -- map is a { ["statename"] = pagenumber } table
|
flickerstreak@68
|
270 local f = self.frame
|
flickerstreak@68
|
271 local tmp = { }
|
flickerstreak@68
|
272 for s, p in pairs(map) do
|
flickerstreak@71
|
273 table.insert(tmp, ("%s:page%d"):format(s,p))
|
flickerstreak@68
|
274 end
|
flickerstreak@68
|
275 local spec = table.concat(tmp,";")
|
flickerstreak@72
|
276 local current = f:GetAttribute("statebutton")
|
flickerstreak@72
|
277 if spec ~= f:GetAttribute("statebutton") then
|
flickerstreak@72
|
278 f:SetAttribute("statebutton", spec)
|
flickerstreak@72
|
279 end
|
flickerstreak@71
|
280 SecureStateHeader_Refresh(f)
|
flickerstreak@68
|
281 end
|
flickerstreak@33
|
282
|
flickerstreak@68
|
283 function Bar:SetStateKeybindOverrideMap(states) -- 'states' is an array of state-names that should have keybind overrides enabled
|
flickerstreak@68
|
284 local f = self.frame
|
flickerstreak@68
|
285 for i = 1, #states do
|
flickerstreak@68
|
286 local s = states[i]
|
flickerstreak@68
|
287 states[i] = ("%s:%s"):format(s,s)
|
flickerstreak@68
|
288 end
|
flickerstreak@71
|
289 table.insert(states,"_defaultbindings")
|
flickerstreak@68
|
290 f:SetAttribute("statebindings",table.concat(states,";"))
|
flickerstreak@71
|
291 SecureStateHeader_Refresh(f)
|
flickerstreak@68
|
292 for b in pairs(self.buttons) do
|
flickerstreak@71
|
293 -- TODO: signal child frames that they should maintain multiple bindings
|
flickerstreak@68
|
294 end
|
flickerstreak@68
|
295 end
|
flickerstreak@33
|
296
|
flickerstreak@71
|
297 local _ofskeys = { "point", "relpoint", "x", "y" }
|
flickerstreak@71
|
298 function Bar:SetStateAnchorMap( map ) -- 'map' is a { ["statename"] = { point=point, relpoint=relpoint, x=x, y=y } } table
|
flickerstreak@71
|
299 local f = self.frame
|
flickerstreak@71
|
300 local c = self.config
|
flickerstreak@71
|
301 local default = { point = c.anchor, relpoint = c.relativePoint, x = c.x, y = c.y }
|
flickerstreak@71
|
302 for _, key in pairs(_ofskeys) do
|
flickerstreak@71
|
303 local t = { }
|
flickerstreak@71
|
304 for state, info in pairs(map) do
|
flickerstreak@71
|
305 if info[key] then
|
flickerstreak@71
|
306 table.insert(t, ("%s:%s"):format(state, info[key]))
|
flickerstreak@71
|
307 end
|
flickerstreak@71
|
308 end
|
flickerstreak@71
|
309 if #t > 0 and default[key] then table.insert(t, tostring(default[key])) end
|
flickerstreak@71
|
310 f:SetAttribute(("headofs%s"):format(key), table.concat(t,";") or "")
|
flickerstreak@71
|
311 end
|
flickerstreak@71
|
312 SecureStateHeader_Refresh(f)
|
flickerstreak@71
|
313 end
|
flickerstreak@71
|
314
|
flickerstreak@71
|
315 function Bar:SetStateScaleMap( map ) -- 'map' is a { ["statename"] = scalevalue } table
|
flickerstreak@71
|
316 local f = self.frame
|
flickerstreak@71
|
317 local t = { }
|
flickerstreak@71
|
318 for state, scale in pairs(map) do
|
flickerstreak@71
|
319 table.insert( t, ("%s:%s"):format(state,scale) )
|
flickerstreak@71
|
320 end
|
flickerstreak@71
|
321 if #t > 0 then table.insert(t, "1.0") end
|
flickerstreak@71
|
322 f:SetAttribute("headscale",table.concat(t,";") or "")
|
flickerstreak@71
|
323 SecureStateHeader_Refresh(f)
|
flickerstreak@71
|
324 end
|
flickerstreak@71
|
325
|
flickerstreak@71
|
326
|
flickerstreak@33
|
327 --
|
flickerstreak@33
|
328 -- Bar config overlay
|
flickerstreak@33
|
329 --
|
flickerstreak@52
|
330 local CreateControls
|
flickerstreak@33
|
331
|
flickerstreak@33
|
332 do
|
flickerstreak@33
|
333 -- upvalue some of these for small OnUpdate performance boost
|
flickerstreak@33
|
334 local GetSize = Bar.GetSize
|
flickerstreak@33
|
335 local GetButtonSize = Bar.GetButtonSize
|
flickerstreak@33
|
336 local GetButtonGrid = Bar.GetButtonGrid
|
flickerstreak@33
|
337 local SetSize = Bar.SetSize
|
flickerstreak@33
|
338 local SetButtonSize = Bar.SetButtonSize
|
flickerstreak@33
|
339 local SetButtonGrid = Bar.SetButtonGrid
|
flickerstreak@33
|
340 local ApplyAnchor = Bar.ApplyAnchor
|
flickerstreak@33
|
341
|
flickerstreak@52
|
342 local function StoreExtents(bar)
|
flickerstreak@33
|
343 local f = bar.frame
|
flickerstreak@33
|
344 local point, relativeTo, relativePoint, x, y = f:GetPoint(1)
|
flickerstreak@33
|
345 relativeTo = relativeTo or f:GetParent()
|
flickerstreak@33
|
346 local anchorTo
|
flickerstreak@63
|
347 for name, b in ReAction:IterateBars() do
|
flickerstreak@52
|
348 if b and b:GetFrame() == relativeTo then
|
flickerstreak@52
|
349 anchorTo = name
|
flickerstreak@52
|
350 break
|
flickerstreak@33
|
351 end
|
flickerstreak@33
|
352 end
|
flickerstreak@33
|
353 anchorTo = anchorTo or relativeTo:GetName()
|
flickerstreak@33
|
354 local c = bar.config
|
flickerstreak@33
|
355 c.anchor = point
|
flickerstreak@33
|
356 c.anchorTo = anchorTo
|
flickerstreak@33
|
357 c.relativePoint = relativePoint
|
flickerstreak@33
|
358 c.x = x
|
flickerstreak@33
|
359 c.y = y
|
flickerstreak@33
|
360 c.width, c.height = f:GetWidth(), f:GetHeight()
|
flickerstreak@33
|
361 end
|
flickerstreak@33
|
362
|
flickerstreak@52
|
363 local function StoreSize(bar)
|
flickerstreak@52
|
364 local f = bar.frame
|
flickerstreak@52
|
365 local c = bar.config
|
flickerstreak@52
|
366 c.width, c.height = f:GetWidth(), f:GetHeight()
|
flickerstreak@52
|
367 end
|
flickerstreak@52
|
368
|
flickerstreak@52
|
369 local function RecomputeButtonSize(bar)
|
flickerstreak@33
|
370 local w, h = GetSize(bar)
|
flickerstreak@33
|
371 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
372 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
373
|
flickerstreak@33
|
374 local scaleW = (floor(w/c) - s) / bw
|
flickerstreak@33
|
375 local scaleH = (floor(h/r) - s) / bh
|
flickerstreak@33
|
376 local scale = min(scaleW, scaleH)
|
flickerstreak@33
|
377
|
flickerstreak@33
|
378 SetButtonSize(bar, scale * bw, scale * bh, s)
|
flickerstreak@33
|
379 end
|
flickerstreak@33
|
380
|
flickerstreak@52
|
381 local function RecomputeButtonSpacing(bar)
|
flickerstreak@33
|
382 local w, h = GetSize(bar)
|
flickerstreak@33
|
383 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
384 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
385
|
flickerstreak@33
|
386 SetButtonGrid(bar,r,c,min(floor(w/c) - bw, floor(h/r) - bh))
|
flickerstreak@33
|
387 end
|
flickerstreak@33
|
388
|
flickerstreak@52
|
389 local function RecomputeGrid(bar)
|
flickerstreak@33
|
390 local w, h = GetSize(bar)
|
flickerstreak@33
|
391 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
392 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
393
|
flickerstreak@33
|
394 SetButtonGrid(bar, floor(h/(bh+s)), floor(w/(bw+s)), s)
|
flickerstreak@33
|
395 end
|
flickerstreak@33
|
396
|
flickerstreak@52
|
397 local function ClampToButtons(bar)
|
flickerstreak@33
|
398 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
399 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@50
|
400 SetSize(bar, (bw+s)*c + 1, (bh+s)*r + 1)
|
flickerstreak@33
|
401 end
|
flickerstreak@33
|
402
|
flickerstreak@52
|
403 local function HideGameTooltip()
|
flickerstreak@33
|
404 GameTooltip:Hide()
|
flickerstreak@33
|
405 end
|
flickerstreak@33
|
406
|
flickerstreak@52
|
407 local anchorInside = { inside = true }
|
flickerstreak@52
|
408 local anchorOutside = { outside = true }
|
flickerstreak@52
|
409 local edges = { "BOTTOM", "TOP", "LEFT", "RIGHT" }
|
flickerstreak@52
|
410 local oppositeEdges = {
|
flickerstreak@52
|
411 TOP = "BOTTOM",
|
flickerstreak@52
|
412 BOTTOM = "TOP",
|
flickerstreak@52
|
413 LEFT = "RIGHT",
|
flickerstreak@52
|
414 RIGHT = "LEFT"
|
flickerstreak@52
|
415 }
|
flickerstreak@52
|
416 local pointsOnEdge = {
|
flickerstreak@52
|
417 BOTTOM = { "BOTTOM", "BOTTOMLEFT", "BOTTOMRIGHT", },
|
flickerstreak@52
|
418 TOP = { "TOP", "TOPLEFT", "TOPRIGHT", },
|
flickerstreak@52
|
419 RIGHT = { "RIGHT", "BOTTOMRIGHT", "TOPRIGHT", },
|
flickerstreak@52
|
420 LEFT = { "LEFT", "BOTTOMLEFT", "TOPLEFT", },
|
flickerstreak@52
|
421 }
|
flickerstreak@52
|
422 local edgeSelector = {
|
flickerstreak@52
|
423 BOTTOM = 1, -- select x of x,y
|
flickerstreak@52
|
424 TOP = 1, -- select x of x,y
|
flickerstreak@52
|
425 LEFT = 2, -- select y of x,y
|
flickerstreak@52
|
426 RIGHT = 2, -- select y of x,y
|
flickerstreak@52
|
427 }
|
flickerstreak@52
|
428 local snapPoints = {
|
flickerstreak@52
|
429 [anchorOutside] = {
|
flickerstreak@52
|
430 BOTTOMLEFT = {"BOTTOMRIGHT","TOPLEFT","TOPRIGHT"},
|
flickerstreak@52
|
431 BOTTOM = {"TOP"},
|
flickerstreak@52
|
432 BOTTOMRIGHT = {"BOTTOMLEFT","TOPRIGHT","TOPLEFT"},
|
flickerstreak@52
|
433 RIGHT = {"LEFT"},
|
flickerstreak@52
|
434 TOPRIGHT = {"TOPLEFT","BOTTOMRIGHT","BOTTOMLEFT"},
|
flickerstreak@52
|
435 TOP = {"BOTTOM"},
|
flickerstreak@52
|
436 TOPLEFT = {"TOPRIGHT","BOTTOMLEFT","BOTTOMRIGHT"},
|
flickerstreak@52
|
437 LEFT = {"RIGHT"},
|
flickerstreak@52
|
438 CENTER = {"CENTER"}
|
flickerstreak@52
|
439 },
|
flickerstreak@52
|
440 [anchorInside] = {
|
flickerstreak@52
|
441 BOTTOMLEFT = {"BOTTOMLEFT"},
|
flickerstreak@52
|
442 BOTTOM = {"BOTTOM"},
|
flickerstreak@52
|
443 BOTTOMRIGHT = {"BOTTOMRIGHT"},
|
flickerstreak@52
|
444 RIGHT = {"RIGHT"},
|
flickerstreak@52
|
445 TOPRIGHT = {"TOPRIGHT"},
|
flickerstreak@52
|
446 TOP = {"TOP"},
|
flickerstreak@52
|
447 TOPLEFT = {"TOPLEFT"},
|
flickerstreak@52
|
448 LEFT = {"LEFT"},
|
flickerstreak@52
|
449 CENTER = {"CENTER"}
|
flickerstreak@52
|
450 }
|
flickerstreak@52
|
451 }
|
flickerstreak@52
|
452 local insidePointOffsetFuncs = {
|
flickerstreak@52
|
453 BOTTOMLEFT = function(x, y) return x, y end,
|
flickerstreak@52
|
454 BOTTOM = function(x, y) return 0, y end,
|
flickerstreak@52
|
455 BOTTOMRIGHT = function(x, y) return -x, y end,
|
flickerstreak@52
|
456 RIGHT = function(x, y) return -x, 0 end,
|
flickerstreak@52
|
457 TOPRIGHT = function(x, y) return -x, -y end,
|
flickerstreak@52
|
458 TOP = function(x, y) return 0, -y end,
|
flickerstreak@52
|
459 TOPLEFT = function(x, y) return x, -y end,
|
flickerstreak@52
|
460 LEFT = function(x, y) return x, 0 end,
|
flickerstreak@52
|
461 CENTER = function(x, y) return 0, 0 end,
|
flickerstreak@52
|
462 }
|
flickerstreak@52
|
463 local pointCoordFuncs = {
|
flickerstreak@52
|
464 BOTTOMLEFT = function(f) return f:GetLeft(), f:GetBottom() end,
|
flickerstreak@52
|
465 BOTTOM = function(f) return nil, f:GetBottom() end,
|
flickerstreak@52
|
466 BOTTOMRIGHT = function(f) return f:GetRight(), f:GetBottom() end,
|
flickerstreak@52
|
467 RIGHT = function(f) return f:GetRight(), nil end,
|
flickerstreak@52
|
468 TOPRIGHT = function(f) return f:GetRight(), f:GetTop() end,
|
flickerstreak@52
|
469 TOP = function(f) return nil, f:GetTop() end,
|
flickerstreak@52
|
470 TOPLEFT = function(f) return f:GetLeft(), f:GetTop() end,
|
flickerstreak@52
|
471 LEFT = function(f) return f:GetLeft(), nil end,
|
flickerstreak@52
|
472 CENTER = function(f) return f:GetCenter() end,
|
flickerstreak@52
|
473 }
|
flickerstreak@52
|
474 local edgeBoundsFuncs = {
|
flickerstreak@52
|
475 BOTTOM = function(f) return f:GetLeft(), f:GetRight() end,
|
flickerstreak@52
|
476 LEFT = function(f) return f:GetBottom(), f:GetTop() end
|
flickerstreak@52
|
477 }
|
flickerstreak@52
|
478 edgeBoundsFuncs.TOP = edgeBoundsFuncs.BOTTOM
|
flickerstreak@52
|
479 edgeBoundsFuncs.RIGHT = edgeBoundsFuncs.LEFT
|
flickerstreak@52
|
480
|
flickerstreak@52
|
481
|
flickerstreak@52
|
482 -- Returns absolute coordinates x,y of the named point 'p' of frame 'f'
|
flickerstreak@52
|
483 local function GetPointCoords( f, p )
|
flickerstreak@52
|
484 local x, y = pointCoordFuncs[p](f)
|
flickerstreak@52
|
485 if not(x and y) then
|
flickerstreak@52
|
486 local cx, cy = f:GetCenter()
|
flickerstreak@52
|
487 x = x or cx
|
flickerstreak@52
|
488 y = y or cy
|
flickerstreak@52
|
489 end
|
flickerstreak@52
|
490 return x, y
|
flickerstreak@52
|
491 end
|
flickerstreak@52
|
492
|
flickerstreak@52
|
493
|
flickerstreak@52
|
494 -- Returns true if frame 'f1' can be anchored to frame 'f2'
|
flickerstreak@52
|
495 local function CheckAnchorable( f1, f2 )
|
flickerstreak@52
|
496 -- can't anchor a frame to itself or to nil
|
flickerstreak@52
|
497 if f1 == f2 or f2 == nil then
|
flickerstreak@52
|
498 return false
|
flickerstreak@52
|
499 end
|
flickerstreak@52
|
500
|
flickerstreak@52
|
501 -- can always anchor to UIParent
|
flickerstreak@52
|
502 if f2 == UIParent then
|
flickerstreak@52
|
503 return true
|
flickerstreak@52
|
504 end
|
flickerstreak@52
|
505
|
flickerstreak@52
|
506 -- also can't do circular anchoring of frames
|
flickerstreak@52
|
507 -- walk the anchor chain, which generally shouldn't be that expensive
|
flickerstreak@52
|
508 -- (who nests draggables that deep anyway?)
|
flickerstreak@52
|
509 for i = 1, f2:GetNumPoints() do
|
flickerstreak@52
|
510 local _, f = f2:GetPoint(i)
|
flickerstreak@52
|
511 if not f then f = f2:GetParent() end
|
flickerstreak@52
|
512 return CheckAnchorable(f1,f)
|
flickerstreak@52
|
513 end
|
flickerstreak@52
|
514
|
flickerstreak@52
|
515 return true
|
flickerstreak@52
|
516 end
|
flickerstreak@52
|
517
|
flickerstreak@52
|
518 -- Returns true if frames f1 and f2 specified edges overlap
|
flickerstreak@52
|
519 local function CheckEdgeOverlap( f1, f2, e )
|
flickerstreak@52
|
520 local l1, u1 = edgeBoundsFuncs[e](f1)
|
flickerstreak@52
|
521 local l2, u2 = edgeBoundsFuncs[e](f2)
|
flickerstreak@52
|
522 return l1 <= l2 and l2 <= u1 or l2 <= l1 and l1 <= u2
|
flickerstreak@52
|
523 end
|
flickerstreak@52
|
524
|
flickerstreak@52
|
525 -- Returns true if point p1 on frame f1 overlaps edge e2 on frame f2
|
flickerstreak@52
|
526 local function CheckPointEdgeOverlap( f1, p1, f2, e2 )
|
flickerstreak@52
|
527 local l, u = edgeBoundsFuncs[e2](f2)
|
flickerstreak@52
|
528 local x, y = GetPointCoords(f1,p1)
|
flickerstreak@52
|
529 x = select(edgeSelector[e2], x, y)
|
flickerstreak@52
|
530 return l <= x and x <= u
|
flickerstreak@52
|
531 end
|
flickerstreak@52
|
532
|
flickerstreak@52
|
533 -- Returns the distance between corresponding edges. It is
|
flickerstreak@52
|
534 -- assumed that the passed in edges e1 and e2 are the same or opposites
|
flickerstreak@52
|
535 local function GetEdgeDistance( f1, f2, e1, e2 )
|
flickerstreak@52
|
536 local x1, y1 = pointCoordFuncs[e1](f1)
|
flickerstreak@52
|
537 local x2, y2 = pointCoordFuncs[e2](f2)
|
flickerstreak@52
|
538 return math.abs((x1 or y1) - (x2 or y2))
|
flickerstreak@52
|
539 end
|
flickerstreak@52
|
540
|
flickerstreak@52
|
541 local globalSnapTargets = { [UIParent] = anchorInside }
|
flickerstreak@52
|
542
|
flickerstreak@52
|
543 local function GetClosestFrameEdge(f1,f2,a)
|
flickerstreak@52
|
544 local dist, edge, opp
|
flickerstreak@52
|
545 if f2:IsVisible() and CheckAnchorable(f1,f2) then
|
flickerstreak@52
|
546 for _, e in pairs(edges) do
|
flickerstreak@52
|
547 local o = a.inside and e or oppositeEdges[e]
|
flickerstreak@52
|
548 if CheckEdgeOverlap(f1,f2,e) then
|
flickerstreak@52
|
549 local d = GetEdgeDistance(f1, f2, e, o)
|
flickerstreak@52
|
550 if not dist or (d < dist) then
|
flickerstreak@52
|
551 dist, edge, opp = d, e, o
|
flickerstreak@52
|
552 end
|
flickerstreak@52
|
553 end
|
flickerstreak@52
|
554 end
|
flickerstreak@52
|
555 end
|
flickerstreak@52
|
556 return dist, edge, opp
|
flickerstreak@52
|
557 end
|
flickerstreak@52
|
558
|
flickerstreak@52
|
559 local function GetClosestVisibleEdge( f )
|
flickerstreak@52
|
560 local r, o, e1, e2
|
flickerstreak@52
|
561 local a = anchorOutside
|
flickerstreak@63
|
562 for _, b in ReAction:IterateBars() do
|
flickerstreak@52
|
563 local d, e, opp = GetClosestFrameEdge(f,b:GetFrame(),a)
|
flickerstreak@52
|
564 if d and (not r or d < r) then
|
flickerstreak@52
|
565 r, o, e1, e2 = d, b:GetFrame(), e, opp
|
flickerstreak@52
|
566 end
|
flickerstreak@52
|
567 end
|
flickerstreak@52
|
568 for f2, a2 in pairs(globalSnapTargets) do
|
flickerstreak@52
|
569 local d, e, opp = GetClosestFrameEdge(f,f2,a2)
|
flickerstreak@52
|
570 if d and (not r or d < r) then
|
flickerstreak@52
|
571 r, o, e1, e2, a = d, f2, e, opp, a2
|
flickerstreak@52
|
572 end
|
flickerstreak@52
|
573 end
|
flickerstreak@52
|
574 return o, e1, e2, a
|
flickerstreak@52
|
575 end
|
flickerstreak@52
|
576
|
flickerstreak@52
|
577 local function GetClosestVisiblePoint(f1)
|
flickerstreak@52
|
578 local f2, e1, e2, a = GetClosestVisibleEdge(f1)
|
flickerstreak@52
|
579 if f2 then
|
flickerstreak@52
|
580 local rsq, p, rp, x, y
|
flickerstreak@52
|
581 -- iterate pointsOnEdge in order and use < to prefer edge centers to corners
|
flickerstreak@52
|
582 for _, p1 in ipairs(pointsOnEdge[e1]) do
|
flickerstreak@52
|
583 if CheckPointEdgeOverlap(f1,p1,f2,e2) then
|
flickerstreak@52
|
584 for _, p2 in pairs(snapPoints[a][p1]) do
|
flickerstreak@52
|
585 local x1, y1 = GetPointCoords(f1,p1)
|
flickerstreak@52
|
586 local x2, y2 = GetPointCoords(f2,p2)
|
flickerstreak@52
|
587 local dx = x1 - x2
|
flickerstreak@52
|
588 local dy = y1 - y2
|
flickerstreak@52
|
589 local rsq2 = dx*dx + dy*dy
|
flickerstreak@52
|
590 if not rsq or rsq2 < rsq then
|
flickerstreak@52
|
591 rsq, p, rp, x, y = rsq2, p1, p2, dx, dy
|
flickerstreak@52
|
592 end
|
flickerstreak@52
|
593 end
|
flickerstreak@52
|
594 end
|
flickerstreak@52
|
595 end
|
flickerstreak@52
|
596 return f2, p, rp, x, y
|
flickerstreak@52
|
597 end
|
flickerstreak@52
|
598 end
|
flickerstreak@52
|
599
|
flickerstreak@52
|
600 local function GetClosestPointSnapped(f1, rx, ry, xOff, yOff)
|
flickerstreak@52
|
601 local o, p, rp, x, y = GetClosestVisiblePoint(f1)
|
flickerstreak@52
|
602 local s = false
|
flickerstreak@52
|
603
|
flickerstreak@52
|
604 local sx, sy = insidePointOffsetFuncs[p](xOff or 0, yOff or 0)
|
flickerstreak@52
|
605 local xx, yy = pointCoordFuncs[p](f1)
|
flickerstreak@52
|
606 if xx and yy then
|
flickerstreak@52
|
607 if math.abs(x) <= rx then
|
flickerstreak@52
|
608 x = sx
|
flickerstreak@52
|
609 s = true
|
flickerstreak@52
|
610 end
|
flickerstreak@52
|
611 if math.abs(y) <= ry then
|
flickerstreak@52
|
612 y = sy
|
flickerstreak@52
|
613 s = true
|
flickerstreak@52
|
614 end
|
flickerstreak@52
|
615 elseif xx then
|
flickerstreak@52
|
616 if math.abs(x) <= rx then
|
flickerstreak@52
|
617 x = sx
|
flickerstreak@52
|
618 s = true
|
flickerstreak@52
|
619 if math.abs(y) <= ry then
|
flickerstreak@52
|
620 y = sy
|
flickerstreak@52
|
621 end
|
flickerstreak@52
|
622 end
|
flickerstreak@52
|
623 elseif yy then
|
flickerstreak@52
|
624 if math.abs(y) <= ry then
|
flickerstreak@52
|
625 y = sy
|
flickerstreak@52
|
626 s = true
|
flickerstreak@52
|
627 if math.abs(x) <= rx then
|
flickerstreak@52
|
628 x = sx
|
flickerstreak@52
|
629 end
|
flickerstreak@52
|
630 end
|
flickerstreak@52
|
631 end
|
flickerstreak@52
|
632
|
flickerstreak@52
|
633 if x == -0 then x = 0 end
|
flickerstreak@52
|
634 if y == -0 then y = 0 end
|
flickerstreak@52
|
635
|
flickerstreak@52
|
636 if s then
|
flickerstreak@52
|
637 return o, p, rp, math.floor(x), math.floor(y)
|
flickerstreak@52
|
638 end
|
flickerstreak@52
|
639 end
|
flickerstreak@52
|
640
|
flickerstreak@52
|
641 local function CreateSnapIndicator()
|
flickerstreak@52
|
642 local si = CreateFrame("Frame",nil,UIParent)
|
flickerstreak@52
|
643 si:SetFrameStrata("HIGH")
|
flickerstreak@52
|
644 si:SetHeight(8)
|
flickerstreak@52
|
645 si:SetWidth(8)
|
flickerstreak@52
|
646 local tex = si:CreateTexture()
|
flickerstreak@52
|
647 tex:SetAllPoints()
|
flickerstreak@52
|
648 tex:SetTexture(1.0, 0.82, 0, 0.8)
|
flickerstreak@52
|
649 tex:SetBlendMode("ADD")
|
flickerstreak@52
|
650 tex:SetDrawLayer("OVERLAY")
|
flickerstreak@52
|
651 return si
|
flickerstreak@52
|
652 end
|
flickerstreak@52
|
653
|
flickerstreak@52
|
654 local si1 = CreateSnapIndicator()
|
flickerstreak@52
|
655 local si2 = CreateSnapIndicator()
|
flickerstreak@52
|
656
|
flickerstreak@52
|
657 local function DisplaySnapIndicator( f, rx, ry, xOff, yOff )
|
flickerstreak@52
|
658 local o, p, rp, x, y, snap = GetClosestPointSnapped(f, rx, ry, xOff, yOff)
|
flickerstreak@52
|
659 if o then
|
flickerstreak@52
|
660 si1:ClearAllPoints()
|
flickerstreak@52
|
661 si2:ClearAllPoints()
|
flickerstreak@52
|
662 si1:SetPoint("CENTER", f, p, 0, 0)
|
flickerstreak@52
|
663 local xx, yy = pointCoordFuncs[rp](o)
|
flickerstreak@52
|
664 x = math.abs(x) <=rx and xx and 0 or x
|
flickerstreak@52
|
665 y = math.abs(y) <=ry and yy and 0 or y
|
flickerstreak@52
|
666 si2:SetPoint("CENTER", o, rp, x, y)
|
flickerstreak@52
|
667 si1:Show()
|
flickerstreak@52
|
668 si2:Show()
|
flickerstreak@52
|
669 else
|
flickerstreak@52
|
670 if si1:IsVisible() then
|
flickerstreak@52
|
671 si1:Hide()
|
flickerstreak@52
|
672 si2:Hide()
|
flickerstreak@52
|
673 end
|
flickerstreak@52
|
674 end
|
flickerstreak@52
|
675 end
|
flickerstreak@52
|
676
|
flickerstreak@52
|
677 local function HideSnapIndicator()
|
flickerstreak@52
|
678 if si1:IsVisible() then
|
flickerstreak@52
|
679 si1:Hide()
|
flickerstreak@52
|
680 si2:Hide()
|
flickerstreak@52
|
681 end
|
flickerstreak@52
|
682 end
|
flickerstreak@52
|
683
|
flickerstreak@71
|
684 function CreateControls(bar)
|
flickerstreak@33
|
685 local f = bar.frame
|
flickerstreak@33
|
686
|
flickerstreak@33
|
687 f:SetMovable(true)
|
flickerstreak@33
|
688 f:SetResizable(true)
|
flickerstreak@33
|
689 f:SetClampedToScreen(true)
|
flickerstreak@33
|
690
|
flickerstreak@33
|
691 -- buttons on the bar should be direct children of the bar frame.
|
flickerstreak@33
|
692 -- The control elements need to float on top of this, which we could
|
flickerstreak@33
|
693 -- do with SetFrameLevel() or Raise(), but it's more reliable to do it
|
flickerstreak@33
|
694 -- via frame nesting, hence good old foo's appearance here.
|
flickerstreak@33
|
695 local foo = CreateFrame("Frame",nil,f)
|
flickerstreak@33
|
696 foo:SetAllPoints()
|
flickerstreak@51
|
697 foo:SetClampedToScreen(true)
|
flickerstreak@33
|
698
|
flickerstreak@33
|
699 local control = CreateFrame("Button", nil, foo)
|
flickerstreak@33
|
700 control:EnableMouse(true)
|
flickerstreak@33
|
701 control:SetToplevel(true)
|
flickerstreak@33
|
702 control:SetPoint("TOPLEFT", -4, 4)
|
flickerstreak@33
|
703 control:SetPoint("BOTTOMRIGHT", 4, -4)
|
flickerstreak@33
|
704 control:SetBackdrop({
|
flickerstreak@33
|
705 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
flickerstreak@33
|
706 tile = true,
|
flickerstreak@33
|
707 tileSize = 16,
|
flickerstreak@33
|
708 edgeSize = 16,
|
flickerstreak@33
|
709 insets = { left = 0, right = 0, top = 0, bottom = 0 },
|
flickerstreak@33
|
710 })
|
flickerstreak@33
|
711
|
flickerstreak@33
|
712 -- textures
|
flickerstreak@33
|
713 local bgTex = control:CreateTexture(nil,"BACKGROUND")
|
flickerstreak@33
|
714 bgTex:SetTexture(0.7,0.7,1.0,0.2)
|
flickerstreak@33
|
715 bgTex:SetPoint("TOPLEFT",4,-4)
|
flickerstreak@33
|
716 bgTex:SetPoint("BOTTOMRIGHT",-4,4)
|
flickerstreak@33
|
717 local hTex = control:CreateTexture(nil,"HIGHLIGHT")
|
flickerstreak@33
|
718 hTex:SetTexture(0.7,0.7,1.0,0.2)
|
flickerstreak@33
|
719 hTex:SetPoint("TOPLEFT",4,-4)
|
flickerstreak@33
|
720 hTex:SetPoint("BOTTOMRIGHT",-4,4)
|
flickerstreak@33
|
721 hTex:SetBlendMode("ADD")
|
flickerstreak@33
|
722
|
flickerstreak@33
|
723 -- label
|
flickerstreak@33
|
724 local label = control:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
|
flickerstreak@33
|
725 label:SetAllPoints()
|
flickerstreak@33
|
726 label:SetJustifyH("CENTER")
|
flickerstreak@33
|
727 label:SetShadowColor(0,0,0,1)
|
flickerstreak@33
|
728 label:SetShadowOffset(2,-2)
|
flickerstreak@33
|
729 label:SetTextColor(1,1,1,1)
|
flickerstreak@33
|
730 label:SetText(bar:GetName())
|
flickerstreak@33
|
731 label:Show()
|
flickerstreak@33
|
732 bar.controlLabelString = label -- so that bar:SetName() can update it
|
flickerstreak@33
|
733
|
flickerstreak@71
|
734 local function StopResize()
|
flickerstreak@33
|
735 f:StopMovingOrSizing()
|
flickerstreak@33
|
736 f.isMoving = false
|
flickerstreak@33
|
737 f:SetScript("OnUpdate",nil)
|
flickerstreak@52
|
738 StoreSize(bar)
|
flickerstreak@33
|
739 ClampToButtons(bar)
|
flickerstreak@33
|
740 ApplyAnchor(bar)
|
flickerstreak@63
|
741 ReAction:RefreshOptions()
|
flickerstreak@33
|
742 end
|
flickerstreak@33
|
743
|
flickerstreak@33
|
744 -- edge drag handles
|
flickerstreak@33
|
745 for _, point in pairs({"LEFT","TOP","RIGHT","BOTTOM"}) do
|
flickerstreak@33
|
746 local edge = CreateFrame("Frame",nil,control)
|
flickerstreak@33
|
747 edge:EnableMouse(true)
|
flickerstreak@33
|
748 edge:SetWidth(8)
|
flickerstreak@33
|
749 edge:SetHeight(8)
|
flickerstreak@33
|
750 if point == "TOP" or point == "BOTTOM" then
|
flickerstreak@33
|
751 edge:SetPoint(point.."LEFT")
|
flickerstreak@33
|
752 edge:SetPoint(point.."RIGHT")
|
flickerstreak@33
|
753 else
|
flickerstreak@33
|
754 edge:SetPoint("TOP"..point)
|
flickerstreak@33
|
755 edge:SetPoint("BOTTOM"..point)
|
flickerstreak@33
|
756 end
|
flickerstreak@33
|
757 local tex = edge:CreateTexture(nil,"HIGHLIGHT")
|
flickerstreak@33
|
758 tex:SetTexture(1.0,0.82,0,0.7)
|
flickerstreak@33
|
759 tex:SetBlendMode("ADD")
|
flickerstreak@33
|
760 tex:SetAllPoints()
|
flickerstreak@33
|
761 edge:RegisterForDrag("LeftButton")
|
flickerstreak@33
|
762 edge:SetScript("OnMouseDown",
|
flickerstreak@33
|
763 function()
|
flickerstreak@33
|
764 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
765 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
766 f:SetMinResize( bw+s+1, bh+s+1 )
|
flickerstreak@33
|
767 f:StartSizing(point)
|
flickerstreak@33
|
768 f:SetScript("OnUpdate",
|
flickerstreak@33
|
769 function()
|
flickerstreak@33
|
770 RecomputeGrid(bar)
|
flickerstreak@33
|
771 bar:RefreshLayout()
|
flickerstreak@33
|
772 end
|
flickerstreak@33
|
773 )
|
flickerstreak@33
|
774 end
|
flickerstreak@33
|
775 )
|
flickerstreak@33
|
776 edge:SetScript("OnMouseUp", StopResize)
|
flickerstreak@33
|
777 edge:SetScript("OnEnter",
|
flickerstreak@33
|
778 function()
|
flickerstreak@33
|
779 GameTooltip:SetOwner(f, "ANCHOR_"..point)
|
flickerstreak@33
|
780 GameTooltip:AddLine(L["Drag to add/remove buttons"])
|
flickerstreak@33
|
781 GameTooltip:Show()
|
flickerstreak@33
|
782 end
|
flickerstreak@33
|
783 )
|
flickerstreak@33
|
784 edge:SetScript("OnLeave", HideGameTooltip)
|
flickerstreak@33
|
785 edge:Show()
|
flickerstreak@33
|
786 end
|
flickerstreak@33
|
787
|
flickerstreak@33
|
788 -- corner drag handles, again nested in an anonymous frame so that they are on top
|
flickerstreak@33
|
789 local foo2 = CreateFrame("Frame",nil,control)
|
flickerstreak@33
|
790 foo2:SetAllPoints(true)
|
flickerstreak@33
|
791 for _, point in pairs({"BOTTOMLEFT","TOPLEFT","BOTTOMRIGHT","TOPRIGHT"}) do
|
flickerstreak@33
|
792 local corner = CreateFrame("Frame",nil,foo2)
|
flickerstreak@33
|
793 corner:EnableMouse(true)
|
flickerstreak@33
|
794 corner:SetWidth(12)
|
flickerstreak@33
|
795 corner:SetHeight(12)
|
flickerstreak@33
|
796 corner:SetPoint(point)
|
flickerstreak@33
|
797 local tex = corner:CreateTexture(nil,"HIGHLIGHT")
|
flickerstreak@33
|
798 tex:SetTexture(1.0,0.82,0,0.7)
|
flickerstreak@33
|
799 tex:SetBlendMode("ADD")
|
flickerstreak@33
|
800 tex:SetAllPoints()
|
flickerstreak@33
|
801 corner:RegisterForDrag("LeftButton","RightButton")
|
flickerstreak@71
|
802 local function updateTooltip()
|
flickerstreak@33
|
803 local size, size2 = bar:GetButtonSize()
|
flickerstreak@33
|
804 local rows, cols, spacing = bar:GetButtonGrid()
|
flickerstreak@33
|
805 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
|
flickerstreak@33
|
806 GameTooltipTextRight4:SetText(size)
|
flickerstreak@33
|
807 GameTooltipTextRight5:SetText(tostring(spacing))
|
flickerstreak@33
|
808 end
|
flickerstreak@33
|
809 corner:SetScript("OnMouseDown",
|
flickerstreak@33
|
810 function(_,btn)
|
flickerstreak@33
|
811 local bw, bh = GetButtonSize(bar)
|
flickerstreak@33
|
812 local r, c, s = GetButtonGrid(bar)
|
flickerstreak@33
|
813 if btn == "LeftButton" then -- button resize
|
flickerstreak@33
|
814 f:SetMinResize( (s+12)*c+1, (s+12)*r+1 )
|
flickerstreak@33
|
815 f:SetScript("OnUpdate",
|
flickerstreak@33
|
816 function()
|
flickerstreak@33
|
817 RecomputeButtonSize(bar)
|
flickerstreak@33
|
818 bar:RefreshLayout()
|
flickerstreak@33
|
819 updateTooltip()
|
flickerstreak@33
|
820 end
|
flickerstreak@33
|
821 )
|
flickerstreak@33
|
822 elseif btn == "RightButton" then -- spacing resize
|
flickerstreak@33
|
823 f:SetMinResize( bw*c, bh*r )
|
flickerstreak@33
|
824 f:SetScript("OnUpdate",
|
flickerstreak@33
|
825 function()
|
flickerstreak@33
|
826 RecomputeButtonSpacing(bar)
|
flickerstreak@33
|
827 bar:RefreshLayout()
|
flickerstreak@33
|
828 updateTooltip()
|
flickerstreak@33
|
829 end
|
flickerstreak@33
|
830 )
|
flickerstreak@33
|
831 end
|
flickerstreak@33
|
832 f:StartSizing(point)
|
flickerstreak@33
|
833 end
|
flickerstreak@33
|
834 )
|
flickerstreak@33
|
835 corner:SetScript("OnMouseUp",StopResize)
|
flickerstreak@33
|
836 corner:SetScript("OnEnter",
|
flickerstreak@33
|
837 function()
|
flickerstreak@33
|
838 GameTooltip:SetOwner(f, "ANCHOR_"..point)
|
flickerstreak@33
|
839 GameTooltip:AddLine(L["Drag to resize buttons"])
|
flickerstreak@33
|
840 GameTooltip:AddLine(L["Right-click-drag"])
|
flickerstreak@33
|
841 GameTooltip:AddLine(L["to change spacing"])
|
flickerstreak@33
|
842 local size, size2 = bar:GetButtonSize()
|
flickerstreak@33
|
843 local rows, cols, spacing = bar:GetButtonGrid()
|
flickerstreak@33
|
844 size = (size == size2) and tostring(size) or format("%dx%d",size,size2)
|
flickerstreak@33
|
845 GameTooltip:AddDoubleLine(L["Size:"], size)
|
flickerstreak@33
|
846 GameTooltip:AddDoubleLine(L["Spacing:"], tostring(spacing))
|
flickerstreak@33
|
847 GameTooltip:Show()
|
flickerstreak@33
|
848 end
|
flickerstreak@33
|
849 )
|
flickerstreak@33
|
850 corner:SetScript("OnLeave",
|
flickerstreak@33
|
851 function()
|
flickerstreak@33
|
852 GameTooltip:Hide()
|
flickerstreak@33
|
853 f:SetScript("OnUpdate",nil)
|
flickerstreak@33
|
854 end
|
flickerstreak@33
|
855 )
|
flickerstreak@33
|
856
|
flickerstreak@33
|
857 end
|
flickerstreak@33
|
858
|
flickerstreak@33
|
859 control:RegisterForDrag("LeftButton")
|
flickerstreak@33
|
860 control:RegisterForClicks("RightButtonDown")
|
flickerstreak@33
|
861
|
flickerstreak@33
|
862 control:SetScript("OnDragStart",
|
flickerstreak@33
|
863 function()
|
flickerstreak@33
|
864 f:StartMoving()
|
flickerstreak@33
|
865 f.isMoving = true
|
flickerstreak@52
|
866 local w,h = bar:GetButtonSize()
|
flickerstreak@52
|
867 f:ClearAllPoints()
|
flickerstreak@52
|
868 f:SetScript("OnUpdate", function()
|
flickerstreak@52
|
869 if IsShiftKeyDown() then
|
flickerstreak@52
|
870 DisplaySnapIndicator(f,w,h)
|
flickerstreak@52
|
871 else
|
flickerstreak@52
|
872 HideSnapIndicator()
|
flickerstreak@52
|
873 end
|
flickerstreak@52
|
874 end)
|
flickerstreak@33
|
875 end
|
flickerstreak@33
|
876 )
|
flickerstreak@33
|
877
|
flickerstreak@52
|
878 local function updateDragTooltip()
|
flickerstreak@52
|
879 GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT")
|
flickerstreak@52
|
880 GameTooltip:AddLine(bar.name)
|
flickerstreak@52
|
881 GameTooltip:AddLine(L["Drag to move"])
|
flickerstreak@52
|
882 GameTooltip:AddLine(("|cff00ff00%s|r %s"):format(L["Shift-drag"],L["to anchor to nearby frames"]))
|
flickerstreak@52
|
883 GameTooltip:AddLine(("|cff00cccc%s|r %s"):format(L["Right-click"],L["for options"]))
|
flickerstreak@52
|
884 local _, a = bar:GetAnchor()
|
flickerstreak@52
|
885 if a and a ~= "UIParent" then
|
flickerstreak@52
|
886 GameTooltip:AddLine(L["Currently anchored to <%s>"]:format(a))
|
flickerstreak@52
|
887 end
|
flickerstreak@52
|
888 GameTooltip:Show()
|
flickerstreak@52
|
889 end
|
flickerstreak@52
|
890
|
flickerstreak@33
|
891 control:SetScript("OnDragStop",
|
flickerstreak@33
|
892 function()
|
flickerstreak@33
|
893 f:StopMovingOrSizing()
|
flickerstreak@33
|
894 f.isMoving = false
|
flickerstreak@33
|
895 f:SetScript("OnUpdate",nil)
|
flickerstreak@52
|
896
|
flickerstreak@52
|
897 if IsShiftKeyDown() then
|
flickerstreak@52
|
898 local w, h = bar:GetButtonSize()
|
flickerstreak@52
|
899 local a, p, rp, x, y = GetClosestPointSnapped(f,w,h)
|
flickerstreak@52
|
900 if a then
|
flickerstreak@52
|
901 f:ClearAllPoints()
|
flickerstreak@52
|
902 f:SetPoint(p,a,rp,x,y)
|
flickerstreak@52
|
903 end
|
flickerstreak@52
|
904 HideSnapIndicator()
|
flickerstreak@52
|
905 end
|
flickerstreak@52
|
906
|
flickerstreak@33
|
907 StoreExtents(bar)
|
flickerstreak@63
|
908 ReAction:RefreshOptions()
|
flickerstreak@52
|
909 updateDragTooltip()
|
flickerstreak@33
|
910 end
|
flickerstreak@33
|
911 )
|
flickerstreak@33
|
912
|
flickerstreak@33
|
913 control:SetScript("OnEnter",
|
flickerstreak@33
|
914 function()
|
flickerstreak@63
|
915 -- TODO: add bar type and status information to name
|
flickerstreak@63
|
916 --[[
|
flickerstreak@33
|
917 local name = bar.name
|
flickerstreak@33
|
918 for _, m in ReAction:IterateModules() do
|
flickerstreak@33
|
919 local suffix = safecall(m,"GetBarNameModifier",bar)
|
flickerstreak@33
|
920 if suffix then
|
flickerstreak@33
|
921 name = ("%s %s"):format(name,suffix)
|
flickerstreak@33
|
922 end
|
flickerstreak@33
|
923 end
|
flickerstreak@63
|
924 ]]--
|
flickerstreak@52
|
925
|
flickerstreak@52
|
926 updateDragTooltip()
|
flickerstreak@33
|
927 end
|
flickerstreak@33
|
928 )
|
flickerstreak@33
|
929
|
flickerstreak@33
|
930 control:SetScript("OnLeave", HideGameTooltip)
|
flickerstreak@33
|
931
|
flickerstreak@33
|
932 control:SetScript("OnClick",
|
flickerstreak@33
|
933 function()
|
flickerstreak@33
|
934 bar:ShowMenu()
|
flickerstreak@33
|
935 end
|
flickerstreak@33
|
936 )
|
flickerstreak@33
|
937
|
flickerstreak@33
|
938 return control
|
flickerstreak@33
|
939 end
|
flickerstreak@33
|
940 end
|
flickerstreak@33
|
941
|
flickerstreak@33
|
942
|
flickerstreak@33
|
943 local OpenMenu, CloseMenu
|
flickerstreak@33
|
944 do
|
flickerstreak@33
|
945 -- Looking for a lightweight AceConfig3-struct-compatible
|
flickerstreak@33
|
946 -- replacement for Dewdrop, encapsulate here
|
flickerstreak@33
|
947 -- Considering Blizzard's EasyMenu/UIDropDownMenu, but that's
|
flickerstreak@33
|
948 -- a bit tricky to convert from AceConfig3-struct
|
flickerstreak@33
|
949 local Dewdrop = AceLibrary("Dewdrop-2.0")
|
flickerstreak@71
|
950 function OpenMenu (frame, opts)
|
flickerstreak@33
|
951 Dewdrop:Open(frame, "children", opts, "cursorX", true, "cursorY", true)
|
flickerstreak@33
|
952 end
|
flickerstreak@71
|
953 function CloseMenu(frame)
|
flickerstreak@33
|
954 if Dewdrop:GetOpenedParent() == frame then
|
flickerstreak@33
|
955 Dewdrop:Close()
|
flickerstreak@33
|
956 end
|
flickerstreak@33
|
957 end
|
flickerstreak@33
|
958 end
|
flickerstreak@33
|
959
|
flickerstreak@33
|
960
|
flickerstreak@33
|
961 function Bar:ShowControls(show)
|
flickerstreak@33
|
962 if show then
|
flickerstreak@33
|
963 if not self.controlFrame then
|
flickerstreak@33
|
964 self.controlFrame = CreateControls(self)
|
flickerstreak@33
|
965 end
|
flickerstreak@33
|
966 self.controlFrame:Show()
|
flickerstreak@33
|
967 elseif self.controlFrame then
|
flickerstreak@33
|
968 CloseMenu(self.controlFrame)
|
flickerstreak@33
|
969 self.controlFrame:Hide()
|
flickerstreak@33
|
970 end
|
flickerstreak@33
|
971 end
|
flickerstreak@33
|
972
|
flickerstreak@33
|
973 function Bar:ShowMenu()
|
flickerstreak@33
|
974 if not self.menuOpts then
|
flickerstreak@33
|
975 self.menuOpts = {
|
flickerstreak@33
|
976 type = "group",
|
flickerstreak@33
|
977 args = {
|
flickerstreak@33
|
978 openConfig = {
|
flickerstreak@33
|
979 type = "execute",
|
flickerstreak@58
|
980 name = L["Settings..."],
|
flickerstreak@58
|
981 desc = L["Open the editor for this bar"],
|
flickerstreak@63
|
982 func = function() CloseMenu(self.controlFrame); ReAction:ShowEditor(self) end,
|
flickerstreak@33
|
983 disabled = InCombatLockdown,
|
flickerstreak@33
|
984 order = 1
|
flickerstreak@33
|
985 },
|
flickerstreak@33
|
986 delete = {
|
flickerstreak@33
|
987 type = "execute",
|
flickerstreak@33
|
988 name = L["Delete Bar"],
|
flickerstreak@33
|
989 desc = L["Remove the bar from the current profile"],
|
flickerstreak@50
|
990 confirm = L["Are you sure you want to remove this bar?"],
|
flickerstreak@33
|
991 func = function() ReAction:EraseBar(self) end,
|
flickerstreak@33
|
992 order = 2
|
flickerstreak@33
|
993 },
|
flickerstreak@33
|
994 }
|
flickerstreak@33
|
995 }
|
flickerstreak@33
|
996 end
|
flickerstreak@33
|
997 OpenMenu(self.controlFrame, self.menuOpts)
|
flickerstreak@33
|
998 end
|
flickerstreak@33
|
999
|
flickerstreak@33
|
1000
|
flickerstreak@33
|
1001
|
flickerstreak@28
|
1002 ------ Export as a class-factory ------
|
flickerstreak@28
|
1003 ReAction.Bar = {
|
flickerstreak@28
|
1004 new = function(self, ...)
|
flickerstreak@28
|
1005 local x = { }
|
flickerstreak@28
|
1006 for k,v in pairs(Bar) do
|
flickerstreak@28
|
1007 x[k] = v
|
flickerstreak@28
|
1008 end
|
flickerstreak@28
|
1009 Constructor(x, ...)
|
flickerstreak@28
|
1010 return x
|
flickerstreak@28
|
1011 end
|
flickerstreak@28
|
1012 }
|