From 715111122837440d3a1463d0d6932c469418dcbb Mon Sep 17 00:00:00 2001 From: Frank Gevaerts Date: Wed, 13 Jun 2012 23:07:49 +0200 Subject: Make touchscreen handling work with skinned lists. Change-Id: I7df93319c8f16f05e840d74b022aab4803bb8f80 --- apps/gui/bitmap/list-skinned.c | 14 ++++++++++++++ apps/gui/bitmap/list.c | 15 ++++++++++----- apps/gui/list.h | 2 ++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/gui/bitmap/list-skinned.c b/apps/gui/bitmap/list-skinned.c index 81ef6fc18f..d0803b5dc8 100644 --- a/apps/gui/bitmap/list-skinned.c +++ b/apps/gui/bitmap/list-skinned.c @@ -167,6 +167,20 @@ void skinlist_get_scrollbar(int* nb_item, int* first_shown, int* last_shown) } } +bool skinlist_get_item(struct screen *display, struct gui_synclist *list, int x, int y, int *item) +{ + const int screen = display->screen_type; + if (!skinlist_is_configured(screen, list)) + return false; + + int row = y / listcfg[screen]->height; + int column = x / listcfg[screen]->width; + struct viewport *parent = (list->parent[screen]); + int cols = (parent->width / listcfg[screen]->width); + *item = row * cols+ column; + return true; +} + bool skinlist_draw(struct screen *display, struct gui_synclist *list) { int cur_line, display_lines; diff --git a/apps/gui/bitmap/list.c b/apps/gui/bitmap/list.c index 3a45a8124c..aad3eda98f 100644 --- a/apps/gui/bitmap/list.c +++ b/apps/gui/bitmap/list.c @@ -704,7 +704,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * list) enum screen_type screen; struct viewport *parent; short x, y; - int action, adj_y, line, line_height, list_start_item; + int action, adj_x, adj_y, line, line_height, list_start_item; bool recurse; static int last_y = -1; @@ -714,6 +714,7 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * list) list_start_item = list->start_item[screen]; /* start with getting the action code and finding the click location */ action = action_get_touchscreen_press(&x, &y); + adj_x = x - parent->x; adj_y = y - parent->y; @@ -736,13 +737,17 @@ unsigned gui_synclist_do_touchscreen(struct gui_synclist * list) line = 0; /* silence gcc 'used uninitialized' warning */ if (click_loc & LIST) { - /* selection needs to be corrected if items are only partially visible */ - line = (adj_y - y_offset) / line_height; - if (list_display_title(list, screen)) - line -= 1; /* adjust for the list title */ + if(!skinlist_get_item(&screens[screen], list, adj_x, adj_y, &line)) + { + /* selection needs to be corrected if items are only partially visible */ + line = (adj_y - y_offset) / line_height; + if (list_display_title(list, screen)) + line -= 1; /* adjust for the list title */ + } if (line >= list->nb_items) return ACTION_NONE; list->selected_item = list_start_item+line; + gui_synclist_speak_item(list); } if (action == BUTTON_TOUCHSCREEN) diff --git a/apps/gui/list.h b/apps/gui/list.h index 647b4ea20e..162bb38e1a 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -188,6 +188,8 @@ struct listitem_viewport_cfg { bool tile; struct skin_viewport selected_item_vp; }; + +bool skinlist_get_item(struct screen *display, struct gui_synclist *list, int x, int y, int *item); bool skinlist_draw(struct screen *display, struct gui_synclist *list); bool skinlist_is_selected_item(void); void skinlist_set_cfg(enum screen_type screen, -- cgit v1.2.3