Fix cycling between different touch devices in the GL touch menu

This commit is contained in:
Aaron Culliney 2015-08-21 23:33:08 -07:00
parent 52ef663a2c
commit 3f934ecd3f
11 changed files with 73 additions and 65 deletions

View File

@ -362,13 +362,8 @@ public class Apple2Activity extends Activity {
if ((nativeFlags & NATIVE_TOUCH_INPUT_DEVICE_CHANGED) != 0) { if ((nativeFlags & NATIVE_TOUCH_INPUT_DEVICE_CHANGED) != 0) {
int touchDevice = Apple2Preferences.nativeGetCurrentTouchDevice(); int touchDevice = Apple2Preferences.nativeGetCurrentTouchDevice();
if (touchDevice == Apple2Preferences.TouchDeviceVariant.JOYSTICK.ordinal()) { Apple2Preferences.TouchDeviceVariant nextVariant = Apple2Preferences.TouchDeviceVariant.next(touchDevice);
Apple2Preferences.CURRENT_TOUCH_DEVICE.saveTouchDevice(this, Apple2Preferences.TouchDeviceVariant.JOYSTICK); Apple2Preferences.CURRENT_TOUCH_DEVICE.saveTouchDevice(this, nextVariant);
} else if (touchDevice == Apple2Preferences.TouchDeviceVariant.JOYSTICK_KEYPAD.ordinal()) {
Apple2Preferences.CURRENT_TOUCH_DEVICE.saveTouchDevice(this, Apple2Preferences.TouchDeviceVariant.JOYSTICK_KEYPAD);
} else {
Apple2Preferences.CURRENT_TOUCH_DEVICE.saveTouchDevice(this, Apple2Preferences.TouchDeviceVariant.KEYBOARD);
}
} }
if ((nativeFlags & NATIVE_TOUCH_CPU_SPEED_DEC) != 0) { if ((nativeFlags & NATIVE_TOUCH_CPU_SPEED_DEC) != 0) {
int percentSpeed = Apple2Preferences.nativeGetCPUSpeed(); int percentSpeed = Apple2Preferences.nativeGetCPUSpeed();

View File

@ -465,9 +465,19 @@ public enum Apple2Preferences {
KEYBOARD(3); KEYBOARD(3);
private int dev; private int dev;
public static final int size = TouchDeviceVariant.values().length;
TouchDeviceVariant(int dev) { TouchDeviceVariant(int dev) {
this.dev = dev; this.dev = dev;
} }
static TouchDeviceVariant next(int ord) {
++ord;
if (ord >= size) {
ord = 1;
}
return TouchDeviceVariant.values()[ord];
}
} }
public enum TouchJoystickButtons { public enum TouchJoystickButtons {

View File

@ -169,6 +169,8 @@ void Java_org_deadc0de_apple2ix_Apple2Activity_nativeOnPause(JNIEnv *env, jobjec
} }
LOG("%s", "native onPause..."); LOG("%s", "native onPause...");
video_backend->animation_hideTouchMenu();
if (isSystemPause) { if (isSystemPause) {
// going to background // going to background
cpu_pauseBackground(); cpu_pauseBackground();

View File

@ -13,17 +13,8 @@
#include <jni.h> #include <jni.h>
typedef enum AndroidTouchDevice {
// Maps to values in Apple2Preferences.java
ANDROID_TOUCH_NONE = 0,
ANDROID_TOUCH_JOYSTICK,
ANDROID_TOUCH_JOYSTICK_KEYPAD,
ANDROID_TOUCH_KEYBOARD,
ANDROID_TOUCH_DEVICE_MAX,
} AndroidTouchDevice;
typedef enum AndroidTouchJoystickButtonValues { typedef enum AndroidTouchJoystickButtonValues {
//ANDROID_TOUCH_NONE = 0, //ANDROID_TOUCHJOY_NONE = 0,
ANDROID_TOUCHJOY_BUTTON0 = 1, ANDROID_TOUCHJOY_BUTTON0 = 1,
ANDROID_TOUCHJOY_BUTTON1, ANDROID_TOUCHJOY_BUTTON1,
ANDROID_TOUCHJOY_BUTTON_BOTH, ANDROID_TOUCHJOY_BUTTON_BOTH,
@ -78,29 +69,29 @@ void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetMockingboardVolume(JN
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetCurrentTouchDevice(JNIEnv *env, jclass cls, jint touchDevice) { void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetCurrentTouchDevice(JNIEnv *env, jclass cls, jint touchDevice) {
LOG("native set default touch device : %d", touchDevice); LOG("native set default touch device : %d", touchDevice);
assert(touchDevice >= 0 && touchDevice < ANDROID_TOUCH_DEVICE_MAX); assert(touchDevice >= 0 && touchDevice < TOUCH_DEVICE_DEVICE_MAX);
switch (touchDevice) { switch (touchDevice) {
case ANDROID_TOUCH_JOYSTICK: case TOUCH_DEVICE_JOYSTICK:
keydriver_setTouchKeyboardOwnsScreen(false); keydriver_setTouchKeyboardOwnsScreen(false);
joydriver_setTouchJoystickOwnsScreen(true); joydriver_setTouchJoystickOwnsScreen(true);
joydriver_setTouchVariant(EMULATED_JOYSTICK); joydriver_setTouchVariant(EMULATED_JOYSTICK);
video_backend->animation_showTouchJoystick(); video_backend->animation_showTouchJoystick();
break; break;
case ANDROID_TOUCH_JOYSTICK_KEYPAD: case TOUCH_DEVICE_JOYSTICK_KEYPAD:
keydriver_setTouchKeyboardOwnsScreen(false); keydriver_setTouchKeyboardOwnsScreen(false);
joydriver_setTouchJoystickOwnsScreen(true); joydriver_setTouchJoystickOwnsScreen(true);
joydriver_setTouchVariant(EMULATED_KEYPAD); joydriver_setTouchVariant(EMULATED_KEYPAD);
video_backend->animation_showTouchJoystick(); video_backend->animation_showTouchJoystick();
break; break;
case ANDROID_TOUCH_KEYBOARD: case TOUCH_DEVICE_KEYBOARD:
keydriver_setTouchKeyboardOwnsScreen(true); keydriver_setTouchKeyboardOwnsScreen(true);
joydriver_setTouchJoystickOwnsScreen(false); joydriver_setTouchJoystickOwnsScreen(false);
video_backend->animation_showTouchKeyboard(); video_backend->animation_showTouchKeyboard();
break; break;
case ANDROID_TOUCH_NONE: case TOUCH_DEVICE_NONE:
default: default:
break; break;
} }
@ -111,14 +102,14 @@ jint Java_org_deadc0de_apple2ix_Apple2Preferences_nativeGetCurrentTouchDevice(JN
if (joydriver_ownsScreen()) { if (joydriver_ownsScreen()) {
touchjoy_variant_t variant = joydriver_getTouchVariant(); touchjoy_variant_t variant = joydriver_getTouchVariant();
if (variant == EMULATED_JOYSTICK) { if (variant == EMULATED_JOYSTICK) {
return ANDROID_TOUCH_JOYSTICK; return TOUCH_DEVICE_JOYSTICK;
} else if (variant == EMULATED_KEYPAD) { } else if (variant == EMULATED_KEYPAD) {
return ANDROID_TOUCH_JOYSTICK_KEYPAD; return TOUCH_DEVICE_JOYSTICK_KEYPAD;
} }
} else if (keydriver_ownsScreen()) { } else if (keydriver_ownsScreen()) {
return ANDROID_TOUCH_KEYBOARD; return TOUCH_DEVICE_KEYBOARD;
} }
return ANDROID_TOUCH_NONE; return TOUCH_DEVICE_NONE;
} }
void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetTouchMenuEnabled(JNIEnv *env, jclass cls, jboolean enabled) { void Java_org_deadc0de_apple2ix_Apple2Preferences_nativeSetTouchMenuEnabled(JNIEnv *env, jclass cls, jboolean enabled) {

View File

@ -321,8 +321,8 @@ const unsigned char interface_glyphs[256] =
0x7f, 0x77, 0x77, 0x41, 0x77, 0x77, 0x7f, 0x00, 0x7f, 0x77, 0x77, 0x41, 0x77, 0x77, 0x7f, 0x00,
/* : 0x17 ----------------------- glyph_backspace */ /* : 0x17 ----------------------- glyph_backspace */
0x00, 0x08, 0x04, 0x7e, 0x04, 0x08, 0x00, 0x00, 0x00, 0x08, 0x04, 0x7e, 0x04, 0x08, 0x00, 0x00,
/* : 0x18 */ /* : 0x18 ----------------------- glyph_joystick_kpad */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x2a, 0x08, 0x77, 0x08, 0x2a, 0x08, 0x00,
/* : 0x19 ----------------------- glyph_leftspace */ /* : 0x19 ----------------------- glyph_leftspace */
0x00, 0x7e, 0x02, 0x42, 0x42, 0x42, 0x02, 0x7e, 0x00, 0x7e, 0x02, 0x42, 0x42, 0x42, 0x02, 0x7e,
/* : 0x1A ----------------------- glyph_midspace */ /* : 0x1A ----------------------- glyph_midspace */

View File

@ -1390,14 +1390,14 @@
...#... ...#...
....... .......
....... .......
: 0x18 : 0x18 ----------------------- glyph_joystick_kpad
....... ...#...
....... .#.#.#.
....... ...#...
....... ###.###
....... ...#...
....... .#.#.#.
....... ...#...
....... .......
: 0x19 ----------------------- glyph_leftspace : 0x19 ----------------------- glyph_leftspace
....... .......

View File

@ -45,6 +45,14 @@ void interface_plotChar(uint8_t *fboff, int fb_pix_width, interface_colorscheme_
void interface_plotMessage(uint8_t *fb, interface_colorscheme_t cs, char *message, int message_cols, int message_rows); void interface_plotMessage(uint8_t *fb, interface_colorscheme_t cs, char *message, int message_cols, int message_rows);
#if INTERFACE_TOUCH #if INTERFACE_TOUCH
typedef enum interface_device_t {
TOUCH_DEVICE_NONE = 0,
TOUCH_DEVICE_JOYSTICK,
TOUCH_DEVICE_JOYSTICK_KEYPAD,
TOUCH_DEVICE_KEYBOARD,
TOUCH_DEVICE_DEVICE_MAX,
} interface_device_t;
typedef enum interface_touch_event_t { typedef enum interface_touch_event_t {
TOUCH_CANCEL = 0, TOUCH_CANCEL = 0,
TOUCH_DOWN, TOUCH_DOWN,

View File

@ -35,8 +35,9 @@ void c_calibrate_joystick(void);
#if INTERFACE_TOUCH #if INTERFACE_TOUCH
typedef enum touchjoy_variant_t { typedef enum touchjoy_variant_t {
EMULATED_JOYSTICK = 0, // touch interface emulates a physical joystick device EMULATED_NONE = 0,
EMULATED_KEYPAD, // touch interface generates key presses EMULATED_JOYSTICK, // touch interface emulates a physical joystick device
EMULATED_KEYPAD, // touch interface generates key presses
} touchjoy_variant_t; } touchjoy_variant_t;
typedef enum touchjoy_button_type_t { typedef enum touchjoy_button_type_t {

View File

@ -705,6 +705,18 @@ static void gltouchjoy_setTouchButtonTypes(
buttons.northChar = northChar; buttons.northChar = northChar;
buttons.northScancode = northScancode; buttons.northScancode = northScancode;
buttons.activeChar = ICONTEXT_NONACTIONABLE;
char currButtonDisplayChar = touchDownChar;
if (touchDownChar == TOUCH_BUTTON0) {
currButtonDisplayChar = MOUSETEXT_OPENAPPLE;
} else if (touchDownChar == TOUCH_BUTTON1) {
currButtonDisplayChar = MOUSETEXT_CLOSEDAPPLE;
} else if (touchDownChar == TOUCH_BOTH) {
currButtonDisplayChar = '+';
}
_setup_button_object_with_char(currButtonDisplayChar);
} }
static void gltouchjoy_setTapDelay(float secs) { static void gltouchjoy_setTapDelay(float secs) {

View File

@ -96,7 +96,17 @@ static inline void _present_menu(GLModel *parent) {
static inline void _show_top_left(void) { static inline void _show_top_left(void) {
topMenuTemplate[0][0] = ICONTEXT_MENU_SPROUT; topMenuTemplate[0][0] = ICONTEXT_MENU_SPROUT;
topMenuTemplate[0][1] = MOUSETEXT_RIGHT; topMenuTemplate[0][1] = MOUSETEXT_RIGHT;
topMenuTemplate[1][0] = joydriver_ownsScreen() ? ICONTEXT_UPPERCASE : ICONTEXT_MENU_TOUCHJOY;
if (joydriver_ownsScreen()) {
if (joydriver_getTouchVariant() == EMULATED_JOYSTICK) {
topMenuTemplate[1][0] = ICONTEXT_MENU_TOUCHJOY_KPAD;
} else {
topMenuTemplate[1][0] = ICONTEXT_UPPERCASE;
}
} else {
topMenuTemplate[1][0] = ICONTEXT_MENU_TOUCHJOY;
}
topMenuTemplate[1][1] = ICONTEXT_NONACTIONABLE; topMenuTemplate[1][1] = ICONTEXT_NONACTIONABLE;
menu.topLeftShowing = true; menu.topLeftShowing = true;
_present_menu(menu.model); _present_menu(menu.model);
@ -269,29 +279,9 @@ static inline int64_t _tap_menu_item(float x, float y) {
break; break;
case ICONTEXT_MENU_TOUCHJOY: case ICONTEXT_MENU_TOUCHJOY:
LOG("showing touch joystick ..."); case ICONTEXT_MENU_TOUCHJOY_KPAD:
keydriver_setTouchKeyboardOwnsScreen(false);
if (video_backend->animation_hideTouchKeyboard) {
video_backend->animation_hideTouchKeyboard();
}
joydriver_setTouchJoystickOwnsScreen(true);
if (video_backend->animation_showTouchJoystick) {
video_backend->animation_showTouchJoystick();
}
flags |= TOUCH_FLAGS_INPUT_DEVICE_CHANGE;
_hide_top_left();
break;
case ICONTEXT_UPPERCASE: case ICONTEXT_UPPERCASE:
LOG("showing touch keyboard ..."); LOG("switching input device ...");
joydriver_setTouchJoystickOwnsScreen(false);
if (video_backend->animation_hideTouchJoystick) {
video_backend->animation_hideTouchJoystick();
}
keydriver_setTouchKeyboardOwnsScreen(true);
if (video_backend->animation_showTouchKeyboard) {
video_backend->animation_showTouchKeyboard();
}
flags |= TOUCH_FLAGS_INPUT_DEVICE_CHANGE; flags |= TOUCH_FLAGS_INPUT_DEVICE_CHANGE;
_hide_top_left(); _hide_top_left();
break; break;
@ -524,10 +514,8 @@ static void _animation_showTouchMenu(void) {
} }
static void _animation_hideTouchMenu(void) { static void _animation_hideTouchMenu(void) {
timingBegin = (struct timespec){ 0 }; _hide_top_left();
} _hide_top_right();
static void gltouchmenu_set(void) {
timingBegin = (struct timespec){ 0 }; timingBegin = (struct timespec){ 0 };
} }

View File

@ -212,6 +212,7 @@ uint8_t floating_bus_hibit(const bool hibit);
#define ICONTEXT_MENU_SPROUT (MOUSETEXT_BEGIN+0x1B) #define ICONTEXT_MENU_SPROUT (MOUSETEXT_BEGIN+0x1B)
#define ICONTEXT_MENU_TOUCHJOY (ICONTEXT_BEGIN+0x12) #define ICONTEXT_MENU_TOUCHJOY (ICONTEXT_BEGIN+0x12)
#define ICONTEXT_MENU_TOUCHJOY_KPAD (ICONTEXT_BEGIN+0x18)
#define ICONTEXT_KBD_BEGIN (ICONTEXT_BEGIN+0x13) #define ICONTEXT_KBD_BEGIN (ICONTEXT_BEGIN+0x13)
#define ICONTEXT_CTRL (ICONTEXT_KBD_BEGIN+0x00) #define ICONTEXT_CTRL (ICONTEXT_KBD_BEGIN+0x00)