Multitouch on iPad


#1

I’m still a newbie in JUCE.
I’m trying to capture multitouch events in my iPad:
Each finger I put on, generate a mouseDown. Ok.
But when I put off the fingers, only one mouseUp is generated (the first finger I put off).
Sorry for my bad English. I hope you understand what I mean …

Thank you very much in advance!

PD: Events are related to the component “OpenGLComponent”. I’m using the source version 1.54.12. The iOS version is 4.3.


#2

Can anyone help me please?

I’ve to create an iPad interface with gestures, and I’m blocked by this issue.

Thx!


#3

Hmm, I can’t test this on my phone right now, but does it help if you make this change to the end of UIViewComponentPeer::handleTouches() ?

[code] else if (isUp)
{
if (! ([touch phase] == UITouchPhaseEnded || [touch phase] == UITouchPhaseCancelled))
continue;

        modsToSend = modsToSend.withoutMouseButtons();
        currentTouches.set (touchIndex, nil);

        int totalActiveTouches = 0;
        for (int j = currentTouches.size(); --j >= 0;)
            if (currentTouches.getUnchecked(j) != nil)
                ++totalActiveTouches;

        if (totalActiveTouches == 0)
            isCancel = true;
    }

    handleMouseEvent (touchIndex, pos, modsToSend, time);
    if (! isValidPeer (this)) // (in case this component was deleted by the event)
        return;

    if (isUp || isCancel)
    {
        handleMouseEvent (touchIndex, Point<int> (-1, -1), modsToSend, time);
        if (! isValidPeer (this))
            return;
    }
}

if (isCancel)
{
    currentTouches.clear();
    currentModifiers = currentModifiers.withoutMouseButtons();
}

}
[/code]

There’s another thread that’s worth looking at too:
http://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=7067


#4

The problem persists.
The program arrives ok to:

juce_MouseInputSource.cpp:131

void sendMouseUp (Component* const comp, const Point<int>& screenPos, const Time& time)
    {
        //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->getLocalPoint (nullptr, screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
        comp->internalMouseUp (source, comp->getLocalPoint (nullptr, screenPos), time, getCurrentModifiers());
    }

But only the first time the component recives the “mouseUp”.


#5

Yes, but if there’s a problem, it’ll be in the UIViewComponentPeer::handleTouches method. I can’t debug it on my phone at the moment, so it’s tricky to work out, and I can’t see anything else wrong…


#6

Ah, appears to be a old-problem…
Tracing the code:

juce_MouseInputSource.cpp:131

void sendMouseUp (Component* const comp, const Point<int>& screenPos, const Time& time) { //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->getLocalPoint (nullptr, screenPos).toString() + " - Comp: " + String::toHexString ((int) comp)); comp->internalMouseUp (source, comp->getLocalPoint (nullptr, screenPos), time, getCurrentModifiers()); }

Here always arrives, then goto:

juce_Component.cpp:2466

void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
{
    if (flags.mouseDownFlag)
flags.mouseDownFlag = false;

The first time, “flags.mouseDownFlag” is “true”, and the routine continues, and send the “mouseUp”, the second time is “false”, so no execute MouseUp.


#7

Ah, it seems a problem already discussed.
Surely what I’m going to say you know, but just in case …

Tracing the code:

juce_MouseInputSource.cpp:131

void sendMouseUp (Component* const comp, const Point<int>& screenPos, const Time& time) { //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->getLocalPoint (nullptr, screenPos).toString() + " - Comp: " + String::toHexString ((int) comp)); comp->internalMouseUp (source, comp->getLocalPoint (nullptr, screenPos), time, getCurrentModifiers()); }

Here always arrives, then goto:

juce_Component.cpp:2466

void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
{
    if (flags.mouseDownFlag)
    {     
      flags.mouseDownFlag = false;

The first time, “flags.mouseDownFlag” is “true”, and the routine continues, and send the “mouseUp”. The second time is “false”, so no execute MouseUp.


#8

Ah! Drat! That code was written before multi-touch came along!

Ok, thanks very much, I’ll see what I can figure out…!


#9

BTW, I was surprised that I hadn’t spotted this problem before, but of course that’s because I was testing the ability to drag different components at the same time… this will only be an issue when all the events are arriving in the same component.


#10

I only just caught up with this thread. I’m suprised it didn’t show up earlier too as I seem to remember I was dragging around multiple components with separate fingers when the issues in http://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=7067 showed up.


#11

I’ve checked some stuff in now - give it a go…


#12

I’ll try this evening… My iPad is at home…

Thx!

Javier.


#13

It seems to work!
:smiley:

I’ll check more next week…

Thanks!


#14

At this time, all go ok…

I’ve implemented pinch-zoom in/out in my application :smiley:


#15

Would you mind posting some of your pinch/zoom code? That’s been on my todo list as well, but I hadn’t gotten around to it yet…


#16

The code is very specific to my application.
Basically, I keep the fingers are pressed on a map whenever a mouseDown event occurs, and erase when a mouseUp event.
In the mouseDrag event check if are two fingers pressed, and if true, the distance between the actual event and the other in the map.
With this distance, calculate the zoom factor.
I could put the code, but there are many specific parts.
If you are still interested, I would …


#17

Oh, no, never mind then… I thought you were using the generic gesture recognizers in ios… Thanks though…