From b5f4d90b4b4e88f83828681c7d708338fdcee8d0 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Tue, 5 Jun 2007 10:42:41 +0000 Subject: Make the bitmap loading code handle the progressbar and backdrop bitmaps in a slightly more generic way. This hopefully simplifies the code a bit and should make adding special bitmaps less painful. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13560 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/gwps.h | 7 +++++++ apps/gui/wps_parser.c | 53 +++++++++++++++++++++------------------------------ 2 files changed, 29 insertions(+), 31 deletions(-) (limited to 'apps/gui') diff --git a/apps/gui/gwps.h b/apps/gui/gwps.h index 26a800cbbd..609e2af91f 100644 --- a/apps/gui/gwps.h +++ b/apps/gui/gwps.h @@ -69,6 +69,13 @@ struct align_pos { #ifdef HAVE_LCD_BITMAP #define MAX_IMAGES (26*2) /* a-z and A-Z */ + +#if LCD_DEPTH > 1 +#define MAX_BITMAPS MAX_IMAGES+2 /* WPS images + pbar bitmap + backdrop */ +#else +#define MAX_BITMAPS MAX_IMAGES+1 /* WPS images + pbar bitmap */ +#endif + #define IMG_BUFSIZE ((LCD_HEIGHT*LCD_WIDTH*LCD_DEPTH/8) \ + (2*LCD_HEIGHT*LCD_WIDTH/8)) diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c index d363d6d8cb..5be93c6d91 100644 --- a/apps/gui/wps_parser.c +++ b/apps/gui/wps_parser.c @@ -65,11 +65,7 @@ static int line; #ifdef HAVE_LCD_BITMAP /* pointers to the bitmap filenames in the WPS source */ -static const char *bmp_names[MAX_IMAGES]; -static const char *pb_bmp_name; -#if LCD_DEPTH > 1 -static const char *backdrop_bmp_name; -#endif +static const char *bmp_names[MAX_BITMAPS]; #endif #ifdef DEBUG @@ -472,13 +468,13 @@ static int parse_image_special(const char *wps_bufptr, if (token->type == WPS_TOKEN_IMAGE_PROGRESS_BAR) { /* format: %P|filename.bmp| */ - pb_bmp_name = wps_bufptr + 1; + bmp_names[MAX_IMAGES] = wps_bufptr + 1; } #if LCD_DEPTH > 1 else if (token->type == WPS_TOKEN_IMAGE_BACKDROP) { /* format: %X|filename.bmp| */ - backdrop_bmp_name = wps_bufptr + 1; + bmp_names[MAX_IMAGES + 1] = wps_bufptr + 1; } #endif @@ -912,54 +908,49 @@ static void wps_reset(struct wps_data *data) static void clear_bmp_names(void) { int n; - for (n = 0; n < MAX_IMAGES; n++) + for (n = 0; n < MAX_BITMAPS; n++) { bmp_names[n] = NULL; } - pb_bmp_name = NULL; -#if LCD_DEPTH > 1 - backdrop_bmp_name = NULL; -#endif } static void load_wps_bitmaps(struct wps_data *wps_data, char *bmpdir) { char img_path[MAX_PATH]; + struct bitmap *bitmap; + bool *loaded; int n; - for (n = 0; n < MAX_IMAGES; n++) + for (n = 0; n < MAX_BITMAPS - 1; n++) { if (bmp_names[n]) { get_image_filename(bmp_names[n], bmpdir, img_path, sizeof(img_path)); + if (n == MAX_IMAGES) { + /* progressbar bitmap */ + bitmap = &wps_data->progressbar.bm; + loaded = &wps_data->progressbar.have_bitmap_pb; + } else { + /* regular bitmap */ + bitmap = &wps_data->img[n].bm; + loaded = &wps_data->img[n].loaded; + } + /* load the image */ - wps_data->img[n].bm.data = wps_data->img_buf_ptr; - if (load_bitmap(wps_data, img_path, &wps_data->img[n].bm)) + bitmap->data = wps_data->img_buf_ptr; + if (load_bitmap(wps_data, img_path, bitmap)) { - wps_data->img[n].loaded = true; + *loaded = true; } } } - if (pb_bmp_name) - { - get_image_filename(pb_bmp_name, bmpdir, img_path, sizeof(img_path)); - - /* load the image */ - wps_data->progressbar.bm.data = wps_data->img_buf_ptr; - if (load_bitmap(wps_data, img_path, &wps_data->progressbar.bm) - && wps_data->progressbar.bm.width <= LCD_WIDTH) - { - wps_data->progressbar.have_bitmap_pb = true; - } - } - #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1)) - if (backdrop_bmp_name) + if (bmp_names[MAX_IMAGES + 1]) { - get_image_filename(backdrop_bmp_name, bmpdir, + get_image_filename(bmp_names[MAX_IMAGES + 1], bmpdir, img_path, sizeof(img_path)); #ifdef HAVE_REMOTE_LCD if (wps_data->remote_wps) -- cgit v1.2.3