|
|
@ -30,7 +30,8 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput, |
|
|
|
private AndroidTouchInputListener listenerTouch = null; |
|
|
|
private AndroidTouchInputListener listenerTouch = null; |
|
|
|
private ScaleGestureDetector scaledetector; |
|
|
|
private ScaleGestureDetector scaledetector; |
|
|
|
private GestureDetector detector; |
|
|
|
private GestureDetector detector; |
|
|
|
private Vector2f lastPos = new Vector2f(); |
|
|
|
private int lastX; |
|
|
|
|
|
|
|
private int lastY; |
|
|
|
private boolean dragging = false; |
|
|
|
private boolean dragging = false; |
|
|
|
|
|
|
|
|
|
|
|
private List<Object> currentEvents = new ArrayList<Object>(); |
|
|
|
private List<Object> currentEvents = new ArrayList<Object>(); |
|
|
@ -175,21 +176,23 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput, |
|
|
|
this.detector.onTouchEvent(event); |
|
|
|
this.detector.onTouchEvent(event); |
|
|
|
this.scaledetector.onTouchEvent(event); |
|
|
|
this.scaledetector.onTouchEvent(event); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int newX = getWidth() - (int) event.getX(); |
|
|
|
|
|
|
|
int newY = (int) event.getY(); |
|
|
|
|
|
|
|
|
|
|
|
switch (event.getAction()) |
|
|
|
switch (event.getAction()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case MotionEvent.ACTION_DOWN: |
|
|
|
case MotionEvent.ACTION_DOWN: |
|
|
|
|
|
|
|
|
|
|
|
// Store current pos
|
|
|
|
|
|
|
|
lastPos.set(event.getX(),event.getY()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (FIRE_MOUSE_EVENTS) |
|
|
|
if (FIRE_MOUSE_EVENTS) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Handle mouse events
|
|
|
|
// Handle mouse events
|
|
|
|
btn = new MouseButtonEvent(0, true, (int)lastPos.getX(), (int)lastPos.getY()); |
|
|
|
btn = new MouseButtonEvent(0, true, newX, newY); |
|
|
|
btn.setTime(event.getEventTime()); |
|
|
|
btn.setTime(event.getEventTime()); |
|
|
|
processEvent(btn); |
|
|
|
processEvent(btn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Store current pos
|
|
|
|
|
|
|
|
lastX = -1; |
|
|
|
|
|
|
|
lastY = -1; |
|
|
|
|
|
|
|
|
|
|
|
// Handle gesture events
|
|
|
|
// Handle gesture events
|
|
|
|
touch = new TouchEvent(TouchEvent.Type.GRABBED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null); |
|
|
|
touch = new TouchEvent(TouchEvent.Type.GRABBED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null); |
|
|
@ -203,14 +206,18 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput, |
|
|
|
if (FIRE_MOUSE_EVENTS) |
|
|
|
if (FIRE_MOUSE_EVENTS) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Handle mouse events
|
|
|
|
// Handle mouse events
|
|
|
|
btn = new MouseButtonEvent(0, false, (int)event.getX(), (int)event.getY()); |
|
|
|
btn = new MouseButtonEvent(0, false, newX, newY); |
|
|
|
btn.setTime(event.getEventTime()); |
|
|
|
btn.setTime(event.getEventTime()); |
|
|
|
processEvent(btn); |
|
|
|
processEvent(btn); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Store current pos
|
|
|
|
|
|
|
|
lastX = -1; |
|
|
|
|
|
|
|
lastY = -1; |
|
|
|
|
|
|
|
|
|
|
|
// Handle gesture events
|
|
|
|
// Handle gesture events
|
|
|
|
if(dragging) |
|
|
|
if(dragging) |
|
|
|
{ |
|
|
|
{ |
|
|
|
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STOPPED,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null); |
|
|
|
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STOPPED,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null); |
|
|
|
processEvent(touch); |
|
|
|
processEvent(touch); |
|
|
|
} |
|
|
|
} |
|
|
|
touch = new TouchEvent(TouchEvent.Type.RELEASED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null); |
|
|
|
touch = new TouchEvent(TouchEvent.Type.RELEASED, TouchEvent.Operation.NOP,event.getX(),event.getY(),0,0,null); |
|
|
@ -222,22 +229,21 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput, |
|
|
|
if(!scaledetector.isInProgress()) |
|
|
|
if(!scaledetector.isInProgress()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!dragging) |
|
|
|
if(!dragging) |
|
|
|
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STARTED,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null); |
|
|
|
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.STARTED,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null); |
|
|
|
else |
|
|
|
else |
|
|
|
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.RUNNING,event.getX(),event.getY(),event.getX()-lastPos.getX(),event.getY()-lastPos.getY(),null); |
|
|
|
touch = new TouchEvent(TouchEvent.Type.DRAGGED, TouchEvent.Operation.RUNNING,event.getX(),event.getY(),event.getX()-lastX,event.getY()-lastY,null); |
|
|
|
|
|
|
|
|
|
|
|
processEvent(touch); |
|
|
|
processEvent(touch); |
|
|
|
dragging=true; |
|
|
|
dragging=true; |
|
|
|
} |
|
|
|
} |
|
|
|
if (FIRE_MOUSE_EVENTS) |
|
|
|
if (FIRE_MOUSE_EVENTS) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int newX = getWidth() - (int) event.getX(); |
|
|
|
|
|
|
|
int newY = (int) event.getY(); |
|
|
|
|
|
|
|
int dx; |
|
|
|
int dx; |
|
|
|
int dy; |
|
|
|
int dy; |
|
|
|
if (lastPos.getX() != -1){ |
|
|
|
if (lastX != -1){ |
|
|
|
dx = newX - (int)lastPos.getX(); |
|
|
|
dx = newX - lastX; |
|
|
|
dy = newY - (int)lastPos.getY(); |
|
|
|
dy = newY - lastY; |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
dx = 0; |
|
|
|
dx = 0; |
|
|
|
dy = 0; |
|
|
|
dy = 0; |
|
|
@ -246,6 +252,8 @@ public class AndroidInput extends GLSurfaceView implements KeyInput, MouseInput, |
|
|
|
mot.setTime(event.getEventTime()); |
|
|
|
mot.setTime(event.getEventTime()); |
|
|
|
processEvent(mot); |
|
|
|
processEvent(mot); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
lastX = newX; |
|
|
|
|
|
|
|
lastY = newY; |
|
|
|
bWasHandled = true; |
|
|
|
bWasHandled = true; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|