Thread: Resize frame
View Single Post
01-25-14, 10:47 AM   #15
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
If you call this after you created a frame, then the frame is gonna be scaleable, and it's gonna build up everything needed for it:

Lua Code:
  1. function PowaAurasOptions:ResizeFrame(frame)
  2.     local Width = frame:GetWidth()
  3.     local Height = frame:GetHeight()
  4.     local resizeframe = CreateFrame("Frame", nil, frame)
  5.     resizeframe:SetPoint("BottomRight", frame, "BottomRight", - 8, 7)
  6.     resizeframe:SetWidth(16)
  7.     resizeframe:SetHeight(16)
  8.     resizeframe:SetFrameLevel(frame:GetFrameLevel() + 7)
  9.     resizeframe:EnableMouse(true)
  10.     local resizetexture = resizeframe:CreateTexture(nil, "Artwork")
  11.     resizetexture:SetPoint("TopLeft", resizeframe, "TopLeft", 0, 0)
  12.     resizetexture:SetWidth(16)
  13.     resizetexture:SetHeight(16)
  14.     resizetexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  15.     frame:SetMaxResize(Width * 1.5, Height * 1.5)
  16.     frame:SetMinResize(Width / 1.5, Height / 1.5)
  17.     frame:SetResizable(true)
  18.     resizeframe:SetScript("OnEnter", function(self)
  19.         resizetexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  20.     end)
  21.     resizeframe:SetScript("OnLeave", function(self)
  22.         resizetexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  23.     end)
  24.     resizeframe:SetScript("OnMouseDown", function(self, button)
  25.         if button == "RightButton" then
  26.             frame:SetWidth(Width)
  27.             frame:SetHeight(Height)
  28.         else
  29.             resizetexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  30.             frame:StartSizing("Right")
  31.         end
  32.     end)
  33.     resizeframe:SetScript("OnMouseUp", function(self, button)
  34.         local x, y = GetCursorPosition()
  35.         local fx = self:GetLeft() * self:GetEffectiveScale()
  36.         local fy = self:GetBottom() * self:GetEffectiveScale()
  37.         if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
  38.             resizetexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  39.         else
  40.             resizetexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  41.         end
  42.         frame:StopMovingOrSizing()
  43.     end)
  44.     local scrollframe = CreateFrame("ScrollFrame", nil, frame)
  45.     scrollframe:SetWidth(Width)
  46.     scrollframe:SetHeight(Height)
  47.     scrollframe:SetPoint("Topleft", frame, "Topleft", 0, 0)
  48.     frame:SetScript("OnSizeChanged", function(self)
  49.         local s = self:GetWidth() / Width
  50.         scrollframe:SetScale(s)
  51.         local childrens = {self:GetChildren()}
  52.         for _, child in ipairs(childrens) do
  53.             if child ~= resizeframe then
  54.                 child:SetScale(s)
  55.             end
  56.         end
  57.         self:SetHeight(Height * s)
  58.     end)
  59. end

There are still a few thing to do it with, like change the resize button's texture onmousedown and up.
Also ot exlude or only scale the scale button itself with lower frequency, to prevent it beeing unclickable. But its working properly.

Right click on the resize texture, reset the frame to the original size.

Last edited by Resike : 01-25-14 at 06:11 PM.
  Reply With Quote