Android: added mouseEventsInvertY option to Harness
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7827 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
bb718f942c
commit
7b0f06ff4d
@ -56,6 +56,9 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|||||||
*/
|
*/
|
||||||
protected boolean eglConfigVerboseLogging = false;
|
protected boolean eglConfigVerboseLogging = false;
|
||||||
|
|
||||||
|
protected boolean mouseEventsEnabled = true;
|
||||||
|
protected boolean mouseEventsInvertY = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the exit dialog, default is "Do you want to exit?"
|
* Title of the exit dialog, default is "Do you want to exit?"
|
||||||
*/
|
*/
|
||||||
@ -102,6 +105,9 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
|
|||||||
AppSettings settings = new AppSettings(true);
|
AppSettings settings = new AppSettings(true);
|
||||||
AndroidInput input = new AndroidInput(this);
|
AndroidInput input = new AndroidInput(this);
|
||||||
|
|
||||||
|
input.setMouseEventsInvertY(mouseEventsInvertY);
|
||||||
|
input.setMouseEventsEnabled(mouseEventsEnabled);
|
||||||
|
|
||||||
// Create application instance
|
// Create application instance
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -28,26 +28,33 @@ import com.jme3.util.RingBuffer;
|
|||||||
public class AndroidInput extends GLSurfaceView implements TouchInput,
|
public class AndroidInput extends GLSurfaceView implements TouchInput,
|
||||||
GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener
|
GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener
|
||||||
{
|
{
|
||||||
private final static Logger logger = Logger.getLogger(AndroidInput.class.getName());
|
|
||||||
private boolean isInitialized = false;
|
|
||||||
private RawInputListener listener = null;
|
|
||||||
|
|
||||||
final private static int MAX_EVENTS = 1024;
|
final private static int MAX_EVENTS = 1024;
|
||||||
|
|
||||||
|
// Custom settings
|
||||||
|
public boolean mouseEventsEnabled = true;
|
||||||
|
public boolean mouseEventsInvertY = false;
|
||||||
|
|
||||||
|
public boolean keyboardEventsEnabled = false;
|
||||||
|
|
||||||
|
public boolean dontSendHistory = false;
|
||||||
|
|
||||||
|
|
||||||
|
// Used to transfer events from android thread to GLThread
|
||||||
final private RingBuffer<TouchEvent> eventQueue = new RingBuffer<TouchEvent>(MAX_EVENTS);
|
final private RingBuffer<TouchEvent> eventQueue = new RingBuffer<TouchEvent>(MAX_EVENTS);
|
||||||
final private RingBuffer<TouchEvent> eventPoolUnConsumed = new RingBuffer<TouchEvent>(MAX_EVENTS);
|
final private RingBuffer<TouchEvent> eventPoolUnConsumed = new RingBuffer<TouchEvent>(MAX_EVENTS);
|
||||||
final private RingBuffer<TouchEvent> eventPool = new RingBuffer<TouchEvent>(MAX_EVENTS);
|
final private RingBuffer<TouchEvent> eventPool = new RingBuffer<TouchEvent>(MAX_EVENTS);
|
||||||
final private HashMap<Integer, Vector2f> lastPositions = new HashMap<Integer, Vector2f>();
|
final private HashMap<Integer, Vector2f> lastPositions = new HashMap<Integer, Vector2f>();
|
||||||
|
|
||||||
public boolean fireMouseEvents = true;
|
// Internal
|
||||||
public boolean fireKeyboardEvents = false;
|
|
||||||
public boolean dontSendHistory = false;
|
|
||||||
|
|
||||||
private ScaleGestureDetector scaledetector;
|
private ScaleGestureDetector scaledetector;
|
||||||
private GestureDetector detector;
|
private GestureDetector detector;
|
||||||
private int lastX;
|
private int lastX;
|
||||||
private int lastY;
|
private int lastY;
|
||||||
|
|
||||||
|
private final static Logger logger = Logger.getLogger(AndroidInput.class.getName());
|
||||||
|
private boolean isInitialized = false;
|
||||||
|
private RawInputListener listener = null;
|
||||||
|
|
||||||
|
|
||||||
private static final int[] ANDROID_TO_JME = {
|
private static final int[] ANDROID_TO_JME = {
|
||||||
0x0, // unknown
|
0x0, // unknown
|
||||||
@ -173,8 +180,8 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches a touch event from the reuse pool
|
* Fetches a touch event from the reuse pool
|
||||||
* @param wait
|
* @param wait if true waits for a reusable event to get available/released by an other thread, if false returns a new one if needed
|
||||||
* @return
|
* @return a usable TouchEvent
|
||||||
*/
|
*/
|
||||||
private TouchEvent getNextFreeTouchEvent(boolean wait)
|
private TouchEvent getNextFreeTouchEvent(boolean wait)
|
||||||
{
|
{
|
||||||
@ -486,6 +493,7 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------- INSIDE GLThread ---------------
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
@ -511,14 +519,18 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
{
|
{
|
||||||
listener.onTouchEvent(event);
|
listener.onTouchEvent(event);
|
||||||
|
|
||||||
if (fireMouseEvents)
|
if (mouseEventsEnabled)
|
||||||
{
|
{
|
||||||
newX = this.getWidth() - (int) event.getX();
|
newX = this.getWidth() - (int) event.getX();
|
||||||
|
if (mouseEventsInvertY)
|
||||||
newY = this.getHeight() - (int) event.getY();
|
newY = this.getHeight() - (int) event.getY();
|
||||||
|
else
|
||||||
|
newY = (int) event.getY();
|
||||||
|
|
||||||
switch (event.getType())
|
switch (event.getType())
|
||||||
{
|
{
|
||||||
case DOWN:
|
case DOWN:
|
||||||
// Handle mouse events
|
// Handle mouse down event
|
||||||
btn = new MouseButtonEvent(0, true, newX, newY);
|
btn = new MouseButtonEvent(0, true, newX, newY);
|
||||||
btn.setTime(event.getTime());
|
btn.setTime(event.getTime());
|
||||||
listener.onMouseButtonEvent(btn);
|
listener.onMouseButtonEvent(btn);
|
||||||
@ -528,7 +540,7 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UP:
|
case UP:
|
||||||
// Handle mouse events
|
// Handle mouse up event
|
||||||
btn = new MouseButtonEvent(0, false, newX, newY);
|
btn = new MouseButtonEvent(0, false, newX, newY);
|
||||||
btn.setTime(event.getTime());
|
btn.setTime(event.getTime());
|
||||||
listener.onMouseButtonEvent(btn);
|
listener.onMouseButtonEvent(btn);
|
||||||
@ -576,8 +588,9 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// --------------- ENDOF INSIDE GLThread ---------------
|
||||||
|
|
||||||
// --------------- Gesture detected callback events ----------------------------------
|
// --------------- Gesture detected callback events ---------------
|
||||||
|
|
||||||
public boolean onDown(MotionEvent event)
|
public boolean onDown(MotionEvent event)
|
||||||
{
|
{
|
||||||
@ -694,13 +707,12 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
@Override
|
@Override
|
||||||
public void setSimulateMouse(boolean simulate)
|
public void setSimulateMouse(boolean simulate)
|
||||||
{
|
{
|
||||||
fireMouseEvents = simulate;
|
mouseEventsEnabled = simulate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSimulateKeyboard(boolean simulate)
|
public void setSimulateKeyboard(boolean simulate)
|
||||||
{
|
{
|
||||||
fireKeyboardEvents = simulate;
|
keyboardEventsEnabled = simulate;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setOmitHistoricEvents(boolean dontSendHistory)
|
public void setOmitHistoricEvents(boolean dontSendHistory)
|
||||||
@ -708,4 +720,22 @@ public class AndroidInput extends GLSurfaceView implements TouchInput,
|
|||||||
this.dontSendHistory = dontSendHistory;
|
this.dontSendHistory = dontSendHistory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move to TouchInput
|
||||||
|
public boolean isMouseEventsEnabled() {
|
||||||
|
return mouseEventsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseEventsEnabled(boolean mouseEventsEnabled) {
|
||||||
|
this.mouseEventsEnabled = mouseEventsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseEventsInvertY() {
|
||||||
|
return mouseEventsInvertY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMouseEventsInvertY(boolean mouseEventsInvertY) {
|
||||||
|
this.mouseEventsInvertY = mouseEventsInvertY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user