--- ../rockbox-devel/apps/screens.c 2006-01-21 18:43:56.000000000 -0500 +++ apps/screens.c 2006-02-14 10:44:15.059191300 -0500 @@ -52,6 +52,8 @@ #include "screen_access.h" #include "quickscreen.h" #include "logo.h" +#include "list.h" +#include "select.h" #if defined(HAVE_LCD_BITMAP) #include "widgets.h" @@ -961,196 +963,211 @@ } #endif -int draw_id3_item(int line, int top, int header, const char* body) -{ - if (line >= top) - { -#if defined(HAVE_LCD_BITMAP) - const int rows = LCD_HEIGHT / font_get(FONT_UI)->height; -#else - const int rows = 2; -#endif - int y = line - top; - - if (y < rows) - { - lcd_puts(0, y, str(header)); - } - - if (++y < rows) - { - lcd_puts_scroll(0, y, - body ? (const unsigned char*) body : str(LANG_ID3_NO_INFO)); - } - } - - return line + 2; -} - #if CONFIG_CODEC == SWCODEC #define ID3_ITEMS 13 #else #define ID3_ITEMS 11 #endif -bool browse_id3(void) +static int id3_lines = 2; + +char* id3_name_callback(int selected_item, void *data, char *buffer) { char buf[64]; - const struct mp3entry* id3 = audio_current_track(); -#if defined(HAVE_LCD_BITMAP) - const int y_margin = lcd_getymargin(); - const int line_height = font_get(FONT_UI)->height; - const int rows = (LCD_HEIGHT - y_margin) / line_height; - const bool show_scrollbar = global_settings.scrollbar - && (ID3_ITEMS * 2 > rows); -#else - const int rows = 2; -#endif - const int top_max = (ID3_ITEMS * 2) - (rows & ~1); - int top = 0; - int button; - bool exit = false; - - if (!id3 || (!(audio_status() & AUDIO_STATUS_PLAY))) - { - return false; - } + char* value = NULL; + struct mp3entry *id3 = (struct mp3entry *)data; -#if defined(HAVE_LCD_BITMAP) - lcd_setmargins(show_scrollbar ? SCROLLBAR_WIDTH : 0, y_margin); -#endif - - while (!exit) - { - int line = 0; - int old_top = top; - char* body; - - lcd_clear_display(); - gui_syncstatusbar_draw(&statusbars, true); - line = draw_id3_item(line, top, LANG_ID3_TITLE, id3->title); - line = draw_id3_item(line, top, LANG_ID3_ARTIST, id3->artist); - line = draw_id3_item(line, top, LANG_ID3_ALBUM, id3->album); - - if (id3->track_string) - { - body = id3->track_string; - } - else if (id3->tracknum) - { - snprintf(buf, sizeof(buf), "%d", id3->tracknum); - body = buf; - } - else - { - body = NULL; + if (id3_lines == 3) { + if ( ((selected_item+1) % 3) == 0 ) { + /* add a space or the inverse selector doesn't show */ + buffer[0] = ' '; + buffer[1] = '\0'; + return buffer; } + selected_item -= selected_item/3; + } - line = draw_id3_item(line, top, LANG_ID3_TRACKNUM, body); - - body = id3->genre_string ? id3->genre_string : id3_get_genre(id3); - line = draw_id3_item(line, top, LANG_ID3_GENRE, body); - - if (id3->year_string) - { - body = id3->year_string; - } - else if (id3->year) - { - snprintf(buf, sizeof(buf), "%d", id3->year); - body = buf; - } - else - { - body = NULL; - } - - line = draw_id3_item(line, top, LANG_ID3_YEAR, body); - - gui_wps_format_time(buf, sizeof(buf), id3->length); - line = draw_id3_item(line, top, LANG_ID3_LENGHT, buf); + /* Skip a case number between items, the default case will add a space */ + switch (selected_item) { + /* title */ + case 0: + value = str(LANG_ID3_TITLE); + break; + case 1: + value = id3->title; + break; + + /* artist */ + case 2: + value = str(LANG_ID3_ARTIST); + break; + case 3: + value = id3->artist; + break; + + /* album */ + case 4: + value = str(LANG_ID3_ALBUM); + break; + case 5: + value = id3->album; + break; + + /* track number */ + case 6: + value = str(LANG_ID3_TRACKNUM); + break; + case 7: + if (id3->track_string) + { + value = id3->track_string; + } + else if (id3->tracknum) + { + snprintf(buf, sizeof(buf), "%d", id3->tracknum); + value = buf; + } + break; - snprintf(buf, sizeof(buf), "%d/%d", playlist_get_display_index(), - playlist_amount()); - line = draw_id3_item(line, top, LANG_ID3_PLAYLIST, buf); + /* genre */ + case 8: + value = str(LANG_ID3_GENRE); + break; + case 9: + value = id3->genre_string ? id3->genre_string : id3_get_genre(id3); + break; - snprintf(buf, sizeof(buf), "%d kbps%s", id3->bitrate, - id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) ""); - line = draw_id3_item(line, top, LANG_ID3_BITRATE, buf); + /* year */ + case 10: + value = str(LANG_ID3_YEAR); + break; + case 11: + if (id3->year_string) + { + value = id3->year_string; + } + else if (id3->year) + { + snprintf(buf, sizeof(buf), "%d", id3->year); + value = buf; + } + break; - snprintf(buf, sizeof(buf), "%ld Hz", id3->frequency); - line = draw_id3_item(line, top, LANG_ID3_FRECUENCY, buf); + /* length */ + case 12: + value = str(LANG_ID3_LENGHT); + break; + case 13: + gui_wps_format_time(buf, sizeof(buf), id3->length); + value = buf; + break; + + /* playlist position */ + case 14: + value = str(LANG_ID3_PLAYLIST); + break; + case 15: + snprintf(buf, sizeof(buf), "%d/%d", playlist_get_display_index(), + playlist_amount()); + value = buf; + break; + + /* bitrate */ + case 16: + value = str(LANG_ID3_BITRATE); + break; + case 17: + snprintf(buf, sizeof(buf), "%d kbps%s", id3->bitrate, + id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) ""); + value = buf; + break; + + /* frequency */ + case 18: + value = str(LANG_ID3_FRECUENCY); + break; + case 19: + snprintf(buf, sizeof(buf), "%ld Hz", id3->frequency); + value = buf; + break; #if CONFIG_CODEC == SWCODEC - line = draw_id3_item(line, top, LANG_ID3_TRACK_GAIN, - id3->track_gain_string); + /* replaygain track gain */ + case 20: + value = str(LANG_ID3_TRACK_GAIN); + break; + case 21: + value = id3->track_gain_string; + break; + + /* replaygain album gain */ + case 22: + value = str(LANG_ID3_ALBUM_GAIN); + break; + case 23: + value = id3->album_gain_string; + break; +#endif + + /* path (leave this last) */ + case (2*ID3_ITEMS-2): + value = str(LANG_ID3_PATH); + break; + case (2*ID3_ITEMS-1): + value = id3->path; + break; + } - line = draw_id3_item(line, top, LANG_ID3_ALBUM_GAIN, - id3->album_gain_string); -#endif + if (value == NULL) + value = str(LANG_ID3_NO_INFO); - line = draw_id3_item(line, top, LANG_ID3_PATH, id3->path); + strcpy(buffer, value); + return(buffer); +} -#if defined(HAVE_LCD_BITMAP) - if (show_scrollbar) - { - scrollbar(0, y_margin, SCROLLBAR_WIDTH - 1, rows * line_height, - ID3_ITEMS * 2 + (rows & 1), top, top + rows, VERTICAL); - } -#endif +bool browse_id3(void) +{ + struct mp3entry* id3 = audio_current_track(); + struct gui_synclist id3_lists; + bool exit = false; + int item_number = 0; + int total_items = ID3_ITEMS*id3_lines; - while (!exit && (top == old_top)) - { - gui_syncstatusbar_draw(&statusbars, false); - lcd_update(); - button = button_get_w_tmo(HZ / 2); + gui_synclist_init(&id3_lists, &id3_name_callback, id3); + gui_synclist_set_nb_items(&id3_lists, total_items); + gui_synclist_select_item(&id3_lists, item_number); + gui_synclist_draw(&id3_lists); - switch(button) - { - /* It makes more sense to have the keys mapped "backwards" when - * scrolling a list. - */ -#if defined(HAVE_LCD_BITMAP) - case SETTINGS_INC: - case SETTINGS_INC | BUTTON_REPEAT: -#else - case SETTINGS_DEC: -#endif - if (top > 0) - { - top -= 2; - } - else if (!(button & BUTTON_REPEAT)) - { - top = top_max; - } - - break; + while (!exit) { + int button = button_get_w_tmo(HZ / 2); + gui_synclist_do_button(&id3_lists, button); -#if defined(HAVE_LCD_BITMAP) - case SETTINGS_DEC: - case SETTINGS_DEC | BUTTON_REPEAT: -#else - case SETTINGS_INC: -#endif - if (top < top_max) - { - top += 2; - } - else if (!(button & BUTTON_REPEAT)) - { - top = 0; + switch (button) { + case SELECT_OK: +#ifdef SELECT_RC_OK2 + case SELECT_RC_OK2: +#endif + /* switch between having a space between item pairs and not */ + item_number = gui_synclist_get_sel_pos(&id3_lists); + if (id3_lines == 2) { + id3_lines = 3; + total_items = 3*ID3_ITEMS - 1; + item_number += (item_number/2); + } else { + id3_lines = 2; + total_items = 2*ID3_ITEMS; + item_number -= (item_number/3); } - + + gui_synclist_set_nb_items(&id3_lists, total_items); + gui_synclist_select_item(&id3_lists, item_number); + gui_synclist_draw(&id3_lists); break; -#ifdef SETTINGS_OK2 - case SETTINGS_OK2: + case SELECT_CANCEL: +#ifdef SELECT_RC_CANCEL + case SELECT_RC_CANCEL: #endif - case SETTINGS_CANCEL: - lcd_stop_scroll(); - /* Eat release event */ - button_get(true); exit = true; break; @@ -1161,7 +1178,6 @@ } break; - } } }