Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ADAPTED FROM LUABEE'S CODE BLOCKS.
- AccessorFunc( PANEL, "m_Dragging", "Dragging", FORCE_BOOL )
- AccessorFunc( PANEL, "m_DragOffset", "DragOffset" )
- function PANEL:OnMousePressed(mc)
- self.m_DragOffset = {0,0}
- if (mc == MOUSE_LEFT) then
- self:StartDragging()
- end
- end
- function PANEL:OnMouseReleased()
- local ox,oy = self:GetDragOffset()[1] or 0, self:GetDragOffset()[2] or 0
- local mx,my = self:GetParent():ScreenToLocal(gui.MousePos())
- self:SetPos(mx-ox,my-oy)
- self:StopDragging()
- end
- function PANEL:Think()
- if self.m_Dragging then
- local ox,oy = self:GetDragOffset()[1], self:GetDragOffset()[2]
- local mx,my = self:GetParent():ScreenToLocal(gui.MousePos())
- self:SetPos(mx-ox,my-oy)
- end
- end
- function PANEL:StartDragging(t)
- self.m_Dragging = true
- self:MouseCapture(true)
- self:MoveToFront()
- local mx,my = self:ScreenToLocal(gui.MousePos())
- self:SetDragOffset({mx,my})
- end
- function PANEL:StopDragging()
- self.m_Dragging = false
- self:MouseCapture(false)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement