diff --git a/android/phoenix/jni/Android.mk b/android/phoenix/jni/Android.mk index c4465faefd..757d41bc1b 100644 --- a/android/phoenix/jni/Android.mk +++ b/android/phoenix/jni/Android.mk @@ -58,10 +58,14 @@ else endif -LOCAL_CFLAGS += -Wall -pthread -Wno-unused-function -fno-stack-protector -funroll-loops -DNDEBUG -DRARCH_MOBILE -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_DYLIB -DHAVE_GLSL -DHAVE_MENU -DHAVE_RGUI -DHAVE_ZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREADS -D__LIBRETRO__ -DHAVE_RSOUND -DHAVE_NETPLAY -DHAVE_NETWORKING -DRARCH_INTERNAL -DHAVE_FILTERS_BUILTIN -DHAVE_GLUI -DHAVE_XMB -std=gnu99 -DHAVE_LIBRETRODB +LOCAL_CFLAGS += -Wall -pthread -Wno-unused-function -fno-stack-protector -funroll-loops -DRARCH_MOBILE -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_FBO -DHAVE_OVERLAY -DHAVE_OPENGLES -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_DYLIB -DHAVE_GLSL -DHAVE_MENU -DHAVE_RGUI -DHAVE_ZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREADS -D__LIBRETRO__ -DHAVE_RSOUND -DHAVE_NETPLAY -DHAVE_NETWORKING -DRARCH_INTERNAL -DHAVE_FILTERS_BUILTIN -DHAVE_GLUI -DHAVE_XMB -std=gnu99 -DHAVE_LIBRETRODB LOCAL_CFLAGS += -DHAVE_7ZIP -LOCAL_CFLAGS += -O2 +ifeq ($(NDK_DEBUG),1) +LOCAL_CFLAGS += -O0 -g +else +LOCAL_CFLAGS += -O2 -DNDEBUG +endif LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -landroid -lEGL $(GLES_LIB) $(LOGGER_LDLIBS) -ldl LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(RARCH_DIR)/libretro-common/include/ diff --git a/driver.h b/driver.h index 42be50f91a..f1b4c4bd0b 100644 --- a/driver.h +++ b/driver.h @@ -64,6 +64,8 @@ extern "C" { * It is only used internally for overlays. */ #define RARCH_DEVICE_POINTER_SCREEN (RETRO_DEVICE_POINTER | 0x10000) +#define RARCH_DEVICE_ID_POINTER_BACK (RETRO_DEVICE_ID_POINTER_PRESSED | 0x10000) + /* libretro has 16 buttons from 0-15 (libretro.h) * Analog binds use RETRO_DEVICE_ANALOG, but we follow the same scheme * internally in RetroArch for simplicity, so they are mapped into [16, 23]. diff --git a/input/drivers/android_input.c b/input/drivers/android_input.c index a7c6e2f651..33ce2cc645 100644 --- a/input/drivers/android_input.c +++ b/input/drivers/android_input.c @@ -728,6 +728,8 @@ static int16_t android_input_state(void *data, return (idx < android->pointer_count) && (android->pointer[idx].x != -0x8000) && (android->pointer[idx].y != -0x8000); + case RARCH_DEVICE_ID_POINTER_BACK: + return BIT_GET(android->pad_state[0], AKEYCODE_BACK); } break; case RARCH_DEVICE_POINTER_SCREEN: @@ -741,6 +743,8 @@ static int16_t android_input_state(void *data, return (idx < android->pointer_count) && (android->pointer[idx].full_x != -0x8000) && (android->pointer[idx].full_y != -0x8000); + case RARCH_DEVICE_ID_POINTER_BACK: + return BIT_GET(android->pad_state[0], AKEYCODE_BACK); } break; } diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 4a8887d69c..8fd676eddd 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -171,6 +171,15 @@ typedef struct unsigned ptr; } mouse; + struct + { + bool pressed; + bool oldpressed; + bool back; + bool oldback; + bool cancel; + } pointer; + struct { const char **buffer; diff --git a/menu/menu_entries_cbs_iterate.c b/menu/menu_entries_cbs_iterate.c index 1f31383d12..45280c5cbb 100644 --- a/menu/menu_entries_cbs_iterate.c +++ b/menu/menu_entries_cbs_iterate.c @@ -150,6 +150,78 @@ static INLINE struct video_shader *shader_manager_get_current_shader(const char return NULL; } +static int pointer_post_iterate(menu_file_list_cbs_t *cbs, const char *path, + const char *label, unsigned type, unsigned action) +{ + menu_handle_t *menu = menu_driver_get_ptr(); + settings_t *settings = config_get_ptr(); +#if defined(HAVE_XMB) || defined(HAVE_GLUI) + driver_t *driver = driver_get_ptr(); +#endif + + if (!menu) + return -1; + + if (!settings->menu.mouse.enable) + return 0; + +#if defined(HAVE_XMB) + if (driver->menu_ctx == &menu_ctx_xmb) + return 0; +#endif +#if defined(HAVE_GLUI) + if (driver->menu_ctx == &menu_ctx_glui) + return 0; +#endif + + if (menu->pointer.pressed) + { + if (menu->pointer.oldpressed) + { + if (menu->mouse.ptr <= menu_list_get_size(menu->menu_list)-1) + menu_navigation_set(&menu->navigation, menu->mouse.ptr, false); + } + else + menu->pointer.oldpressed = true; + } + else + { + if (menu->pointer.oldpressed) + { + menu->pointer.oldpressed = false; + driver_t *driver = driver_get_ptr(); + rarch_setting_t *setting = + (rarch_setting_t*)setting_find_setting + (driver->menu->list_settings, + driver->menu->menu_list->selection_buf->list[menu->navigation.selection_ptr].label); + + if (menu->mouse.ptr == menu->navigation.selection_ptr && !menu->pointer.cancel + && cbs && cbs->action_toggle && setting && + (setting->type == ST_BOOL || setting->type == ST_UINT || setting->type == ST_FLOAT + || setting->type == ST_STRING)) + return cbs->action_toggle(type, label, MENU_ACTION_RIGHT, true); + if (menu->mouse.ptr == menu->navigation.selection_ptr && !menu->pointer.cancel + && cbs && cbs->action_ok) + return cbs->action_ok(path, label, type, + menu->navigation.selection_ptr); + else if (menu->mouse.ptr <= menu_list_get_size(menu->menu_list) - 1) + menu_navigation_set(&menu->navigation, menu->mouse.ptr, false); + } + } + + if (menu->pointer.back) + { + if (!menu->pointer.oldback) + { + menu->pointer.oldback = true; + menu_list_pop_stack(menu->menu_list); + } + } + menu->pointer.oldback = menu->pointer.back; + + return 0; +} + static int mouse_post_iterate(menu_file_list_cbs_t *cbs, const char *path, const char *label, unsigned type, unsigned action) { @@ -567,6 +639,72 @@ static int action_iterate_message(const char *label, unsigned action) return 0; } +static int pointer_iterate(unsigned *action) +{ + const struct retro_keybind *binds[MAX_USERS]; + menu_handle_t *menu = menu_driver_get_ptr(); + runloop_t *runloop = rarch_main_get_ptr(); + settings_t *settings = config_get_ptr(); +#if defined(HAVE_XMB) || defined(HAVE_GLUI) + driver_t *driver = driver_get_ptr(); +#endif + + int pointer_x, pointer_y, screen_x, screen_y; + + if (!menu) + return -1; + + if (!settings->menu.mouse.enable) + return 0; + +#if defined(HAVE_XMB) + if (driver->menu_ctx == &menu_ctx_xmb) + return 0; +#endif +#if defined(HAVE_GLUI) + if (driver->menu_ctx == &menu_ctx_glui) + return 0; +#endif + + menu->pointer.pressed = input_driver_state(binds, 0, RETRO_DEVICE_POINTER, + 0, RETRO_DEVICE_ID_POINTER_PRESSED); + menu->pointer.back = input_driver_state(binds, 0, RETRO_DEVICE_POINTER, + 0, RARCH_DEVICE_ID_POINTER_BACK); + + pointer_x = input_driver_state(binds, 0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_X); + pointer_y = input_driver_state(binds, 0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_Y); + + screen_x = ((pointer_x + 0x7fff) * (int)menu->frame_buf.width) / 0xFFFF; + screen_y = ((pointer_y + 0x7fff) * (int)menu->frame_buf.height) / 0xFFFF; + + if (menu->pointer.pressed) + { + menu->mouse.x = screen_x; + menu->mouse.y = screen_y; + if (menu->mouse.x < 5) + menu->mouse.x = 5; + if (menu->mouse.y < 5) + menu->mouse.y = 5; + if (menu->mouse.x > (int)menu->frame_buf.width - 5) + menu->mouse.x = menu->frame_buf.width - 5; + if (menu->mouse.y > (int)menu->frame_buf.height - 5) + menu->mouse.y = menu->frame_buf.height - 5; + + menu->mouse.scrollup = (menu->mouse.y == 5); + menu->mouse.scrolldown = (menu->mouse.y == (int)menu->frame_buf.height - 5); + + menu->pointer.cancel = false; + } + else + menu->pointer.cancel = screen_x < 5 || screen_x > (int)menu->frame_buf.width - 5 + || screen_x < 5 || screen_x > (int)menu->frame_buf.height - 5; + + if (menu->pointer.pressed || menu->pointer.back || menu->mouse.x != screen_x || menu->mouse.y != screen_y) + runloop->frames.video.current.menu.animation.is_active = true; + + return 0; +} + static int mouse_iterate(unsigned *action) { const struct retro_keybind *binds[MAX_USERS]; @@ -669,6 +807,7 @@ static int action_iterate_main(const char *label, unsigned action) menu->navigation.selection_ptr, &path_offset, &label_offset, &type_offset); mouse_iterate(&action); + pointer_iterate(&action); if (!strcmp(label, "help")) return action_iterate_help(label, action); @@ -765,7 +904,8 @@ static int action_iterate_main(const char *label, unsigned action) if (ret) return ret; - ret = mouse_post_iterate(cbs, path_offset, label_offset, type_offset, action); + ret = mouse_post_iterate(cbs, path_offset, label_offset, type_offset, action); + ret |= pointer_post_iterate(cbs, path_offset, label_offset, type_offset, action); menu_driver_render();