taps and presses: Official support

how about an official implementation for all possible presses and taps that everyone ends up having to program themselves and reinvent the wheel? Long Press. Double Tap. Triple Tap. Three-finger swipe, two finger swipe, etc.

@matkatmusic agreed, however one of the key obstacles in designing an API like that is that there is no view hierarchy on which to recognise the gestures.

So you could easily create such a system for the whole screen, but then people still have to do their own hit testing.

I’m still thinking about the API

@Simeon it’s way easier to implement hit testing than detecting different touch types. I say implement the fullscreen touch API.

If i were developing it, I would have a method that just returns a table which contains the existing individual touches, how long each touch has been alive, the location of them, and if the collective touch could be considered a specific gesture, like a Swipe, or Pinch or Double/Triple tap, etc…

touch = {
 "touches" = {},
 "coords" = {}, 
 "durations" = {},
 "gesture" = "" }

then just make touched() return said table every time touched() is triggered

I actually made a library for pretty much everything you’re asking for here: http://codea.io/talk/discussion/5561/flickable-easy-touch-library-for-taps-swipes-and-long-presses#latest

It also hooks itself into the touched function, so you don’t need to do anything to set it up except add it as a dependency.

Edit: due to the threaded renderer in Codea 2.1, the demo broke a tiny bit. Just add this line to the first line of draw: rectMode(CENTER)

@matkatmusic You can’t deal with different touch types without implementing hit testing because it’s not useful to know that a collection of touches is a gesture without knowing that they’re all on the same object.

I actually like the fact that you have to ‘reinvent the wheel’ constantly in Codea. It prevents me of becoming a lazy coder and it forces me to think of creative ways to handle seemingly simple problems. Also, the resulting functions are way more flexible than some built in ones.

And people can always build their own personal library if they aren’t fond of this, right?

@matkatmusic OSX and iOS are completely different user environments. In OSX, I have a pointer and that designates a window that will receive all touch information. So when I do a gesture on my trackpad, it is sent to the window with the coordinates of the pointer. But in iOS, I can direct my touches far more intelligently and say “this touch is on that menu, but that touch is on that sphere”. So I can be far more specific with iOS than OSX, but Codea is not the right level for delegating that information since only within my program do I know about what objects are on the screen.

I’ve also implemented a gesture recognition library. I think I can safely lay claim to its being the first such written in Codea. It works by gathering touches according to which object has been touched and only then does it analyse them to see if they are a gesture. So I’m writing here from several years’ experience working with Codea and touches and never have I wished for Codea to tell me anything about my touches beyond what it does already. In fact, it tells me more than I use in that it tells me the tapCount and I never use that except in very, very basic programs.

Actually, in writing that then I’ve thought of the one thing that really would be useful to have in addition to the current touch information. That is the precise time of the touch event. I can get it to within the current frame cycle but it would be nice to have it more accurate than that.

@Loopspace I don’t agree with that. Look at how it works on OS X. you click the mouse, and the OS initially issues a message that a <single/double/triple/left/right> click occured at coordinates x/y on the screen. The WindowServer receives this message and figures out which window that x/y coordinate lives in. Then the WindowServer sends forwards the message to the correct app, which then handles the click.

I’m advocating for something similar to the first step. Just tell the user that a <___> touch occurred at x/y, and let us handle the rest. if it’s a multi-finger tap or gesture, the x/y is the average of all the fingers at the onset of the 1st tap, in cases of double/triple tapping.

@matkatmusic What if you were making something, for instance a game, where you wanted feedback on each individual touch? What if using a joystick triggered a gesture? Would using multiple joysticks cause a different gesture and make all your touches just one touch in the middle of the screen, not on any joystick?

Maybe a different function similar to touched(touch), that only handles detected gestures? But still, how would you figure out wen gestures are happening, which touches are involved, what state it’s in, etc.? Maybe you could try coding a version yourself, in Codea, and see if you can figure out an easy way of detecting gestures?

@SkyTheCoder I did: http://codea.io/talk/discussion/5558/my-touchevent-class#latest

@Simeon I notice from the UITouch documentation that a touch event does have a timestamp defined as seconds since boot. Could this be used to get an accurate time of when the touch occurred? How accurate is that timestamp? Is it actually just seconds, or does it include part-seconds as well? (Milliseconds would be best, of course.)

@loopspace can you link to your library?

@matkatmusic You can find it on github at https://gist.github.com/loopspace/5611534#file-touch-lua. I use toadkick’s cmodule project for sideways importing which has the effect that the code looks like it is commented out. Simply remove the outermost comments, and make Touches global.

I also wrote an example of using it also available as a gist at https://gist.github.com/loopspace/2f8e3306d08f68fee1b2 (this is self-contained so includes the touch handling code).

This kind of feature --I called it gesture-- had been requested like ages ago. Along with other features like basic shapes, etc. Even before the app got the “Codea” name. It’s 2015 now, and still nothing. :slight_smile: