How to know if the mouse is offscreen?

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.
Post Reply
User avatar
Djent
Prole
Posts: 27
Joined: Sun Jan 20, 2013 3:22 pm
Location: Rhode Island

How to know if the mouse is offscreen?

Post by Djent »

I'm making a dinky paint program where the paint color cycles through the rainbow, and I was wondering if there was any way to know if the user's mouse has left the window. It isn't in the best interest of the program to have a square of color cycling at the edge of my window, and I'd like to pause the color cycle when the mouse leaves the window. love.mouse.getX/Y only go to the length of the window. It would be nice if they returned nil if the mouse was offscreen, but oh well. Is there any way to get around this?

Also, to clarify, I'm not talking about the window being unfocused.

Thanks
User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: How to know if the mouse is offscreen?

Post by IndieKid »

Djent wrote:I'm making a dinky paint program where the paint color cycles through the rainbow, and I was wondering if there was any way to know if the user's mouse has left the window. It isn't in the best interest of the program to have a square of color cycling at the edge of my window, and I'd like to pause the color cycle when the mouse leaves the window. love.mouse.getX/Y only go to the length of the window. It would be nice if they returned nil if the mouse was offscreen, but oh well. Is there any way to get around this?

Also, to clarify, I'm not talking about the window being unfocused.

Thanks
Maybe you can try to get X, Y and if X or Y is less than 0 or more than love.graphics.getWidth/Height() then it's offset. I hadn't tried but maybe this works. Or you can try X,Y equal to 0, or equal to love.graphics.getWidth/getHeight() (-1). The second will work.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: How to know if the mouse is offscreen?

Post by xXxMoNkEyMaNxXx »

Does it have something to do with focus lost?
I saw that the mouse never returns values outside of the screen.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How to know if the mouse is offscreen?

Post by Nixola »

Bitbucket discussion about this, with my dumb answer at the end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: How to know if the mouse is offscreen?

Post by Ubermann »

Or for a simpler solution, but maybe less comfortable for the end-user:

love.mouse.setGrab( true )
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 99 guests