Page 1 of 2

Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 1:23 am
by luminosity
I've got a cursor replacement system in my game, hiding the mouse, then drawing the current cursor image at the mouse's co-ordinates. This works fine, except if the game is not running fullscreen, and the mouse cursor is moved outside the window the image sticks around wherever the cursor exited it. After some testing it appears that getPosition always returns the last spot the mouse was inside the window, and I don't see another way to query if the mouse is outside the window.

Note that I don't want to lock the cursor inside the window, unless the game is being run fullscreen. Is there a way for me to detect when the mouse moves outside the love window so I can stop drawing the cursor?

Thanks

P.S. Love the framework. Keep up the good work. :)

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 6:08 am
by bartbes
This is a limit to SDL as far as I can tell, combine that with the fact that we don't expose a mouse-enter and mouse-leave event, it's pretty much impossible, but is it bad?

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 8:47 am
by luminosity
The main point of changing the cursor is for showing what action will be taken if the user clicks on a hex in my hex grid, so I can probably work around if it's not doable, by switching the regular cursor on at any time the mouse isn't over the grid. It would be nice if the cursor could always display special ability icons while special abilities are selected though, to remind the user that it is selected.

Is it hard to expose mouse enter and leave? If it's a bother than working around it isn't a big deal.

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 9:11 am
by Thursdaybloom
The window dimensions are set in conf.lua so maybe making it only draw the cursor if the mouse is within the dimensions? I can't try that right now however.

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 9:56 am
by zac352
There should really be an actual way to change the cursor. I hate hiding it and replacing it with an image.. :roll:

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 11:07 am
by Thursdaybloom
In regards to amount of characters typed to achieve results, how is that better than the current method?

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 11:54 am
by giniu
zac352 wrote:There should really be an actual way to change the cursor.
sdl 1.3 probably supports changing system cursor, but it's only b&w and still, animated and colour cursors are on wishlist, and not on required features for 1.3/2.0. So I doubt there will be any cross-platform way to change cursor anytime soon, unless someone who needs it will implement this feature - do I see volunteer? :P

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 1:13 pm
by leiradel
giniu wrote:sdl 1.3 probably supports changing system cursor...
SDL 1.2 already supported changing the system cursor, but it only supports black & white cursors because that's a limit of many OSes and SDL has to respect the lowest common denominator.

Cheers,

Andre

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 1:24 pm
by giniu
leiradel wrote:SDL 1.2 already supported changing the system cursor, but it only supports black & white cursors because that's a limit of many OSes and SDL has to respect the lowest common denominator.
my mistake, never needed it and that's the reason I wasn't aware of it being here already. Anyway, in 1.3 whole input/output was rewritten once iirc, and I heard it will be rewritten again (tablet support was there, then disappeared from done things and it was rumoured to be back after stabilization of other parts, though not in current version), so you cannot be sure if it will be in 1.3 - it wasn't in required features in roadmap so it might as well go out I guess - also - I think black&white only cursors isn't really that useful. Useful cursor support might be added to 1.3, so that's far far away, and if you tracked development of 1.3 for some time, it might sound like "week after duke nukem forever" :P

Re: Detecting if cursor is outside the window

Posted: Fri Oct 08, 2010 1:54 pm
by vrld
back on topic: you could calculate the mouse speed and if it very suddenly drops to zero near a screen edge, the mouse probably left the window. :ehem: