WoW:Making Draggable Frames: Difference between revisions

m
Move page script moved page Making Draggable Frames to WoW:Making Draggable Frames without leaving a redirect
(→‎Using TitleRegion: Invalid XML)
m (Move page script moved page Making Draggable Frames to WoW:Making Draggable Frames without leaving a redirect)
 
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{UIHowTo}}
{{wow/uihowto}}
Draggable frames can be moved by having the user hold down a mouse button over the frame, then move the mouse to reposition the frame. This HOWTO describes how to make a frame draggable.
Draggable frames can be moved by having the user hold down a mouse button over the frame, then move the mouse to reposition the frame. This HOWTO describes how to make a frame draggable.


Line 10: Line 10:
=== Using OnDragStart / OnDragStop ===
=== Using OnDragStart / OnDragStop ===
The code below creates a draggable Frame widget and uses the OnDrag widget handlers to initiate dragging. Note the use of movable and enableMouse attributes:
The code below creates a draggable Frame widget and uses the OnDrag widget handlers to initiate dragging. Note the use of movable and enableMouse attributes:
<Frame name="DragFrame1" enableMouse="true" movable="true">
  <Ui>
  <Frame name="DragFrame1" enableMouse="true" movable="true">
   <Scripts>
   <Scripts>
   <OnLoad>self:RegisterForDrag("LeftButton");</OnLoad>
   <OnLoad>self:RegisterForDrag("LeftButton");</OnLoad>
Line 18: Line 19:
   <nowiki><!-- Tags below add a visual element to the frame. --></nowiki>
   <nowiki><!-- Tags below add a visual element to the frame. --></nowiki>
   <Layers>
   <Layers>
   <Layer level="ARTWORK">
   &lt;Layer level="ARTWORK">
    <Texture setAllPoints="true">
<nowiki> </nowiki>  <Texture setAllPoints="true">
    <Color r="1.0" g="0.5" b="0.0" a="0.5" />
<nowiki> </nowiki>  <Color r="1.0" g="0.5" b="0.0" a="0.5" />
    </Texture>
<nowiki>  </Texture>
   </Layer>
   </Layer>
   </Layers>
   </Layers>
   <Size x="64" y="64" />
   </nowiki><Size x="64" y="64" />
  <Anchors><Anchor point="CENTER" relativeTo="UIParent"/></Anchors>
<nowiki> </nowiki><Anchors><Anchor point="CENTER" relativeTo="UIParent"/></Anchors>
  </Frame>
  </Frame>
</Ui>


Note the use of the OnLoad Script, In order to drag a frame it must register for drag via {{api|Frame RegisterForDrag|Frame:RegisterForDrag("button")}}.
Note the use of the OnLoad Script, In order to drag a frame it must register for drag via {{api|Frame RegisterForDrag|Frame:RegisterForDrag("button")}}. Above code edited to include the <Ui> </Ui> tags as it
is .xml and won't work without this.


=== Using OnMouseUp/OnMouseDown ===
=== Using OnMouseUp/OnMouseDown ===
Line 69: Line 72:
   <nowiki><!-- Tags below add a visual element to the frame. --></nowiki>
   <nowiki><!-- Tags below add a visual element to the frame. --></nowiki>
   <Layers>
   <Layers>
   <Layer level="ARTWORK">
   &lt;Layer level="ARTWORK">
    <Texture setAllPoints="true">
<nowiki> </nowiki>  <Texture setAllPoints="true">
    <Color r="1.0" g="0.5" b="0.0" a="0.5" />
<nowiki> </nowiki>  <Color r="1.0" g="0.5" b="0.0" a="0.5" />
    </Texture>
<nowiki>  </Texture>
  </Layer>
    </Layer>
  </Layers>
  </Layers>
  <Anchors><Anchor point="CENTER" relativeTo="UIParent"/></Anchors>
  </nowiki><Anchors><Anchor point="CENTER" relativeTo="UIParent"/></Anchors>
  </Frame>
  </Frame>


Line 92: Line 95:
  tex:SetAllPoints();
  tex:SetAllPoints();
  tex:SetTexture(1.0, 0.5, 0); tex:SetAlpha(0.5);
  tex:SetTexture(1.0, 0.5, 0); tex:SetAlpha(0.5);


=== Using OnMouseDown / OnMouseUp ===
=== Using OnMouseDown / OnMouseUp ===
Line 100: Line 101:
  frame:SetMovable(true)
  frame:SetMovable(true)
  frame:EnableMouse(true)
  frame:EnableMouse(true)
  frame:SetScript("OnMouseDown", function(self)
  frame:SetScript("OnMouseDown", function(self, button)
   if button == "LeftButton" and not self.isMoving then
   if button == "LeftButton" and not self.isMoving then
     self:StartMoving();
     self:StartMoving();
Line 106: Line 107:
   end
   end
  end)
  end)
  frame:SetScript("OnMouseUp", function(self)
  frame:SetScript("OnMouseUp", function(self, button)
   if button == "LeftButton" and self.isMoving then
   if button == "LeftButton" and self.isMoving then
     self:StopMovingOrSizing();
     self:StopMovingOrSizing();
Line 123: Line 124:
  tex:SetAllPoints();
  tex:SetAllPoints();
  tex:SetTexture(1.0, 0.5, 0); tex:SetAlpha(0.5);
  tex:SetTexture(1.0, 0.5, 0); tex:SetAlpha(0.5);


==General Notes==
==General Notes==
Anonymous user