Moving window glitchy

BlitzMax Forums/BlitzMax GUI Programming/Moving window glitchy

I have used this simple idea for moving windows or controls in multiple languages and never had a problem.

When you click down on the control, the app remembers that location, so when you move the mouse it moves the control depending on the difference. In blitzmax the control seems to go crazy lol.

Global ItemWindow:TGadget
Global Panela:TGadget 

Global X1:Int
Global Y1:Int


ItemWindow = CreateWindow("Test Window", 100, 100, 600, 450, Null, Null) 
Panela= CreatePanel(0, 0, 600, 450, ItemWindow,PANEL_ACTIVE) 

Repeat
WaitEvent()
	Select EventID() 
		Case event_mousedown
			If EventData() = 1
				If EventSource() = Panela
					x1 = CurrentEvent.x
					y1 = CurrentEvent.y
				End If
			Else
				End
			End If
		Case event_mousemove
			If EventData() = 1 
				If EventSource() = panela
					SetGadgetShape(ItemWindow,Int(GadgetX(ItemWindow)) - (X1-CurrentEvent.x),Int(GadgetY(ItemWindow)) - (y1-CurrentEvent.y),GadgetWidth(ItemWindow),GadgetHeight(ItemWindow))
					x1 = CurrentEvent.x
					y1 = CurrentEvent.y
				End If
			End If
	End Select
Forever


What am I missing? This code works fine for me in other languages.

ps. Right click to close.

Time