From 7fa39df4277fba4b567a57c79a8933afc96d9339 Mon Sep 17 00:00:00 2001 From: Tomas Salfischberger Date: Sun, 22 Jan 2006 01:42:05 +0000 Subject: Horizontal scrolling patch by Shachar Liberman git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8412 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/list.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- apps/gui/list.h | 37 +++++++++++++++++ 2 files changed, 156 insertions(+), 8 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/list.c b/apps/gui/list.c index 83a1fbfb22..2ae5f995f4 100644 --- a/apps/gui/list.c +++ b/apps/gui/list.c @@ -37,7 +37,8 @@ #define SCROLL_LIMIT 2 #endif - +static int offset_step = 15; +static bool offset_outof_view = false; void gui_list_init(struct gui_list * gui_list, list_get_name callback_get_item_name, @@ -53,6 +54,7 @@ void gui_list_init(struct gui_list * gui_list, gui_list->limit_scroll = false; gui_list->data=data; gui_list->cursor_flash_state=false; + gui_list->offsetval = 0; } void gui_list_set_display(struct gui_list * gui_list, struct screen * display) @@ -179,14 +181,47 @@ void gui_list_draw(struct gui_list * gui_list) entry_name = gui_list->callback_get_item_name(current_item, gui_list->data, entry_buffer); - if(current_item == gui_list->selected_item) - { - /* The selected item must be displayed scrolling */ + #ifdef HAVE_LCD_BITMAP - if (global_settings.invert_cursor)/* Display inverted-line-style*/ - display->puts_scroll_style(0, i, entry_name, STYLE_INVERT); + /* position the string at the right offset place */ + int item_offset; + int str_width,h; + display->getstringsize(entry_name, &str_width, &h); + + if (offset_outof_view) + item_offset = gui_list->offsetval; + else + /* if text is smaller then view */ + if (str_width <= display->width - text_pos) + item_offset = 0; + else + /* if text got out of view */ + if (gui_list->offsetval > str_width - (display->width - text_pos)) + item_offset = str_width - (display->width - text_pos); else - display->puts_scroll(0, i, entry_name); + item_offset = gui_list->offsetval; + +#endif + + if(current_item == gui_list->selected_item) { + /* The selected item must be displayed scrolling */ +#ifdef HAVE_LCD_BITMAP + if (global_settings.invert_cursor) /* Display inverted-line-style*/ + + /* if text got out of view */ + if (item_offset > str_width - (display->width - text_pos)) + /* don't scroll */ + display->puts_style_offset(0, i, entry_name, STYLE_INVERT,item_offset); + else + display->puts_scroll_style_offset(0, i, entry_name, STYLE_INVERT,item_offset); + + else /* if (global_settings.invert_cursor) */ + + if (item_offset > str_width - (display->width - text_pos)) + display->puts_offset(0, i, entry_name,item_offset); + else + display->puts_scroll_offset(0, i, entry_name,item_offset); + #else display->puts_scroll(text_pos, i, entry_name); #endif @@ -197,7 +232,7 @@ void gui_list_draw(struct gui_list * gui_list) else {/* normal item */ #ifdef HAVE_LCD_BITMAP - display->puts(0, i, entry_name); + display->puts_offset(0, i, entry_name,item_offset); #else display->puts(text_pos, i, entry_name); #endif @@ -229,6 +264,40 @@ void gui_list_draw(struct gui_list * gui_list) gui_textarea_update(display); } +#ifdef HAVE_LCD_BITMAP +void gui_list_screen_scroll_step(int ofs) +{ + offset_step = ofs; +} + +void gui_list_screen_scroll_out_of_view(bool enable) +{ + if (enable) + offset_outof_view = true; + else + offset_outof_view = false; +} + +void gui_list_offset_right(struct gui_list * gui_list) +{ + /* there should be a callback to find out what's the longest item on the list, + * and then, by finding out the width with get_stringsize, we would stop the + * list from scrolling at that point */ + + gui_list->offsetval+=offset_step; + if (gui_list->offsetval > 1000) + gui_list->offsetval = 1000; +} + +void gui_list_offset_left(struct gui_list * gui_list) +{ + gui_list->offsetval-=offset_step; + if (gui_list->offsetval < 0) + gui_list->offsetval = 0; + +} +#endif /* HAVE_LCD_BITMAP */ + void gui_list_select_item(struct gui_list * gui_list, int item_number) { if( item_number > gui_list->nb_items-1 || item_number < 0 ) @@ -384,6 +453,7 @@ void gui_synclist_set_nb_items(struct gui_synclist * lists, int nb_items) FOR_NB_SCREENS(i) { gui_list_set_nb_items(&(lists->gui_list[i]), nb_items); + lists->gui_list[i].offsetval = 0; } } void gui_synclist_set_icon_callback(struct gui_synclist * lists, list_get_icon icon_callback) @@ -432,6 +502,22 @@ void gui_synclist_select_next_page(struct gui_synclist * lists, screens[screen].nb_lines); } +#ifdef HAVE_LCD_BITMAP +void gui_synclist_offset_right(struct gui_synclist * lists) +{ + int i; + FOR_NB_SCREENS(i) + gui_list_offset_right(&(lists->gui_list[i])); +} + +void gui_synclist_offset_left(struct gui_synclist * lists) +{ + int i; + FOR_NB_SCREENS(i) + gui_list_offset_left(&(lists->gui_list[i])); +} +#endif /* HAVE_LCD_BITMAP */ + void gui_synclist_select_previous_page(struct gui_synclist * lists, enum screen_type screen) { @@ -502,6 +588,31 @@ unsigned gui_synclist_do_button(struct gui_synclist * lists, unsigned button) gui_synclist_select_next(lists); gui_synclist_draw(lists); return LIST_NEXT; + +#ifdef LIST_PGRIGHT + case LIST_PGRIGHT: + case LIST_PGRIGHT | BUTTON_REPEAT: +#ifdef LIST_RC_PGRIGHT + case LIST_RC_PGRIGHT: + case LIST_RC_PGRIGHT | BUTTON_REPEAT: +#endif + gui_synclist_offset_right(lists); + gui_synclist_draw(lists); + return true; +#endif + +#ifdef LIST_PGLEFT + case LIST_PGLEFT: + case LIST_PGLEFT | BUTTON_REPEAT: +#ifdef LIST_RC_PGLEFT + case LIST_RC_PGLEFT: + case LIST_RC_PGLEFT | BUTTON_REPEAT: +#endif + gui_synclist_offset_left(lists); + gui_synclist_draw(lists); + return true; +#endif + /* for pgup / pgdown, we are obliged to have a different behaviour depending on the screen * for which the user pressed the key since for example, remote and main screen doesn't * have the same number of lines*/ diff --git a/apps/gui/list.h b/apps/gui/list.h index 25fb07d7c4..e177f5ef75 100644 --- a/apps/gui/list.h +++ b/apps/gui/list.h @@ -33,12 +33,16 @@ #define LIST_PREV BUTTON_UP #define LIST_PGUP (BUTTON_ON | BUTTON_UP) #define LIST_PGDN (BUTTON_ON | BUTTON_DOWN) +#define LIST_PGRIGHT (BUTTON_ON | BUTTON_RIGHT) +#define LIST_PGLEFT (BUTTON_ON | BUTTON_LEFT) #ifdef CONFIG_REMOTE_KEYPAD #define LIST_RC_NEXT BUTTON_RC_FF #define LIST_RC_PREV BUTTON_RC_REW #define LIST_RC_PGUP BUTTON_RC_SOURCE #define LIST_RC_PGDN BUTTON_RC_BITRATE +#define LIST_RC_PGRIGHT (BUTTON_RC_VOL_UP) +#define LIST_RC_PGLEFT (BUTTON_RC_VOL_DOWN) #endif /* CONFIG_REMOTE_KEYPAD */ #elif CONFIG_KEYPAD == RECORDER_PAD @@ -46,6 +50,8 @@ #define LIST_PREV BUTTON_UP #define LIST_PGUP (BUTTON_ON | BUTTON_UP) #define LIST_PGDN (BUTTON_ON | BUTTON_DOWN) +#define LIST_PGRIGHT (BUTTON_ON | BUTTON_RIGHT) +#define LIST_PGLEFT (BUTTON_ON | BUTTON_LEFT) #ifdef CONFIG_REMOTE_KEYPAD #define LIST_RC_NEXT BUTTON_RC_RIGHT @@ -64,6 +70,8 @@ #elif CONFIG_KEYPAD == ONDIO_PAD #define LIST_NEXT BUTTON_DOWN #define LIST_PREV BUTTON_UP +#define LIST_PGRIGHT (BUTTON_MENU | BUTTON_RIGHT) +#define LIST_PGLEFT (BUTTON_MENU | BUTTON_LEFT) #elif (CONFIG_KEYPAD == IPOD_4G_PAD) #define LIST_NEXT BUTTON_SCROLL_FWD @@ -78,6 +86,8 @@ #define LIST_PREV BUTTON_UP #define LIST_PGUP (BUTTON_ON | BUTTON_UP) #define LIST_PGDN (BUTTON_ON | BUTTON_DOWN) +#define LIST_PGRIGHT (BUTTON_ON | BUTTON_RIGHT) +#define LIST_PGLEFT (BUTTON_ON | BUTTON_LEFT) #elif CONFIG_KEYPAD == IAUDIO_X5_PAD #define LIST_NEXT BUTTON_DOWN @@ -116,12 +126,14 @@ typedef void list_get_icon(int selected_item, * a buffer when it's not necessary) * Returns a pointer to a string that contains the text to display */ + typedef char * list_get_name(int selected_item, void * data, char *buffer); struct gui_list { + int offsetval; /* value of screen offset */ int nb_items; int selected_item; bool cursor_flash_state; @@ -222,6 +234,13 @@ extern void gui_list_draw(struct gui_list * gui_list); * (Item 0 gets selected if the end of the list is reached) * - gui_list : the list structure */ + +extern void gui_list_screen_scroll_step(int ofs); +/* parse global setting to static int */ + +extern void gui_list_screen_scroll_out_of_view(bool enable); +/* parse global setting to static bool */ + extern void gui_list_select_next(struct gui_list * gui_list); /* @@ -236,6 +255,22 @@ extern void gui_list_select_previous(struct gui_list * gui_list); * - gui_list : the list structure * - nb_lines : the number of lines to try to move the cursor */ + +extern void gui_list_offset_right(struct gui_list * gui_list); + +/* + * Makes all the item in the list scroll by one step to the right. + * Should stop increasing the value when reaching the widest item value + * in the list. + */ + +extern void gui_list_offset_left(struct gui_list * gui_list); + +/* + * Makes all the item in the list scroll by one step to the left. + * stops at starting position. + */ + extern void gui_list_select_next_page(struct gui_list * gui_list, int nb_lines); @@ -312,6 +347,8 @@ extern void gui_synclist_select_item(struct gui_synclist * lists, int item_number); extern void gui_synclist_select_next(struct gui_synclist * lists); extern void gui_synclist_select_previous(struct gui_synclist * lists); +extern void gui_synclist_offset_right(struct gui_synclist * lists); +extern void gui_synclist_offset_left(struct gui_synclist * lists); extern void gui_synclist_select_next_page(struct gui_synclist * lists, enum screen_type screen); extern void gui_synclist_select_previous_page(struct gui_synclist * lists, -- cgit v1.2.3