-
Notifications
You must be signed in to change notification settings - Fork 116
/
FrameUtil.lua
95 lines (74 loc) · 2.02 KB
/
FrameUtil.lua
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
---------------
--NOTE - Please do not change this section without understanding the full implications of the secure environment
local _, tbl = ...;
if tbl then
tbl.SecureCapsuleGet = SecureCapsuleGet;
local function Import(name)
tbl[name] = tbl.SecureCapsuleGet(name);
end
Import("IsOnGlueScreen");
if ( tbl.IsOnGlueScreen() ) then
tbl._G = _G; --Allow us to explicitly access the global environment at the glue screens
end
setfenv(1, tbl);
end
----------------
FrameUtil = {};
function FrameUtil.RegisterFrameForEvents(frame, events)
for i, event in ipairs(events) do
frame:RegisterEvent(event);
end
end
function FrameUtil.UnregisterFrameForEvents(frame, events)
for i, event in ipairs(events) do
frame:UnregisterEvent(event);
end
end
function ApplyDefaultScale(frame, minScale, maxScale)
local scale = GetDefaultScale();
if minScale then
scale = math.max(scale, minScale);
end
if maxScale then
scale = math.min(scale, maxScale);
end
frame:SetScale(scale);
end
function DoesAncestryInclude(ancestry, frame)
if ancestry then
local currentFrame = frame;
while currentFrame do
if currentFrame == ancestry then
return true;
end
currentFrame = currentFrame:GetParent();
end
end
return false;
end
function GetUnscaledFrameRect(frame, scale)
local frameLeft, frameBottom, frameWidth, frameHeight = frame:GetScaledRect();
if frameLeft == nil then
return 1, 1, 1, 1;
end
return frameLeft / scale, frameBottom / scale, frameWidth / scale, frameHeight / scale;
end
function ApplyDefaultScale(frame, minScale, maxScale)
local scale = GetDefaultScale();
if minScale then
scale = math.max(scale, minScale);
end
if maxScale then
scale = math.min(scale, maxScale);
end
frame:SetScale(scale);
end
function UpdateScaleForFit(frame)
local horizRatio = UIParent:GetWidth() / GetUIPanelWidth(frame);
local vertRatio = UIParent:GetHeight() / GetUIPanelHeight(frame);
if ( horizRatio < 1 or vertRatio < 1 ) then
frame:SetScale(min(horizRatio, vertRatio));
else
frame:SetScale(1);
end
end