Thread Tools Display Modes
01-25-14, 03:05 PM   #21
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Duugu View Post
Nice one. I'll definitly bookmark this for later use.



My guess is that's due to the way the moving stuff works. It re-anchors the frame all the time (to the nearest anchor point or whatever ... I don't know ). If you anchor a frame to center/center and move it to the left then it will be re-anchored to left/left or something.

You can work around this annoying behavior with re-anchoring it to the desired anchor on OnDragStop.

Lua Code:
  1. frame:SetScript("OnDragStop", function(self)
  2.         self:StopMovingOrSizing()
  3.         self.x = self:GetLeft()
  4.         self.y = (self:GetTop() - self:GetHeight())
  5.         self:ClearAllPoints()
  6.         self:SetPoint("BOTTOMLEFT", self:GetParent(), "BOTTOMLEFT", self.x, self.y)
  7.     end)
I actually did the same thing ondragstop, however i havn't repointed the frame just saved the coords, but i don't think reparenting is needed there:

Lua Code:
  1. function PowaAurasOptions:FrameMouseUp(frame, button)
  2.     frame.x = frame:GetLeft()
  3.     frame.y = frame:GetBottom()
  4.     frame:StopMovingOrSizing()
  5. end
  Reply With Quote
01-25-14, 06:12 PM   #22
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Edit: Updated my code with the minor leftover modifications.
  Reply With Quote
01-26-14, 11:39 AM   #23
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by Seerah View Post
Peggle does not have a license which allows you to "reverse engineer" and "ninja" its code.
IANAL. My brief research into the DMCA's reverse engineering exemption says that reverse engineering is okay to achieve "interoperability". "Interoperability" is defined as "the ability of computer programs to exchange information, and of such programs mutually to use the information which has been exchanged". In this case, as nothing is trying to inter-operate with Peggle, it doesn't look like it's covered.

So, to sum up: the obfuscation in Peggle probably qualifies as "a technological measure that effectively controls access to a work protected under this title" meaning that, unless it's for "interoperability", reverse engineering the obfuscation is not protected under the DMCA. It is almost certainly denotatively illegal to remove the obfuscation from the Peggle source code. (...for any purpose other than to achieve "interoperability" with it.)

Personally, it would probably be the last addon on my list of addons to look for good code in. Given the fact that there is almost certainly an un-obfuscated addon that has frame code that does what you were looking for properly, getting down to Peggle on the list of addons to check would almost certainly never happen.*


-------------
* That said, if somehow Peggle was my last bastion of hope in a miraculously disastrous sequence of attempts to learn what I needed to learn by other means... They can't be calling any API other than the API we are all using. At the point of last resort, if reading their code improves my understanding of how to call the API, what to provide to it and in what order it should be called, I don't consider such learning to be profiting from another party's novel implementation. There is likely a discrete set of "correct" ways to configure frames' properties and behaviors. To me, seeing a "correct" way of doing something in Peggle's code and using the information to make one's own code more correct does not diminish their copyright.
  Reply With Quote
01-26-14, 12:49 PM   #24
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by pelf View Post
IANAL. My brief research into the DMCA's reverse engineering exemption says that reverse engineering is okay to achieve "interoperability". "Interoperability" is defined as "the ability of computer programs to exchange information, and of such programs mutually to use the information which has been exchanged". In this case, as nothing is trying to inter-operate with Peggle, it doesn't look like it's covered.

So, to sum up: the obfuscation in Peggle probably qualifies as "a technological measure that effectively controls access to a work protected under this title" meaning that, unless it's for "interoperability", reverse engineering the obfuscation is not protected under the DMCA. It is almost certainly denotatively illegal to remove the obfuscation from the Peggle source code. (...for any purpose other than to achieve "interoperability" with it.)

Personally, it would probably be the last addon on my list of addons to look for good code in. Given the fact that there is almost certainly an un-obfuscated addon that has frame code that does what you were looking for properly, getting down to Peggle on the list of addons to check would almost certainly never happen.*


-------------
* That said, if somehow Peggle was my last bastion of hope in a miraculously disastrous sequence of attempts to learn what I needed to learn by other means... They can't be calling any API other than the API we are all using. At the point of last resort, if reading their code improves my understanding of how to call the API, what to provide to it and in what order it should be called, I don't consider such learning to be profiting from another party's novel implementation. There is likely a discrete set of "correct" ways to configure frames' properties and behaviors. To me, seeing a "correct" way of doing something in Peggle's code and using the information to make one's own code more correct does not diminish their copyright.
I think you summed up pretty good. However you can't deny Peggle could hold a lot of usable code for any developer who is intrested making similar game addons as Peggle.

While PopCap stated that they only obfuscated their code to keep the memory usage at the bottom, is a big fat lie. I also don't think they did it so other's can't use their code. Because whoever want to use their code the obfuscatiton won't stop them.

I think they only did this to generate a hype about the addon after it's release, and i think they have suceeded. Because it's been 4 years and it's still on the table.

Personally i don't think i hurt anyone with reviewing the code, also changing lines like this:

Lua Code:
  1. local f=CreateFrame("Frame", "", n);

To this:

Lua Code:
  1. local frame = CreateFrame("Frame", nil, parent)

Even scratch any level of reverse engineering.

But anyone would like check the original code i used to write mine, and compare it to my final versions feel free to ask, i'll gladly provide it.

Also i could have keep the info i gained to myself (Who would have noticed if it's from Peggle or not?), but instead i decided to share it with the community, for future learning/usage.

Last edited by Resike : 01-26-14 at 12:55 PM.
  Reply With Quote
01-27-14, 06:29 AM   #25
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
I think they only did this to generate a hype about the addon after it's release, and i think they have suceeded. Because it's been 4 years and it's still on the table.
Off topic, but I really don't think "it has obfuscated code" is, or has ever been, a selling point for any addon. I had a lot of friends and guildmates who played Peggle back in Wrath -- and I myself played Bejeweled -- and I never once heard anyone mention anything about code obfuscation. Peggle has "succeeded" because it's a fun little distraction you can play inside WoW while you're waiting for your raid to form, waiting for your queue to pop, etc. There are other minigame addons, sure, but most of them do not come anywhere near the level of immediately-accessible fun, replay value, and overall polish that professionally-made games like Peggle and Bejeweled offer. It's not really a mystery why these are more popular than, say, in-game chess.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-27-14, 06:39 AM   #26
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Off topic, but I really don't think "it has obfuscated code" is, or has ever been, a selling point for any addon. I had a lot of friends and guildmates who played Peggle back in Wrath -- and I myself played Bejeweled -- and I never once heard anyone mention anything about code obfuscation. Peggle has "succeeded" because it's a fun little distraction you can play inside WoW while you're waiting for your raid to form, waiting for your queue to pop, etc. There are other minigame addons, sure, but most of them do not come anywhere near the level of immediately-accessible fun, replay value, and overall polish that professionally-made games like Peggle and Bejeweled offer. It's not really a mystery why these are more popular than, say, in-game chess.
I'm not telling its a hype about user level more likely on dev level:

http://wow.joystiq.com/2009/05/04/po...-ok-with-that/

https://threadmeters.com/wow/hYSRcv/...cated_code_OK/

We spoke with PopCap about the issue, and they told us that yes, they run a program called luasrcdiet on their code to shrink it down and keep the memory footprint to a minimum.
  Reply With Quote
01-27-14, 04:55 PM   #27
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
I'm not telling its a hype about user level more likely on dev level:
Eh, I haven't even heard of that second site, and I've never read anything on the first... I don't know any other addon authors who read "addon news sites" either, though obviously if they continue to exist then I guess someone must be reading them, but really, who cares? It's just overblown link bait that doesn't tell me anything useful or interesting. All that matters is what Blizzard is doing with the API, and I don't need some random ad-infested blog-spam site to tell me about API changes.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-10-14, 03:33 PM   #28
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I recently updated this code to allow the user 4 way rescaling, also some other tweaks.

Lua Code:
  1. -- This should be the saved variable which locks the scale
  2. local ScaleLocked = false
  3.  
  4. -- Frame must have a global reference to properly save it's postion
  5. function ResizeFrame(frame)
  6.     if not frame then
  7.         return
  8.     end
  9.     if frame.resizeable then
  10.         return
  11.     end
  12.     frame.width = frame:GetWidth()
  13.     frame.height = frame:GetHeight()
  14.     frame.scale = frame:GetScale()
  15.     frame.frameLevel = frame:GetFrameLevel()
  16.     frame:SetMovable(true)
  17.     frame:SetResizable(true)
  18.     frame:SetMaxResize(frame.width * 1.5, frame.height * 1.5)
  19.     frame:SetMinResize(frame.width / 1.5, frame.height / 1.5)
  20.     frame:SetUserPlaced(true)
  21.     if not frame.bottomrightframe then
  22.         frame.bottomrightframe = CreateFrame("Frame", nil, frame)
  23.         frame.bottomrightframe:SetFrameStrata(frame:GetFrameStrata())
  24.         frame.bottomrightframe:SetPoint("BottomRight", frame, "BottomRight", -8, 7)
  25.         frame.bottomrightframe:SetWidth(16)
  26.         frame.bottomrightframe:SetHeight(16)
  27.         frame.bottomrightframe:SetFrameLevel(frame.frameLevel + 7 or 20)
  28.         frame.bottomrightframe:EnableMouse(true)
  29.     end
  30.     if ScaleLocked then
  31.         frame.bottomrightframe:Hide()
  32.     else
  33.         frame.bottomrightframe:Show()
  34.     end
  35.     if not frame.bottomrighttexture then
  36.         frame.bottomrighttexture = frame.bottomrightframe:CreateTexture(nil, "Overlay")
  37.         frame.bottomrighttexture:SetPoint("TopLeft", frame.bottomrightframe, "TopLeft", 0, 0)
  38.         frame.bottomrighttexture:SetWidth(16)
  39.         frame.bottomrighttexture:SetHeight(16)
  40.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  41.     end
  42.     frame.bottomrightframe:SetScript("OnEnter", function(self)
  43.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  44.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  45.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  46.     end)
  47.     frame.bottomrightframe:SetScript("OnLeave", function(self)
  48.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  49.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  50.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  51.     end)
  52.     frame.bottomrightframe:SetScript("OnMouseDown", function(self, button)
  53.         if button == "RightButton" then
  54.             frame.resizing = nil
  55.             frame:SetWidth(frame.width)
  56.             frame:SetHeight(frame.height)
  57.             local childrens = {frame:GetChildren()}
  58.             for _, child in ipairs(childrens) do
  59.                 if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
  60.                     child:SetScale(frame.scale)
  61.                 end
  62.             end
  63.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  64.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  65.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  66.         end
  67.         if button == "MiddleButton" then
  68.             frame.bottomrightframe:Hide()
  69.             frame.bottomleftframe:Hide()
  70.             frame.toprightframe:Hide()
  71.             frame.topleftframe:Hide()
  72.             ScaleLocked = true
  73.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  74.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  75.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  76.         elseif button == "LeftButton" then
  77.             frame.resizing = true
  78.             frame.direction = "BottomRight"
  79.             frame:StartSizing("Right")
  80.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  81.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  82.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  83.         end
  84.     end)
  85.     frame.bottomrightframe:SetScript("OnMouseUp", function(self, button)
  86.         local x, y = GetCursorPosition()
  87.         local fx = self:GetLeft() * self:GetEffectiveScale()
  88.         local fy = self:GetBottom() * self:GetEffectiveScale()
  89.         if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
  90.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  91.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  92.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  93.         else
  94.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  95.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  96.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  97.         end
  98.         frame.resizing = nil
  99.         frame.direction = nil
  100.         frame:StopMovingOrSizing()
  101.     end)
  102.     if not frame.bottomleftframe then
  103.         frame.bottomleftframe = CreateFrame("Frame", nil, frame)
  104.         frame.bottomleftframe:SetFrameStrata(frame:GetFrameStrata())
  105.         frame.bottomleftframe:SetPoint("BottomLeft", frame, "BottomLeft", 8, 7)
  106.         frame.bottomleftframe:SetWidth(16)
  107.         frame.bottomleftframe:SetHeight(16)
  108.         frame.bottomleftframe:SetFrameLevel(frame.frameLevel + 7 or 20)
  109.         frame.bottomleftframe:EnableMouse(true)
  110.     end
  111.     if ScaleLocked then
  112.         frame.bottomleftframe:Hide()
  113.     else
  114.         frame.bottomleftframe:Show()
  115.     end
  116.     if not frame.bottomlefttexture then
  117.         frame.bottomlefttexture = frame.bottomleftframe:CreateTexture(nil, "Overlay")
  118.         local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.bottomlefttexture:GetTexCoord()
  119.         frame.bottomlefttexture:SetTexCoord(URx, URy, LRx, LRy, ULx, ULy, LLx, LLy)
  120.         frame.bottomlefttexture:SetPoint("TopLeft", frame.bottomleftframe, "TopLeft", 0, 0)
  121.         frame.bottomlefttexture:SetWidth(16)
  122.         frame.bottomlefttexture:SetHeight(16)
  123.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  124.     end
  125.     frame.bottomleftframe:SetScript("OnEnter", function(self)
  126.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  127.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  128.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  129.     end)
  130.     frame.bottomleftframe:SetScript("OnLeave", function(self)
  131.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  132.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  133.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  134.     end)
  135.     frame.bottomleftframe:SetScript("OnMouseDown", function(self, button)
  136.         if button == "RightButton" then
  137.             frame.resizing = nil
  138.             frame:SetWidth(frame.width)
  139.             frame:SetHeight(frame.height)
  140.             local childrens = {frame:GetChildren()}
  141.             for _, child in ipairs(childrens) do
  142.                 if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
  143.                     child:SetScale(frame.scale)
  144.                 end
  145.             end
  146.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  147.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  148.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  149.         end
  150.         if button == "MiddleButton" then
  151.             frame.bottomrightframe:Hide()
  152.             frame.bottomleftframe:Hide()
  153.             frame.toprightframe:Hide()
  154.             frame.topleftframe:Hide()
  155.             ScaleLocked = true
  156.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  157.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  158.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  159.         elseif button == "LeftButton" then
  160.             frame.resizing = true
  161.             frame.direction = "BottomLeft"
  162.             frame:StartSizing("Left")
  163.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  164.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  165.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  166.         end
  167.     end)
  168.     frame.bottomleftframe:SetScript("OnMouseUp", function(self, button)
  169.         local x, y = GetCursorPosition()
  170.         local fx = self:GetLeft() * self:GetEffectiveScale()
  171.         local fy = self:GetBottom() * self:GetEffectiveScale()
  172.         if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
  173.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  174.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  175.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  176.         else
  177.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  178.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  179.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  180.         end
  181.         frame.resizing = nil
  182.         frame.direction = nil
  183.         frame:StopMovingOrSizing()
  184.     end)
  185.     if not frame.topleftframe then
  186.         frame.topleftframe = CreateFrame("Frame", nil, frame)
  187.         frame.topleftframe:SetFrameStrata(frame:GetFrameStrata())
  188.         frame.topleftframe:SetPoint("TopLeft", frame, "TopLeft", 8, -7)
  189.         frame.topleftframe:SetWidth(16)
  190.         frame.topleftframe:SetHeight(16)
  191.         frame.topleftframe:SetFrameLevel(frame.frameLevel + 7 or 20)
  192.         frame.topleftframe:EnableMouse(true)
  193.     end
  194.     if ScaleLocked then
  195.         frame.topleftframe:Hide()
  196.     else
  197.         frame.topleftframe:Show()
  198.     end
  199.     if not frame.toplefttexture then
  200.         frame.toplefttexture = frame.topleftframe:CreateTexture(nil, "Overlay")
  201.         local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.toplefttexture:GetTexCoord()
  202.         frame.toplefttexture:SetTexCoord(LRx, LRy, URx, URy, LLx, LLy, ULx, ULy)
  203.         frame.toplefttexture:SetPoint("TopLeft", frame.topleftframe, "TopLeft", 0, 0)
  204.         frame.toplefttexture:SetWidth(16)
  205.         frame.toplefttexture:SetHeight(16)
  206.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  207.     end
  208.     frame.topleftframe:SetScript("OnEnter", function(self)
  209.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  210.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  211.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  212.     end)
  213.     frame.topleftframe:SetScript("OnLeave", function(self)
  214.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  215.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  216.         frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  217.     end)
  218.     frame.topleftframe:SetScript("OnMouseDown", function(self, button)
  219.         frame.direction = "TopLeft"
  220.         if button == "RightButton" then
  221.             frame:SetWidth(frame.width)
  222.             frame:SetHeight(frame.height)
  223.             local childrens = {frame:GetChildren()}
  224.             for _, child in ipairs(childrens) do
  225.                 if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
  226.                     child:SetScale(frame.scale)
  227.                 end
  228.             end
  229.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  230.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  231.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  232.         end
  233.         if button == "MiddleButton" then
  234.             frame.bottomrightframe:Hide()
  235.             frame.bottomleftframe:Hide()
  236.             frame.toprightframe:Hide()
  237.             frame.topleftframe:Hide()
  238.             ScaleLocked = true
  239.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  240.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  241.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  242.         elseif button == "LeftButton" then
  243.             frame.resizing = true
  244.             frame:StartSizing("Top")
  245.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  246.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  247.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  248.         end
  249.     end)
  250.     frame.topleftframe:SetScript("OnMouseUp", function(self, button)
  251.         local x, y = GetCursorPosition()
  252.         local fx = self:GetLeft() * self:GetEffectiveScale()
  253.         local fy = self:GetBottom() * self:GetEffectiveScale()
  254.         if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
  255.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  256.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  257.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  258.         else
  259.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  260.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  261.             frame.bottomlefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  262.         end
  263.         frame.resizing = nil
  264.         frame.direction = nil
  265.         frame:StopMovingOrSizing()
  266.     end)
  267.     if not frame.toprightframe then
  268.         frame.toprightframe = CreateFrame("Frame", nil, frame)
  269.         frame.toprightframe:SetFrameStrata(frame:GetFrameStrata())
  270.         frame.toprightframe:SetPoint("TopRight", frame, "TopRight", -8, -7)
  271.         frame.toprightframe:SetWidth(16)
  272.         frame.toprightframe:SetHeight(16)
  273.         frame.toprightframe:SetFrameLevel(frame.frameLevel + 7 or 20)
  274.         frame.toprightframe:EnableMouse(true)
  275.     end
  276.     if ScaleLocked then
  277.         frame.toprightframe:Hide()
  278.     else
  279.         frame.toprightframe:Show()
  280.     end
  281.     if not frame.toprighttexture then
  282.         frame.toprighttexture = frame.toprightframe:CreateTexture(nil, "Overlay")
  283.         local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = frame.toprighttexture:GetTexCoord()
  284.         frame.toprighttexture:SetTexCoord(LLx, LLy, ULx, ULy, LRx, LRy, URx, URy)
  285.         frame.toprighttexture:SetPoint("TopLeft", frame.toprightframe, "TopLeft", 0, 0)
  286.         frame.toprighttexture:SetWidth(16)
  287.         frame.toprighttexture:SetHeight(16)
  288.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  289.     end
  290.     frame.toprightframe:SetScript("OnEnter", function(self)
  291.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  292.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  293.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  294.     end)
  295.     frame.toprightframe:SetScript("OnLeave", function(self)
  296.         frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  297.         frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  298.         frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  299.     end)
  300.     frame.toprightframe:SetScript("OnMouseDown", function(self, button)
  301.         frame.direction = "TopRight"
  302.         if button == "RightButton" then
  303.             frame:SetWidth(frame.width)
  304.             frame:SetHeight(frame.height)
  305.             local childrens = {frame:GetChildren()}
  306.             for _, child in ipairs(childrens) do
  307.                 if child ~= frame.bottomleftframe and child ~= frame.bottomrightframe and child ~= frame.toprightframe and child ~= frame.topleftframe then
  308.                     child:SetScale(frame.scale)
  309.                 end
  310.             end
  311.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  312.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  313.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  314.         end
  315.         if button == "MiddleButton" then
  316.             frame.bottomrightframe:Hide()
  317.             frame.bottomleftframe:Hide()
  318.             frame.toprightframe:Hide()
  319.             frame.topleftframe:Hide()
  320.             ScaleLocked = true
  321.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  322.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  323.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  324.         elseif button == "LeftButton" then
  325.             frame.resizing = true
  326.             frame:StartSizing("Top")
  327.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  328.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  329.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
  330.         end
  331.     end)
  332.     frame.toprightframe:SetScript("OnMouseUp", function(self, button)
  333.         local x, y = GetCursorPosition()
  334.         local fx = self:GetLeft() * self:GetEffectiveScale()
  335.         local fy = self:GetBottom() * self:GetEffectiveScale()
  336.         if x >= fx and x <= (fx + self:GetWidth()) and y >= fy and y <= (fy + self:GetHeight()) then
  337.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  338.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  339.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
  340.         else
  341.             frame.toprighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  342.             frame.toplefttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  343.             frame.bottomrighttexture:SetTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
  344.         end
  345.         frame.resizing = nil
  346.         frame.direction = nil
  347.         frame:StopMovingOrSizing()
  348.     end)
  349.     frame:SetScript("OnSizeChanged", function(self)
  350.         local left, bottom = self:GetLeft(), self:GetBottom()
  351.         if self.direction == "TopLeft" or self.direction == "TopRight" then
  352.             if self.resizing then
  353.                 self:ClearAllPoints()
  354.                 if frame.direction == "TopLeft" then
  355.                     self:SetPoint("BottomRight", UIParent, "BottomRight", - (UIParent:GetWidth() - (left + self:GetWidth())), bottom)
  356.                 else
  357.                     self:SetPoint("BottomLeft", UIParent, "BottomLeft", left, bottom)
  358.                 end
  359.             end
  360.             local s = self:GetHeight() / frame.height
  361.             local childrens = {self:GetChildren()}
  362.             for _, child in ipairs(childrens) do
  363.                 if child ~= self.bottomleftframe and child ~= self.bottomrightframe and child ~= self.toprightframe and child ~= self.topleftframe then
  364.                     child:SetScale(s)
  365.                 end
  366.             end
  367.             self:SetWidth(frame.width * s)
  368.         else
  369.             if self.resizing then
  370.                 self:ClearAllPoints()
  371.                 if frame.direction == "BottomLeft" then
  372.                     self:SetPoint("TopLeft", UIParent, "TopLeft", left, (UIParent:GetWidth() - (bottom + self:GetHeight())))
  373.                 else
  374.                     self:SetPoint("TopLeft", UIParent, "TopLeft", left, (UIParent:GetWidth() - (bottom + self:GetHeight())))
  375.                 end
  376.             end
  377.             local s = self:GetWidth() / frame.width
  378.             local childrens = {self:GetChildren()}
  379.             for _, child in ipairs(childrens) do
  380.                 if child ~= self.bottomleftframe and child ~= self.bottomrightframe and child ~= self.toprightframe and child ~= self.topleftframe then
  381.                     child:SetScale(s)
  382.                 end
  383.             end
  384.             self:SetHeight(frame.height * s)
  385.         end
  386.     end)
  387.     frame.resizeable = true
  388. end

Last edited by Resike : 07-11-14 at 07:23 AM.
  Reply With Quote
07-10-14, 05:15 PM   #29
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Why bother checking whether the corner resizers were already created, when the function will only run once per frame anyway? And if you're intending for the function to be able to run multiple times per frame (so that the checks make sense) then why re-create and re-set the same scripts on the resizers over and over instead of setting them just once when you create the resizers? Also, you have a huge amount of duplicate code in there, you're not using proper capitalization for frame types or layers or points, you're using if-end/if-end instead of if-else-end, and several things in there just don't make any sense, like:

Code:
frame.bottomrightframe:SetFrameLevel(frame.frameLevel + 7 or 20)
What on earth is the "or 20" for? There's no check being performed here...
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-11-14, 07:23 AM   #30
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Why bother checking whether the corner resizers were already created, when the function will only run once per frame anyway? And if you're intending for the function to be able to run multiple times per frame (so that the checks make sense) then why re-create and re-set the same scripts on the resizers over and over instead of setting them just once when you create the resizers? Also, you have a huge amount of duplicate code in there, you're not using proper capitalization for frame types or layers or points, you're using if-end/if-end instead of if-else-end, and several things in there just don't make any sense, like:

Code:
frame.bottomrightframe:SetFrameLevel(frame.frameLevel + 7 or 20)
What on earth is the "or 20" for? There's no check being performed here...
I actually just merged this from two different codes, so it's not optimized properly yet. About the capitalization it's simply because it's much easier to read "TopLeft", then "TOPLEFT" at least for me.
  Reply With Quote
07-11-14, 08:04 PM   #31
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That's not a very good excuse for using values that are techinically wrong. While the WoW API will auto-correct "TopLeft" to "TOPLEFT" when you pass that wrong value into eg. SetPoint, the value you get back from, eg. GetPoint will be the correctly-written "TOPLEFT", which means if you're ever comparing values, either your comparison will fail because you're using the wrong value, or your code ends up with inconsistent capitalization depending on what you're doing with the string at the moment. Much better to just use the correct values in the first place in a case-sensitive language like Lua.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-13-14, 02:14 PM   #32
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
That's not a very good excuse for using values that are techinically wrong. While the WoW API will auto-correct "TopLeft" to "TOPLEFT" when you pass that wrong value into eg. SetPoint, the value you get back from, eg. GetPoint will be the correctly-written "TOPLEFT", which means if you're ever comparing values, either your comparison will fail because you're using the wrong value, or your code ends up with inconsistent capitalization depending on what you're doing with the string at the moment. Much better to just use the correct values in the first place in a case-sensitive language like Lua.
Lua might be case sensitive, but its a wow api, doesn't really matter whats the input it its will be stored in capitalized, and will be used capitalized. And im fairly sure the function which handles this stuff won't investiage if it's got the right capitalized variable or not simply just gonna slap in into a strupper(). If i'm gonna compare values like this, then i'll be carefull and use the correctly capitalized way ofc.
However i'm pretty sure every programmer have his own little things, which might seems meaningless to others, but not everyone follows the book by every word.
  Reply With Quote
07-14-14, 03:12 AM   #33
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Eh, you're free to write code however you want, but I just don't see why you'd willfully write things incorrectly just because certain API functions will silently correct for your mistakes. I guess it's the same mentality that leads people to write crap like "ur" and "bcuz"... as long as it works, why bother doing it right?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-14-14, 03:54 AM   #34
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Eh, you're free to write code however you want, but I just don't see why you'd willfully write things incorrectly just because certain API functions will silently correct for your mistakes. I guess it's the same mentality that leads people to write crap like "ur" and "bcuz"... as long as it works, why bother doing it right?
It not the same thing, it's actually the opposite, i do it for better readability not to shorten things or because i can.
I think it specially annoying if you are forced to use function like this case sensitive, just like the java "String".

Last edited by Resike : 07-14-14 at 03:58 AM.
  Reply With Quote
07-14-14, 04:13 AM   #35
Talyrius
An Onyxian Warder
 
Talyrius's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 363
Originally Posted by Phanx View Post
... I guess it's the same mentality that leads people to write crap like "ur" and "bcuz"... as long as it works, why bother doing it right?
ikr? propr eng is a catwot! ev1 kno dat...

Edit:
"Weird Al" Yankovic - Word Crimes

Last edited by Talyrius : 07-16-14 at 01:18 AM.
  Reply With Quote
07-14-14, 05:04 AM   #36
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Talyrius View Post
ikr? propr eng is a catwot! ev1 kno dat...
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Resize frame

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off