Detecting if cursor is outside the window

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
luminosity
Prole
Posts: 34
Joined: Fri Sep 24, 2010 5:46 am

Detecting if cursor is outside the window

Post by luminosity » Fri Oct 08, 2010 1:23 am

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. :)

User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Detecting if cursor is outside the window

Post by bartbes » Fri Oct 08, 2010 6:08 am

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?

luminosity
Prole
Posts: 34
Joined: Fri Sep 24, 2010 5:46 am

Re: Detecting if cursor is outside the window

Post by luminosity » Fri Oct 08, 2010 8:47 am

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.

User avatar
Thursdaybloom
Citizen
Posts: 81
Joined: Mon Feb 15, 2010 3:43 am
Location: Australia

Re: Detecting if cursor is outside the window

Post by Thursdaybloom » Fri Oct 08, 2010 9:11 am

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.

User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: Detecting if cursor is outside the window

Post by zac352 » Fri Oct 08, 2010 9:56 am

There should really be an actual way to change the cursor. I hate hiding it and replacing it with an image.. :roll:
Hello, I am not dead.

User avatar
Thursdaybloom
Citizen
Posts: 81
Joined: Mon Feb 15, 2010 3:43 am
Location: Australia

Re: Detecting if cursor is outside the window

Post by Thursdaybloom » Fri Oct 08, 2010 11:07 am

In regards to amount of characters typed to achieve results, how is that better than the current method?

giniu
Party member
Posts: 221
Joined: Mon Nov 30, 2009 4:44 pm

Re: Detecting if cursor is outside the window

Post by giniu » Fri Oct 08, 2010 11:54 am

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

User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Detecting if cursor is outside the window

Post by leiradel » Fri Oct 08, 2010 1:13 pm

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

giniu
Party member
Posts: 221
Joined: Mon Nov 30, 2009 4:44 pm

Re: Detecting if cursor is outside the window

Post by giniu » Fri Oct 08, 2010 1:24 pm

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

User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Detecting if cursor is outside the window

Post by vrld » Fri Oct 08, 2010 1:54 pm

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:
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests