rmtew  committed 71d6cd6

Added support for Android OS gesture detection on the SDL drawing surface, these are forwarded down to the JNI for special BrogueX handling, bypassing the default SDL touch event handling.

  • Participants
  • Parent commits 5b45119
  • Branches default
  • Tags broguex-

Comments (0)

Files changed (4)

File AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android=""
-      android:versionCode="17"
-      android:versionName="">
+      android:versionCode="18"
+      android:versionName="">
     <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

File res/raw/help.txt

 What about cursor mode?  This is when moving moves the cursor, leaving a trail from it to your character.
-* To enter cursor mode, touch the middle of the screen (basically the enter key).
-* To exit the cursor mode, either press the Android back key, or touch the middle of the screen (basically the enter key) while the cursor is over your character '@'.
+* To directly enter cursor mode, touch the middle of the screen (basically the enter key).
+* To place the cursor and enter cursor mode, long press (hold finger on) the map position you wish to have selected.
+* To select an item featured in the left hand overview pane with the cursor and enter cursor mode, long press (hold finger on) the entry in the left hand overview panel.
+* To exit the cursor mode, press the Android back key.  Pressing the center of the screen (again, the enter key) will move to the cursor position.

File res/raw/releasenotes.txt

-BrogueX 17 (Brogue 1.7.2)
+BrogueX 18 (Brogue 1.7.2)
 * Bad reviews do not contain enough information about complaints and problems.  So email (as well) please!
 * See the "help" menu item for information about controls.
 - The move tapping layer turns the screen into an invisible keyboard.  See the Android "help" menu option for details.
-- Updated to Brogue v1.7.2.
-- Brogue "feature"?: You may find yourself moving a cursor, and not your character.  See the in-game help.
-- Bug fix: "open game" main menu no longer errors for more than 15 save games.
-- Bug fix: Loading a game no longer errors for one case.
-- Bug fix: Quit button restored.  It minimises - because Android apps can't quit.
+- Long pressing the screen in "move tapping layer" will perform a mouse click at that position.  Read below for a summary, and also the help menu for the complete breakdown.
+Note: Mouse clicks behave exactly the same, as they do in the Linux, Windows or MacOS versions of Brogue.  You can use it to select a map location, to quickly move there.  You can use it to select an item or monster that is within your field of view, to then move to them.  Selection can be cancelled by pressing your device's back key (the escape key).  The current selection can be moved towards by pressing the center of the screen (the enter key).

File src/org/disinterest/broguex/

 import android.content.*;
 import android.view.*;
+import android.view.GestureDetector.OnGestureListener;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup.LayoutParams;
 import android.view.inputmethod.InputMethodManager;
     public static native void nativeTCODSetFPS(int value);
     public static native void nativeSDLToggleScreenKeyboard();
     public static native void nativeFakeMouseClick(int cx, int cy);
+    public static native void nativeGestureFling(int touchDevId, float x0, float y0, float x1, float y1);
+    public static native void nativeGestureLongTouch(int touchDevId, float x, float y);
     // Java functions called from C
 						int idx = arg0.getId();
 						boolean controlPress = buttonMode == BROGUE_NG_NOTHING && labels[idx].endsWith(customGameLabel);
 						if (buttonMode == BROGUE_NG_NOTHING && hotkeys[idx] == 'q') {
-							Log.d("broguex", "quit hotkye");
+							Log.d("broguex", "quit hotkey");
     Because of this, that's where we set up the SDL thread
 class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, 
-    View.OnKeyListener, View.OnTouchListener, SensorEventListener  {
+    View.OnKeyListener, View.OnTouchListener, SensorEventListener, OnGestureListener {
+	private static GestureDetector mGestureDetector;
     // Sensors
     private static SensorManager mSensorManager;
+        mGestureDetector = new GestureDetector(context, this);
         // Set an ID for this view so that Android does not whine.
     // Touch events
     public boolean onTouch(View v, MotionEvent event) {
+        if (SDLActivity.moveTappingLayerActive()) {
+        	/* SDL touch events reroute through onSingleTapUp() */
+        	SDLSurface.mGestureDetector.onTouchEvent(event);
+        	return true;
+        }
+        return SDL_onTouch(event);
+    }
+    public boolean SDL_onTouch(MotionEvent event) {
              final int touchDevId = event.getDeviceId();
              final int pointerCount = event.getPointerCount();
              /* BrogueX control modification. */
              if (SDLActivity.moveTappingLayerActive()) {
-            	 if (action == MotionEvent.ACTION_DOWN)
+            	 if (action == MotionEvent.ACTION_UP)
             		 onMoveTapJiggeryPokery(x, y);
             	 return true;
+	public boolean onDown(MotionEvent e) {
+		return false;
+	}
+	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
+			float velocityY) {
+		float x1, y1, x2, y2;
+		x1 = e1.getX() / mWidth;
+		y1 = e1.getY() / mHeight;
+		x2 = e2.getX() / mWidth;
+		y2 = e2.getY() / mHeight;
+		SDLActivity.nativeGestureFling(e1.getDeviceId(), x1, y1, x2, y2);
+		return false;
+	}
+	public void onLongPress(MotionEvent e) {
+		float x, y;
+		x = e.getX() / mWidth;
+		y = e.getY() / mHeight;		
+		SDLActivity.nativeGestureLongTouch(e.getDeviceId(), x, y);
+	}
+	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
+		return false;
+	}
+	public void onShowPress(MotionEvent e) {
+	}
+	public boolean onSingleTapUp(MotionEvent e) {
+        return SDL_onTouch(e);
+	}