Moving window glitchy

BlitzMax Forums/MaxGUI Module/Moving window glitchy

Retimer(Posted 2008) [#1]
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


Brucey(Posted 2008) [#2]
You might need to use an EventHook.

Search the forums for more details :-)


Retimer(Posted 2008) [#3]
I figured as much. It seems like the event is lagged and getting the events out of order.


Dreamora(Posted 2008) [#4]
There is no order in events ... if you rely on an order, then your code is procedural, not event based.


skidracer(Posted 2008) [#5]
I don't think an EventHook will help, the problem is the event coordinates are relative to the panel so the act of moving it's parent window is effectively moving the mouse (window moves left mouse has effectively moved right in relation to the windows contents).

Taking this into account:

Import maxgui.drivers

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
					dx= CurrentEvent.x-x1
					dy= CurrentEvent.y-y1
					SetGadgetShape(ItemWindow,GadgetX(ItemWindow)+dx,GadgetY(ItemWindow)+dy,GadgetWidth(ItemWindow),GadgetHeight(ItemWindow))
					x1 = CurrentEvent.x-dx
					y1 = CurrentEvent.y-dy
				End If
			End If
	End Select
Forever



Retimer(Posted 2008) [#6]
Ahhh! Thanks a lot skid. The event hook worked, but the scaling of the mouse coordinates was strange, forcing me to move the mouse almost twice as much as the window would move.

But this source works flawlessly. Cheers.