-- This should be the saved variable which locks the scale
local ScaleLocked = false
-- Frame must have a global reference to properly save it's postion
function ResizeFrame(frame)
if not frame then
return
end
if frame.resizeable then
return
end
frame.width = frame:GetWidth()
frame.height = frame:GetHeight()
frame.scale = frame:GetScale()
frame.frameLevel = frame:GetFrameLevel()
frame:SetMovable(true)
frame:SetResizable(true)
frame:SetMaxResize(frame.width * 1.5, frame.height * 1.5)
frame:SetMinResize(frame.width / 1.5, frame.height / 1.5)
frame:SetUserPlaced(true)
if not frame.bottomrightframe then
frame.bottomrightframe = CreateFrame("Frame", nil, frame)
frame.bottomrightframe:SetFrameStrata(frame:GetFrameStrata())
frame.bottomrightframe:SetPoint("BottomRight", frame, "BottomRight", -8, 7)
frame.bottomrightframe:SetWidth(16)
frame.bottomrightframe:SetHeight(16)
frame.bottomrightframe:SetFrameLevel(frame.frameLevel + 7 or 20)
frame.bottomrightframe:EnableMouse(true)
end
if ScaleLocked then
frame.bottomrightframe:Hide()
else
frame.bottomrightframe:Show()
end
if not frame.bottomrighttexture then
frame.bottomrighttexture = frame.bottomrightframe:CreateTexture(nil, "Overlay")
frame.bottomrighttexture:SetPoint("TopLeft", frame.bottomrightframe, "TopLeft", 0, 0)
frame.bottomrighttexture:SetWidth(16)
frame.bottomrighttexture:SetHeight(16)
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.bottomrightframe:SetScript("OnEnter", function(self)
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.bottomrightframe:SetScript("OnLeave", function(self)
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.bottomrightframe:SetScript("OnMouseDown", function(self, button)
if button == "RightButton" then
frame.resizing = nil
frame:SetWidth(frame.width)
frame:SetHeight(frame.height)
local childrens = {frame:GetChildren()}
for _, child in ipairs(childrens) do
if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
child:SetScale(frame.scale)
end
end
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
if button == "MiddleButton" then
frame.bottomrightframe:Hide()
frame.bottomleftframe:Hide()
frame.toprightframe:Hide()
frame.topleftframe:Hide()
ScaleLocked = true
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
elseif button == "LeftButton" then
frame.resizing = true
frame.direction = "BottomRight"
frame:StartSizing("Right")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
end)
frame.bottomrightframe:SetScript("OnMouseUp", function(self, button)
local x, y = GetCursorPosition()
local fx = self:GetLeft() * self:GetEffectiveScale()
local fy = self:GetBottom() * self:GetEffectiveScale()
if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
else
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.resizing = nil
frame.direction = nil
frame:StopMovingOrSizing()
end)
if not frame.bottomleftframe then
frame.bottomleftframe = CreateFrame("Frame", nil, frame)
frame.bottomleftframe:SetFrameStrata(frame:GetFrameStrata())
frame.bottomleftframe:SetPoint("BottomLeft", frame, "BottomLeft", 8, 7)
frame.bottomleftframe:SetWidth(16)
frame.bottomleftframe:SetHeight(16)
frame.bottomleftframe:SetFrameLevel(frame.frameLevel + 7 or 20)
frame.bottomleftframe:EnableMouse(true)
end
if ScaleLocked then
frame.bottomleftframe:Hide()
else
frame.bottomleftframe:Show()
end
if not frame.bottomlefttexture then
frame.bottomlefttexture = frame.bottomleftframe:CreateTexture(nil, "Overlay")
local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.bottomlefttexture:GetTexCoord()
frame.bottomlefttexture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy)
frame.bottomlefttexture:SetPoint("TopLeft", frame.bottomleftframe, "TopLeft", 0, 0)
frame.bottomlefttexture:SetWidth(16)
frame.bottomlefttexture:SetHeight(16)
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.bottomleftframe:SetScript("OnEnter", function(self)
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.bottomleftframe:SetScript("OnLeave", function(self)
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.bottomleftframe:SetScript("OnMouseDown", function(self, button)
if button == "RightButton" then
frame.resizing = nil
frame:SetWidth(frame.width)
frame:SetHeight(frame.height)
local childrens = {frame:GetChildren()}
for _, child in ipairs(childrens) do
if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
child:SetScale(frame.scale)
end
end
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
if button == "MiddleButton" then
frame.bottomrightframe:Hide()
frame.bottomleftframe:Hide()
frame.toprightframe:Hide()
frame.topleftframe:Hide()
ScaleLocked = true
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
elseif button == "LeftButton" then
frame.resizing = true
frame.direction = "BottomLeft"
frame:StartSizing("Left")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
end)
frame.bottomleftframe:SetScript("OnMouseUp", function(self, button)
local x, y = GetCursorPosition()
local fx = self:GetLeft() * self:GetEffectiveScale()
local fy = self:GetBottom() * self:GetEffectiveScale()
if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
else
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.resizing = nil
frame.direction = nil
frame:StopMovingOrSizing()
end)
if not frame.topleftframe then
frame.topleftframe = CreateFrame("Frame", nil, frame)
frame.topleftframe:SetFrameStrata(frame:GetFrameStrata())
frame.topleftframe:SetPoint("TopLeft", frame, "TopLeft", 8, -7)
frame.topleftframe:SetWidth(16)
frame.topleftframe:SetHeight(16)
frame.topleftframe:SetFrameLevel(frame.frameLevel + 7 or 20)
frame.topleftframe:EnableMouse(true)
end
if ScaleLocked then
frame.topleftframe:Hide()
else
frame.topleftframe:Show()
end
if not frame.toplefttexture then
frame.toplefttexture = frame.topleftframe:CreateTexture(nil, "Overlay")
local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.toplefttexture:GetTexCoord()
frame.toplefttexture:SetTexCoord(LRx, LRy, URx, URy, LLx, LLy, ULx, ULy)
frame.toplefttexture:SetPoint("TopLeft", frame.topleftframe, "TopLeft", 0, 0)
frame.toplefttexture:SetWidth(16)
frame.toplefttexture:SetHeight(16)
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.topleftframe:SetScript("OnEnter", function(self)
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.topleftframe:SetScript("OnLeave", function(self)
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.topleftframe:SetScript("OnMouseDown", function(self, button)
frame.direction = "TopLeft"
if button == "RightButton" then
frame:SetWidth(frame.width)
frame:SetHeight(frame.height)
local childrens = {frame:GetChildren()}
for _, child in ipairs(childrens) do
if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
child:SetScale(frame.scale)
end
end
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
if button == "MiddleButton" then
frame.bottomrightframe:Hide()
frame.bottomleftframe:Hide()
frame.toprightframe:Hide()
frame.topleftframe:Hide()
ScaleLocked = true
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
elseif button == "LeftButton" then
frame.resizing = true
frame:StartSizing("Top")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
end)
frame.topleftframe:SetScript("OnMouseUp", function(self, button)
local x, y = GetCursorPosition()
local fx = self:GetLeft() * self:GetEffectiveScale()
local fy = self:GetBottom() * self:GetEffectiveScale()
if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
else
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.resizing = nil
frame.direction = nil
frame:StopMovingOrSizing()
end)
if not frame.toprightframe then
frame.toprightframe = CreateFrame("Frame", nil, frame)
frame.toprightframe:SetFrameStrata(frame:GetFrameStrata())
frame.toprightframe:SetPoint("TopRight", frame, "TopRight", -8, -7)
frame.toprightframe:SetWidth(16)
frame.toprightframe:SetHeight(16)
frame.toprightframe:SetFrameLevel(frame.frameLevel + 7 or 20)
frame.toprightframe:EnableMouse(true)
end
if ScaleLocked then
frame.toprightframe:Hide()
else
frame.toprightframe:Show()
end
if not frame.toprighttexture then
frame.toprighttexture = frame.toprightframe:CreateTexture(nil, "Overlay")
local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.toprighttexture:GetTexCoord()
frame.toprighttexture:SetTexCoord(LLx, LLy, ULx, ULy, LRx, LRy, URx, URy)
frame.toprighttexture:SetPoint("TopLeft", frame.toprightframe, "TopLeft", 0, 0)
frame.toprighttexture:SetWidth(16)
frame.toprighttexture:SetHeight(16)
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.toprightframe:SetScript("OnEnter", function(self)
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
end)
frame.toprightframe:SetScript("OnLeave", function(self)
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end)
frame.toprightframe:SetScript("OnMouseDown", function(self, button)
frame.direction = "TopRight"
if button == "RightButton" then
frame:SetWidth(frame.width)
frame:SetHeight(frame.height)
local childrens = {frame:GetChildren()}
for _, child in ipairs(childrens) do
if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
child:SetScale(frame.scale)
end
end
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
if button == "MiddleButton" then
frame.bottomrightframe:Hide()
frame.bottomleftframe:Hide()
frame.toprightframe:Hide()
frame.topleftframe:Hide()
ScaleLocked = true
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
elseif button == "LeftButton" then
frame.resizing = true
frame:StartSizing("Top")
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
end
end)
frame.toprightframe:SetScript("OnMouseUp", function(self, button)
local x, y = GetCursorPosition()
local fx = self:GetLeft() * self:GetEffectiveScale()
local fy = self:GetBottom() * self:GetEffectiveScale()
if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
else
frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
end
frame.resizing = nil
frame.direction = nil
frame:StopMovingOrSizing()
end)
frame:SetScript("OnSizeChanged", function(self)
local left, bottom = self:GetLeft(), self:GetBottom()
if self.direction == "TopLeft" or self.direction == "TopRight" then
if self.resizing then
self:ClearAllPoints()
if frame.direction == "TopLeft" then
self:SetPoint("BottomRight", UIParent, "BottomRight", - (UIParent:GetWidth() - (left + self:GetWidth())), bottom)
else
self:SetPoint("BottomLeft", UIParent, "BottomLeft", left, bottom)
end
end
local s = self:GetHeight() / frame.height
local childrens = {self:GetChildren()}
for _, child in ipairs(childrens) do
if child ~= self.bottomleftframe and child ~= self.bottomrightframe and child ~= self.toprightframe and child ~= self.topleftframe then
child:SetScale(s)
end
end
self:SetWidth(frame.width * s)
else
if self.resizing then
self:ClearAllPoints()
if frame.direction == "BottomLeft" then
self:SetPoint("TopLeft", UIParent, "TopLeft", left, (UIParent:GetWidth() - (bottom + self:GetHeight())))
else
self:SetPoint("TopLeft", UIParent, "TopLeft", left, (UIParent:GetWidth() - (bottom + self:GetHeight())))
end
end
local s = self:GetWidth() / frame.width
local childrens = {self:GetChildren()}
for _, child in ipairs(childrens) do
if child ~= self.bottomleftframe and child ~= self.bottomrightframe and child ~= self.toprightframe and child ~= self.topleftframe then
child:SetScale(s)
end
end
self:SetHeight(frame.height * s)
end
end)
frame.resizeable = true
end