MouseX(), MouseY()

BlitzMax Forums/BlitzMax Programming/MouseX(), MouseY()

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

The jumping is because the code is simply bugged.
It positions the top left corner at the mouse cursor, no mather where you clicked it.

Here is the correct code:

MYwindow:TGadget=CreateWindow("Candy_test",0,0,640,480,0,1)

MYcanvas:TGadget=CreateCanvas(48,48,48,48,MYwindow)

Global mx:Int, my:Int
Repeat
	WaitEvent()
	Select EventID()
		Case EVENT_WINDOWCLOSE
			DebugLog "CLOSING WINDOW"
			End
		Case EVENT_MOUSEDOWN
			 Select EventSource()
			 	Case MYCANVAS
					DebugLog EventX() + " " + EventY()
					mx	= EventX()
					my	= EventY()
					drag = 1
			End Select
		 Case event_mouseup
			drag=0
		Case EVENT_GADGETPAINT
	  	    SetGraphics CanvasGraphics (MyCanvas)
    		DrawRect  20,20,50,80
        	Flip
		Case event_mousemove
			If drag
			 DebugLog "canvs : " + GadgetX(mycanvas) + " " + GadgetY(mycanvas)
			DebugLog "window : " + GadgetX(mywindow) + " " + GadgetY(mywindow)
			DebugLog MouseX() + " " + MouseY()
				x = EventX() + GadgetX(mycanvas) - mx
				y = EventY() + GadgetY(mycanvas) - my
				SetGadgetShape (mycanvas, x,y,GadgetWidth(mycanvas),GadgetHeight(mycanvas))
	        EndIf
	End Select
	
Forever
End