From 5a169bb71707dae31a886e1b932341b70eacf2df Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 23 Jun 2008 06:04:17 +0000 Subject: commit FS#9027 - conditional viewports ** BREAKS CURRENT WPS's ** * %P has been removed, merged with the new %pb * %pb is now %pb or %pb|bitmap|x|y|width|height| (any of those params can be - to use sane defaults... check wiki/task for more explaination) * New %Vl and %Vd tags which are used to setup and display conditionaly displayed viewports (%Vl||| to set up, then %Vd to enable the viewport * bumps the max allowed viewport count to 24 * you can setup 3 different progressbars in a WPS... max of one per viewport though http://www.rockbox.org/tracker/task/9027?getfile=16785 is a simple perl script to convert old %P/%pb to the new %pb syntax I'll commit changes to the cabbie wps soon which shows how to use %Vl/%Vd properly... Reminder: %m will be removed soonish also so when fixing your WPS's remember to use conditional viewports to replace %m git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17759 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps-common.c | 133 ++++++++++++++++----------- apps/gui/gwps.h | 31 +++++-- apps/gui/wps_debug.c | 4 + apps/gui/wps_parser.c | 178 +++++++++++++++++++++++++----------- apps/settings.c | 37 ++++---- wps/Rockboxed.112x64x1.wps | 2 +- wps/Rockboxed.128x128x16.wps | 3 +- wps/Rockboxed.132x80x16.wps | 3 +- wps/Rockboxed.138x110x2.wps | 3 +- wps/Rockboxed.160x128x16.wps | 3 +- wps/Rockboxed.160x128x2.wps | 3 +- wps/Rockboxed.176x132x16.wps | 3 +- wps/Rockboxed.176x220x16.wps | 3 +- wps/Rockboxed.220x176x16.wps | 3 +- wps/Rockboxed.240x320x16.wps | 3 +- wps/Rockboxed.320x240x16.wps | 3 +- wps/UniCatcher.128x96x1.wps | 2 +- wps/UniCatcher.160x128x16.wps | 2 +- wps/UniCatcher.160x128x2.wps | 2 +- wps/UniCatcher.176x132x16.wps | 2 +- wps/UniCatcher.176x220x16.wps | 2 +- wps/UniCatcher.220x176x16.wps | 2 +- wps/UniCatcher.240x320x16.wps | 2 +- wps/UniCatcher.320x240x16.wps | 2 +- wps/boxes.220x176x16.wps | 3 +- wps/cabbiev2.112x64x1.wps | 3 +- wps/cabbiev2.128x128x16.wps | 3 +- wps/cabbiev2.128x64x1.wps | 3 +- wps/cabbiev2.128x96x2.wps | 3 +- wps/cabbiev2.132x80x16.wps | 3 +- wps/cabbiev2.138x110x2.wps | 3 +- wps/cabbiev2.160x128x1.wps | 3 +- wps/cabbiev2.160x128x16.wps | 3 +- wps/cabbiev2.160x128x2.wps | 3 +- wps/cabbiev2.176x132x16.wps | 3 +- wps/cabbiev2.176x220x16.wps | 3 +- wps/cabbiev2.220x176x16.wps | 3 +- wps/cabbiev2.240x320x16.wps | 3 +- wps/cabbiev2.320x240x16.wps | 3 +- wps/iCatcher.112x64x1.wps | 2 +- wps/iCatcher.128x128x16.wps | 2 +- wps/iCatcher.128x64x1.160x128x2.wps | 2 +- wps/iCatcher.128x96x1.wps | 2 +- wps/iCatcher.132x80x16.wps | 2 +- wps/iCatcher.138x110x2.wps | 2 +- wps/iCatcher.160x128x16.wps | 2 +- wps/iCatcher.160x128x2.wps | 2 +- wps/iCatcher.176x132x16.wps | 2 +- wps/iCatcher.176x220x16.wps | 2 +- wps/iCatcher.220x176x16.wps | 2 +- wps/iCatcher.240x320x16.wps | 2 +- wps/iCatcher.320x240x16.wps | 2 +- 52 files changed, 297 insertions(+), 205 deletions(-) diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 634d199461..6e159b88b4 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -506,53 +506,33 @@ void display_keylock_text(bool locked) #ifdef HAVE_LCD_BITMAP -static void draw_progressbar(struct gui_wps *gwps, int line) +static void draw_progressbar(struct gui_wps *gwps, + struct progressbar *pb) { - struct wps_data *data = gwps->data; struct screen *display = gwps->display; struct wps_state *state = gwps->state; - int h = font_get(display->getfont())->height; - - int sb_y; - if (data->progress_top < 0) - sb_y = line*h + display->getymargin() + - ((h > data->progress_height + 1) - ? (h - data->progress_height) / 2 : 1); - else - sb_y = data->progress_top; - - if (!data->progress_end) - data->progress_end=display->getwidth(); - - if (gwps->data->progressbar.have_bitmap_pb) - gui_bitmap_scrollbar_draw(display, data->progressbar.bm, - data->progress_start, sb_y, - data->progress_end-data->progress_start, - data->progressbar.bm.height, + if (pb->have_bitmap_pb) + gui_bitmap_scrollbar_draw(display, pb->bm, + pb->x, pb->y, pb->width, pb->bm.height, state->id3->length ? state->id3->length : 1, 0, state->id3->length ? state->id3->elapsed - + state->ff_rewind_count : 0, - HORIZONTAL); + + state->ff_rewind_count : 0, + HORIZONTAL); else - gui_scrollbar_draw(display, data->progress_start, sb_y, - data->progress_end-data->progress_start, - data->progress_height, + gui_scrollbar_draw(display, pb->x, pb->y, pb->width, pb->height, state->id3->length ? state->id3->length : 1, 0, state->id3->length ? state->id3->elapsed - + state->ff_rewind_count : 0, - HORIZONTAL); - + + state->ff_rewind_count : 0, + HORIZONTAL); #ifdef AB_REPEAT_ENABLE if ( ab_repeat_mode_enabled() && state->id3->length != 0 ) ab_draw_markers(display, state->id3->length, - data->progress_start, data->progress_end, sb_y, - data->progress_height); + pb->x, pb->x + pb->width, pb->y, pb->height); #endif if ( cuesheet_is_enabled() && state->id3->cuesheet_type ) cue_draw_markers(display, state->id3->length, - data->progress_start, data->progress_end, - sb_y+1, data->progress_height-2); + pb->x, pb->x + pb->width, pb->y+1, pb->height-2); } /* clears the area where the image was shown */ @@ -1621,7 +1601,24 @@ static bool get_line(struct gui_wps *gwps, *buf++ = 0; cur_align_start = buf; break; - + case WPS_VIEWPORT_ENABLE: + { + char label = data->tokens[i].value.i; + int j; + char temp = VP_DRAW_HIDEABLE; + for(j=0;jnum_viewports;j++) + { + temp = VP_DRAW_HIDEABLE; + if ((data->viewports[j].hidden_flags&VP_DRAW_HIDEABLE) && + (data->viewports[j].label == label)) + { + if (data->viewports[j].hidden_flags&VP_DRAW_WASHIDDEN) + temp |= VP_DRAW_WASHIDDEN; + data->viewports[j].hidden_flags = temp; + } + } + } + break; default: { /* get the value of the tag and copy it to the buffer */ @@ -1945,6 +1942,7 @@ bool gui_wps_refresh(struct gui_wps *gwps, int v, line, i, subline_idx; unsigned char flags; char linebuf[MAX_PATH]; + unsigned char vp_refresh_mode; struct align_pos align; align.left = NULL; @@ -1994,14 +1992,21 @@ bool gui_wps_refresh(struct gui_wps *gwps, state->ff_rewind_count = ffwd_offset; + /* disable any viewports which are conditionally displayed */ for (v = 0; v < data->num_viewports; v++) { - display->set_viewport(&data->viewports[v].vp); - - if (refresh_mode == WPS_REFRESH_ALL) + if (data->viewports[v].hidden_flags&VP_DRAW_HIDEABLE) { - display->clear_viewport(); + if (data->viewports[v].hidden_flags&VP_DRAW_HIDDEN) + data->viewports[v].hidden_flags |= VP_DRAW_WASHIDDEN; + else + data->viewports[v].hidden_flags |= VP_DRAW_HIDDEN; } + } + for (v = 0; v < data->num_viewports; v++) + { + display->set_viewport(&data->viewports[v].vp); + vp_refresh_mode = refresh_mode; #ifdef HAVE_LCD_BITMAP /* Set images to not to be displayed */ @@ -2010,7 +2015,26 @@ bool gui_wps_refresh(struct gui_wps *gwps, data->img[i].display = -1; } #endif - + /* dont redraw the viewport if its disabled */ + if ((data->viewports[v].hidden_flags&VP_DRAW_HIDDEN)) + { + if (!(data->viewports[v].hidden_flags&VP_DRAW_WASHIDDEN)) + display->scroll_stop(&data->viewports[v].vp); + data->viewports[v].hidden_flags |= VP_DRAW_WASHIDDEN; + continue; + } + else if (((data->viewports[v].hidden_flags& + (VP_DRAW_WASHIDDEN|VP_DRAW_HIDEABLE)) + == (VP_DRAW_WASHIDDEN|VP_DRAW_HIDEABLE))) + { + vp_refresh_mode = WPS_REFRESH_ALL; + data->viewports[v].hidden_flags = VP_DRAW_HIDEABLE; + } + if (vp_refresh_mode == WPS_REFRESH_ALL) + { + display->clear_viewport(); + } + for (line = data->viewports[v].first_line; line <= data->viewports[v].last_line; line++) { @@ -2024,30 +2048,21 @@ bool gui_wps_refresh(struct gui_wps *gwps, data->lines[line].curr_subline); flags = data->sublines[subline_idx].line_type; - if (refresh_mode == WPS_REFRESH_ALL || (flags & refresh_mode) + if (vp_refresh_mode == WPS_REFRESH_ALL || (flags & vp_refresh_mode) || new_subline_refresh) { /* get_line tells us if we need to update the line */ update_line = get_line(gwps, line, data->lines[line].curr_subline, &align, linebuf, sizeof(linebuf)); } - #ifdef HAVE_LCD_BITMAP - /* progressbar */ - if (flags & refresh_mode & WPS_REFRESH_PLAYER_PROGRESS) - { - /* the progressbar should be alone on its line */ - update_line = false; - draw_progressbar(gwps, line - data->viewports[v].first_line); - } - /* peakmeter */ - if (flags & refresh_mode & WPS_REFRESH_PEAK_METER) + if (flags & vp_refresh_mode & WPS_REFRESH_PEAK_METER) { /* the peakmeter should be alone on its line */ update_line = false; - int h = font_get(display->getfont())->height; + int h = font_get(data->viewports[v].vp.font)->height; int peak_meter_y = display->getymargin() + (line - data->viewports[v].first_line)* h; /* The user might decide to have the peak meter in the last @@ -2066,7 +2081,7 @@ bool gui_wps_refresh(struct gui_wps *gwps, #else /* HAVE_LCD_CHARCELL */ /* progressbar */ - if (flags & refresh_mode & WPS_REFRESH_PLAYER_PROGRESS) + if (flags & vp_refresh_mode & WPS_REFRESH_PLAYER_PROGRESS) { if (data->full_line_progressbar) draw_player_fullbar(gwps, linebuf, sizeof(linebuf)); @@ -2075,22 +2090,32 @@ bool gui_wps_refresh(struct gui_wps *gwps, } #endif - if (update_line) + if (update_line && + /* conditionals clear the line which means if the %Vd is put into the default + viewport there will be a blank line. + To get around this we dont allow any actual drawing to happen in the + deault vp if other vp's are defined */ + ((data->num_viewports>1 && v!=0) || data->num_viewports == 1)) { if (flags & WPS_REFRESH_SCROLL) { /* if the line is a scrolling one we don't want to update too often, so that it has the time to scroll */ - if ((refresh_mode & WPS_REFRESH_SCROLL) || new_subline_refresh) + if ((vp_refresh_mode & WPS_REFRESH_SCROLL) || new_subline_refresh) write_line(display, &align, line - data->viewports[v].first_line, true); } else write_line(display, &align, line - data->viewports[v].first_line, false); } - } #ifdef HAVE_LCD_BITMAP + /* progressbar */ + if (vp_refresh_mode & WPS_REFRESH_PLAYER_PROGRESS) + { + if (data->viewports[v].pb) + draw_progressbar(gwps, data->viewports[v].pb); + } /* Now display any images in this viewport */ wps_display_images(gwps, &data->viewports[v].vp); #endif diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h index 494d12a084..25cfc08505 100644 --- a/apps/gui/gwps.h +++ b/apps/gui/gwps.h @@ -70,7 +70,13 @@ struct gui_img{ bool always_display; /* not using the preload/display mechanism */ }; -struct prog_img{ /*progressbar image*/ +struct progressbar { + /* regular pb */ + short x; + short y; + short width; + short height; + /*progressbar image*/ struct bitmap bm; bool have_bitmap_pb; }; @@ -85,6 +91,7 @@ struct align_pos { #ifdef HAVE_LCD_BITMAP #define MAX_IMAGES (26*2) /* a-z and A-Z */ +#define MAX_PROGRESSBARS 3 /* The image buffer is big enough to store one full-screen native bitmap, plus two full-screen mono bitmaps. */ @@ -92,7 +99,7 @@ struct align_pos { #define IMG_BUFSIZE ((LCD_HEIGHT*LCD_WIDTH*LCD_DEPTH/8) \ + (2*LCD_HEIGHT*LCD_WIDTH/8)) -#define WPS_MAX_VIEWPORTS 16 +#define WPS_MAX_VIEWPORTS 24 #define WPS_MAX_LINES ((LCD_HEIGHT/5+1) * 2) #define WPS_MAX_SUBLINES (WPS_MAX_LINES*3) #define WPS_MAX_TOKENS 1024 @@ -271,8 +278,11 @@ enum wps_token_type { #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD) /* Virtual LED */ - WPS_TOKEN_VLED_HDD + WPS_TOKEN_VLED_HDD, #endif + + /* Viewport display */ + WPS_VIEWPORT_ENABLE }; struct wps_token { @@ -323,12 +333,17 @@ struct wps_line { long subline_expire_time; }; +#define VP_DRAW_HIDEABLE 0x1 +#define VP_DRAW_HIDDEN 0x2 +#define VP_DRAW_WASHIDDEN 0x4 struct wps_viewport { struct viewport vp; /* The LCD viewport struct */ - + struct progressbar *pb; /* Indexes of the first and last lines belonging to this viewport in the lines[] array */ int first_line, last_line; + char hidden_flags; + char label; }; /* wps_data @@ -338,17 +353,15 @@ struct wps_data { #ifdef HAVE_LCD_BITMAP struct gui_img img[MAX_IMAGES]; - struct prog_img progressbar; unsigned char img_buf[IMG_BUFSIZE]; unsigned char* img_buf_ptr; int img_buf_free; bool wps_sb_tag; bool show_sb_on_wps; - short progress_top; - short progress_height; - short progress_start; - short progress_end; + struct progressbar progressbar[MAX_PROGRESSBARS]; + short progressbar_count; + bool peak_meter_enabled; #ifdef HAVE_ALBUMART diff --git a/apps/gui/wps_debug.c b/apps/gui/wps_debug.c index 9bff1d23ae..4fa12167f2 100644 --- a/apps/gui/wps_debug.c +++ b/apps/gui/wps_debug.c @@ -431,6 +431,10 @@ static char *get_token_desc(struct wps_token *token, struct wps_data *data, snprintf(buf, bufsize, "pitch value"); break; #endif + case WPS_VIEWPORT_ENABLE: + snprintf(buf, bufsize, "enable VP:%d", + token->value.i); + break; default: snprintf(buf, bufsize, "FIXME (code: %d)", diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index 53605e27cc..dc9abd98fb 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c @@ -80,13 +80,13 @@ static int line; #ifdef HAVE_LCD_BITMAP #if LCD_DEPTH > 1 -#define MAX_BITMAPS (MAX_IMAGES+2) /* WPS images + pbar bitmap + backdrop */ +#define MAX_BITMAPS (MAX_IMAGES+MAX_PROGRESSBARS+1) /* WPS images + pbar bitmap + backdrop */ #else -#define MAX_BITMAPS (MAX_IMAGES+1) /* WPS images + pbar bitmap */ +#define MAX_BITMAPS (MAX_IMAGES+MAX_PROGRESSBARS) /* WPS images + pbar bitmap */ #endif #define PROGRESSBAR_BMP MAX_IMAGES -#define BACKDROP_BMP (MAX_IMAGES+1) +#define BACKDROP_BMP (MAX_BITMAPS-1) /* pointers to the bitmap filenames in the WPS source */ static const char *bmp_names[MAX_BITMAPS]; @@ -129,6 +129,8 @@ static int parse_dir_level(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data); #ifdef HAVE_LCD_BITMAP +static int parse_viewport_display(const char *wps_bufptr, + struct wps_token *token, struct wps_data *wps_data); static int parse_viewport(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data); static int parse_leftmargin(const char *wps_bufptr, @@ -317,13 +319,14 @@ static const struct wps_tag all_tags[] = { parse_image_display }, { WPS_TOKEN_IMAGE_DISPLAY, "x", 0, parse_image_load }, - { WPS_TOKEN_IMAGE_PROGRESS_BAR, "P", 0, parse_image_special }, #ifdef HAVE_ALBUMART { WPS_NO_TOKEN, "Cl", 0, parse_albumart_load }, { WPS_TOKEN_ALBUMART_DISPLAY, "C", WPS_REFRESH_STATIC, parse_albumart_conditional }, #endif + { WPS_VIEWPORT_ENABLE, "Vd", WPS_REFRESH_DYNAMIC, + parse_viewport_display }, { WPS_NO_TOKEN, "V", 0, parse_viewport }, #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) @@ -536,6 +539,22 @@ static int parse_image_load(const char *wps_bufptr, return skip_end_of_line(wps_bufptr); } +static int parse_viewport_display(const char *wps_bufptr, + struct wps_token *token, + struct wps_data *wps_data) +{ + (void)wps_data; + char letter = wps_bufptr[0]; + + if (letter < 'a' || letter > 'z') + { + /* invalid viewport tag */ + return WPS_ERROR_INVALID_PARAM; + } + token->value.i = letter; + return 1; +} + static int parse_viewport(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data) @@ -563,17 +582,35 @@ static int parse_viewport(const char *wps_bufptr, } #endif - if (*wps_bufptr != '|') - return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */ - - ptr = wps_bufptr + 1; - /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */ - if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) return WPS_ERROR_INVALID_PARAM; - + wps_data->num_viewports++; + /* check for the optional letter to signify its a hideable viewport */ + /* %Vl|