Advertisement
Guest User

Drag and Drop GMod Panels

a guest
Sep 20th, 2013
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. --ADAPTED FROM LUABEE'S CODE BLOCKS.
  2.  
  3. AccessorFunc( PANEL, "m_Dragging", "Dragging", FORCE_BOOL )
  4. AccessorFunc( PANEL, "m_DragOffset", "DragOffset" )
  5.  
  6. function PANEL:OnMousePressed(mc)
  7.     self.m_DragOffset = {0,0}
  8.     if (mc == MOUSE_LEFT) then
  9.         self:StartDragging()
  10.     end
  11. end
  12.  
  13. function PANEL:OnMouseReleased()
  14.     local ox,oy = self:GetDragOffset()[1] or 0, self:GetDragOffset()[2] or 0
  15.     local mx,my = self:GetParent():ScreenToLocal(gui.MousePos())
  16.     self:SetPos(mx-ox,my-oy)   
  17.     self:StopDragging()
  18. end
  19.  
  20. function PANEL:Think()
  21.     if self.m_Dragging then
  22.         local ox,oy = self:GetDragOffset()[1], self:GetDragOffset()[2]
  23.         local mx,my =  self:GetParent():ScreenToLocal(gui.MousePos())
  24.         self:SetPos(mx-ox,my-oy)
  25.     end
  26. end
  27.  
  28. function PANEL:StartDragging(t)
  29.     self.m_Dragging = true
  30.     self:MouseCapture(true)
  31.     self:MoveToFront()
  32.     local mx,my = self:ScreenToLocal(gui.MousePos())
  33.     self:SetDragOffset({mx,my})
  34. end
  35.  
  36. function PANEL:StopDragging()
  37.     self.m_Dragging = false
  38.     self:MouseCapture(false)
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement