Thread Tools Display Modes
05-04-12, 02:01 PM   #1
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
resizing a frame...

so does anyone know an addon that moves/re-sizes some frames ( or can post some generic code) for moving / resizing a frame that doesn't rely on any library so I can get some idea of how it is supposed to be done.

I know Frame:CreateTitleRegion() is a nice easy way to move a frame around ( and I have done that )
but I have found no real examples on how to move a frame around without using that nor any examples on how to resize a frame that doesn't use some library function.

all the sites I have found give an example of the specific commands but not how you tie them together to actually make them work. or like StartSizing() on wowwiki, just plain undocumented or are referencing methods of doing stuff with XML... I just want to know how to do it in plain lua.

Last edited by Billtopia : 05-04-12 at 05:08 PM.
  Reply With Quote
05-04-12, 09:52 PM   #2
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
If you're talking about repositioning frames programmatically as opposed to dragging them around the screen, the way frames are generally positioned is using SetPoint. See:

http://wowprogramming.com/docs/widgets/Region/SetPoint

You can also use things like SetWidth and SetHeight to specify the width/height after using SetPoint to position it, etc.

But the basic idea with SetPoint is to take a point on your frame and position it relative to some other frame, or the screen. So frame:SetPoint("TOP", otherFrame, "BOTTOM", 0, -10) for example, positions the top edge of your frame on the bottom edge of otherFrame, with an x offset of 0 and y offset of -10. You can then set other points, e.g. the bottom of your frame on the top of another frame, and your frame will be resized to fit in that space. Using :ClearAllPoints() will reset all such points, which you may very well need to do if you're trying to move a frame that has already had various points set in Blizzard code for instance.

Note that at the end of this process you probably want your frame to have both a width and a height. You might do this by setting both TOPLEFT and BOTTOMRIGHT for example, or alternatively setting just TOP and BOTTOM then using SetWidth, or setting none of the above (e.g. just RIGHT, TOPLEFT, CENTER, etc.) and then setting both SetWidth and SetHeight (or SetSize) to manually set its dimensions. When it comes to positioning things "absolutely", you can use UIParent as your relative frame since it occupies the entire viewport.

Last edited by Barjack : 05-04-12 at 10:02 PM.
  Reply With Quote
05-05-12, 06:05 AM   #3
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
sorry, not what I meant, I can move, and resize the frame with lua with no real problems. what I want to be able to do is have the user move a frame around (without needing Frame:CreateTitleRegion() ) and have them be able to resize the frame by picking a point and stretching the frame. resizing the frame, as I said, is more important than being able to move it because CreateTitleRegion is so easy it is like cheating.

my problem is that even wowprogramming gives no example of how to use the APIs to do this. just single line examples of the function itself (or its signature) , not how it is tied together, or if I do find an example it is in XML and all I want is plain lua.
  Reply With Quote
05-05-12, 09:09 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Hmm, I've never used CreateTitleRegion in my addons and can drag my frames around pretty easily. However, I've never needed to resize at run time so have never experimented with it.

All my movable frames are set as thus:

Lua Code:
  1. self:RegisterForDrag("LeftButton","RightButton");
  2. self:EnableMouse(true);
  3. self:SetMovable(true);
  4. self:SetScript("OnMouseDown",OnMouseDown);
  5. self:SetScript("OnMouseUp",OnMouseUp);
  6. self:SetScript("OnHide",OnHide);

With the OnMouseDown, OnMouseUp and OnHide functions being coded as such:
Lua Code:
  1. function OnMouseDown(self)
  2.     self:StartMoving();
  3.     self.isMoving = true;
  4.     self.hasMoved = false;
  5. end
  6. function OnMouseUp(self)
  7.     if ( self.isMoving ) then
  8.         self:StopMovingOrSizing();
  9.         self.isMoving = false;
  10.         self.hasMoved = true;
  11.     end
  12. end
  13.  
  14. function OnHide(self)      
  15.     if ( self.isMoving ) then
  16.         self:StopMovingOrSizing();
  17.         self.isMoving = false;
  18.     end
  19. end

Although there are also OnDragStart and OnDragStop functions that may work better.


However, looking at this page : http://www.wowwiki.com/API_Frame_SetUserPlaced it sounds like there are times when this doesn't work consistently to restore the new placement and looking at http://www.wowwiki.com/API_Frame_IsUserPlaced points out that frames created programmatically won't work with those commands. In which case you may also have to keep a copy of its setpoint values so that it can be restored successfully.

Hopefully that gives you a bit more info on how you can get your frames moving by the user.

The following may help explain things a bit better too. It's where I got my info from.
http://www.wowwiki.com/Making_Draggable_Frames

As to sizing it might be simply the case of replacing StartMoving to StartSizing in the above examples. You would have to play about with it to see if thats the case.


edit: After spotting some problems occurring recently I have realised that OnDragStart and OnDragStop is the better option to use if you also want to use other click options on the frame. same code just different functions.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 09-27-14 at 10:28 AM. Reason: New Info
  Reply With Quote
05-05-12, 09:59 AM   #5
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
thanks... I looked all over and didn't find that. I will have to slap google around a bit.

I will try that for resizing as well, and see how it works.

I did read something on the problems with moving it like above. It said that WoW would find the nearest anchor to the moved frame and anchor to that and to combat it you had to get the frames position 3 times, once for your original position to what you anchored to, and as soon as you start the dragging because the relative coordinates change, and the third time when the moving is done. you subtract the 2nd from the 3rd and add it to the 1st and then you clear all the points and reset the anchor to where you want it using the new position from above.

(my addon I just stuck the center on UIParent's center and made the user move it as soon as they log in using CreateTitleRegion )
  Reply With Quote
05-05-12, 11:28 AM   #6
Billtopia
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 110
I only needed a small change for resizing... so one button moves and the other resizes...
not sure if it is the best way but it works
Thanks Xrystal

also DO Frame:SetMinResize( #, # ) or when messing with it you can crash your WoW client lol
I tried it without, and WoW doesn't like it when you try and flip over your frame...

lua Code:
  1. local OnMouseDown = function(self, button)
  2.     if button == "LeftButton" then
  3.         self:StartMoving()
  4.         self.isMoving = true
  5.         self.hasMoved = false
  6.     elseif button == "RightButton" then
  7.         self:StartSizing()
  8.         self.isMoving = true
  9.         self.hasMoved = false
  10.     end
  11. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » resizing a frame...


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