Touch and mouse support for the OSK

This commit is contained in:
Jean-André Santoni 2016-10-30 11:48:35 +01:00
parent ec058911d3
commit 41611e3d74
7 changed files with 118 additions and 6 deletions

View File

@ -315,6 +315,34 @@ static void mui_render_keyboard(mui_handle_t *mui, const char *grid[], unsigned
}
}
/* Returns the OSK key at a given position */
static int mui_osk_ptr_at_pos(void *data, int x, int y)
{
unsigned i, width, height;
mui_handle_t *mui = (mui_handle_t*)data;
if (!mui)
return -1;
video_driver_get_size(&width, &height);
for (i = 0; i <= 40; i++)
{
int line_y;
int ptr_width = height / 12;
line_y = (i / 10)*height/10.0;
int ptr_x = width/11.0 + (i % 10) * width/11.0 - ptr_width/2;
int ptr_y = height*2.5/4.0 + line_y - ptr_width/2 - mui->font->size / 4;
if (x > ptr_x && x < ptr_x + ptr_width
&& y > ptr_y && y < ptr_y + ptr_width)
return i;
}
return -1;
}
static void mui_draw_tab_begin(mui_handle_t *mui,
unsigned width, unsigned height,
float *tabs_bg_color, float *tabs_separator_color)
@ -1818,4 +1846,7 @@ menu_ctx_driver_t menu_ctx_mui = {
"glui",
mui_environ,
mui_pointer_tap,
NULL,
NULL,
mui_osk_ptr_at_pos,
};

View File

@ -730,6 +730,34 @@ static void xmb_render_keyboard(xmb_handle_t *xmb, const char *grid[], unsigned
}
}
/* Returns the OSK key at a given position */
static int xmb_osk_ptr_at_pos(void *data, int x, int y)
{
unsigned i, width, height;
xmb_handle_t *xmb = (xmb_handle_t*)data;
if (!xmb)
return -1;
video_driver_get_size(&width, &height);
for (i = 0; i <= 40; i++)
{
int line_y;
int ptr_width = height / 12;
line_y = (i / 10)*height/10.0;
int ptr_x = width/11.0 + (i % 10) * width/11.0 - ptr_width/2;
int ptr_y = height*2.5/4.0 + line_y - ptr_width/2 - xmb->font->size / 4;
if (x > ptr_x && x < ptr_x + ptr_width
&& y > ptr_y && y < ptr_y + ptr_width)
return i;
}
return -1;
}
static void xmb_render_messagebox_internal(
xmb_handle_t *xmb, const char *message)
{
@ -3682,4 +3710,5 @@ menu_ctx_driver_t menu_ctx_xmb = {
xmb_pointer_tap,
xmb_update_thumbnail_path,
xmb_update_thumbnail_image,
xmb_osk_ptr_at_pos,
};

View File

@ -916,6 +916,18 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
point->cbs, point->entry, point->action);
}
break;
case RARCH_MENU_CTL_OSK_PTR_AT_POS:
{
menu_ctx_pointer_t *point = (menu_ctx_pointer_t*)data;
if (!menu_driver_ctx || !menu_driver_ctx->pointer_tap)
{
point->retcode = 0;
return false;
}
point->retcode = menu_driver_ctx->osk_ptr_at_pos(menu_userdata,
point->x, point->y);
}
break;
case RARCH_MENU_CTL_BIND_INIT:
{
menu_ctx_bind_t *bind = (menu_ctx_bind_t*)data;

View File

@ -142,6 +142,7 @@ enum rarch_menu_ctl_state
RARCH_MENU_CTL_ENVIRONMENT,
RARCH_MENU_CTL_DRIVER_DATA_GET,
RARCH_MENU_CTL_POINTER_TAP,
RARCH_MENU_CTL_OSK_PTR_AT_POS,
RARCH_MENU_CTL_BIND_INIT,
RARCH_MENU_CTL_UPDATE_THUMBNAIL_PATH,
RARCH_MENU_CTL_UPDATE_THUMBNAIL_IMAGE
@ -274,6 +275,7 @@ typedef struct menu_ctx_driver
menu_entry_t *entry, unsigned action);
void (*update_thumbnail_path)(void *data, unsigned i);
void (*update_thumbnail_image)(void *data);
int (*osk_ptr_at_pos)(void *data, int x, int y);
} menu_ctx_driver_t;
typedef struct menu_ctx_load_image

View File

@ -101,6 +101,11 @@ unsigned menu_event_get_osk_ptr()
return osk_ptr;
}
void menu_event_set_osk_ptr(unsigned i)
{
osk_ptr = i;
}
const char** menu_event_get_osk_grid()
{
return osk_grid;

View File

@ -40,6 +40,7 @@ void menu_event_keyboard_set(bool down, enum retro_key key);
unsigned char menu_event_keyboard_is_set(enum retro_key key);
unsigned menu_event_get_osk_ptr();
void menu_event_set_osk_ptr(unsigned);
const char** menu_event_get_osk_grid();
RETRO_END_DECLS

View File

@ -32,6 +32,7 @@
#include "menu_animation.h"
#include "menu_display.h"
#include "menu_navigation.h"
#include "menu_event.h"
#include "../configuration.h"
@ -221,6 +222,15 @@ static int menu_input_mouse_frame(
if (settings->menu.mouse.enable)
ret = menu_input_mouse_post_iterate(&mouse_state, cbs, action);
if (menu_input_dialog_get_display_kb())
{
menu_ctx_pointer_t point;
point.x = menu_input_mouse_state(MENU_MOUSE_X_AXIS);
point.y = menu_input_mouse_state(MENU_MOUSE_Y_AXIS);
menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point);
menu_event_set_osk_ptr(point.retcode);
}
if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_BUTTON_L))
{
menu_ctx_pointer_t point;
@ -232,9 +242,20 @@ static int menu_input_mouse_frame(
point.entry = entry;
point.action = action;
menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point);
ret = point.retcode;
if (menu_input_dialog_get_display_kb())
{
menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point);
if (point.retcode > -1)
{
menu_event_set_osk_ptr(point.retcode);
input_keyboard_line_append(menu_event_get_osk_grid()[point.retcode]);
}
}
else
{
menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point);
ret = point.retcode;
}
}
if (BIT64_GET(mouse_state, MENU_MOUSE_ACTION_BUTTON_R))
@ -423,9 +444,20 @@ static int menu_input_pointer_post_iterate(
point.entry = entry;
point.action = action;
menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point);
ret = point.retcode;
if (menu_input_dialog_get_display_kb())
{
menu_driver_ctl(RARCH_MENU_CTL_OSK_PTR_AT_POS, &point);
if (point.retcode > -1)
{
menu_event_set_osk_ptr(point.retcode);
input_keyboard_line_append(menu_event_get_osk_grid()[point.retcode]);
}
}
else
{
menu_driver_ctl(RARCH_MENU_CTL_POINTER_TAP, &point);
ret = point.retcode;
}
}
pointer_oldpressed[0] = false;