-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlignGrid.lua
62 lines (52 loc) · 1.89 KB
/
AlignGrid.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
local feature = ns.Register({
identifier = "AlignGrid",
description = "Draws an align grid on a screen if Ctrl+Alt+Shift is being pressed.",
category = "interface",
config = {},
data = {}
})
local frame = CreateFrame("Frame", nil, UIParent)
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function()
if not ns.IsEnabled(feature.identifier) then return end
if event == "ADDON_LOADED" then
frame.grid = CreateFrame("Frame")
frame.grid:Hide()
frame.grid:SetAllPoints(UIParent)
local w, h = GetScreenWidth() * UIParent:GetEffectiveScale(), GetScreenHeight() * UIParent:GetEffectiveScale()
local ratio = w / h
local sqsize = w / 20
local wline = floor(sqsize - mod(sqsize, 2))
local hline = floor(sqsize / ratio - mod((sqsize / ratio), 2))
-- Plot vertical lines.
for i = 0, wline do
local t = frame.grid:CreateTexture(nil, "BACKGROUND")
if i == wline / 2 then
t:SetTexture(1, 1, 0, 0.7) -- Yellow line in the middle
else
t:SetTexture(0, 0, 0, 0.7) -- Black lines elsewhere
end
t:SetPoint("TOPLEFT", frame.grid, "TOPLEFT", i * w / wline - 1, 0)
t:SetPoint("BOTTOMRIGHT", frame.grid, "BOTTOMLEFT", i * w / wline + 1, 0)
end
-- Plot horizontal lines.
for i = 0, hline do
local t = frame.grid:CreateTexture(nil, "BACKGROUND")
if i == hline / 2 then
t:SetTexture(1, 1, 0, 0.7) -- Yellow line in the middle
else
t:SetTexture(0, 0, 0, 0.7) -- Black lines elsewhere
end
t:SetPoint("TOPLEFT", frame.grid, "TOPLEFT", 0, -i * h / hline + 1)
t:SetPoint("BOTTOMRIGHT", frame.grid, "TOPRIGHT", 0, -i * h / hline - 1)
end
end
frame:SetScript("OnUpdate", function()
if IsControlKeyDown() and IsShiftKeyDown() and IsAltKeyDown() then
frame.grid:Show()
else
frame.grid:Hide()
end
end)
frame:UnregisterEvent("ADDON_LOADED")
end)