diff options
-rw-r--r-- | apps/gui/skin_engine/wps_parser.c | 97 | ||||
-rw-r--r-- | apps/gui/viewport.c | 104 | ||||
-rw-r--r-- | apps/gui/viewport.h | 7 |
3 files changed, 116 insertions, 92 deletions
diff --git a/apps/gui/skin_engine/wps_parser.c b/apps/gui/skin_engine/wps_parser.c index 440133327a..3df2c5f0aa 100644 --- a/apps/gui/skin_engine/wps_parser.c +++ b/apps/gui/skin_engine/wps_parser.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "file.h" | 25 | #include "file.h" |
26 | #include "misc.h" | 26 | #include "misc.h" |
27 | #include "plugin.h" | 27 | #include "plugin.h" |
28 | #include "viewport.h" | ||
28 | 29 | ||
29 | #ifdef __PCTOOL__ | 30 | #ifdef __PCTOOL__ |
30 | #ifdef WPSEDITOR | 31 | #ifdef WPSEDITOR |
@@ -587,26 +588,12 @@ static int parse_viewport(const char *wps_bufptr, | |||
587 | { | 588 | { |
588 | (void)token; /* Kill warnings */ | 589 | (void)token; /* Kill warnings */ |
589 | const char *ptr = wps_bufptr; | 590 | const char *ptr = wps_bufptr; |
590 | struct viewport* vp; | 591 | |
591 | int depth; | 592 | const int screen = |
592 | uint32_t set = 0; | ||
593 | enum { | ||
594 | PL_X = 0, | ||
595 | PL_Y, | ||
596 | PL_WIDTH, | ||
597 | PL_HEIGHT, | ||
598 | PL_FONT, | ||
599 | PL_FG, | ||
600 | PL_BG, | ||
601 | }; | ||
602 | int lcd_width = LCD_WIDTH, lcd_height = LCD_HEIGHT; | ||
603 | #ifdef HAVE_REMOTE_LCD | 593 | #ifdef HAVE_REMOTE_LCD |
604 | if (wps_data->remote_wps) | 594 | wps_data->remote_wps ? SCREEN_REMOTE : |
605 | { | ||
606 | lcd_width = LCD_REMOTE_WIDTH; | ||
607 | lcd_height = LCD_REMOTE_HEIGHT; | ||
608 | } | ||
609 | #endif | 595 | #endif |
596 | SCREEN_MAIN; | ||
610 | 597 | ||
611 | if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) | 598 | if (wps_data->num_viewports >= WPS_MAX_VIEWPORTS) |
612 | return WPS_ERROR_INVALID_PARAM; | 599 | return WPS_ERROR_INVALID_PARAM; |
@@ -635,87 +622,19 @@ static int parse_viewport(const char *wps_bufptr, | |||
635 | return WPS_ERROR_INVALID_PARAM; | 622 | return WPS_ERROR_INVALID_PARAM; |
636 | 623 | ||
637 | ptr++; | 624 | ptr++; |
638 | vp = &wps_data->viewports[wps_data->num_viewports].vp; | 625 | struct viewport *vp = &wps_data->viewports[wps_data->num_viewports].vp; |
639 | /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */ | 626 | /* format: %V|x|y|width|height|font|fg_pattern|bg_pattern| */ |
640 | 627 | ||
641 | /* Set the defaults for fields not user-specified */ | 628 | /* Set the defaults for fields not user-specified */ |
642 | vp->drawmode = DRMODE_SOLID; | 629 | vp->drawmode = DRMODE_SOLID; |
643 | 630 | ||
644 | /* Work out the depth of this display */ | 631 | if (!(ptr = viewport_parse_viewport(vp, screen, ptr, '|'))) |
645 | #ifdef HAVE_REMOTE_LCD | 632 | return WPS_ERROR_INVALID_PARAM; |
646 | depth = (wps_data->remote_wps ? LCD_REMOTE_DEPTH : LCD_DEPTH); | ||
647 | #else | ||
648 | depth = LCD_DEPTH; | ||
649 | #endif | ||
650 | |||
651 | #ifdef HAVE_LCD_COLOR | ||
652 | if (depth == 16) | ||
653 | { | ||
654 | if (!(ptr = parse_list("dddddcc", &set, '|', ptr, &vp->x, &vp->y, &vp->width, | ||
655 | &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) | ||
656 | return WPS_ERROR_INVALID_PARAM; | ||
657 | } | ||
658 | else | ||
659 | #endif | ||
660 | #if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) | ||
661 | if (depth == 2) { | ||
662 | /* Default to black on white */ | ||
663 | vp->fg_pattern = 0; | ||
664 | vp->bg_pattern = 3; | ||
665 | if (!(ptr = parse_list("dddddgg", &set, '|', ptr, &vp->x, &vp->y, &vp->width, | ||
666 | &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) | ||
667 | return WPS_ERROR_INVALID_PARAM; | ||
668 | } | ||
669 | else | ||
670 | #endif | ||
671 | #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) | ||
672 | if (depth == 1) | ||
673 | { | ||
674 | if (!(ptr = parse_list("ddddd", &set, '|', ptr, &vp->x, &vp->y, | ||
675 | &vp->width, &vp->height, &vp->font))) | ||
676 | return WPS_ERROR_INVALID_PARAM; | ||
677 | } | ||
678 | else | ||
679 | #endif | ||
680 | {} | ||
681 | 633 | ||
682 | /* Check for trailing | */ | 634 | /* Check for trailing | */ |
683 | if (*ptr != '|') | 635 | if (*ptr != '|') |
684 | return WPS_ERROR_INVALID_PARAM; | 636 | return WPS_ERROR_INVALID_PARAM; |
685 | 637 | ||
686 | if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) | ||
687 | return WPS_ERROR_INVALID_PARAM; | ||
688 | |||
689 | /* fix defaults */ | ||
690 | if (!LIST_VALUE_PARSED(set, PL_WIDTH)) | ||
691 | vp->width = lcd_width - vp->x; | ||
692 | if (!LIST_VALUE_PARSED(set, PL_HEIGHT)) | ||
693 | vp->height = lcd_height - vp->y; | ||
694 | |||
695 | /* Default to using the user font if the font was an invalid number */ | ||
696 | if (!LIST_VALUE_PARSED(set, PL_FONT) || | ||
697 | ((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))) | ||
698 | vp->font = FONT_UI; | ||
699 | |||
700 | /* Validate the viewport dimensions - we know that the numbers are | ||
701 | non-negative integers */ | ||
702 | if ((vp->x >= lcd_width) || | ||
703 | ((vp->x + vp->width) > lcd_width) || | ||
704 | (vp->y >= lcd_height) || | ||
705 | ((vp->y + vp->height) > lcd_height)) | ||
706 | { | ||
707 | return WPS_ERROR_INVALID_PARAM; | ||
708 | } | ||
709 | |||
710 | #ifdef HAVE_LCD_COLOR | ||
711 | if (depth == 16) | ||
712 | { | ||
713 | if (!LIST_VALUE_PARSED(set, PL_FG)) | ||
714 | vp->fg_pattern = global_settings.fg_color; | ||
715 | if (!LIST_VALUE_PARSED(set, PL_BG)) | ||
716 | vp->bg_pattern = global_settings.bg_color; | ||
717 | } | ||
718 | #endif | ||
719 | 638 | ||
720 | wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1; | 639 | wps_data->viewports[wps_data->num_viewports-1].last_line = wps_data->num_lines - 1; |
721 | 640 | ||
diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index d635c10481..52704d9f69 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c | |||
@@ -35,6 +35,15 @@ | |||
35 | #include "screen_access.h" | 35 | #include "screen_access.h" |
36 | #include "appevents.h" | 36 | #include "appevents.h" |
37 | 37 | ||
38 | |||
39 | |||
40 | #define LINE_SEL_FROM_SETTINGS(vp) \ | ||
41 | do { \ | ||
42 | vp->lss_pattern = global_settings.lss_color; \ | ||
43 | vp->lse_pattern = global_settings.lse_color; \ | ||
44 | vp->lst_pattern = global_settings.lst_color; \ | ||
45 | } while (0) | ||
46 | |||
38 | static int statusbar_enabled = 0; | 47 | static int statusbar_enabled = 0; |
39 | 48 | ||
40 | int viewport_get_nb_lines(struct viewport *vp) | 49 | int viewport_get_nb_lines(struct viewport *vp) |
@@ -88,9 +97,7 @@ void viewport_set_defaults(struct viewport *vp, enum screen_type screen) | |||
88 | #ifdef HAVE_LCD_COLOR | 97 | #ifdef HAVE_LCD_COLOR |
89 | vp->fg_pattern = global_settings.fg_color; | 98 | vp->fg_pattern = global_settings.fg_color; |
90 | vp->bg_pattern = global_settings.bg_color; | 99 | vp->bg_pattern = global_settings.bg_color; |
91 | vp->lss_pattern = global_settings.lss_color; | 100 | LINE_SEL_FROM_SETTINGS(vp); |
92 | vp->lse_pattern = global_settings.lse_color; | ||
93 | vp->lst_pattern = global_settings.lst_color; | ||
94 | #elif LCD_DEPTH > 1 | 101 | #elif LCD_DEPTH > 1 |
95 | vp->fg_pattern = LCD_DEFAULT_FG; | 102 | vp->fg_pattern = LCD_DEFAULT_FG; |
96 | vp->bg_pattern = LCD_DEFAULT_BG; | 103 | vp->bg_pattern = LCD_DEFAULT_BG; |
@@ -151,3 +158,94 @@ void viewportmanager_statusbar_changed(void* data) | |||
151 | #endif | 158 | #endif |
152 | viewportmanager_set_statusbar(statusbar_enabled); | 159 | viewportmanager_set_statusbar(statusbar_enabled); |
153 | } | 160 | } |
161 | |||
162 | const char* viewport_parse_viewport(struct viewport *vp, | ||
163 | enum screen_type screen, | ||
164 | const char *bufptr, | ||
165 | const char separator) | ||
166 | { | ||
167 | /* parse the list to the viewport struct */ | ||
168 | const char *ptr = bufptr; | ||
169 | int depth; | ||
170 | uint32_t set = 0; | ||
171 | |||
172 | enum { | ||
173 | PL_X = 0, | ||
174 | PL_Y, | ||
175 | PL_WIDTH, | ||
176 | PL_HEIGHT, | ||
177 | PL_FONT, | ||
178 | PL_FG, | ||
179 | PL_BG, | ||
180 | }; | ||
181 | |||
182 | /* Work out the depth of this display */ | ||
183 | depth = screens[screen].depth; | ||
184 | #ifdef HAVE_LCD_COLOR | ||
185 | if (depth == 16) | ||
186 | { | ||
187 | if (!(ptr = parse_list("dddddcc", &set, separator, ptr, &vp->x, &vp->y, &vp->width, | ||
188 | &vp->height, &vp->font, &vp->fg_pattern,&vp->bg_pattern))) | ||
189 | return VP_ERROR; | ||
190 | } | ||
191 | else | ||
192 | #endif | ||
193 | #if (LCD_DEPTH == 2) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 2) | ||
194 | if (depth == 2) { | ||
195 | if (!(ptr = parse_list("dddddgg", &set, separator, ptr, &vp->x, &vp->y, &vp->width, | ||
196 | &vp->height, &vp->font, &vp->fg_pattern, &vp->bg_pattern))) | ||
197 | return VP_ERROR; | ||
198 | } | ||
199 | else | ||
200 | #endif | ||
201 | #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1) | ||
202 | if (depth == 1) | ||
203 | { | ||
204 | if (!(ptr = parse_list("ddddd", &set, separator, ptr, &vp->x, &vp->y, &vp->width, | ||
205 | &vp->height, &vp->font))) | ||
206 | return VP_ERROR; | ||
207 | } | ||
208 | else | ||
209 | #endif | ||
210 | {} | ||
211 | |||
212 | /* X and Y *must* be set */ | ||
213 | if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y)) | ||
214 | return VP_ERROR; | ||
215 | |||
216 | /* fix defaults */ | ||
217 | if (!LIST_VALUE_PARSED(set, PL_WIDTH)) | ||
218 | vp->width = screens[screen].lcdwidth - vp->x; | ||
219 | if (!LIST_VALUE_PARSED(set, PL_HEIGHT)) | ||
220 | vp->height = screens[screen].lcdheight - vp->y; | ||
221 | |||
222 | #if (LCD_DEPTH > 1) | ||
223 | if (!LIST_VALUE_PARSED(set, PL_FG)) | ||
224 | vp->fg_pattern = global_settings.fg_color; | ||
225 | if (!LIST_VALUE_PARSED(set, PL_BG)) | ||
226 | vp->bg_pattern = global_settings.bg_color; | ||
227 | #endif | ||
228 | #ifdef HAVE_LCD_COLOR | ||
229 | LINE_SEL_FROM_SETTINGS(vp); | ||
230 | #endif | ||
231 | /* Validate the viewport dimensions - we know that the numbers are | ||
232 | non-negative integers, ignore bars and assume the viewport takes them | ||
233 | * into account */ | ||
234 | if ((vp->x >= screens[screen].lcdwidth) || | ||
235 | ((vp->x + vp->width) > screens[screen].lcdwidth) || | ||
236 | (vp->y >= screens[screen].lcdheight) || | ||
237 | ((vp->y + vp->height) > screens[screen].lcdheight)) | ||
238 | { | ||
239 | return VP_ERROR; | ||
240 | } | ||
241 | |||
242 | /* Default to using the user font if the font was an invalid number or '-'*/ | ||
243 | if (((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI)) | ||
244 | || !LIST_VALUE_PARSED(set, PL_FONT) | ||
245 | ) | ||
246 | vp->font = FONT_UI; | ||
247 | |||
248 | vp->drawmode = DRMODE_SOLID; | ||
249 | |||
250 | return ptr; | ||
251 | } | ||
diff --git a/apps/gui/viewport.h b/apps/gui/viewport.h index acc9758ee3..65a9815bcd 100644 --- a/apps/gui/viewport.h +++ b/apps/gui/viewport.h | |||
@@ -38,6 +38,13 @@ int viewport_load_config(const char *config, struct viewport *vp); | |||
38 | 38 | ||
39 | void viewport_set_defaults(struct viewport *vp, enum screen_type screen); | 39 | void viewport_set_defaults(struct viewport *vp, enum screen_type screen); |
40 | 40 | ||
41 | /* parse a viewport list, which looks like | ||
42 | * X|Y|width|height|font|foregorund color|background color | ||
43 | * | is a separator */ | ||
44 | const char* viewport_parse_viewport(struct viewport *vp, | ||
45 | enum screen_type screen, | ||
46 | const char *bufptr, | ||
47 | const char separator); | ||
41 | /* Used to specify which screens the statusbar (SB) should be displayed on. | 48 | /* Used to specify which screens the statusbar (SB) should be displayed on. |
42 | * | 49 | * |
43 | * The parameter is a bit OR'ed combination of the following (screen is | 50 | * The parameter is a bit OR'ed combination of the following (screen is |