WoW:Making Draggable Frames: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
 
No edit summary
Line 53: Line 53:
Some advanced dragging addons use overlays that make default blizzard frames draggable.  This is possible by using GetParent when starting and stopping drag.  Unfortunetly this means that the parent frame must already  
Some advanced dragging addons use overlays that make default blizzard frames draggable.  This is possible by using GetParent when starting and stopping drag.  Unfortunetly this means that the parent frame must already  
be movable="true". (In the upcomming patch you will be able to use SetMovable(1) to modify a frames' movable tag.)  Another drawback with overlay frames that are mouse enabled is that they will prevent the parent frame's click script tags from being called so you often have to simulate their click events.
be movable="true". (In the upcomming patch you will be able to use SetMovable(1) to modify a frames' movable tag.)  Another drawback with overlay frames that are mouse enabled is that they will prevent the parent frame's click script tags from being called so you often have to simulate their click events.
== Quick Dragging Code ==
While somewhat untested there is an easier and more automatic way to activate dragging. If you have your <Frame> delcaration attributes "enableMouse" and "movable" set to true, dragging may be accomplished by adding a <TitleRegion> tag inside of your <Frame>
<Frame name="myname" frameStrata="HIGH" toplevel="true" enableMouse="true" movable="true" parent="UIParent">
  <TitleRegion setAllPoints="true"/>
  ...
</Frame>
I haven't discovered any adverse side effects to doing this yet, I am not even sure if this is the intended use for it.

Revision as of 19:22, 19 March 2005

XML Declarations

First, the XML tags movable="true" and enableMouse="true" must be in the frames declaration. Note: Some frame templates like 'button' already include enableMouse="true".

Example:

<Frame name="TellTrackFrame" enableMouse="true" movable="true" resizable="true" parent="UIParent" hidden="true">

Simple Dragging

One simple way to detect drag is to add OnDragStart and OnDragStop script elements to the frame:

<Scripts>
<OnDragStart>
 this:StartMoving();
 this.isMoving = true;
</OnDragStart>
<OnDragStop>
 this:StopMovingOrSizing();
 this.isMoving = false;
</OnDragStop>
</Scripts>

Advanced Dragging

Another way, which is more responsive but requires an onhide element so that the frame wont get stuck to the mouse:

<Scripts>
<OnMouseUp>
 if ( this.isMoving ) then
  this:StopMovingOrSizing();
  this.isMoving = false;
 end
</OnMouseUp>
<OnMouseDown>
 if ( ( ( not this.isLocked ) or ( this.isLocked == 0 ) ) and ( arg1 == "LeftButton" ) ) then
  this:StartMoving();
  this.isMoving = true;
 end
</OnMouseDown>
<OnHide>
 if ( this.isMoving ) then
  this:StopMovingOrSizing();
  this.isMoving = false;
 end
</OnHide>
</Scripts>

Note: this method also demonstrates an optional isLocked parameter to determine whether you can drag the frame or not.

Parent Dragging

Some advanced dragging addons use overlays that make default blizzard frames draggable. This is possible by using GetParent when starting and stopping drag. Unfortunetly this means that the parent frame must already be movable="true". (In the upcomming patch you will be able to use SetMovable(1) to modify a frames' movable tag.) Another drawback with overlay frames that are mouse enabled is that they will prevent the parent frame's click script tags from being called so you often have to simulate their click events.

Quick Dragging Code

While somewhat untested there is an easier and more automatic way to activate dragging. If you have your <Frame> delcaration attributes "enableMouse" and "movable" set to true, dragging may be accomplished by adding a <TitleRegion> tag inside of your <Frame>

<Frame name="myname" frameStrata="HIGH" toplevel="true" enableMouse="true" movable="true" parent="UIParent">
 <TitleRegion setAllPoints="true"/>
 ...
</Frame>

I haven't discovered any adverse side effects to doing this yet, I am not even sure if this is the intended use for it.