Page 1 of 1

Mouse versus Touch

Posted: Fri Mar 30, 2018 3:32 pm
by Ref
Have written a simple function to detect mouse interaction with a given area of the screen.

Code: Select all

listbox.contact 	= function( x, y, w, h )	-- mouse over/clicked rectangle
	local contact, hover
	local mx, my = love.mouse.getPosition( )
	if mx > x and my > y and mx < x+w and my < y+h then
		hover = true
		if love.mouse.isDown( 1 ) then contact = true end
	end
	return hover, contact
end
Works exacted as expected when using the mouse.
However, I found that it also works for Touch EXCEPT that if I touch within the area, it indicates that I am still hovering over it even after I remove my finger.
Is this expected behavior?
Is there a way to turn off hover when the touch is no longer in contact with the screen?
Tried setting hover, mx and my to nil or false - no effect.
Only way to disable is to touch somewhere else on the screen.
I realize that that is how the mouse reacts but it seems strange that when there is no touch contact that the last touch response would be retained.

Re: Mouse versus Touch

Posted: Fri Mar 30, 2018 8:07 pm
by pgimeno
Well, it seems normal that getPosition retains the latest values. What position did you expect to get when your finger is lifted from the screen?

Re: Mouse versus Touch

Posted: Fri Mar 30, 2018 9:01 pm
by Ref
You're right but it just seemed strange that a value would continue to be returned when there was no longer any contact.
With the mouse, the mouse is still actively over the selected area while the finger is no longer on the screen -
mx, my = love.mouse.getPosition( ) returning values even when no contact is being made.

The reason that it does is because it moves the mouse to the touch location - something that I hadn't noticed.
Attached script shows the issue.
Just trying to develop some logic for use.

Re: Mouse versus Touch

Posted: Sat Mar 31, 2018 1:37 am
by pgimeno
Imagine for a moment that you're a developer of Löve 0.10, and you're implementing mobile support. For the benefit of applications that aren't prepared to handle touchscreens but have mouse support, you decide to try to implement some kind of mouse emulation, so that these applications can kinda get away with that basic emulation. How do you implement love.mouse.getPosition() when the touch is released?

Option 1: return the coordinates of the last touch. It was in a good position right before the user lifted your finger anyway.
Option 2: return some position off the screen, since the "finger" is not in the screen anyway. But the application may not be ready to handle that.
Option 3: return 0,0. Well, that's a mouse movement that may not be wanted.
Option 4: return nothing, or nil. That will cause most applications to crash, because they depend on a valid value.

It seems clear that the most logical option is 1.

As for your problem, maybe you could just clear hover on touchreleased. Or maybe you can try to add full support for touches, tracking their ids on touchpressed/touchreleased and so on.

Re: Mouse versus Touch

Posted: Sat Mar 31, 2018 1:43 am
by Ref
Agree!
I just didn't anticipate that touch moved the mouse.
Now I can anticipate.