summaryrefslogtreecommitdiff
path: root/apps/gui/wps_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/wps_parser.c')
-rw-r--r--apps/gui/wps_parser.c178
1 files changed, 126 insertions, 52 deletions
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;
80#ifdef HAVE_LCD_BITMAP 80#ifdef HAVE_LCD_BITMAP
81 81
82#if LCD_DEPTH > 1 82#if LCD_DEPTH > 1
83#define MAX_BITMAPS (MAX_IMAGES+2) /* WPS images + pbar bitmap + backdrop */ 83#define MAX_BITMAPS (MAX_IMAGES+MAX_PROGRESSBARS+1) /* WPS images + pbar bitmap + backdrop */
84#else 84#else
85#define MAX_BITMAPS (MAX_IMAGES+1) /* WPS images + pbar bitmap */ 85#define MAX_BITMAPS (MAX_IMAGES+MAX_PROGRESSBARS) /* WPS images + pbar bitmap */
86#endif 86#endif
87 87
88#define PROGRESSBAR_BMP MAX_IMAGES 88#define PROGRESSBAR_BMP MAX_IMAGES
89#define BACKDROP_BMP (MAX_IMAGES+1) 89#define BACKDROP_BMP (MAX_BITMAPS-1)
90 90
91/* pointers to the bitmap filenames in the WPS source */ 91/* pointers to the bitmap filenames in the WPS source */
92static const char *bmp_names[MAX_BITMAPS]; 92static const char *bmp_names[MAX_BITMAPS];
@@ -129,6 +129,8 @@ static int parse_dir_level(const char *wps_bufptr,
129 struct wps_token *token, struct wps_data *wps_data); 129 struct wps_token *token, struct wps_data *wps_data);
130 130
131#ifdef HAVE_LCD_BITMAP 131#ifdef HAVE_LCD_BITMAP
132static int parse_viewport_display(const char *wps_bufptr,
133 struct wps_token *token, struct wps_data *wps_data);
132static int parse_viewport(const char *wps_bufptr, 134static int parse_viewport(const char *wps_bufptr,
133 struct wps_token *token, struct wps_data *wps_data); 135 struct wps_token *token, struct wps_data *wps_data);
134static int parse_leftmargin(const char *wps_bufptr, 136static int parse_leftmargin(const char *wps_bufptr,
@@ -317,13 +319,14 @@ static const struct wps_tag all_tags[] = {
317 parse_image_display }, 319 parse_image_display },
318 320
319 { WPS_TOKEN_IMAGE_DISPLAY, "x", 0, parse_image_load }, 321 { WPS_TOKEN_IMAGE_DISPLAY, "x", 0, parse_image_load },
320 { WPS_TOKEN_IMAGE_PROGRESS_BAR, "P", 0, parse_image_special },
321#ifdef HAVE_ALBUMART 322#ifdef HAVE_ALBUMART
322 { WPS_NO_TOKEN, "Cl", 0, parse_albumart_load }, 323 { WPS_NO_TOKEN, "Cl", 0, parse_albumart_load },
323 { WPS_TOKEN_ALBUMART_DISPLAY, "C", WPS_REFRESH_STATIC, 324 { WPS_TOKEN_ALBUMART_DISPLAY, "C", WPS_REFRESH_STATIC,
324 parse_albumart_conditional }, 325 parse_albumart_conditional },
325#endif 326#endif
326 327
328 { WPS_VIEWPORT_ENABLE, "Vd", WPS_REFRESH_DYNAMIC,
329 parse_viewport_display },
327 { WPS_NO_TOKEN, "V", 0, parse_viewport }, 330 { WPS_NO_TOKEN, "V", 0, parse_viewport },
328 331
329#if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)) 332#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,
536 return skip_end_of_line(wps_bufptr); 539 return skip_end_of_line(wps_bufptr);
537} 540}
538 541
542static int parse_viewport_display(const char *wps_bufptr,
543 struct wps_token *token,
544 struct wps_data *wps_data)
545{
546 (void)wps_data;
547 char letter = wps_bufptr[0];
548
549 if (letter < 'a' || letter > 'z')
550 {
551 /* invalid viewport tag */
552 return WPS_ERROR_INVALID_PARAM;
553 }
554 token->value.i = letter;
555 return 1;
556}
557
539static int parse_viewport(const char *wps_bufptr, 558static int parse_viewport(const char *wps_bufptr,
540 struct wps_token *token, 559 struct wps_token *token,
541 struct wps_data *wps_data) 560 struct wps_data *wps_data)
@@ -563,17 +582,35 @@ static int parse_viewport(const char *wps_bufptr,
563 } 582 }
564#endif 583#endif
565 584
566 if (*wps_bufptr != '|')
567 return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */
568
569 ptr = wps_bufptr + 1;
570 /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */
571
572 if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) 585 if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS)
573 return WPS_ERROR_INVALID_PARAM; 586 return WPS_ERROR_INVALID_PARAM;
574 587
575 wps_data->num_viewports++; 588 wps_data->num_viewports++;
589 /* check for the optional letter to signify its a hideable viewport */
590 /* %Vl|<label>|<rest of tags>| */
591 wps_data->viewports[wps_data->num_viewports].hidden_flags = 0;
592
593 if (*ptr == 'l')
594 {
595 if (*(ptr+1) == '|')
596 {
597 char label = *(ptr+2);
598 if (label >= 'a' && label < 'a' + WPS_MAX_VIEWPORTS)
599 {
600 wps_data->viewports[wps_data->num_viewports].hidden_flags = VP_DRAW_HIDEABLE;
601 wps_data->viewports[wps_data->num_viewports].label = label;
602 }
603 else
604 return WPS_ERROR_INVALID_PARAM; /* malformed token: e.g. %Cl7 */
605 ptr += 3;
606 }
607 }
608 if (*ptr != '|')
609 return WPS_ERROR_INVALID_PARAM;
610
611 ptr++;
576 vp = &wps_data->viewports[wps_data->num_viewports].vp; 612 vp = &wps_data->viewports[wps_data->num_viewports].vp;
613 /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */
577 614
578 /* Set the defaults for fields not user-specified */ 615 /* Set the defaults for fields not user-specified */
579 vp->drawmode = DRMODE_SOLID; 616 vp->drawmode = DRMODE_SOLID;
@@ -687,14 +724,8 @@ static int parse_image_special(const char *wps_bufptr,
687 724
688 if (pos > newline) 725 if (pos > newline)
689 return WPS_ERROR_INVALID_PARAM; 726 return WPS_ERROR_INVALID_PARAM;
690
691 if (token->type == WPS_TOKEN_IMAGE_PROGRESS_BAR)
692 {
693 /* format: %P|filename.bmp| */
694 bmp_names[PROGRESSBAR_BMP] = wps_bufptr + 1;
695 }
696#if LCD_DEPTH > 1 727#if LCD_DEPTH > 1
697 else if (token->type == WPS_TOKEN_IMAGE_BACKDROP) 728 if (token->type == WPS_TOKEN_IMAGE_BACKDROP)
698 { 729 {
699 /* format: %X|filename.bmp| */ 730 /* format: %X|filename.bmp| */
700 bmp_names[BACKDROP_BMP] = wps_bufptr + 1; 731 bmp_names[BACKDROP_BMP] = wps_bufptr + 1;
@@ -762,40 +793,82 @@ static int parse_progressbar(const char *wps_bufptr,
762 struct wps_data *wps_data) 793 struct wps_data *wps_data)
763{ 794{
764 (void)token; /* Kill warnings */ 795 (void)token; /* Kill warnings */
796 /* %pb or %pb|filename|x|y|width|height|
797 using - for any of the params uses "sane" values */
765#ifdef HAVE_LCD_BITMAP 798#ifdef HAVE_LCD_BITMAP
799 enum {
800 PB_FILENAME = 0,
801 PB_X,
802 PB_Y,
803 PB_WIDTH,
804 PB_HEIGHT
805 };
806 const char *filename;
807 int x, y, height, width, set = 0;
808 const char *ptr = wps_bufptr;
809 struct progressbar *pb;
810 struct viewport *vp = &wps_data->viewports[wps_data->num_viewports].vp;
811 int font_height = font_get(vp->font)->height;
812 int line_y_pos = font_height*(wps_data->num_lines -
813 wps_data->viewports[wps_data->num_viewports].first_line);
814
815 /** Remove this bit when the remove lcd margins patch goes in **/
816 bool draw_sb = global_settings.statusbar;
766 817
767 short *vals[] = { 818 if (wps_data->wps_sb_tag)
768 &wps_data->progress_height, 819 draw_sb = wps_data->show_sb_on_wps;
769 &wps_data->progress_start,
770 &wps_data->progress_end,
771 &wps_data->progress_top };
772
773 /* default values : */
774 wps_data->progress_height = 6;
775 wps_data->progress_start = 0;
776 wps_data->progress_end = 0;
777 wps_data->progress_top = -1;
778
779 int i = 0;
780 char *newline = strchr(wps_bufptr, '\n');
781 char *prev = strchr(wps_bufptr, '|');
782 if (prev && prev < newline) {
783 char *next = strchr(prev+1, '|');
784 while (i < 4 && next && next < newline)
785 {
786 *(vals[i++]) = atoi(++prev);
787 prev = strchr(prev, '|');
788 next = strchr(++next, '|');
789 }
790 820
791 if (wps_data->progress_height < 3) 821 if (wps_data->num_viewports == 0 && draw_sb)
792 wps_data->progress_height = 3; 822 line_y_pos += STATUSBAR_HEIGHT;
793 if (wps_data->progress_end < wps_data->progress_start + 3) 823 /** Remove the above bit when the remove lcd margins patch goes in **/
794 wps_data->progress_end = 0; 824
825 if (wps_data->progressbar_count +1 >= MAX_PROGRESSBARS)
826 return WPS_ERROR_INVALID_PARAM;
827
828 pb = &wps_data->progressbar[wps_data->progressbar_count];
829 pb->have_bitmap_pb = false;
830
831 if (*wps_bufptr != '|') /* regular old style */
832 {
833 pb->x = 0;
834 pb->width = vp->width;
835 pb->height = SYSFONT_HEIGHT-2;
836 pb->y = line_y_pos + (font_height-pb->height)/2;
837
838 wps_data->viewports[wps_data->num_viewports].pb =
839 &wps_data->progressbar[wps_data->progressbar_count];
840 wps_data->progressbar_count++;
841 return 0;
795 } 842 }
796 843 ptr = wps_bufptr + 1;
797 return newline - wps_bufptr; 844
798 845 if (!(ptr = parse_list("sdddd", &set, '|', ptr, &filename,
846 &x, &y, &width, &height)))
847 return WPS_ERROR_INVALID_PARAM;
848 if (LIST_VALUE_PARSED(set, PB_FILENAME)) /* filename */
849 bmp_names[PROGRESSBAR_BMP+wps_data->progressbar_count] = filename;
850 if (LIST_VALUE_PARSED(set, PB_X)) /* x */
851 pb->x = x;
852 else
853 pb->x = vp->x;
854 if (LIST_VALUE_PARSED(set, PB_WIDTH)) /* width */
855 pb->width = width;
856 else
857 pb->width = vp->width - pb->x;
858 if (LIST_VALUE_PARSED(set, PB_HEIGHT)) /* height, default to font height */
859 pb->height = height;
860 else
861 pb->height = font_height;
862 if (LIST_VALUE_PARSED(set, PB_Y)) /* y */
863 pb->y = y;
864 else
865 pb->y = line_y_pos + (font_height-pb->height)/2;
866 wps_data->progressbar[wps_data->progressbar_count].have_bitmap_pb = false;
867 wps_data->viewports[wps_data->num_viewports].pb =
868 &wps_data->progressbar[wps_data->progressbar_count];
869 wps_data->progressbar_count++;
870 /* Skip the rest of the line */
871 return skip_end_of_line(wps_bufptr)-1;
799#else 872#else
800 873
801 if (*(wps_bufptr-1) == 'f') 874 if (*(wps_bufptr-1) == 'f')
@@ -1359,7 +1432,6 @@ static void wps_images_clear(struct wps_data *data)
1359 data->img[i].always_display = false; 1432 data->img[i].always_display = false;
1360 data->img[i].num_subimages = 1; 1433 data->img[i].num_subimages = 1;
1361 } 1434 }
1362 data->progressbar.have_bitmap_pb = false;
1363} 1435}
1364#endif 1436#endif
1365 1437
@@ -1373,6 +1445,8 @@ void wps_data_init(struct wps_data *wps_data)
1373 wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */ 1445 wps_data->img_buf_ptr = wps_data->img_buf; /* where in image buffer */
1374 wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */ 1446 wps_data->img_buf_free = IMG_BUFSIZE; /* free space in image buffer */
1375 wps_data->peak_meter_enabled = false; 1447 wps_data->peak_meter_enabled = false;
1448 /* progress bars */
1449 wps_data->progressbar_count = 0;
1376#else /* HAVE_LCD_CHARCELLS */ 1450#else /* HAVE_LCD_CHARCELLS */
1377 int i; 1451 int i;
1378 for (i = 0; i < 8; i++) 1452 for (i = 0; i < 8; i++)
@@ -1414,10 +1488,10 @@ static bool load_wps_bitmaps(struct wps_data *wps_data, char *bmpdir)
1414 get_image_filename(bmp_names[n], bmpdir, 1488 get_image_filename(bmp_names[n], bmpdir,
1415 img_path, sizeof(img_path)); 1489 img_path, sizeof(img_path));
1416 1490
1417 if (n == PROGRESSBAR_BMP) { 1491 if (n >= PROGRESSBAR_BMP ) {
1418 /* progressbar bitmap */ 1492 /* progressbar bitmap */
1419 bitmap = &wps_data->progressbar.bm; 1493 bitmap = &wps_data->progressbar[n-PROGRESSBAR_BMP].bm;
1420 loaded = &wps_data->progressbar.have_bitmap_pb; 1494 loaded = &wps_data->progressbar[n-PROGRESSBAR_BMP].have_bitmap_pb;
1421 } else { 1495 } else {
1422 /* regular bitmap */ 1496 /* regular bitmap */
1423 bitmap = &wps_data->img[n].bm; 1497 bitmap = &wps_data->img[n].bm;