From 745da4d66b4ddd9d61ff7bcb35de5fb7e9448d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Thu, 3 Nov 2016 09:21:27 +0100 Subject: [PATCH] Adapt OSK rendering to vertical screens like phones --- menu/drivers/materialui.c | 23 ++++++++++++++++------- menu/drivers/xmb.c | 23 ++++++++++++++++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index c7b5a9e4a8..22b0e76081 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -300,7 +300,11 @@ static void mui_render_keyboard(mui_handle_t *mui, const char *grid[], unsigned width, height, &dark[0]); - int ptr_width = height / 10; + int ptr_width = width / 11; + int ptr_height = height / 10; + + if (ptr_width >= ptr_height) + ptr_width = ptr_height; for (i = 0; i < 44; i++) { @@ -314,15 +318,15 @@ static void mui_render_keyboard(mui_handle_t *mui, const char *grid[], unsigned menu_display_draw_texture( width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width, - height/2.0 + ptr_width*1.5 + line_y, - ptr_width, ptr_width, + height/2.0 + ptr_height*1.5 + line_y, + ptr_width, ptr_height, width, height, &white[0], texture); mui_draw_text(mui->font, width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width + ptr_width/2.0, - height/2.0 + ptr_width + line_y, + height/2.0 + ptr_height + line_y, width, height, grid[i], 0xffffffff, TEXT_ALIGN_CENTER); } } @@ -338,15 +342,20 @@ static int mui_osk_ptr_at_pos(void *data, int x, int y) video_driver_get_size(&width, &height); + int ptr_width = width / 11; + int ptr_height = height / 10; + + if (ptr_width >= ptr_height) + ptr_width = ptr_height; + for (i = 0; i < 44; i++) { - int ptr_width = height / 10; int line_y = (i / 11)*height/10.0; int ptr_x = width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width; - int ptr_y = height/2.0 + ptr_width*1.5 + line_y - ptr_width; + int ptr_y = height/2.0 + ptr_height*1.5 + line_y - ptr_height; if (x > ptr_x && x < ptr_x + ptr_width - && y > ptr_y && y < ptr_y + ptr_width) + && y > ptr_y && y < ptr_y + ptr_height) return i; } diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 1720ffcc6a..9f84e9c911 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -715,7 +715,11 @@ static void xmb_render_keyboard(xmb_handle_t *xmb, const char *grid[], unsigned width, height, &dark[0]); - int ptr_width = height / 10; + int ptr_width = width / 11; + int ptr_height = height / 10; + + if (ptr_width >= ptr_height) + ptr_width = ptr_height; for (i = 0; i < 44; i++) { @@ -729,8 +733,8 @@ static void xmb_render_keyboard(xmb_handle_t *xmb, const char *grid[], unsigned menu_display_draw_texture( width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width, - height/2.0 + ptr_width*1.5 + line_y, - ptr_width, ptr_width, + height/2.0 + ptr_height*1.5 + line_y, + ptr_width, ptr_height, width, height, &white[0], texture); @@ -739,7 +743,7 @@ static void xmb_render_keyboard(xmb_handle_t *xmb, const char *grid[], unsigned xmb_draw_text(xmb, grid[i], width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width + ptr_width/2.0, - height/2.0 + ptr_width + xmb->font->size/4.0 + line_y, + height/2.0 + ptr_height + xmb->font->size/4.0 + line_y, 1, 1, TEXT_ALIGN_CENTER, width, height, xmb->font); } } @@ -755,15 +759,20 @@ static int xmb_osk_ptr_at_pos(void *data, int x, int y) video_driver_get_size(&width, &height); + int ptr_width = width / 11; + int ptr_height = height / 10; + + if (ptr_width >= ptr_height) + ptr_width = ptr_height; + for (i = 0; i < 44; i++) { - int ptr_width = height / 10; int line_y = (i / 11)*height/10.0; int ptr_x = width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width; - int ptr_y = height/2.0 + ptr_width*1.5 + line_y - ptr_width; + int ptr_y = height/2.0 + ptr_height*1.5 + line_y - ptr_height; if (x > ptr_x && x < ptr_x + ptr_width - && y > ptr_y && y < ptr_y + ptr_width) + && y > ptr_y && y < ptr_y + ptr_height) return i; }