Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
352 lines (303 loc) · 10.5 KB
/
Copy pathUI.lua
File metadata and controls
352 lines (303 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
--| Purpose: A library of functions for creating interface objects
--| Authors: Atriace@Gmail.com
--| Website: massive.atriace.com
----------------------------------------------------------------------------------
local parent, db = ...
DEFAULT_CHAT_FRAME:AddMessage("Massive: UI Loaded", 1, 0, 0)
function db.CreateWindow(title, sizeX, sizeY, fade, direction, parent)
-- Deprecated. To be replaced by db.shape()
-- Primary output window
local frame = CreateFrame("ScrollingMessageFrame", title, _G["Massive"])
frame:StopMovingOrSizing()
frame:ClearAllPoints()
if parent then
frame:SetPoint("TOPLEFT", parent, "TOPRIGHT", 13, 0)
end
frame:SetFrameStrata("HIGH")
frame:SetWidth(256)
frame:SetHeight(256)
frame:SetPoint("CENTER",0,0)
-- frame:SetInsertMode(direction)
frame:SetJustifyH("LEFT")
frame:SetMaxLines(50000)
frame:SetFading(false)
frame:SetFadeDuration(3)
frame:SetTimeVisible(60)
frame:SetResizable(true)
frame:SetMinResize(50, 50)
frame:SetClampedToScreen(true)
frame:SetClampRectInsets(-9, 7, 7, -7)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:EnableMouseWheel(true)
frame:SetScript("OnMouseWheel", db.ScrollReport)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
frame:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
frame:SetScript("OnMouseUp", function(self) db.SnapWindows(self) end)
frame:SetScript("OnHide", frame:GetScript("OnMouseUp"))
frame:SetFont(db.dir..db.font..".ttf", 10)
frame:SetSpacing(3)
db.CreateBorder(title, frame)
db.CreateGrip(title, frame)
db.CreateTitle(title, frame)
frame:AddMessage("<< "..title.." Online >>", .5, .5, .5, 0)
return frame
end
function db.shape(p)
-- Creates a shape
local q = {
["x"] = 0,
["y"] = 0,
["width"] = 100,
["height"] = 100,
["color"] = hue.black,
["alpha"] = 1,
["edge"] = {
["color"] = hue.white,
["width"] = 0,
["alpha"] = 0.5
}
}
db.merge(p, q)
-- Unfinished
end
function db.CreateTitle(title, frame)
-- Deprecated. To be replaced by createText
local bg = _G[frame:GetName().."_BG"]
local bar = CreateFrame("Frame", title.."Bar", frame)
bar:ClearAllPoints()
bar:SetHeight(32)
bar:SetPoint("TOPLEFT", bg, "TOPLEFT", 0, 0)
bar:SetPoint("TOPRIGHT", bg, "TOPRIGHT", 0, 0)
bar:SetFrameStrata("DIALOG")
local texture = bar:CreateTexture(title.."Bar_Texture","BACKGROUND")
texture:SetTexture(.1,.1,.1,.9)
texture:SetAllPoints(bar)
local fontstring = bar:CreateFontString(title.."Title","DIALOG")
fontstring:SetFont(db.dir..db.font..".ttf", 13)
fontstring:SetJustifyH("LEFT")
fontstring:SetPoint("left", bar, "left", 15, -1)
fontstring:SetShadowColor(0, 0, 0, 1)
fontstring:SetShadowOffset(0, -1)
fontstring:SetText(title)
end
function createText(p)
-- Creates a text object
local q = {
["text"] = "Text",
["width"] = 150,
["height"] = 20,
["alpha"] = 1,
["blendMode"] = "normal",
["autoSize"] = "left",
["wordWrap"] = false,
["multiline"] = true,
["selectable"] = false,
["condenseWhite"] = false,
["format"] = {
["align"] = "left",
["color"] = "0x000000",
["font"] = "VeraMoBd.ttf",
["size"] = 12,
["leading"] = 4
}
}
db.merge(p, q)
end
function align(a, b, p)
-- Places a relative to b
if (a and b) then
local q = {
["h"] = 0.0, -- 0-1, left to right
["v"] = 0.0, -- 0-1, top to bottom
["pad"] = 0, -- in pixels
["padX"] = nil,
["padY"] = nil,
["overlap"] = true, -- inside or outside That's region
["overlapX"] = nil,
["overlapY"] = nil,
["scale"] = 1, -- Scale isn't implimented yet.
["scaleX"] = nil,
["scaleY"] = nil,
["apply"] = true, -- Apply the calculations to A or just return the values
["clamp"] = true -- Keeps placement clamped to whole pixel values
}
merge(p,q)
-- Simplify operations by only dealing with proxies. We'll apply these later if requested.
local loc = toGlobal(b)
local bProxe = new Proxe(b)
bProxe.x = loc.x + bProxe.bound.x
bProxe.y = loc.y + bProxe.bound.y
loc = toGlobal(a)
local aProxe = new Proxe(a)
aProxe.x = loc.x + aProxe.bound.x
aProxe.y = loc.y + aProxe.bound.y
-- If declared, use the XY specific values, otherwise, the generic value.
-- padX = (padX ~= nil) ? padX : pad
-- padY = (padY ~= nil) ? padY : pad
-- overlapX = (overlapX ~= nil) ? overlapX : overlap
-- overlapY = (overlapY ~= nil) ? overlapY : overlap
-- scaleX = (scaleX ~= nil) ? scaleX : scale
-- scaleY = (scaleY ~= nil) ? scaleY : scale
-- Apply final scale values.
aProxe.scaleX = scaleX
aProxe.scaleY = scaleY
aProxe.width = aProxe.width * scaleX
aProxe.height = aProxe.height * scaleY
-- Place the XY of This at the coordinates defined by the percentages of (H)orizontal and (V)ertical values relative to That plus padding.
local offset = {}
local h2 = 1 - h
if (overlapX) then
h2 = h
padX = -padX
end
offset.x = (bProxe.width + padX * 2) * h - padX - aProxe.width * h2 + bProxe.x
local v2 = 1 - v
if (overlapY) then
v2 = v
padY = -padY
end
offset.y = (bProxe.height + padY * 2) * v -padY - aProxe.height * v2 + bProxe.y
-- Convert the values back to local space (removing offsets).
offset = toLocal(offset, aProxe.parent).locs()
-- Undo the boundary compensation
offset.x = offset.x - aProxe.bound.x
offset.y = offset.y - aProxe.bound.y
if (clamp) then
offset.y = Math.round(offset.y)
offset.x = Math.round(offset.x)
end
if (apply) then
a.x = offset.x
a.y = offset.y
else
delete(offset.parent)
db.merge(offset, aProxe)
end
-- Undo the scale
aProxe.width = a.width
aProxe.height = a.height
return aProxe
else
local aName, bName
if (a ~= nil and a.name) then
aName = a.name
else
aName = "nil"
end
if (b ~= nil and b.name) then
bName = b.name
else
bName = "nil"
end
db.print("Cannot align a nil object. " .. aName .. " to " .. bName, "error")
db.report(a)
db.report(b)
--return Proxe()
end
end
-- public static function toGlobal(box, offset = nil) {
-- /* Finds the absolute stage coordinate of the object passed to it. */
-- local proxy = new Proxe(box)
-- //db.print("from " + (box.name?box.name:"anonymous object") + " at " + proxy.x + "," + proxy.y, "system")
-- if (offset ~= nil) { db.merge(offset, proxy) }
-- if (box.hasOwnProperty("parent") and box.parent ~= Ref._) {
-- local limit = Ref._.parent
-- local ref = proxy
-- while (ref.parent and ref.parent ~= limit) {
-- //db.print("/"+ref.parent)
-- ref = ref.parent
-- proxy.x += ref.x
-- proxy.y += ref.y
-- //db.print(proxy.name + ".scale:" + proxy.scaleX + " * " + ref.name + ".scale:" + ref.scaleX + " = " + (proxy.scaleX*ref.scaleX))
-- proxy.scaleX = proxy.scaleX*ref.scaleX
-- proxy.scaleY = proxy.scaleY*ref.scaleY
-- }
-- }
-- //db.print(box.x + "," + box.y + " = " + proxy.x + "," + proxy.y)
-- return proxy
-- }
-- public static function toLocal(source, targetSpace:DisplayObjectContainer, offset = nil) {
-- /* Returns coordinates of source in the local space of target. */
-- //db.print("to " + targetSpace.name, "system")
-- local proxy = new Proxe(source)
-- if (offset ~= nil) { db.merge(offset, proxy) }
-- if (source.parent ~= targetSpace) {
-- //db.print("Traversing link for " + source.name + " to " + targetSpace.name + ".", "warning")
-- // Both display objects need to share the same global space, so backtrack first
-- proxy = toGlobal(source)
-- // Next construct the path to the target space
-- local path:Array = []
-- local ref:DisplayObjectContainer = targetSpace
-- while (ref.parent and ref.parent ~= Ref._.parent) {
-- path.push(ref)
-- ref = ref.parent
-- }
-- // Now sort the math out
-- for (local i:int = path.length-1 path[i] i--) {
-- proxy.x -= path[i].x
-- proxy.y -= path[i].y
-- //db.print(path[i].name + ' modified offset = ' + proxy.x + "," + proxy.y)
-- }
-- } else {
-- //db.print(source.name + " already exists in " + targetSpace.name + ".", "warning")
-- }
-- return proxy
-- }
function db.CreateEditBox(parent)
local title = parent.."Edit"
local frame = CreateFrame("EditBox", title, _G[parent])
frame:SetFont(db.dir..db.font..".ttf", 11)
frame:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -11)
frame:SetPoint("TOPRIGHT", parent, "BOTTOMRIGHT", 0, -11)
frame:SetFrameStrata("HIGH")
frame:SetHeight(26)
frame:ClearFocus()
frame:SetAutoFocus(false)
frame:SetScript("OnEscapePressed", db.OnEscapePressed)
frame:SetScript("OnEnterPressed", db.OnEnterPressed)
db.CreateBorder(title, frame)
end
function db.CreateBorder(title, frame)
local bg = frame:CreateTexture(title.."_BG","BACKGROUND")
local xOf, yOf, loc, border, i = 5, 5, {
[1] = { "BOTTOMRIGHT", "TOPLEFT" }, -- tl
[2] = { "BOTTOMLEFT", "TOPRIGHT" }, -- tr
[3] = { "TOPRIGHT", "BOTTOMLEFT" }, -- bl
[4] = { "TOPLEFT", "BOTTOMRIGHT" }, -- br
[5] = { "BOTTOM", "TOP", "LEFT", "RIGHT", 1, 2 }, -- top
[6] = { "RIGHT", "LEFT", "TOP", "BOTTOM", 1, 3 }, -- left
[7] = { "LEFT", "RIGHT", "TOP", "BOTTOM", 2, 4 }, -- right
[8] = { "TOP", "BOTTOM", "LEFT", "RIGHT", 3, 4 }, -- bottom
}
bg:SetTexture(0,0,0,0.75)
bg:SetPoint("TOPLEFT", frame, "TOPLEFT", -(xOf+2), yOf)
bg:SetPoint("TOPRIGHT", frame, "TOPRIGHT", xOf, yOf)
bg:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", -(xOf+2), -yOf)
bg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", xOf, -yOf)
for v=1, 8, 1 do
border = frame:CreateTexture(title.."_Border_"..v, "BORDER")
border:SetTexture(1,1,1,.1)
border:SetHeight(1)
border:SetWidth(1)
border:SetPoint(loc[v][1], bg, loc[v][2])
if v>4 then
border:SetPoint(loc[v][3], title.."_Border_"..loc[v][5], loc[v][4])
border:SetPoint(loc[v][4], title.."_Border_"..loc[v][6], loc[v][3])
end
end
end
function db.CreateGrip(title, frame)
local handle = CreateFrame("Button", title.."Handle", frame)
handle:SetWidth(16)
handle:SetHeight(16)
handle:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT")
handle:EnableMouse(true)
handle:RegisterForClicks("LeftButton")
handle:SetScript("OnMouseDown", function() _G[title]:StartSizing() end)
handle:SetScript("OnMouseUp", function() _G[title]:StopMovingOrSizing() end)
local texture = handle:CreateTexture("HandleTexture","HIGH")
texture:SetTexture(db.dir.."grip")
texture:SetAllPoints(handle)
end