1
0
Fork 0
forked from len0rd/rockbox

(Simulator) Touchscreen improvements.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17662 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Maurus Cuelenaere 2008-05-30 22:55:24 +00:00
parent 48b47801e7
commit 944219bb77
3 changed files with 54 additions and 14 deletions

View file

@ -308,6 +308,9 @@ int action_get_touchpad_press(short *x, short *y)
return BUTTON_REPEAT; return BUTTON_REPEAT;
if (short_press) if (short_press)
return BUTTON_REL; return BUTTON_REL;
/* this is to give a BUTTON_REL after a BUTTON_REPEAT */
if (last_button & BUTTON_REL)
return BUTTON_REL;
return BUTTON_TOUCHPAD; return BUTTON_TOUCHPAD;
} }
#endif #endif

View file

@ -278,6 +278,7 @@ void list_draw(struct screen *display, struct viewport *parent,
#if defined(HAVE_TOUCHPAD) #if defined(HAVE_TOUCHPAD)
static int prev_line=0;
/* this needs to be fixed if we ever get more than 1 touchscreen on a target */ /* this needs to be fixed if we ever get more than 1 touchscreen on a target */
/* this also assumes the whole screen is used, which is a bad asusmption but /* this also assumes the whole screen is used, which is a bad asusmption but
fine untill customizable lists comes in... */ fine untill customizable lists comes in... */
@ -309,15 +310,15 @@ unsigned gui_synclist_do_touchpad(struct gui_synclist * gui_list, struct viewpor
nb_lines = viewport_get_nb_lines(&list_text[SCREEN_MAIN]); nb_lines = viewport_get_nb_lines(&list_text[SCREEN_MAIN]);
if (nb_lines < gui_list->nb_items) if (nb_lines < gui_list->nb_items)
{ {
height = nb_lines * display->char_height; height = nb_lines * font_get(parent->font)->height;
size = height*nb_lines / gui_list->nb_items; size = height*nb_lines / gui_list->nb_items;
new_selection = ((y-list_text[SCREEN_MAIN].y)*(gui_list->nb_items-nb_lines))/(height-size); new_selection = ((y-list_text[SCREEN_MAIN].y)*(gui_list->nb_items-nb_lines))/(height-size);
gui_synclist_select_item(gui_list, new_selection);
nb_lines /= 2; nb_lines /= 2;
if (new_selection - gui_list->start_item[SCREEN_MAIN] > nb_lines) if (new_selection - gui_list->start_item[SCREEN_MAIN] > nb_lines)
{
new_selection = gui_list->start_item[SCREEN_MAIN]+nb_lines; new_selection = gui_list->start_item[SCREEN_MAIN]+nb_lines;
}
gui_synclist_select_item(gui_list, new_selection);
gui_list->start_item[SCREEN_MAIN] = new_selection; gui_list->start_item[SCREEN_MAIN] = new_selection;
return ACTION_REDRAW; return ACTION_REDRAW;
} }
@ -329,32 +330,52 @@ unsigned gui_synclist_do_touchpad(struct gui_synclist * gui_list, struct viewpor
pressing the selected item will "enter" it */ pressing the selected item will "enter" it */
if (y > list_text[SCREEN_MAIN].y) if (y > list_text[SCREEN_MAIN].y)
{ {
line = (y-list_text[SCREEN_MAIN].y) / display->char_height; int i, line_height, actual_y;
if (button != BUTTON_REL && button != BUTTON_REPEAT) actual_y = y - list_text[SCREEN_MAIN].y;
line_height = font_get(parent->font)->height;
line = -1;
for(i=0; i<gui_list->nb_items; i++)
{ {
if (line != gui_list->selected_item - gui_list->start_item[SCREEN_MAIN]) if(actual_y > line_height*i && actual_y < line_height*(i+1))
gui_synclist_select_item(gui_list, gui_list->start_item[SCREEN_MAIN]+line); line = i;
return ACTION_REDRAW;
} }
if (line != gui_list->selected_item - gui_list->start_item[SCREEN_MAIN]) if(line == -1)
return ACTION_NONE;
/* BUTTON_TOUCHPAD represents a button press*/
if (line != gui_list->selected_item - gui_list->start_item[SCREEN_MAIN] && button == BUTTON_TOUCHPAD)
{ {
if (gui_list->start_item[SCREEN_MAIN]+line > gui_list->nb_items) if (gui_list->start_item[SCREEN_MAIN]+line > gui_list->nb_items)
return ACTION_NONE; return ACTION_NONE;
gui_synclist_select_item(gui_list, gui_list->start_item[SCREEN_MAIN]+line); gui_synclist_select_item(gui_list, gui_list->start_item[SCREEN_MAIN]+line);
return ACTION_REDRAW;
} }
if (button == BUTTON_REPEAT) if (button == BUTTON_REPEAT)
return ACTION_STD_CONTEXT; return ACTION_STD_CONTEXT;
else if(button == BUTTON_REL)
{
if(prev_line == line)
{
prev_line = 0;
return ACTION_STD_OK;
}
else
{
prev_line = line;
return ACTION_NONE;
}
}
else else
return ACTION_STD_OK; return ACTION_NONE;
} }
/* title goes up one level */ /* title goes up one level */
else if (y > title_text[SCREEN_MAIN].y && draw_title(display, parent, gui_list)) else if (y > title_text[SCREEN_MAIN].y && draw_title(display, parent, gui_list) && button == BUTTON_REL)
{ {
return ACTION_STD_CANCEL; return ACTION_STD_CANCEL;
} }
/* title or statusbar is cancel */ /* title or statusbar is cancel */
else if (global_settings.statusbar) else if (global_settings.statusbar && button == BUTTON_REL)
{ {
return ACTION_STD_CANCEL; return ACTION_STD_CANCEL;
} }

View file

@ -166,6 +166,13 @@ void button_event(int key, bool pressed)
case SDLK_KP3: case SDLK_KP3:
new_btn = BUTTON_BOTTOMRIGHT; new_btn = BUTTON_BOTTOMRIGHT;
break; break;
case SDLK_F10:
if(pressed)
{
touchpad_mode = (touchpad_mode == TOUCHPAD_POINT ? TOUCHPAD_BUTTON : TOUCHPAD_POINT);
printf("Touchpad mode: %s\n", touchpad_mode == TOUCHPAD_POINT ? "TOUCHPAD_POINT" : "TOUCHPAD_BUTTON");
}
break;
#endif #endif
case SDLK_u: case SDLK_u:
@ -1080,6 +1087,15 @@ void mouse_tick_task(void)
last_check = current_tick; last_check = current_tick;
if (SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT)) if (SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT))
{ {
if(background)
{
x -= UI_LCD_POSX;
y -= UI_LCD_POSY;
if(x<0 || y<0 || x>UI_LCD_WIDTH || y>UI_LCD_HEIGHT)
return;
}
mouse_coords = (x<<16)|y; mouse_coords = (x<<16)|y;
button_event(BUTTON_TOUCHPAD, true); button_event(BUTTON_TOUCHPAD, true);
if (debug_wps) if (debug_wps)