Thread: Resize frame
View Single Post
01-24-14, 10:58 AM   #8
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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:
  1. tObj = CreateFrame("Frame", "testframe", UIParent)
  2.     tObj:SetPoint("CENTER", UIParent, "CENTER")
  3.     tObj:SetHeight(100)
  4.     tObj:SetWidth(100)
  5.     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 }})
  6.     tObj:SetBackdropColor(0, 0, 0, 0.75)
  7.     tObj:EnableMouse(true)
  8.     tObj:SetMovable(true)
  9.     tObj:SetResizable(true)
  10.     tObj:SetScript("OnDragStart", function(self)
  11.         self.isMoving = true
  12.         self:StartMoving()
  13.     end)
  14.     tObj:SetScript("OnDragStop", function(self)
  15.         self.isMoving = false
  16.         self:StopMovingOrSizing()
  17.         self.x = self:GetLeft()
  18.         self.y = (self:GetTop() - self:GetHeight())
  19.         self:ClearAllPoints()
  20.         self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self.x, self.y)
  21.     end)
  22.     tObj:SetScript("OnUpdate", function(self)
  23.         if self.isMoving == true then
  24.             self.x = self:GetLeft()
  25.             self.y = (self:GetTop() - self:GetHeight())
  26.             self:ClearAllPoints()
  27.             self:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", self.x, self.y)
  28.         end
  29.     end)
  30.     tObj:SetClampedToScreen(true)
  31.     tObj:RegisterForDrag("LeftButton")
  32.     tObj:SetScale(1)
  33.     tObj.x = tObj:GetLeft()
  34.     tObj.y = (tObj:GetTop() - tObj:GetHeight())
  35.     tObj:Show()
  36.  
  37.     local resizeButton = CreateFrame("Button", "resButton", tObj)
  38.     resizeButton:SetSize(16, 16)
  39.     resizeButton:SetPoint("BOTTOMRIGHT")
  40.     resizeButton:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  41.     resizeButton:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  42.     resizeButton:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  43.     resizeButton:SetScript("OnMouseDown", function(self, button)
  44.         if button == "LeftButton" then
  45.             self.isSizing = true
  46.             self:GetParent():StartSizing("BOTTOMRIGHT")
  47.             self:GetParent():SetUserPlaced(true)
  48.         elseif button == "RightButton" then
  49.             self.isScaling = true
  50.         end
  51.     end)
  52.     resizeButton:SetScript("OnMouseUp", function(self, button)
  53.         if button == "LeftButton" then
  54.             self.isSizing = false
  55.             self:GetParent():StopMovingOrSizing()
  56.         elseif button == "RightButton" then
  57.             self.isScaling = false
  58.         end
  59.     end)
  60.     resizeButton:SetScript("OnUpdate", function(self, button)
  61.         if self.isScaling == true then
  62.             local cx, cy = GetCursorPosition()
  63.             cx = cx / self:GetEffectiveScale() - self:GetParent():GetLeft()
  64.             cy = self:GetParent():GetHeight() - (cy / self:GetEffectiveScale() - self:GetParent():GetBottom() )
  65.  
  66.             local tNewScale = cx / self:GetParent():GetWidth()
  67.             local tx, ty = self:GetParent().x / tNewScale, self:GetParent().y / tNewScale
  68.            
  69.             self:GetParent():ClearAllPoints()
  70.             self:GetParent():SetScale(self:GetParent():GetScale() * tNewScale)
  71.             self:GetParent():SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", tx, ty)
  72.             self:GetParent().x, self:GetParent().y = tx, ty
  73.         end
  74.     end)

Last edited by Duugu : 01-24-14 at 11:21 AM.
  Reply With Quote