Fixed nasty bugs with multitouch input and on-screen keyboard (bad, bad Java!)

This commit is contained in:
pelya
2010-10-06 14:42:17 +03:00
parent b292e52900
commit 586f659e48
3 changed files with 268 additions and 125 deletions

View File

@@ -56,28 +56,101 @@ abstract class DifferentTouchInput
}
private static class MultiTouchInput extends DifferentTouchInput
{
private static final int touchEventMax = 16; // Max multitouch pointers
private class touchEvent
{
public boolean down = false;
public int x = 0;
public int y = 0;
public int pressure = 0;
public int size = 0;
}
private touchEvent touchEvents[];
MultiTouchInput()
{
touchEvents = new touchEvent[touchEventMax];
for( int i = 0; i < touchEventMax; i++ )
touchEvents[i] = new touchEvent();
}
private static class Holder
{
private static final MultiTouchInput sInstance = new MultiTouchInput();
}
public void process(final MotionEvent event)
{
for( int i = 0; i < event.getPointerCount(); i++ )
int action = -1;
if( event.getAction() == MotionEvent.ACTION_UP )
{
int action = -1;
if( event.getAction() == MotionEvent.ACTION_DOWN )
action = 0;
if( event.getAction() == MotionEvent.ACTION_UP )
action = 1;
if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2;
if ( action >= 0 )
DemoGLSurfaceView.nativeMouse( (int)event.getX(i),
(int)event.getY(i),
action,
event.getPointerId(i),
(int)(event.getPressure(i) * 1000.0),
(int)(event.getSize(i) * 1000.0));
action = 1;
for( int i = 0; i < touchEventMax; i++ )
{
if( touchEvents[i].down )
{
touchEvents[i].down = false;
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size );
}
}
}
if( event.getAction() == MotionEvent.ACTION_DOWN )
{
action = 0;
for( int i = 0; i < event.getPointerCount(); i++ )
{
int id = event.getPointerId(i);
if( id >= touchEventMax )
id = touchEventMax-1;
touchEvents[id].down = true;
touchEvents[id].x = (int)event.getX(i);
touchEvents[id].y = (int)event.getY(i);
touchEvents[id].pressure = (int)(event.getPressure(i) * 1000.0);
touchEvents[id].size = (int)(event.getSize(i) * 1000.0);
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, id, touchEvents[i].pressure, touchEvents[i].size );
}
}
if( event.getAction() == MotionEvent.ACTION_MOVE )
{
for( int i = 0; i < touchEventMax; i++ )
{
int ii;
for( ii = 0; ii < event.getPointerCount(); ii++ )
{
if( i == event.getPointerId(ii) )
break;
}
if( ii >= event.getPointerCount() )
{
// Up event
if( touchEvents[i].down )
{
action = 1;
touchEvents[i].down = false;
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, i, touchEvents[i].pressure, touchEvents[i].size );
}
}
else
{
int id = event.getPointerId(ii);
if( id >= touchEventMax )
id = touchEventMax-1;
if( touchEvents[id].down )
action = 2;
else
action = 0;
touchEvents[id].down = true;
touchEvents[id].x = (int)event.getX(i);
touchEvents[id].y = (int)event.getY(i);
touchEvents[id].pressure = (int)(event.getPressure(i) * 1000.0);
touchEvents[id].size = (int)(event.getSize(i) * 1000.0);
DemoGLSurfaceView.nativeMouse( touchEvents[i].x, touchEvents[i].y, action, id, touchEvents[i].pressure, touchEvents[i].size );
}
}
}
}
}