Commits

Anonymous committed 92eb8ae

- Bumped versions in AndroidManifest.xml to 3 and 1.02 respectively.
- Reduced max coords recorded per gesture from 2000 to 200.
- Reduced max fingers allowed per gesture from 10 to 3.
- Fixed bug in finger indexing. All fingers were getting the internal index
number of the current gesture. This was completely wrong.
- Display error message if too many coords are recorded for a gesture.
- Display error message if too many fingers are used in a gesture.
- Display error message if SDL_GestureRecord fails.

  • Participants
  • Parent commits e838939

Comments (0)

Files changed (2)

File AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="org.disinterest.gestures"
-      android:versionCode="2"
-      android:versionName="1.01">
+      android:versionCode="3"
+      android:versionName="1.02">
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-sdk android:minSdkVersion="8"/>
     <application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

File jni/src/main.c

 #define APPFLAG_HAVE_TOUCHID (1 << 0)
 #define APPFLAG_QUITTING     (1 << 1)
 
-#define MAX_GESTURE_COORDS 2000
+#define MAX_GESTURE_COORDS 200
 #define MAX_GESTURES 20
-#define MAX_FINGERS 10
+#define MAX_FINGERS 3
 #define MAX_EVENTS_POLLED_PER_FRAME 20
 
 #define Y_LOWER_GAP 1
 	int finger_index;
 	/* Locate a known finger. */
 	for (finger_index = 0; finger_index < gesture->finger_count; finger_index++)
-		if (gesture->finger_ids[finger_index] == finger_id)
+		if (gesture->finger_ids[finger_index] == finger_id) {
 			return finger_index;
+		}
 	/* Register a new finger. */
 	if (gesture->finger_count < MAX_FINGERS) {
 		gesture->finger_count += 1;
 		finger_index = gesture->finger_count - 1;
 		gesture->finger_ids[finger_index] = finger_id;
 		gesture->coord_counts[finger_index] = 0;
-		return gesture_index;
+		return finger_index;
 	}
 	/* Too many fingers resulting in confusion. */
 	return -1;
 		int cx, cy;
 		int finger_index = get_gesture_finger_index(gesture, event->tfinger.fingerId);
 
-		/* TODO: handle displaying this error. */
 		if (finger_index == -1)
-			return 0;
+			return show_error_message_screen("More fingers in use than this app supports.", 3);
 
-		/* TODO: handle displaying this error. */
 		if (gesture->coord_count == MAX_GESTURE_COORDS)
-			return 0;
+			return show_error_message_screen("More touch motion events occurred than this app supports.", 3);
 
 		SDL_Touch *touch = SDL_GetTouch(event->tfinger.touchId);
 		cx = (event->tfinger.x * console_width) / touch->xres;
 		cy = (event->tfinger.y * console_height) / touch->yres;
 
-		gesture->flags = gesture->flags & ~GESTURE_FLAG_SORTED;
+		gesture->flags &= ~GESTURE_FLAG_SORTED;
 		gesture->coords[gesture->coord_count].finger_index = finger_index;
 		gesture->coords[gesture->coord_count].cx = cx;
 		gesture->coords[gesture->coord_count].cy = cy;
 }
 
 /*
+ * Show a message for a given amount of time.
+ */
+int show_error_message_screen(const char* msg, int seconds) {
+	int clocks0 = clock();
+	static int error_count = 0;
+	int frame_cx = 0,
+		frame_cy = 0,
+		frame_cw = console_width,
+		frame_ch = console_height;
+
+	error_count += 1;
+	do {
+		SDL_Event event;
+		int num_events_polled = 0;
+
+		while (num_events_polled++ < MAX_EVENTS_POLLED_PER_FRAME && SDL_PollEvent(&event)) {
+			switch (event.type) {
+			case SDL_WINDOWEVENT :
+				switch (event.window.event) {
+				case SDL_WINDOWEVENT_RESTORED:
+					TCOD_sys_set_clear_screen();
+					break;
+				}
+				break;
+			}
+		}
+
+		TCOD_console_set_default_background(NULL, TCOD_black);
+		TCOD_console_clear(NULL);
+
+		TCOD_console_print_frame(NULL, frame_cx, frame_cy, frame_cw, frame_ch, 1, TCOD_BKGND_NONE, "ERROR %d", error_count);
+		TCOD_console_print_ex(NULL, console_width/2, console_height/2, TCOD_BKGND_NONE, TCOD_CENTER, msg);
+
+		TCOD_console_flush();
+	} while (((clock() - clocks0)/CLOCKS_PER_SEC) < seconds);
+
+	return 0;
+}
+
+/*
  * Show a message asking the user to touch this screen so that the touch pad being
  * used can be identified.  Store the Id globally.
  */
 	int cx, cy;
 	int num_events_polled = 0;
 
-	TCOD_console_set_default_background(NULL, TCOD_black);
-	TCOD_console_clear(NULL);
-
 	while (num_events_polled++ < MAX_EVENTS_POLLED_PER_FRAME && SDL_PollEvent(&event)) {
 		switch (event.type) {
 		case SDL_FINGERUP:
 		}
 	}
 
+	TCOD_console_set_default_background(NULL, TCOD_black);
+	TCOD_console_clear(NULL);
+
 	cx = console_width / 2;
 	cy = console_height / 2;
 	TCOD_console_print_ex(NULL, cx, cy, TCOD_BKGND_NONE, TCOD_CENTER, "Touch this screen so it can be identified.");
 		frame_cw = console_width,
 		frame_ch = console_height - Y_LOWER_GAP;
 
-	/* TODO: Display some form of error message. */
-	if (!SDL_RecordGesture(touch_id))
+	if (!SDL_RecordGesture(touch_id)) {
+		show_error_message_screen("SDL_RecordGesture(touch_pad_id) call failed", 3);
 		return;
+	}
 
 	INIT_GESTURE(temp_gesture);
 
 	do {
 		int num_events_polled = 0;
-		/*
-		 * TODO: on exit, if recording is finished, commit gesture & it's motion events.
-		 *
-		 * TODO: Reconcile recorded motion event coordinates with aspect ratio.
-		 */
 
 		while (num_events_polled++ < MAX_EVENTS_POLLED_PER_FRAME && SDL_PollEvent(&event)) {
 			switch (event.type) {
 			case SDL_FINGERMOTION:
-				if (!process_fingermotion_event(&event, temp_gesture))
-					; /* TODO: HAndle this. */
+				process_fingermotion_event(&event, temp_gesture);
 				break;
 			case SDL_DOLLARRECORD:
 				/* Store the finalised gesture. */
 				}
 				break;
 			case SDL_FINGERMOTION:
-				if (!process_fingermotion_event(&event, temp_gesture))
-					; /* TODO: HAndle this. */
+				process_fingermotion_event(&event, temp_gesture);
 				break;
 			case SDL_DOLLARGESTURE:
 				have_match = 1;