• Dragging panels
    5 replies, posted
Hey, I'm trying to make panels draggable, and I have it working, however, when your mouse goes off the form, it stops dragging because you have to use the local position of the mouse. Is there any way to change this? If you use the position of the mouse on the actual screen, it goes all weird. This is all being coded in a custom panel, so the code looks like this: [code] function PANEL:OnCursorMoved() if self.CanBeGrabbed == true then self.MouseX, self.MouseY = self:CursorPos() self.CurX,self.CurY = self:GetPos() self.Newx = self.CurX + (self.MouseX - self.tmpX) self.Newy = self.CurY + (self.MouseY - self.tmpY) self:SetPos(self.Newx,self.Newy) end end [/code] tmpX and tmpY are the mouse position on the form when you clicked the form. Any idea how to make it not stop dragging when the mouse is out of the panel? Thanks in advanced.
[url=http://wiki.garrysmod.com/?title=Panel.MouseCapture]MouseCapture[/url] Enable this when dragging, disable it while not dragging.
It still has the same problem of not being able to get the position of the mouse. MouseCapture only seems to check for the mouse clicks and wheels and such. Not the position. =[
[lua]if ( self.Dragging ) then local x = gui.MouseX() - self.tempX local y = gui.MouseY() - self.tempY x = math.Clamp( x, 0, ScrW() - self:GetWide() ) y = math.Clamp( y, 0, ScrH() - self:GetTall() ) self:SetPos( x, y ); end[/lua] This in a think hook, with the MouseCapture set to true works like a charm for me.
Works like a charm :) Thanks! I don't know what math.Clamp or any of that stuff is, so I most likely would have never figured it out :P
You're welcome :smile: [url=http://wiki.garrysmod.com/?title=Math.Clamp]math.Clamp[/url]
Sorry, you need to Log In to post a reply to this thread.