-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigUtils.lua
More file actions
140 lines (121 loc) · 5.28 KB
/
FigUtils.lua
File metadata and controls
140 lines (121 loc) · 5.28 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
function Fig.makeFrame(name, parent)
local f = CreateFrame('frame', name, parent or UIParent)
return f
end
function Fig.getTexturePath(texture)
return 'Interface\\AddOns\\FigUI\\Textures\\' .. texture
end
function Fig.prettyPrintNumber(num)
if num >= 1000000 then
-- do conversion to shorter syntax (eg. 5300000 = 5.3m)
return format('%.1f', tostring(num / 1000000)) .. 'm'
elseif num >= 1000 then
-- do conversion to shorter syntax (eg. 4700 = 4.7k)
return format('%.1f', tostring(num / 1000)) .. 'k'
else
return tostring(num)
end
end
-- Shortens a duration in seconds to a prettier form:
-- Ex. 3600 -> 1h, 180 -> 3m, etc
function Fig.prettyPrintDuration(duration)
if duration > (60 * 60 * 24) then
-- days
return format('%id', math.ceil(dutation / (60 * 60 * 24)))
elseif duration > (60 * 60) then
-- hours
return format('%ih', math.ceil(duration / (60 * 60)))
elseif duration > 60 then
-- minutes
return format('%im', math.ceil(duration / 60))
else
--seconds
return format('%is', math.ceil(duration))
end
end
function Fig.drawOutsetBordersForFrame(frame)
if not frame then return end
if not frame.hasBorders then
-- draw all borders within a frame on top of the parent frame (gets around the issue of textures being drawn under child frames)
local borderFrameLevel = frame:GetFrameLevel() + 20
local borderFrame = CreateFrame('frame', nil, frame)
borderFrame:SetPoint('CENTER')
borderFrame:SetFrameLevel(borderFrameLevel)
borderFrame:SetSize(frame:GetSize())
frame.borders = borderFrame
local borderThickness = 1 -- TODO: make this configurable
-- draw borders
borderFrame.top = borderFrame:CreateTexture(nil, 'OVERLAY')
borderFrame.top:SetColorTexture(0, 0, 0, 1)
borderFrame.top:SetPoint('BOTTOMLEFT', borderFrame, 'TOPLEFT', -borderThickness, 0)
borderFrame.top:SetPoint('BOTTOMRIGHT', borderFrame, 'TOPRIGHT', borderThickness, 0)
borderFrame.top:SetHeight(borderThickness)
borderFrame.bottom = borderFrame:CreateTexture(nil, 'OVERLAY')
borderFrame.bottom:SetColorTexture(0, 0, 0, 1)
borderFrame.bottom:SetPoint('TOPLEFT', borderFrame, 'BOTTOMLEFT', -borderThickness, 0)
borderFrame.bottom:SetPoint('TOPRIGHT', borderFrame, 'BOTTOMRIGHT', borderThickness, 0)
borderFrame.bottom:SetHeight(borderThickness)
borderFrame.left = borderFrame:CreateTexture(nil, 'OVERLAY')
borderFrame.left:SetColorTexture(0, 0, 0, 1)
borderFrame.left:SetPoint('TOPRIGHT', borderFrame, 'TOPLEFT')
borderFrame.left:SetPoint('BOTTOMRIGHT', borderFrame, 'BOTTOMLEFT')
borderFrame.left:SetWidth(borderThickness)
borderFrame.right = borderFrame:CreateTexture(nil, 'OVERLAY')
borderFrame.right:SetColorTexture(0, 0, 0, 1)
borderFrame.right:SetPoint('TOPLEFT', borderFrame, 'TOPRIGHT')
borderFrame.right:SetPoint('BOTTOMLEFT', borderFrame, 'BOTTOMRIGHT')
borderFrame.right:SetWidth(borderThickness)
borderFrame:Show()
frame.hasBorders = true
end
end
function Fig.drawInsetBordersForFrame(frame, drawLayer, borderThickness)
if not frame then return end
if not frame.hasBorders then
drawLayer = drawLayer or 'BORDER' -- allow us to draw borders on top of StatusBar elements that use the BORDER layer
borderThickness = borderThickness or 1
frame.borders = {}
-- draw borders
frame.borders.top = frame:CreateTexture(frame:GetName() .. 'TopBorder', drawLayer)
frame.borders.top:SetDrawLayer(drawLayer, 7)
frame.borders.top:SetColorTexture(0, 0, 0, 1)
frame.borders.top:SetPoint('TOPLEFT', frame, 'TOPLEFT', borderThickness, 0)
frame.borders.top:SetPoint('TOPRIGHT', frame, 'TOPRIGHT', -borderThickness, 0)
frame.borders.top:SetHeight(borderThickness)
frame.borders.top:Show()
frame.borders.bottom = frame:CreateTexture(frame:GetName() .. 'BottomBorder', drawLayer)
frame.borders.bottom:SetDrawLayer(drawLayer, 7)
frame.borders.bottom:SetColorTexture(0, 0, 0, 1)
frame.borders.bottom:SetPoint('BOTTOMLEFT', frame, 'BOTTOMLEFT', borderThickness, 0)
frame.borders.bottom:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMRIGHT', -borderThickness, 0)
frame.borders.bottom:SetHeight(borderThickness)
frame.borders.bottom:Show()
frame.borders.left = frame:CreateTexture(frame:GetName() .. 'LeftBorder', drawLayer)
frame.borders.left:SetDrawLayer(drawLayer, 7)
frame.borders.left:SetColorTexture(0, 0, 0, 1)
frame.borders.left:SetPoint('TOPLEFT', frame, 'TOPLEFT')
frame.borders.left:SetPoint('BOTTOMLEFT', frame, 'BOTTOMLEFT')
frame.borders.left:SetWidth(borderThickness)
frame.borders.left:Show()
frame.borders.right = frame:CreateTexture(frame:GetName() .. 'RightBorder', drawLayer)
frame.borders.right:SetDrawLayer(drawLayer, 7)
frame.borders.right:SetColorTexture(0, 0, 0, 1)
frame.borders.right:SetPoint('TOPRIGHT', frame, 'TOPRIGHT')
frame.borders.right:SetPoint('BOTTOMRIGHT', frame, 'BOTTOMRIGHT')
frame.borders.right:SetWidth(borderThickness)
frame.borders.right:Show()
frame.hasBorders = true
end
end
function Fig.hideBordersForFrame(frame)
if not frame then return end
if frame.hasBorders then
frame.borders:Hide();
end
end
function Fig.showBordersForFrame(frame)
if not frame then return end
if frame.hasBorders then
frame.borders:Show()
end
end