Lua Code:
math.round = function(self)
return math.floor(self + 0.5)
end
local frame = CreateFrame("Frame", "TestFrame", UIParent)
frame:SetSize(400, 200)
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)
-- Hooks
hooksecurefunc(frame, "SetPoint", function(self)
if self.moving 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)
hooksecurefunc(frame, "StopMovingOrSizing", function(self)
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)
self:SetSize(math.round(self:GetWidth()), math.round(self:GetHeight()))
end)
-- Moving and Resizing functions
frame:EnableMouse(true)
--frame:SetMaxResize(800, 400)
frame:SetMinResize(40, 40)
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)
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", -15, 15)
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)
This frame can be moved/resized on the fly, and it keeps it's pixel perfection sizes on all of it's elements all the time, even after any (SetSize|SetWidth|SetHeight|SetPoint) calls.