1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002-2007 Björn Stenberg
11 * Copyright (C) 2007-2008 Nicolas Pennequin
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
28 #include "settings_list.h"
29 #include "rbunicode.h"
34 #include "powermgmt.h"
37 #ifdef HAVE_LCD_CHARCELLS
41 #include "mp3_playback.h"
45 #include "scrollbar.h"
48 #ifdef HAVE_LCD_BITMAP
49 #include "peakmeter.h"
58 #if CONFIG_CODEC == SWCODEC
65 #include "wps_internals.h"
66 #include "skin_engine.h"
68 static bool gui_wps_redraw(struct gui_wps
*gwps
, unsigned refresh_mode
);
71 bool gui_wps_display(struct gui_wps
*gwps
)
73 struct screen
*display
= gwps
->display
;
75 /* Update the values in the first (default) viewport - in case the user
76 has modified the statusbar or colour settings */
78 if (display
->depth
> 1)
80 gwps
->data
->viewports
[0].vp
.fg_pattern
= display
->get_foreground();
81 gwps
->data
->viewports
[0].vp
.bg_pattern
= display
->get_background();
84 display
->clear_display();
85 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
86 if (display
->screen_type
== SCREEN_REMOTE
)
87 show_remote_wps_backdrop();
88 else if (display
->screen_type
== SCREEN_MAIN
)
93 return gui_wps_redraw(gwps
, WPS_REFRESH_ALL
);
96 /* update a skinned screen, update_type is WPS_REFRESH_* values.
97 * Usually it should only be WPS_REFRESH_NON_STATIC
98 * A full update will be done if required (state.do_full_update == true)
100 bool skin_update(struct gui_wps
*gwps
, unsigned int update_type
)
103 /* This maybe shouldnt be here, but while the skin is only used to
104 * display the music screen this is better than whereever we are being
105 * called from. This is also safe for skined screen which dont use the id3 */
106 struct mp3entry
*id3
= gwps
->state
->id3
;
107 bool cuesheet_update
= (id3
!= NULL
? cuesheet_subtrack_changed(id3
) : false);
108 gwps
->state
->do_full_update
= cuesheet_update
|| gwps
->state
->do_full_update
;
110 retval
= gui_wps_redraw(gwps
, gwps
->state
->do_full_update
?
111 WPS_REFRESH_ALL
: update_type
);
116 #ifdef HAVE_LCD_BITMAP
118 static void draw_progressbar(struct gui_wps
*gwps
,
119 struct wps_viewport
*wps_vp
)
121 struct screen
*display
= gwps
->display
;
122 struct wps_state
*state
= gwps
->state
;
123 struct progressbar
*pb
= wps_vp
->pb
;
128 int line_height
= font_get(wps_vp
->vp
.font
)->height
;
129 /* center the pb in the line, but only if the line is higher than the pb */
130 int center
= (line_height
-pb
->height
)/2;
131 /* if Y was not set calculate by font height,Y is -line_number-1 */
132 y
= (-y
-1)*line_height
+ (0 > center
? 0 : center
);
135 if (pb
->have_bitmap_pb
)
136 gui_bitmap_scrollbar_draw(display
, pb
->bm
,
137 pb
->x
, y
, pb
->width
, pb
->bm
.height
,
138 state
->id3
->length
? state
->id3
->length
: 1, 0,
139 state
->id3
->length
? state
->id3
->elapsed
140 + state
->ff_rewind_count
: 0,
143 gui_scrollbar_draw(display
, pb
->x
, y
, pb
->width
, pb
->height
,
144 state
->id3
->length
? state
->id3
->length
: 1, 0,
145 state
->id3
->length
? state
->id3
->elapsed
146 + state
->ff_rewind_count
: 0,
148 #ifdef AB_REPEAT_ENABLE
149 if ( ab_repeat_mode_enabled() && state
->id3
->length
!= 0 )
150 ab_draw_markers(display
, state
->id3
->length
,
151 pb
->x
, pb
->x
+ pb
->width
, y
, pb
->height
);
154 if (state
->id3
->cuesheet
)
155 cue_draw_markers(display
, state
->id3
->cuesheet
, state
->id3
->length
,
156 pb
->x
, pb
->x
+ pb
->width
, y
+1, pb
->height
-2);
159 /* clears the area where the image was shown */
160 static void clear_image_pos(struct gui_wps
*gwps
, int n
)
164 struct wps_data
*data
= gwps
->data
;
165 gwps
->display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
166 gwps
->display
->fillrect(data
->img
[n
].x
, data
->img
[n
].y
,
167 data
->img
[n
].bm
.width
, data
->img
[n
].subimage_height
);
168 gwps
->display
->set_drawmode(DRMODE_SOLID
);
171 static void wps_draw_image(struct gui_wps
*gwps
, int n
, int subimage
)
173 struct screen
*display
= gwps
->display
;
174 struct wps_data
*data
= gwps
->data
;
175 if(data
->img
[n
].always_display
)
176 display
->set_drawmode(DRMODE_FG
);
178 display
->set_drawmode(DRMODE_SOLID
);
181 if(data
->img
[n
].bm
.format
== FORMAT_MONO
) {
183 display
->mono_bitmap_part(data
->img
[n
].bm
.data
,
184 0, data
->img
[n
].subimage_height
* subimage
,
185 data
->img
[n
].bm
.width
, data
->img
[n
].x
,
186 data
->img
[n
].y
, data
->img
[n
].bm
.width
,
187 data
->img
[n
].subimage_height
);
190 display
->transparent_bitmap_part((fb_data
*)data
->img
[n
].bm
.data
,
191 0, data
->img
[n
].subimage_height
* subimage
,
192 data
->img
[n
].bm
.width
, data
->img
[n
].x
,
193 data
->img
[n
].y
, data
->img
[n
].bm
.width
,
194 data
->img
[n
].subimage_height
);
199 static void wps_display_images(struct gui_wps
*gwps
, struct viewport
* vp
)
201 if(!gwps
|| !gwps
->data
|| !gwps
->display
)
205 struct wps_data
*data
= gwps
->data
;
206 struct screen
*display
= gwps
->display
;
208 for (n
= 0; n
< MAX_IMAGES
; n
++)
210 if (data
->img
[n
].loaded
)
212 if (data
->img
[n
].display
>= 0)
214 wps_draw_image(gwps
, n
, data
->img
[n
].display
);
215 } else if (data
->img
[n
].always_display
&& data
->img
[n
].vp
== vp
)
217 wps_draw_image(gwps
, n
, 0);
221 display
->set_drawmode(DRMODE_SOLID
);
224 #else /* HAVE_LCD_CHARCELL */
226 static bool draw_player_progress(struct gui_wps
*gwps
)
228 struct wps_state
*state
= gwps
->state
;
229 struct screen
*display
= gwps
->display
;
230 unsigned char progress_pattern
[7];
237 if (state
->id3
->length
)
238 pos
= 36 * (state
->id3
->elapsed
+ state
->ff_rewind_count
)
239 / state
->id3
->length
;
241 for (i
= 0; i
< 7; i
++, pos
-= 5)
244 progress_pattern
[i
] = 0x1fu
;
246 progress_pattern
[i
] = 0x00u
;
248 progress_pattern
[i
] = 0x1fu
>> pos
;
251 display
->define_pattern(gwps
->data
->wps_progress_pat
[0], progress_pattern
);
255 static void draw_player_fullbar(struct gui_wps
*gwps
, char* buf
, int buf_size
)
257 static const unsigned char numbers
[10][4] = {
258 {0x0e, 0x0a, 0x0a, 0x0e}, /* 0 */
259 {0x04, 0x0c, 0x04, 0x04}, /* 1 */
260 {0x0e, 0x02, 0x04, 0x0e}, /* 2 */
261 {0x0e, 0x02, 0x06, 0x0e}, /* 3 */
262 {0x08, 0x0c, 0x0e, 0x04}, /* 4 */
263 {0x0e, 0x0c, 0x02, 0x0c}, /* 5 */
264 {0x0e, 0x08, 0x0e, 0x0e}, /* 6 */
265 {0x0e, 0x02, 0x04, 0x08}, /* 7 */
266 {0x0e, 0x0e, 0x0a, 0x0e}, /* 8 */
267 {0x0e, 0x0e, 0x02, 0x0e}, /* 9 */
270 struct wps_state
*state
= gwps
->state
;
271 struct screen
*display
= gwps
->display
;
272 struct wps_data
*data
= gwps
->data
;
273 unsigned char progress_pattern
[7];
282 if (!state
->id3
|| buf_size
< 34) /* worst case: 11x UTF-8 char + \0 */
285 time
= state
->id3
->elapsed
+ state
->ff_rewind_count
;
286 if (state
->id3
->length
)
287 pos
= 55 * time
/ state
->id3
->length
;
289 memset(timestr
, 0, sizeof(timestr
));
290 format_time(timestr
, sizeof(timestr
)-2, time
);
291 timestr
[strlen(timestr
)] = ':'; /* always safe */
293 for (i
= 0; i
< 11; i
++, pos
-= 5)
296 memset(progress_pattern
, 0, sizeof(progress_pattern
));
298 if ((digit
= timestr
[time_idx
]))
303 if (timestr
[time_idx
+ 1] == ':') /* ones, left aligned */
305 memcpy(progress_pattern
, numbers
[digit
], 4);
308 else /* tens, shifted right */
310 for (j
= 0; j
< 4; j
++)
311 progress_pattern
[j
] = numbers
[digit
][j
] >> 1;
313 if (time_idx
> 0) /* not the first group, add colon in front */
315 progress_pattern
[1] |= 0x10u
;
316 progress_pattern
[3] |= 0x10u
;
322 progress_pattern
[5] = progress_pattern
[6] = 0x1fu
;
325 if (pos
> 0 && pos
< 5)
328 progress_pattern
[5] = progress_pattern
[6] = (~0x1fu
>> pos
) & 0x1fu
;
331 if (softchar
&& pat_idx
< 8)
333 display
->define_pattern(data
->wps_progress_pat
[pat_idx
],
335 buf
= utf8encode(data
->wps_progress_pat
[pat_idx
], buf
);
339 buf
= utf8encode(' ', buf
);
341 buf
= utf8encode(0xe115, buf
); /* 2/7 _ */
346 #endif /* HAVE_LCD_CHARCELL */
348 /* Return the index to the end token for the conditional token at index.
349 The conditional token can be either a start token or a separator
352 static int find_conditional_end(struct wps_data
*data
, int index
)
355 while (data
->tokens
[ret
].type
!= WPS_TOKEN_CONDITIONAL_END
)
356 ret
= data
->tokens
[ret
].value
.i
;
358 /* ret now is the index to the end token for the conditional. */
362 /* Evaluate the conditional that is at *token_index and return whether a skip
363 has ocurred. *token_index is updated with the new position.
365 static bool evaluate_conditional(struct gui_wps
*gwps
, int *token_index
)
370 struct wps_data
*data
= gwps
->data
;
373 int cond_index
= *token_index
;
376 unsigned char num_options
= data
->tokens
[cond_index
].value
.i
& 0xFF;
377 unsigned char prev_val
= (data
->tokens
[cond_index
].value
.i
& 0xFF00) >> 8;
379 /* treat ?xx<true> constructs as if they had 2 options. */
383 int intval
= num_options
;
384 /* get_token_value needs to know the number of options in the enum */
385 value
= get_token_value(gwps
, &data
->tokens
[cond_index
+ 1],
386 result
, sizeof(result
), &intval
);
388 /* intval is now the number of the enum option we want to read,
389 starting from 1. If intval is -1, we check if value is empty. */
391 intval
= (value
&& *value
) ? 1 : num_options
;
392 else if (intval
> num_options
|| intval
< 1)
393 intval
= num_options
;
395 data
->tokens
[cond_index
].value
.i
= (intval
<< 8) + num_options
;
397 /* skip to the appropriate enum case */
398 int next
= cond_index
+ 2;
399 for (i
= 1; i
< intval
; i
++)
401 next
= data
->tokens
[next
].value
.i
;
405 if (prev_val
== intval
)
407 /* Same conditional case as previously. Return without clearing the
412 cond_end
= find_conditional_end(data
, cond_index
+ 2);
413 for (i
= cond_index
+ 3; i
< cond_end
; i
++)
415 #ifdef HAVE_LCD_BITMAP
416 /* clear all pictures in the conditional and nested ones */
417 if (data
->tokens
[i
].type
== WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
)
418 clear_image_pos(gwps
, data
->tokens
[i
].value
.i
& 0xFF);
421 if (data
->tokens
[i
].type
== WPS_TOKEN_ALBUMART_DISPLAY
)
422 draw_album_art(gwps
, audio_current_aa_hid(), true);
429 /* Read a (sub)line to the given alignment format buffer.
430 linebuf is the buffer where the data is actually stored.
431 align is the alignment format that'll be used to display the text.
432 The return value indicates whether the line needs to be updated.
434 static bool get_line(struct gui_wps
*gwps
,
435 int line
, int subline
,
436 struct align_pos
*align
,
440 struct wps_data
*data
= gwps
->data
;
443 char *buf
= linebuf
; /* will always point to the writing position */
444 char *linebuf_end
= linebuf
+ linebuf_size
- 1;
445 int i
, last_token_idx
;
448 /* alignment-related variables */
450 char* cur_align_start
;
451 cur_align_start
= buf
;
452 cur_align
= WPS_ALIGN_LEFT
;
454 align
->center
= NULL
;
457 /* Process all tokens of the desired subline */
458 last_token_idx
= wps_last_token_index(data
, line
, subline
);
459 for (i
= wps_first_token_index(data
, line
, subline
);
460 i
<= last_token_idx
; i
++)
462 switch(data
->tokens
[i
].type
)
464 case WPS_TOKEN_CONDITIONAL
:
465 /* place ourselves in the right conditional case */
466 update
|= evaluate_conditional(gwps
, &i
);
469 case WPS_TOKEN_CONDITIONAL_OPTION
:
470 /* we've finished in the curent conditional case,
471 skip to the end of the conditional structure */
472 i
= find_conditional_end(data
, i
);
475 #ifdef HAVE_LCD_BITMAP
476 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
:
478 struct gui_img
*img
= data
->img
;
479 int n
= data
->tokens
[i
].value
.i
& 0xFF;
480 int subimage
= data
->tokens
[i
].value
.i
>> 8;
482 if (n
>= 0 && n
< MAX_IMAGES
&& img
[n
].loaded
)
483 img
[n
].display
= subimage
;
488 case WPS_TOKEN_ALIGN_LEFT
:
489 case WPS_TOKEN_ALIGN_CENTER
:
490 case WPS_TOKEN_ALIGN_RIGHT
:
491 /* remember where the current aligned text started */
495 align
->left
= cur_align_start
;
498 case WPS_ALIGN_CENTER
:
499 align
->center
= cur_align_start
;
502 case WPS_ALIGN_RIGHT
:
503 align
->right
= cur_align_start
;
506 /* start a new alignment */
507 switch (data
->tokens
[i
].type
)
509 case WPS_TOKEN_ALIGN_LEFT
:
510 cur_align
= WPS_ALIGN_LEFT
;
512 case WPS_TOKEN_ALIGN_CENTER
:
513 cur_align
= WPS_ALIGN_CENTER
;
515 case WPS_TOKEN_ALIGN_RIGHT
:
516 cur_align
= WPS_ALIGN_RIGHT
;
522 cur_align_start
= buf
;
524 case WPS_VIEWPORT_ENABLE
:
526 char label
= data
->tokens
[i
].value
.i
;
528 char temp
= VP_DRAW_HIDEABLE
;
529 for(j
=0;j
<data
->num_viewports
;j
++)
531 temp
= VP_DRAW_HIDEABLE
;
532 if ((data
->viewports
[j
].hidden_flags
&VP_DRAW_HIDEABLE
) &&
533 (data
->viewports
[j
].label
== label
))
535 if (data
->viewports
[j
].hidden_flags
&VP_DRAW_WASHIDDEN
)
536 temp
|= VP_DRAW_WASHIDDEN
;
537 data
->viewports
[j
].hidden_flags
= temp
;
544 /* get the value of the tag and copy it to the buffer */
545 const char *value
= get_token_value(gwps
, &data
->tokens
[i
],
546 temp_buf
, sizeof(temp_buf
), NULL
);
550 while (*value
&& (buf
< linebuf_end
))
558 /* close the current alignment */
562 align
->left
= cur_align_start
;
565 case WPS_ALIGN_CENTER
:
566 align
->center
= cur_align_start
;
569 case WPS_ALIGN_RIGHT
:
570 align
->right
= cur_align_start
;
577 static void get_subline_timeout(struct gui_wps
*gwps
, int line
, int subline
)
579 struct wps_data
*data
= gwps
->data
;
581 int subline_idx
= wps_subline_index(data
, line
, subline
);
582 int last_token_idx
= wps_last_token_index(data
, line
, subline
);
584 data
->sublines
[subline_idx
].time_mult
= DEFAULT_SUBLINE_TIME_MULTIPLIER
;
586 for (i
= wps_first_token_index(data
, line
, subline
);
587 i
<= last_token_idx
; i
++)
589 switch(data
->tokens
[i
].type
)
591 case WPS_TOKEN_CONDITIONAL
:
592 /* place ourselves in the right conditional case */
593 evaluate_conditional(gwps
, &i
);
596 case WPS_TOKEN_CONDITIONAL_OPTION
:
597 /* we've finished in the curent conditional case,
598 skip to the end of the conditional structure */
599 i
= find_conditional_end(data
, i
);
602 case WPS_TOKEN_SUBLINE_TIMEOUT
:
603 data
->sublines
[subline_idx
].time_mult
= data
->tokens
[i
].value
.i
;
612 /* Calculates which subline should be displayed for the specified line
613 Returns true iff the subline must be refreshed */
614 static bool update_curr_subline(struct gui_wps
*gwps
, int line
)
616 struct wps_data
*data
= gwps
->data
;
618 int search
, search_start
, num_sublines
;
620 bool new_subline_refresh
;
621 bool only_one_subline
;
623 num_sublines
= data
->lines
[line
].num_sublines
;
624 reset_subline
= (data
->lines
[line
].curr_subline
== SUBLINE_RESET
);
625 new_subline_refresh
= false;
626 only_one_subline
= false;
628 /* if time to advance to next sub-line */
629 if (TIME_AFTER(current_tick
, data
->lines
[line
].subline_expire_time
- 1) ||
632 /* search all sublines until the next subline with time > 0
633 is found or we get back to the subline we started with */
637 search_start
= data
->lines
[line
].curr_subline
;
639 for (search
= 0; search
< num_sublines
; search
++)
641 data
->lines
[line
].curr_subline
++;
643 /* wrap around if beyond last defined subline or WPS_MAX_SUBLINES */
644 if (data
->lines
[line
].curr_subline
== num_sublines
)
646 if (data
->lines
[line
].curr_subline
== 1)
647 only_one_subline
= true;
648 data
->lines
[line
].curr_subline
= 0;
651 /* if back where we started after search or
652 only one subline is defined on the line */
654 (data
->lines
[line
].curr_subline
== search_start
)) ||
657 /* no other subline with a time > 0 exists */
658 data
->lines
[line
].subline_expire_time
= (reset_subline
?
660 data
->lines
[line
].subline_expire_time
) + 100 * HZ
;
665 /* get initial time multiplier for this subline */
666 get_subline_timeout(gwps
, line
, data
->lines
[line
].curr_subline
);
668 int subline_idx
= wps_subline_index(data
, line
,
669 data
->lines
[line
].curr_subline
);
671 /* only use this subline if subline time > 0 */
672 if (data
->sublines
[subline_idx
].time_mult
> 0)
674 new_subline_refresh
= true;
675 data
->lines
[line
].subline_expire_time
= (reset_subline
?
676 current_tick
: data
->lines
[line
].subline_expire_time
) +
677 TIMEOUT_UNIT
*data
->sublines
[subline_idx
].time_mult
;
684 return new_subline_refresh
;
687 /* Display a line appropriately according to its alignment format.
688 format_align contains the text, separated between left, center and right.
689 line is the index of the line on the screen.
690 scroll indicates whether the line is a scrolling one or not.
692 static void write_line(struct screen
*display
,
693 struct align_pos
*format_align
,
697 int left_width
= 0, left_xpos
;
698 int center_width
= 0, center_xpos
;
699 int right_width
= 0, right_xpos
;
705 /* calculate different string sizes and positions */
706 display
->getstringsize((unsigned char *)" ", &space_width
, &string_height
);
707 if (format_align
->left
!= 0) {
708 display
->getstringsize((unsigned char *)format_align
->left
,
709 &left_width
, &string_height
);
712 if (format_align
->right
!= 0) {
713 display
->getstringsize((unsigned char *)format_align
->right
,
714 &right_width
, &string_height
);
717 if (format_align
->center
!= 0) {
718 display
->getstringsize((unsigned char *)format_align
->center
,
719 ¢er_width
, &string_height
);
723 right_xpos
= (display
->getwidth() - right_width
);
724 center_xpos
= (display
->getwidth() + left_xpos
- center_width
) / 2;
726 scroll_width
= display
->getwidth() - left_xpos
;
728 /* Checks for overlapping strings.
729 If needed the overlapping strings will be merged, separated by a
732 /* CASE 1: left and centered string overlap */
733 /* there is a left string, need to merge left and center */
734 if ((left_width
!= 0 && center_width
!= 0) &&
735 (left_xpos
+ left_width
+ space_width
> center_xpos
)) {
736 /* replace the former separator '\0' of left and
737 center string with a space */
738 *(--format_align
->center
) = ' ';
739 /* calculate the new width and position of the merged string */
740 left_width
= left_width
+ space_width
+ center_width
;
741 /* there is no centered string anymore */
744 /* there is no left string, move center to left */
745 if ((left_width
== 0 && center_width
!= 0) &&
746 (left_xpos
+ left_width
> center_xpos
)) {
747 /* move the center string to the left string */
748 format_align
->left
= format_align
->center
;
749 /* calculate the new width and position of the string */
750 left_width
= center_width
;
751 /* there is no centered string anymore */
755 /* CASE 2: centered and right string overlap */
756 /* there is a right string, need to merge center and right */
757 if ((center_width
!= 0 && right_width
!= 0) &&
758 (center_xpos
+ center_width
+ space_width
> right_xpos
)) {
759 /* replace the former separator '\0' of center and
760 right string with a space */
761 *(--format_align
->right
) = ' ';
762 /* move the center string to the right after merge */
763 format_align
->right
= format_align
->center
;
764 /* calculate the new width and position of the merged string */
765 right_width
= center_width
+ space_width
+ right_width
;
766 right_xpos
= (display
->getwidth() - right_width
);
767 /* there is no centered string anymore */
770 /* there is no right string, move center to right */
771 if ((center_width
!= 0 && right_width
== 0) &&
772 (center_xpos
+ center_width
> right_xpos
)) {
773 /* move the center string to the right string */
774 format_align
->right
= format_align
->center
;
775 /* calculate the new width and position of the string */
776 right_width
= center_width
;
777 right_xpos
= (display
->getwidth() - right_width
);
778 /* there is no centered string anymore */
782 /* CASE 3: left and right overlap
783 There is no center string anymore, either there never
784 was one or it has been merged in case 1 or 2 */
785 /* there is a left string, need to merge left and right */
786 if ((left_width
!= 0 && center_width
== 0 && right_width
!= 0) &&
787 (left_xpos
+ left_width
+ space_width
> right_xpos
)) {
788 /* replace the former separator '\0' of left and
789 right string with a space */
790 *(--format_align
->right
) = ' ';
791 /* calculate the new width and position of the string */
792 left_width
= left_width
+ space_width
+ right_width
;
793 /* there is no right string anymore */
796 /* there is no left string, move right to left */
797 if ((left_width
== 0 && center_width
== 0 && right_width
!= 0) &&
798 (left_width
> right_xpos
)) {
799 /* move the right string to the left string */
800 format_align
->left
= format_align
->right
;
801 /* calculate the new width and position of the string */
802 left_width
= right_width
;
803 /* there is no right string anymore */
807 ypos
= (line
* string_height
);
810 if (scroll
&& ((left_width
> scroll_width
) ||
811 (center_width
> scroll_width
) ||
812 (right_width
> scroll_width
)))
814 display
->puts_scroll(0, line
,
815 (unsigned char *)format_align
->left
);
819 #ifdef HAVE_LCD_BITMAP
820 /* clear the line first */
821 display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
822 display
->fillrect(left_xpos
, ypos
, display
->getwidth(), string_height
);
823 display
->set_drawmode(DRMODE_SOLID
);
826 /* Nasty hack: we output an empty scrolling string,
827 which will reset the scroller for that line */
828 display
->puts_scroll(0, line
, (unsigned char *)"");
830 /* print aligned strings */
833 display
->putsxy(left_xpos
, ypos
,
834 (unsigned char *)format_align
->left
);
836 if (center_width
!= 0)
838 display
->putsxy(center_xpos
, ypos
,
839 (unsigned char *)format_align
->center
);
841 if (right_width
!= 0)
843 display
->putsxy(right_xpos
, ypos
,
844 (unsigned char *)format_align
->right
);
849 static bool gui_wps_redraw(struct gui_wps
*gwps
, unsigned refresh_mode
)
851 struct wps_data
*data
= gwps
->data
;
852 struct screen
*display
= gwps
->display
;
853 struct wps_state
*state
= gwps
->state
;
855 if (!data
|| !state
|| !display
)
858 struct mp3entry
*id3
= state
->id3
;
863 int v
, line
, i
, subline_idx
;
865 char linebuf
[MAX_PATH
];
867 struct align_pos align
;
872 bool update_line
, new_subline_refresh
;
874 #ifdef HAVE_LCD_BITMAP
876 /* to find out wether the peak meter is enabled we
877 assume it wasn't until we find a line that contains
878 the peak meter. We can't use peak_meter_enabled itself
879 because that would mean to turn off the meter thread
880 temporarily. (That shouldn't matter unless yield
881 or sleep is called but who knows...)
883 bool enable_pm
= false;
887 /* reset to first subline if refresh all flag is set */
888 if (refresh_mode
== WPS_REFRESH_ALL
)
890 display
->set_viewport(&data
->viewports
[0].vp
);
891 display
->clear_viewport();
893 for (i
= 0; i
<= data
->num_lines
; i
++)
895 data
->lines
[i
].curr_subline
= SUBLINE_RESET
;
899 #ifdef HAVE_LCD_CHARCELLS
900 for (i
= 0; i
< 8; i
++)
902 if (data
->wps_progress_pat
[i
] == 0)
903 data
->wps_progress_pat
[i
] = display
->get_locked_pattern();
907 /* disable any viewports which are conditionally displayed */
908 for (v
= 0; v
< data
->num_viewports
; v
++)
910 if (data
->viewports
[v
].hidden_flags
&VP_DRAW_HIDEABLE
)
912 if (data
->viewports
[v
].hidden_flags
&VP_DRAW_HIDDEN
)
913 data
->viewports
[v
].hidden_flags
|= VP_DRAW_WASHIDDEN
;
915 data
->viewports
[v
].hidden_flags
|= VP_DRAW_HIDDEN
;
918 for (v
= 0; v
< data
->num_viewports
; v
++)
920 struct wps_viewport
*wps_vp
= &(data
->viewports
[v
]);
921 unsigned vp_refresh_mode
= refresh_mode
;
922 display
->set_viewport(&wps_vp
->vp
);
924 #ifdef HAVE_LCD_BITMAP
925 /* Set images to not to be displayed */
926 for (i
= 0; i
< MAX_IMAGES
; i
++)
928 data
->img
[i
].display
= -1;
931 /* dont redraw the viewport if its disabled */
932 if ((wps_vp
->hidden_flags
&VP_DRAW_HIDDEN
))
934 if (!(wps_vp
->hidden_flags
&VP_DRAW_WASHIDDEN
))
935 display
->scroll_stop(&wps_vp
->vp
);
936 wps_vp
->hidden_flags
|= VP_DRAW_WASHIDDEN
;
939 else if (((wps_vp
->hidden_flags
&
940 (VP_DRAW_WASHIDDEN
|VP_DRAW_HIDEABLE
))
941 == (VP_DRAW_WASHIDDEN
|VP_DRAW_HIDEABLE
)))
943 vp_refresh_mode
= WPS_REFRESH_ALL
;
944 wps_vp
->hidden_flags
= VP_DRAW_HIDEABLE
;
946 if (vp_refresh_mode
== WPS_REFRESH_ALL
)
948 display
->clear_viewport();
951 for (line
= wps_vp
->first_line
;
952 line
<= wps_vp
->last_line
; line
++)
954 memset(linebuf
, 0, sizeof(linebuf
));
957 /* get current subline for the line */
958 new_subline_refresh
= update_curr_subline(gwps
, line
);
960 subline_idx
= wps_subline_index(data
, line
,
961 data
->lines
[line
].curr_subline
);
962 flags
= data
->sublines
[subline_idx
].line_type
;
964 if (vp_refresh_mode
== WPS_REFRESH_ALL
|| (flags
& vp_refresh_mode
)
965 || new_subline_refresh
)
967 /* get_line tells us if we need to update the line */
968 update_line
= get_line(gwps
, line
, data
->lines
[line
].curr_subline
,
969 &align
, linebuf
, sizeof(linebuf
));
971 #ifdef HAVE_LCD_BITMAP
973 if (flags
& vp_refresh_mode
& WPS_REFRESH_PEAK_METER
)
975 /* the peakmeter should be alone on its line */
978 int h
= font_get(wps_vp
->vp
.font
)->height
;
979 int peak_meter_y
= (line
- wps_vp
->first_line
)* h
;
981 /* The user might decide to have the peak meter in the last
982 line so that it is only displayed if no status bar is
983 visible. If so we neither want do draw nor enable the
985 if (peak_meter_y
+ h
<= display
->getheight()) {
986 /* found a line with a peak meter -> remember that we must
989 peak_meter_enabled
= true;
990 peak_meter_screen(gwps
->display
, 0, peak_meter_y
,
991 MIN(h
, display
->getheight() - peak_meter_y
));
995 peak_meter_enabled
= false;
999 #else /* HAVE_LCD_CHARCELL */
1002 if (flags
& vp_refresh_mode
& WPS_REFRESH_PLAYER_PROGRESS
)
1004 if (data
->full_line_progressbar
)
1005 draw_player_fullbar(gwps
, linebuf
, sizeof(linebuf
));
1007 draw_player_progress(gwps
);
1012 /* conditionals clear the line which means if the %Vd is put into the default
1013 viewport there will be a blank line.
1014 To get around this we dont allow any actual drawing to happen in the
1015 deault vp if other vp's are defined */
1016 ((data
->num_viewports
>1 && v
!=0) || data
->num_viewports
== 1))
1018 if (flags
& WPS_REFRESH_SCROLL
)
1020 /* if the line is a scrolling one we don't want to update
1021 too often, so that it has the time to scroll */
1022 if ((vp_refresh_mode
& WPS_REFRESH_SCROLL
) || new_subline_refresh
)
1023 write_line(display
, &align
, line
- wps_vp
->first_line
, true);
1026 write_line(display
, &align
, line
- wps_vp
->first_line
, false);
1030 #ifdef HAVE_LCD_BITMAP
1032 if (vp_refresh_mode
& WPS_REFRESH_PLAYER_PROGRESS
)
1036 draw_progressbar(gwps
, wps_vp
);
1039 /* Now display any images in this viewport */
1040 wps_display_images(gwps
, &wps_vp
->vp
);
1044 #ifdef HAVE_LCD_BITMAP
1045 data
->peak_meter_enabled
= enable_pm
;
1048 if (refresh_mode
& WPS_REFRESH_STATUSBAR
)
1050 gwps_draw_statusbars();
1052 /* Restore the default viewport */
1053 display
->set_viewport(NULL
);