local AddonName, Addon = ...
local AddOn = { }
math.round = function(self)
return math.floor(self + 0.5)
end
AddOn.events = CreateFrame("Frame")
AddOn.events:RegisterEvent("ADDON_LOADED")
AddOn.events:SetScript("OnEvent", function(self, event, ...)
AddOn[event](AddOn, ...)
end)
function AddOn:ADDON_LOADED(addon)
if addon == AddonName then
self:OnLoad()
self:OnLoad2()
end
end
function AddOn:OnLoad()
local frame = CreateFrame("Frame", "TestFrame", UIParent)
frame:SetSize(84, 84)
frame.width = 84
frame.height = 84
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", (UIParent:GetWidth() / 2) - (frame:GetWidth() / 2), (-UIParent:GetHeight() / 2) + (frame:GetHeight() / 2))
frame:SetClampedToScreen(true)
frame.backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 14,
insets = {left = 3, right = 3, top = 3, bottom = 3},
}
frame:SetBackdrop(frame.backdrop)
frame:SetBackdropColor(0.0, 0.0, 0.0, 0.5)
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
frame.scaled = CreateFrame("Frame", nil, frame)
frame.scaled:SetAllPoints(frame)
frame.texture1 = frame:CreateTexture(nil, "ARTWORK", nil, -8)
frame.texture1:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -10)
frame.texture1:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 10)
frame.texture1:SetColorTexture(1, 1, 1, 1)
frame.texture2 = frame:CreateTexture(nil, "ARTWORK", nil, -7)
frame.texture2:SetPoint("TOPLEFT", frame.texture1, "TOPLEFT", 2, -2)
frame.texture2:SetPoint("BOTTOMRIGHT", frame.texture1, "BOTTOMRIGHT", -2, 2)
frame.texture2:SetColorTexture(0, 0, 0, 1)
frame.texture3 = frame:CreateTexture(nil, "ARTWORK", nil, -6)
frame.texture3:SetPoint("TOPLEFT", frame.texture2, "TOPLEFT", 2, -2)
frame.texture3:SetPoint("BOTTOMRIGHT", frame.texture2, "BOTTOMRIGHT", -2, 2)
frame.texture3:SetColorTexture(1, 1, 1, 1)
frame.texture4 = frame:CreateTexture(nil, "ARTWORK", nil, -5)
frame.texture4:SetPoint("TOPLEFT", frame.texture3, "TOPLEFT", 2, -2)
frame.texture4:SetPoint("BOTTOMRIGHT", frame.texture3, "BOTTOMRIGHT", -2, 2)
frame.texture4:SetColorTexture(0, 0, 0, 1)
frame.texture5 = frame:CreateTexture(nil, "ARTWORK", nil, -4)
frame.texture5:SetPoint("TOPLEFT", frame.texture4, "TOPLEFT", 2, -2)
frame.texture5:SetPoint("BOTTOMRIGHT", frame.texture4, "BOTTOMRIGHT", -2, 2)
frame.texture5:SetColorTexture(1, 1, 1, 1)
frame.texture6 = frame:CreateTexture(nil, "ARTWORK", nil, -3)
frame.texture6:SetPoint("TOPLEFT", frame.texture5, "TOPLEFT", 2, -2)
frame.texture6:SetPoint("BOTTOMRIGHT", frame.texture5, "BOTTOMRIGHT", -2, 2)
frame.texture6:SetColorTexture(0, 0, 0, 1)
frame.texture7 = frame:CreateTexture(nil, "ARTWORK", nil, -2)
frame.texture7:SetPoint("TOPLEFT", frame.texture6, "TOPLEFT", 2, -2)
frame.texture7:SetPoint("BOTTOMRIGHT", frame.texture6, "BOTTOMRIGHT", -2, 2)
frame.texture7:SetColorTexture(1, 1, 1, 1)
frame.texture8 = frame:CreateTexture(nil, "ARTWORK", nil, -1)
frame.texture8:SetPoint("TOPLEFT", frame.texture7, "TOPLEFT", 2, -2)
frame.texture8:SetPoint("BOTTOMRIGHT", frame.texture7, "BOTTOMRIGHT", -2, 2)
frame.texture8:SetColorTexture(0, 0, 0, 1)
frame.texture9 = frame:CreateTexture(nil, "ARTWORK", nil, 0)
frame.texture9:SetPoint("TOPLEFT", frame.texture8, "TOPLEFT", 2, -2)
frame.texture9:SetPoint("BOTTOMRIGHT", frame.texture8, "BOTTOMRIGHT", -2, 2)
frame.texture9:SetColorTexture(1, 1, 1, 1)
frame.texture10 = frame:CreateTexture(nil, "ARTWORK", nil, 1)
frame.texture10:SetPoint("TOPLEFT", frame.texture9, "TOPLEFT", 2, -2)
frame.texture10:SetPoint("BOTTOMRIGHT", frame.texture9, "BOTTOMRIGHT", -2, 2)
frame.texture10:SetColorTexture(0, 0, 0, 1)
frame.texture11 = frame:CreateTexture(nil, "ARTWORK", nil, 2)
frame.texture11:SetPoint("TOPLEFT", frame.texture10, "TOPLEFT", 2, -2)
frame.texture11:SetPoint("BOTTOMRIGHT", frame.texture10, "BOTTOMRIGHT", -2, 2)
frame.texture11:SetColorTexture(1, 1, 1, 1)
frame.pixel = frame.scaled:CreateFontString(nil, "ARTWORK")
frame.pixel:SetPoint("TOPLEFT", frame.texture11, "TOPLEFT", 2, -2)
frame.pixel:SetPoint("BOTTOMRIGHT", frame.texture11, "BOTTOMRIGHT", -2, 2)
frame.pixel:SetFontObject(GameFontNormalSmall)
frame.pixel:SetText("PP")
-- Hooks
-- These roundings only work properly on the default UIParent scales:
hooksecurefunc(frame, "SetPoint", function(self)
if self.moving then
return
end
if math.round(768 / (select(2, GetPhysicalScreenSize())) * 1000) / 1000 ~= math.round(UIParent:GetScale() * 1000) / 1000 then
return
end
self.moving = true
self:SetMovable(true)
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = math.round(left)
local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
self:SetMovable(false)
self.moving = nil
end)
-- These roundings only work properly on the default UIParent scales:
hooksecurefunc(frame, "StopMovingOrSizing", function(self)
if math.round(768 / (select(2, GetPhysicalScreenSize())) * 1000) / 1000 ~= math.round(UIParent:GetScale() * 1000) / 1000 then
return
end
self:SetMovable(true)
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = math.round(left)
local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
self:SetMovable(false)
end)
frame:HookScript("OnSizeChanged", function(self)
-- These roundings only work properly on the default UIParent scales:
if math.round(768 / (select(2, GetPhysicalScreenSize())) * 1000) / 1000 == math.round(UIParent:GetScale() * 1000) / 1000 then
self:SetSize(math.round(self:GetWidth()), math.round(self:GetHeight()))
end
local UIScale = (768 / (select(2, GetPhysicalScreenSize())) / UIParent:GetScale())
local scale = self:GetWidth() / self.width
self.scaled:SetScale(scale)
self.texture2:SetPoint("TOPLEFT", self.texture1, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture2:SetPoint("BOTTOMRIGHT", self.texture1, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture3:SetPoint("TOPLEFT", self.texture2, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture3:SetPoint("BOTTOMRIGHT", self.texture2, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture4:SetPoint("TOPLEFT", self.texture3, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture4:SetPoint("BOTTOMRIGHT", self.texture3, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture5:SetPoint("TOPLEFT", self.texture4, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture5:SetPoint("BOTTOMRIGHT", self.texture4, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture6:SetPoint("TOPLEFT", self.texture5, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture6:SetPoint("BOTTOMRIGHT", self.texture5, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture7:SetPoint("TOPLEFT", self.texture6, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture7:SetPoint("BOTTOMRIGHT", self.texture6, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture8:SetPoint("TOPLEFT", self.texture7, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture8:SetPoint("BOTTOMRIGHT", self.texture7, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture9:SetPoint("TOPLEFT", self.texture8, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture9:SetPoint("BOTTOMRIGHT", self.texture8, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture10:SetPoint("TOPLEFT", self.texture9, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture10:SetPoint("BOTTOMRIGHT", self.texture9, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
self.texture11:SetPoint("TOPLEFT", self.texture10, "TOPLEFT", math.round(2 * scale) * UIScale, math.round(-2 * scale) * UIScale)
self.texture11:SetPoint("BOTTOMRIGHT", self.texture10, "BOTTOMRIGHT", math.round(-2 * scale) * UIScale, math.round(2 * scale) * UIScale)
end)
-- Moving and Resizing functions
frame:EnableMouse(true)
--frame:SetMaxResize(800, 400)
frame:SetMinResize(42, 42)
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:SetMovable(true)
self:StartMoving()
end
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
self:SetMovable(false)
-- These roundings only work properly on the default UIParent scales:
if math.round(768 / (select(2, GetPhysicalScreenSize())) * 1000) / 1000 ~= math.round(UIParent:GetScale() * 1000) / 1000 then
return
end
local left, bottom = self:GetLeft(), self:GetBottom()
if left and bottom then
local x = math.round(left)
local y = math.round(-UIParent:GetHeight() + bottom + self:GetHeight())
self:ClearAllPoints()
self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", x, y)
end
end
end)
frame.br = CreateFrame("Frame", nil, frame)
frame.br:SetPoint("TOPLEFT", frame, "BOTTOMRIGHT", 0, 0)
frame.br:SetSize(12, 12)
frame.br:EnableMouse(true)
frame.br.texture = frame.br:CreateTexture(nil, "OVERLAY")
frame.br.texture:SetPoint("TOPLEFT", frame.br, "TOPLEFT", 0, 0)
frame.br.texture:SetSize(12, 12)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.br:SetScript("OnEnter", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.br:SetScript("OnLeave", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.br:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame:SetResizable(true)
frame:StartSizing("BottomRight")
end
end)
frame.br:SetScript("OnMouseUp", function(self, button)
frame:StopMovingOrSizing()
frame:SetResizable(false)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
end
function AddOn:OnLoad2()
local frame = CreateFrame("Frame", "TestFrame2", UIParent)
frame:SetSize(84, 84)
frame.width = 84
frame.height = 84
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", (UIParent:GetWidth() / 2) - (frame:GetWidth() / 2) + 100, (-UIParent:GetHeight() / 2) + (frame:GetHeight() / 2))
frame:SetClampedToScreen(true)
frame.backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 14,
insets = {left = 3, right = 3, top = 3, bottom = 3},
}
frame:SetBackdrop(frame.backdrop)
frame:SetBackdropColor(0.0, 0.0, 0.0, 0.5)
frame:SetBackdropBorderColor(0.3, 0.3, 0.3, 1.0)
frame.scaled = CreateFrame("Frame", nil, frame)
frame.scaled:SetAllPoints(frame)
frame.texture1 = frame:CreateTexture(nil, "ARTWORK", nil, -8)
frame.texture1:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -10)
frame.texture1:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 10)
frame.texture1:SetColorTexture(1, 1, 1, 1)
frame.texture2 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -7)
frame.texture2:SetPoint("TOPLEFT", frame.texture1, "TOPLEFT", 2, -2)
frame.texture2:SetPoint("BOTTOMRIGHT", frame.texture1, "BOTTOMRIGHT", -2, 2)
frame.texture2:SetColorTexture(0, 0, 0, 2)
frame.texture3 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -6)
frame.texture3:SetPoint("TOPLEFT", frame.texture2, "TOPLEFT", 2, -2)
frame.texture3:SetPoint("BOTTOMRIGHT", frame.texture2, "BOTTOMRIGHT", -2, 2)
frame.texture3:SetColorTexture(1, 1, 1, 1)
frame.texture4 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -5)
frame.texture4:SetPoint("TOPLEFT", frame.texture3, "TOPLEFT", 2, -2)
frame.texture4:SetPoint("BOTTOMRIGHT", frame.texture3, "BOTTOMRIGHT", -2, 2)
frame.texture4:SetColorTexture(0, 0, 0, 1)
frame.texture5 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -4)
frame.texture5:SetPoint("TOPLEFT", frame.texture4, "TOPLEFT", 2, -2)
frame.texture5:SetPoint("BOTTOMRIGHT", frame.texture4, "BOTTOMRIGHT", -2, 2)
frame.texture5:SetColorTexture(1, 1, 1, 1)
frame.texture6 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -3)
frame.texture6:SetPoint("TOPLEFT", frame.texture5, "TOPLEFT", 2, -2)
frame.texture6:SetPoint("BOTTOMRIGHT", frame.texture5, "BOTTOMRIGHT", -2, 2)
frame.texture6:SetColorTexture(0, 0, 0, 1)
frame.texture7 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -2)
frame.texture7:SetPoint("TOPLEFT", frame.texture6, "TOPLEFT", 2, -2)
frame.texture7:SetPoint("BOTTOMRIGHT", frame.texture6, "BOTTOMRIGHT", -2, 2)
frame.texture7:SetColorTexture(1, 1, 1, 1)
frame.texture8 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, -1)
frame.texture8:SetPoint("TOPLEFT", frame.texture7, "TOPLEFT", 2, -2)
frame.texture8:SetPoint("BOTTOMRIGHT", frame.texture7, "BOTTOMRIGHT", -2, 2)
frame.texture8:SetColorTexture(0, 0, 0, 1)
frame.texture9 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, 0)
frame.texture9:SetPoint("TOPLEFT", frame.texture8, "TOPLEFT", 2, -2)
frame.texture9:SetPoint("BOTTOMRIGHT", frame.texture8, "BOTTOMRIGHT", -2, 2)
frame.texture9:SetColorTexture(1, 1, 1, 1)
frame.texture10 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, 1)
frame.texture10:SetPoint("TOPLEFT", frame.texture9, "TOPLEFT", 2, -2)
frame.texture10:SetPoint("BOTTOMRIGHT", frame.texture9, "BOTTOMRIGHT", -2, 2)
frame.texture10:SetColorTexture(0, 0, 0, 1)
frame.texture11 = frame.scaled:CreateTexture(nil, "ARTWORK", nil, 2)
frame.texture11:SetPoint("TOPLEFT", frame.texture10, "TOPLEFT", 2, -2)
frame.texture11:SetPoint("BOTTOMRIGHT", frame.texture10, "BOTTOMRIGHT", -2, 2)
frame.texture11:SetColorTexture(1, 1, 1, 1)
frame.pixel = frame.scaled:CreateFontString(nil, "ARTWORK")
frame.pixel:SetPoint("TOPLEFT", frame.texture11, "TOPLEFT", 2, -2)
frame.pixel:SetPoint("BOTTOMRIGHT", frame.texture11, "BOTTOMRIGHT", -2, 2)
frame.pixel:SetFontObject(GameFontNormalSmall)
frame.pixel:SetText("NPP")
frame:HookScript("OnSizeChanged", function(self)
local scale = self:GetWidth() / self.width
self.scaled:SetScale(scale)
end)
-- Moving and Resizing functions
frame:EnableMouse(true)
--frame:SetMaxResize(800, 400)
frame:SetMinResize(42, 42)
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:SetMovable(true)
self:StartMoving()
end
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
self:SetMovable(false)
end
end)
frame.br = CreateFrame("Frame", nil, frame)
frame.br:SetPoint("TOPLEFT", frame, "BOTTOMRIGHT", 0, 0)
frame.br:SetSize(12, 12)
frame.br:EnableMouse(true)
frame.br.texture = frame.br:CreateTexture(nil, "OVERLAY")
frame.br.texture:SetPoint("TOPLEFT", frame.br, "TOPLEFT", 0, 0)
frame.br.texture:SetSize(12, 12)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.br:SetScript("OnEnter", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.br:SetScript("OnLeave", function(self)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.br:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame:SetResizable(true)
frame:StartSizing("BottomRight")
end
end)
frame.br:SetScript("OnMouseUp", function(self, button)
frame:StopMovingOrSizing()
frame:SetResizable(false)
frame.br.texture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
end