left button at frame background and draging = drag frame
left button at resize button and draging = resize frame
right button at resize button and draging = rescale frame
Rescaling is affected by horizontal mouse movement only. Someone has to implement the y axis.
It's not perfect but it's working.
Nevertheles I do agree with Vrul. Scaling a fame is never the best way to do anything size-related. In best case it just adds an extra level of complexity to your code. In worst case all your visible objects are a total mess.
[e] Didn't tested what would happen to child object of my test frame. And I'm seriously afraid of finding it out. ;D
Lua Code:
tObj = CreateFrame("Frame", "testframe", UIParent)
tObj:SetPoint("CENTER", UIParent, "CENTER")
tObj:SetHeight(100)
tObj:SetWidth(100)
tObj:SetBackdrop({bgFile="Interface\\Tooltips\\UI-Tooltip-Background", edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", tile = false, tileSize = 1, edgeSize = 10, insets = { left = 0, right = 0, top = 0, bottom = 0 }})
tObj:SetBackdropColor(0, 0, 0, 0.75)
tObj:EnableMouse(true)
tObj:SetMovable(true)
tObj:SetResizable(true)
tObj:SetScript("OnDragStart", function(self)
self.isMoving = true
self:StartMoving()
end)
tObj:SetScript("OnDragStop", function(self)
self.isMoving = false
self:StopMovingOrSizing()
self.x = self:GetLeft()
self.y = (self:GetTop() - self:GetHeight())
self:ClearAllPoints()
self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self.x, self.y)
end)
tObj:SetScript("OnUpdate", function(self)
if self.isMoving == true then
self.x = self:GetLeft()
self.y = (self:GetTop() - self:GetHeight())
self:ClearAllPoints()
self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self.x, self.y)
end
end)
tObj:SetClampedToScreen(true)
tObj:RegisterForDrag("LeftButton")
tObj:SetScale(1)
tObj.x = tObj:GetLeft()
tObj.y = (tObj:GetTop() - tObj:GetHeight())
tObj:Show()
local resizeButton = CreateFrame("Button", "resButton", tObj)
resizeButton:SetSize(16, 16)
resizeButton:SetPoint("BOTTOMRIGHT")
resizeButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resizeButton:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resizeButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
resizeButton:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self.isSizing = true
self:GetParent():StartSizing("BOTTOMRIGHT")
self:GetParent():SetUserPlaced(true)
elseif button == "RightButton" then
self.isScaling = true
end
end)
resizeButton:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self.isSizing = false
self:GetParent():StopMovingOrSizing()
elseif button == "RightButton" then
self.isScaling = false
end
end)
resizeButton:SetScript("OnUpdate", function(self, button)
if self.isScaling == true then
local cx, cy = GetCursorPosition()
cx = cx / self:GetEffectiveScale() - self:GetParent():GetLeft()
cy = self:GetParent():GetHeight() - (cy / self:GetEffectiveScale() - self:GetParent():GetBottom() )
local tNewScale = cx / self:GetParent():GetWidth()
local tx, ty = self:GetParent().x / tNewScale, self:GetParent().y / tNewScale
self:GetParent():ClearAllPoints()
self:GetParent():SetScale(self:GetParent():GetScale() * tNewScale)
self:GetParent():SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", tx, ty)
self:GetParent().x, self:GetParent().y = tx, ty
end
end)