/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id: list.c 15948 2007-12-17 04:23:34Z jdgordon $ * * Copyright (C) 2007 by Jonathan Gordon * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ /* This file contains the code to draw the list widget on BITMAP LCDs. */ #include "config.h" #include "lcd.h" #include "font.h" #include "button.h" #include "sprintf.h" #include "string.h" #include "settings.h" #include "kernel.h" #include "system.h" #include "action.h" #include "screen_access.h" #include "list.h" #include "scrollbar.h" #include "statusbar.h" #include "textarea.h" #include "lang.h" #include "sound.h" #include "misc.h" #include "talk.h" #include "viewport.h" #define SCROLLBAR_WIDTH 6 #define ICON_PADDING 2 #define HAVE_RTL_DRAWING 0 /* viewports to be used */ struct viewport title_text, title_icon, list_text, list_icons, list_cursor, scrollbar; int gui_list_get_item_offset(struct gui_synclist * gui_list, int item_width, int text_pos, struct screen * display, struct viewport *vp); bool list_display_title(struct gui_synclist *list, struct viewport *vp); /* Draw the list... internal screen layout: ----------------- |TI| title | TI - title icon ----------------- | | | | __________ | |S|C|I| __________ | S - scrollbar | | | | __items___ | I - icons | | | | __________ | C - cursor ----------------- icons/scrollbar can be put on either side of the items if HAVE_RTL_DRAWING == 1 */ int list_title_height(struct gui_synclist *list, struct viewport *vp) { (void)list; return font_get(vp->font)->height; } static bool draw_title(struct screen *display, struct viewport *parent, struct gui_synclist *list) { #if HAVE_RTL_DRAWING bool icons_on_left = false; #endif bool draw_list_icon = (list->title_icon != Icon_NOICON && global_settings.show_icons); if (!list_display_title(list, parent)) return false; //~ list_init_viewport(title_text); title_text.height = font_get(parent->font)->height; if (draw_list_icon) { //~ list_init_viewport(title_icon); title_icon.width = get_icon_width(display->screen_type) + ICON_PADDING; #if HAVE_RTL_DRAWING if (icons_on_left) { #endif title_text.width -= title_icon.width; title_text.x += title_icon.width; #if HAVE_RTL_DRAWING } else { title_icon.x = parent->x + parent->width - title_icon.width; title_text.width -= title_icon.width; } #endif display->set_viewport(&title_icon); screen_put_icon(display, 0, 0, list->title_icon); } display->set_viewport(&title_text); title_text.drawmode = STYLE_DEFAULT; #ifdef HAVE_LCD_COLOR if (list->title_color >= 0) { title_text.drawmode |= STYLE_COLORED; title_text.drawmode |= list->title_color; } #endif display->puts_scroll_style_offset(0, 0, list->title, title_text.drawmode, 0); return true; } int draw_scrollbar(struct screen *display, struct viewport *parent, struct gui_synclist *list) { /* draw the scrollbar if its needed */ bool scrollbar_to_be_drawn = global_settings.scrollbar && (viewport_get_nb_lines(&list_text) < list->nb_items); int line_height = font_get(parent->font)->height; int start, end; start = list->start_item[display->screen_type]; end = start + viewport_get_nb_lines(&list_text); if(!scrollbar_to_be_drawn) return 0; //~ list_init_viewport(scrollbar); scrollbar = *parent; #if HAVE_RTL_DRAWING if (icons_on_left) { vp.x = parent->x; } else vp.x = parent->x+parent->width - SCROLLBAR_WIDTH; #else scrollbar.x = parent->x; #endif scrollbar.y = title_text.y + title_text.height; scrollbar.height = line_height * (list_text.height / line_height) - 2; display->set_viewport(&scrollbar); gui_scrollbar_draw(display, 0, 0, SCROLLBAR_WIDTH, scrollbar.height, list->nb_items, list->start_item[display->screen_type], list->start_item[display->screen_type] + end-start, VERTICAL); return SCROLLBAR_WIDTH; } bool draw_cursor(struct screen *display, struct viewport *parent, struct gui_synclist *list) { bool cursor_to_be_drawn = !global_settings.cursor_style && list->show_selection_marker; if(!cursor_to_be_drawn) return false; else { int line_height = font_get(parent->font)->height; int start, end, i; start = list->start_item[display->screen_type]; end = start + viewport_get_nb_lines(&list_text); #if HAVE_RTL_DRAWING bool icons_on_left = false; #endif list_cursor = *parent; list_cursor.x = draw_scrollbar(display, parent, list) + ICON_PADDING; list_cursor.y = title_text.y + title_text.height; list_cursor.width = get_icon_width(display->screen_type); list_cursor.height = line_height * (list_text.height / line_height) - 2; display->set_viewport(&list_cursor); for (i=start; inb_items; i++) { /* do the icon */ if (i >= list->selected_item && i < list->selected_item + list->selected_size) { screen_put_icon(display, 0, (i-start), Icon_Cursor); } } return true; } } bool draw_icons(struct screen *display, struct viewport *parent, struct gui_synclist *list) { if (!(list->callback_get_item_icon != NULL && global_settings.show_icons)) return false; int start, end, i, icon_offset; int icon_width = get_icon_width(display->screen_type); start = list->start_item[display->screen_type]; end = start + viewport_get_nb_lines(&list_text); list_icons = *parent; icon_offset = draw_scrollbar(display, parent, list) + (draw_cursor(display, parent, list)?(list_cursor.width):0) + icon_width + ICON_PADDING; list_icons.x = icon_offset; list_icons.width = get_icon_width(display->screen_type); list_icons.y = title_text.y + title_text.height; for (i=start; inb_items; i++) { /* do the icon */ if (list->callback_get_item_icon) { display->set_viewport(&list_icons); screen_put_icon(display, 0, (i-start), list->callback_get_item_icon(i, list->data)); } } return true; } void draw_list(struct screen *display, struct viewport *parent, struct gui_synclist *list) { #if HAVE_RTL_DRAWING bool icons_on_left = false; #endif int start, end, line_height, i; #ifdef HAVE_LCD_COLOR unsigned char cur_line = 0; #endif int item_offset; line_height = font_get(parent->font)->height; display->set_viewport(parent); display->clear_viewport(); list_text = *parent; if (draw_title(display, parent, list)) { list_text.y += line_height; list_text.height -= line_height; } if (draw_scrollbar(display, parent, list)) { /* shift everything right a bit... */ list_text.width -= SCROLLBAR_WIDTH; list_text.x += SCROLLBAR_WIDTH; } if (draw_icons(display, parent, list)) { #if HAVE_RTL_DRAWING if (icons_on_left) { #endif list_text.x += list_icons.width; list_text.width -= list_icons.width; #if HAVE_RTL_DRAWING } #endif } start = list->start_item[display->screen_type]; end = start + viewport_get_nb_lines(&list_text); display->set_viewport(&list_text); //~ /* setup icon placement */ //~ if (list->callback_get_item_icon != NULL || show_cursor) //~ { //~ if (list->callback_get_item_icon != NULL && show_cursor) //~ list_icons.width = icon_width * 2 - SCROLLBAR_WIDTH; //~ else //~ { //~ list_icons.width = icon_width; //~ list_icons.x += 2; //~ } //~ list_text.width -= list_icons.width; //~ #if HAVE_RTL_DRAWING //~ if (icons_on_left) //~ #endif //~ list_text.x += list_icons.width; //~ } for (i=start; inb_items; i++) { /* do the text */ unsigned char *s; char entry_buffer[MAX_PATH]; unsigned char *entry_name; int text_pos = 0; s = list->callback_get_item_name(i, list->data, entry_buffer); entry_name = P2STR(s); display->set_viewport(&list_text); list_text.drawmode = STYLE_DEFAULT; /* position the string at the correct offset place */ int item_width,h; display->getstringsize(entry_name, &item_width, &h); item_offset = gui_list_get_item_offset(list, item_width, text_pos, display, &list_text); //~ #ifdef HAVE_LCD_COLOR //~ /* if the list has a color callback */ //~ if (list->callback_get_item_color) //~ { //~ int color = list->callback_get_item_color(i, list->data); //~ /* if color selected */ //~ if (color >= 0) //~ { //~ list_text.drawmode |= STYLE_COLORED|color; //~ } //~ } //~ #endif if(list->show_selection_marker && i >= list->selected_item && i < list->selected_item + list->selected_size) {/* The selected item must be displayed scrolling */ if (global_settings.cursor_style == 1 #ifdef HAVE_REMOTE_LCD || display->screen_type == SCREEN_REMOTE #endif ) { /* Display inverted-line-style */ list_text.drawmode |= STYLE_INVERT; } #ifdef HAVE_LCD_COLOR else if (global_settings.cursor_style == 2) { /* Display colour line selector */ list_text.drawmode |= STYLE_COLORBAR; } else if (global_settings.cursor_style == 3) { /* Display gradient line selector */ list_text.drawmode = STYLE_GRADIENT; /* Make the lcd driver know how many lines the gradient should cover and current line number */ /* number of selected lines */ list_text.drawmode |= NUMLN_PACK(list->selected_size); /* current line number, zero based */ list_text.drawmode |= CURLN_PACK(cur_line); cur_line++; } #endif /* if the text is smaller than the viewport size */ if (item_offset > item_width - (list_text.width - text_pos)) { /* don't scroll */ display->puts_style_offset(0, i-start, entry_name, list_text.drawmode, item_offset); } else { display->puts_scroll_style_offset(0, i-start, entry_name, list_text.drawmode, item_offset); } } else display->puts_style_offset(0, i-start, entry_name, list_text.drawmode, item_offset); } display->set_viewport(parent); display->update_viewport(); display->set_viewport(NULL); }