Touch interface questions


Hi Everyone,

im having a go at using touch and gestures on iOS. Can someone let me know if i am missing something obvious, like a JUCE class that already handles all this automatically, but what im doing is deducing what to do from the mouse events. or is this how it’s done?

so when i get two mouse down events, i decide i have a dual touch in progress, so then i use the drag position together with the original two coordinates of the down events to figure the extent of my “pinch” movement. im doing this calculation myself, but sure it must be pretty standard. or is it?

one of my problems is that my component in question also responds to an ordinary mouse down event for a different reason. so when i get the first mouse down, i dont know whether to react or whether im going to get a second mouse down following. what do you do here, should i wait a short while before figuring i have a single mouse down?

someone tells me that iOS5 now has a gesture with three touch points. is this true and if so will this be done as three sequential mouse downs. then for this, the same reasoning applies after down 1 and down 2. what to make of them at the point of their arrival.

im hoping someone will reply telling me to simply use `MouseGestureTranslator’ or some such handy thing already present rather than battling this in a custom way.

thanks for any help,
– hugh.


Hi Hugh

No, I’m afraid “MouseGestureRecogniser” is a class that’s on my to-do-list rather than already existing!

It’s fairly straightforward, except when you have situations such as a button whose parent can be zoomed/scrolled with a gesture. It’s easy enough for the parent to receive all the mouse events that arrive in its children and to figure out when they’re performing a gesture, but not so clear what to do if the first mouse-down landed inside a child component, and already started triggering some kind of behaviour before the subsequent events arrived. I’m not sure how best to tell the button “oh, whoops, those weren’t really mouse-down events that you’ve just been processing for the last few milliseconds, they were actually part of a gesture, please ignore them”. Maybe some kind of mouseEventCancelled() method will be necessary.


Hi Jules, thanks for your quick reply,

Ok, i dont mind handling all the cases, i just wanted to check that im not missing the obvious.

Actually, what i have is a component that is a grid of buttons, this receives events as usual. At the same time, the grid itself wants to respond to gestures. this is just the situation you describe.

my button grid draws the button as pressed on mouseDown, so when im doing a gesture the buttons get pressed as well. i am going to experiment. i can either;

(a) allow the buttons to visually press down, so long as the button action is not triggered on release in the case of a gesture. this is possible since the button action is on the mouseUp. although with this idea, you still see the buttons being pressed.


(b) instigate a very short timer so the down even does not visualise immediately, but after the time. is there a handy way in Juce to create a timed event. eg the mouseDown, creates a timer event that is received say 10ms later. i would then perform the real mouseDown at this point, providing another mouseDown has not been received?

thanks for any info & help,
– hugh.


It’s a fundamentally tricky problem, I think.

Using a timer is an alternative, but surely it’ll make the UI feel laggy… Anyone know how this is done in iOS? They have a ‘touch cancelled’ event, so presumably they just cancel any active touches as soon as they realise there’s a gesture going on.


ok, thanks. i think you’re right about lag.

here’s what im going to do. i’ll run with plan A in the meantime. ie once a gesture is recognised, set a flag so that the button mouseUp draws the button as up, but does not perform the action.

with this, gestures will look like they’re pressing buttons, but they wont be. also the movement of the gesture may make this less visible.

this workaround is certainly the easiest and if something comes along that’s better i’ll switch over to that.

– hugh.


I remember seeing somewhere that IOS uses a timer to detect gestures.