Mouse Speed While Mouse Stationary

BlitzMax Forums/MaxGUI Module/Mouse Speed While Mouse Stationary

Spacechimp(Posted 2009) [#1]
I recently purchased MaxGui, and have just started using it.


In many Blitz programs, A standard method of controlling things with the mouse, is to move The mouse, get the position data X, use the Movemouse() command, get position data Y, and then find the difference which give us a mouse speed value:

MoveMouse(x,y)
Mouse_X_New = MouseX()
Mouse_X_Speed = Mouse_X_New - Mouse_X_Old
Mouse_X_Old = Mouse_X_New


I am having a lot of trouble replicating this using the event system which MaxGui uses.

It is my understanding that with the event system, MouseX() etc.. can not be used? I have to get all my mouse hits and what not from the Event Que?

My experience in working with the Event Que so far... well, has been frustrating. The events can and do vary in frequency each loop. EVENT_MOUSEMOVE does not care how the mouse was moved, only that the current mouse coords are different from the previous. Because I can not see if a EventID(EVENT_MOUSEMOVE) happened as a result of a MoveMouse() I am not really sure when I should check my speed using the basic method I described above.

I have tried several different methods of implementing this, but each try has not been successful. I have tried in different ways to determine which EventID(EVENT_MOUSEMOVE) is the one that MoveMouse() created. I thought this would be kind of simple, but for some reason its not. The more elaborate, and most promising (almost an oxymoron I know) is to call MoveMouse() and then remove it from the loop. By doing:



However, I believe events are still being added to the Que as this code is being run. So it really messes it up. The events I create and kick back out into the main loop again are unpredictable, and I lose some events entirely.

If I take out the MoveMouse() driven mouse speed function entirely, and try not to modify the event Que using the last bit of code I posted, I get nice smooth mouse movement. The only draw back is that the pointer moves off/to the border of the canvas/window. And preventing that is, of course, the whole point of this.


A little help in solving this would be flippin sweet! Thanks!


SebHoll(Posted 2009) [#2]
t is my understanding that with the event system, MouseX() etc.. can not be used?

Not quite - it isn't the default behaviour, but you can enable the commands by adding:

EnablePolledInput()

to the top of your source code. This will allow you to use the standard Max2D commands with MaxGUI.

Edit: Also, isn't there already a built-in MouseSpeedX() and MouseSpeedY() function?


Spacechimp(Posted 2009) [#3]
Thank you SebHoll.


jsp(Posted 2009) [#4]
If you want to filter the move events of a certain gadget, for instance a canvas or an active panel you could do so:
WaitEvent()
Select EventID()
	Case EVENT_MOUSEMOVE
		Select EventSource()
			Case MyGadget
				'.... do something
		End Select
End Select