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 ****************************************************************************/
24 #include "string-extra.h"
28 #include "rbunicode.h"
30 #include "powermgmt.h"
38 #include "statusbar.h"
40 #include "scrollbar.h"
41 #include "screen_access.h"
46 #ifdef HAVE_LCD_BITMAP
47 #include "peakmeter.h"
56 #if CONFIG_CODEC == SWCODEC
65 #include "root_menu.h"
68 #include "wps_internals.h"
69 #include "skin_engine.h"
70 #include "statusbar-skinned.h"
72 static bool skin_redraw(struct gui_wps
*gwps
, unsigned refresh_mode
);
74 /* update a skinned screen, update_type is WPS_REFRESH_* values.
75 * Usually it should only be WPS_REFRESH_NON_STATIC
76 * A full update will be done if required (state.do_full_update == true)
78 bool skin_update(struct gui_wps
*gwps
, unsigned int update_type
)
81 /* This maybe shouldnt be here, but while the skin is only used to
82 * display the music screen this is better than whereever we are being
83 * called from. This is also safe for skined screen which dont use the id3 */
84 struct mp3entry
*id3
= gwps
->state
->id3
;
85 bool cuesheet_update
= (id3
!= NULL
? cuesheet_subtrack_changed(id3
) : false);
86 gwps
->sync_data
->do_full_update
|= cuesheet_update
;
88 retval
= skin_redraw(gwps
, gwps
->sync_data
->do_full_update
?
89 WPS_REFRESH_ALL
: update_type
);
93 #ifdef HAVE_LCD_BITMAP
95 void skin_statusbar_changed(struct gui_wps
*skin
)
99 struct wps_data
*data
= skin
->data
;
100 const struct screen
*display
= skin
->display
;
101 const int screen
= display
->screen_type
;
103 struct viewport
*vp
= &find_viewport(VP_DEFAULT_LABEL
, data
)->vp
;
104 viewport_set_defaults(vp
, screen
);
106 if (data
->wps_sb_tag
)
107 { /* fix up the default viewport */
108 if (data
->show_sb_on_wps
)
110 if (statusbar_position(screen
) != STATUSBAR_OFF
)
111 return; /* vp is fixed already */
113 vp
->y
= STATUSBAR_HEIGHT
;
114 vp
->height
= display
->lcdheight
- STATUSBAR_HEIGHT
;
118 if (statusbar_position(screen
) == STATUSBAR_OFF
)
119 return; /* vp is fixed already */
121 vp
->height
= display
->lcdheight
;
122 vp
->width
= display
->lcdwidth
;
127 static void draw_progressbar(struct gui_wps
*gwps
,
128 struct progressbar
*pb
)
130 struct screen
*display
= gwps
->display
;
131 struct viewport
*vp
= pb
->vp
;
132 struct wps_state
*state
= gwps
->state
;
133 struct mp3entry
*id3
= state
->id3
;
134 int y
= pb
->y
, height
= pb
->height
;
135 unsigned long length
, elapsed
;
138 height
= font_get(vp
->font
)->height
;
142 int line_height
= font_get(vp
->font
)->height
;
143 /* center the pb in the line, but only if the line is higher than the pb */
144 int center
= (line_height
-height
)/2;
145 /* if Y was not set calculate by font height,Y is -line_number-1 */
146 y
= (-y
-1)*line_height
+ (0 > center
? 0 : center
);
149 if (pb
->type
== WPS_TOKEN_VOLUMEBAR
)
151 int minvol
= sound_min(SOUND_VOLUME
);
152 int maxvol
= sound_max(SOUND_VOLUME
);
153 length
= maxvol
-minvol
;
154 elapsed
= global_settings
.volume
-minvol
;
156 else if (pb
->type
== WPS_TOKEN_BATTERY_PERCENTBAR
)
159 elapsed
= battery_level();
161 else if (id3
&& id3
->length
)
163 length
= id3
->length
;
164 elapsed
= id3
->elapsed
+ state
->ff_rewind_count
;
167 else if (in_radio_screen() || (get_radio_status() != FMRADIO_OFF
))
169 int min
= fm_region_data
[global_settings
.fm_region
].freq_min
;
170 elapsed
= radio_current_frequency() - min
;
171 length
= fm_region_data
[global_settings
.fm_region
].freq_max
- min
;
180 if (pb
->have_bitmap_pb
)
181 gui_bitmap_scrollbar_draw(display
, pb
->bm
,
182 pb
->x
, y
, pb
->width
, pb
->bm
.height
,
183 length
, 0, elapsed
, HORIZONTAL
);
185 gui_scrollbar_draw(display
, pb
->x
, y
, pb
->width
, height
,
186 length
, 0, elapsed
, HORIZONTAL
);
188 if (pb
->type
== WPS_TOKEN_PROGRESSBAR
&& id3
&& id3
->length
)
190 #ifdef AB_REPEAT_ENABLE
191 if (ab_repeat_mode_enabled())
192 ab_draw_markers(display
, id3
->length
,
193 pb
->x
, y
, pb
->width
, height
);
197 cue_draw_markers(display
, id3
->cuesheet
, id3
->length
,
198 pb
->x
, y
+1, pb
->width
, height
-2);
202 static void draw_playlist_viewer_list(struct gui_wps
*gwps
,
203 struct playlistviewer
*viewer
)
205 struct wps_state
*state
= gwps
->state
;
206 int lines
= viewport_get_nb_lines(viewer
->vp
);
207 int line_height
= font_get(viewer
->vp
->font
)->height
;
211 struct wps_token token
;
212 int x
, length
, alignment
= WPS_TOKEN_ALIGN_LEFT
;
214 struct mp3entry
*pid3
;
215 char buf
[MAX_PATH
*2], tempbuf
[MAX_PATH
];
216 const char *filename
;
218 if (current_screen() == GO_TO_FM
)
220 cur_pos
= radio_current_preset();
221 count
= radio_preset_count();
226 cur_pos
= playlist_get_display_index();
227 count
= playlist_amount()+1;
229 start_item
= MAX(0, cur_pos
+ viewer
->start_offset
);
231 gwps
->display
->set_viewport(viewer
->vp
);
232 for(i
=start_item
; (i
-start_item
)<lines
&& i
<count
; i
++)
236 if (current_screen() == GO_TO_FM
)
239 line
= TRACK_HAS_INFO
;
245 filename
= playlist_peek(i
-cur_pos
);
250 else if (i
== cur_pos
+1)
254 #if CONFIG_CODEC == SWCODEC
257 #ifdef HAVE_TC_RAMCACHE
258 if (tagcache_fill_tags(&viewer
->tempid3
, filename
))
260 pid3
= &viewer
->tempid3
;
264 if (!audio_peek_track(&pid3
, i
-cur_pos
))
272 line
= pid3
? TRACK_HAS_INFO
: TRACK_HAS_NO_INFO
;
274 int j
= 0, cur_string
= 0;
275 unsigned int line_len
= 0;
277 while (j
< viewer
->lines
[line
].count
&& line_len
< sizeof(buf
))
279 const char *out
= NULL
;
280 token
.type
= viewer
->lines
[line
].tokens
[j
];
283 out
= get_id3_token(&token
, pid3
, tempbuf
, sizeof(tempbuf
), -1, NULL
);
286 out
= get_radio_token(&token
, i
-cur_pos
,
287 tempbuf
, sizeof(tempbuf
), -1, NULL
);
291 line_len
= strlcat(buf
, out
, sizeof(buf
));
296 switch (viewer
->lines
[line
].tokens
[j
])
298 case WPS_TOKEN_ALIGN_CENTER
:
299 case WPS_TOKEN_ALIGN_LEFT
:
300 case WPS_TOKEN_ALIGN_LEFT_RTL
:
301 case WPS_TOKEN_ALIGN_RIGHT
:
302 case WPS_TOKEN_ALIGN_RIGHT_RTL
:
303 alignment
= viewer
->lines
[line
].tokens
[j
];
306 case WPS_TOKEN_STRING
:
307 case WPS_TOKEN_CHARACTER
:
308 snprintf(tempbuf
, sizeof(tempbuf
), "%s",
309 viewer
->lines
[line
].strings
[cur_string
]);
312 case WPS_TOKEN_PLAYLIST_POSITION
:
313 snprintf(tempbuf
, sizeof(tempbuf
), "%d", i
);
315 case WPS_TOKEN_FILE_NAME
:
316 get_dir(tempbuf
, sizeof(tempbuf
), filename
, 0);
318 case WPS_TOKEN_FILE_PATH
:
319 snprintf(tempbuf
, sizeof(tempbuf
), "%s", filename
);
327 line_len
= strlcat(buf
, tempbuf
, sizeof(buf
));
332 int vpwidth
= viewer
->vp
->width
;
333 length
= gwps
->display
->getstringsize(buf
, NULL
, NULL
);
334 if (viewer
->lines
[line
].scroll
&& length
>= vpwidth
)
336 gwps
->display
->puts_scroll(0, (i
-start_item
), buf
);
340 if (length
>= vpwidth
)
346 case WPS_TOKEN_ALIGN_CENTER
:
347 x
= (vpwidth
-length
)/2;
349 case WPS_TOKEN_ALIGN_LEFT_RTL
:
350 if (lang_is_rtl() && VP_IS_RTL(viewer
->vp
))
352 x
= vpwidth
- length
;
355 case WPS_TOKEN_ALIGN_LEFT
:
358 case WPS_TOKEN_ALIGN_RIGHT_RTL
:
359 if (lang_is_rtl() && VP_IS_RTL(viewer
->vp
))
364 case WPS_TOKEN_ALIGN_RIGHT
:
365 x
= vpwidth
- length
;
372 gwps
->display
->putsxy(x
, (i
-start_item
)*line_height
, buf
);
378 /* clears the area where the image was shown */
379 static void clear_image_pos(struct gui_wps
*gwps
, struct gui_img
*img
)
383 gwps
->display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
384 gwps
->display
->fillrect(img
->x
, img
->y
, img
->bm
.width
, img
->subimage_height
);
385 gwps
->display
->set_drawmode(DRMODE_SOLID
);
388 static void wps_draw_image(struct gui_wps
*gwps
, struct gui_img
*img
, int subimage
)
390 struct screen
*display
= gwps
->display
;
391 if(img
->always_display
)
392 display
->set_drawmode(DRMODE_FG
);
394 display
->set_drawmode(DRMODE_SOLID
);
397 if(img
->bm
.format
== FORMAT_MONO
) {
399 display
->mono_bitmap_part(img
->bm
.data
,
400 0, img
->subimage_height
* subimage
,
401 img
->bm
.width
, img
->x
,
402 img
->y
, img
->bm
.width
,
403 img
->subimage_height
);
406 display
->transparent_bitmap_part((fb_data
*)img
->bm
.data
,
407 0, img
->subimage_height
* subimage
,
408 STRIDE(display
->screen_type
,
409 img
->bm
.width
, img
->bm
.height
),
410 img
->x
, img
->y
, img
->bm
.width
,
411 img
->subimage_height
);
416 static void wps_display_images(struct gui_wps
*gwps
, struct viewport
* vp
)
418 if(!gwps
|| !gwps
->data
|| !gwps
->display
)
421 struct wps_data
*data
= gwps
->data
;
422 struct screen
*display
= gwps
->display
;
423 struct skin_token_list
*list
= data
->images
;
427 struct gui_img
*img
= (struct gui_img
*)list
->token
->value
.data
;
430 if (img
->display
>= 0)
432 wps_draw_image(gwps
, img
, img
->display
);
434 else if (img
->always_display
&& img
->vp
== vp
)
436 wps_draw_image(gwps
, img
, 0);
442 /* now draw the AA */
443 if (data
->albumart
&& data
->albumart
->vp
== vp
444 && data
->albumart
->draw
)
446 draw_album_art(gwps
, playback_current_aa_hid(data
->playback_aa_slot
),
448 data
->albumart
->draw
= false;
452 display
->set_drawmode(DRMODE_SOLID
);
455 #else /* HAVE_LCD_CHARCELL */
457 static bool draw_player_progress(struct gui_wps
*gwps
)
459 struct wps_state
*state
= gwps
->state
;
460 struct screen
*display
= gwps
->display
;
461 unsigned char progress_pattern
[7];
466 if (LIKELY(state
->id3
))
468 elapsed
= state
->id3
->elapsed
;
469 length
= state
->id3
->length
;
478 pos
= 36 * (elapsed
+ state
->ff_rewind_count
) / length
;
480 for (i
= 0; i
< 7; i
++, pos
-= 5)
483 progress_pattern
[i
] = 0x1fu
;
485 progress_pattern
[i
] = 0x00u
;
487 progress_pattern
[i
] = 0x1fu
>> pos
;
490 display
->define_pattern(gwps
->data
->wps_progress_pat
[0], progress_pattern
);
494 static void draw_player_fullbar(struct gui_wps
*gwps
, char* buf
, int buf_size
)
496 static const unsigned char numbers
[10][4] = {
497 {0x0e, 0x0a, 0x0a, 0x0e}, /* 0 */
498 {0x04, 0x0c, 0x04, 0x04}, /* 1 */
499 {0x0e, 0x02, 0x04, 0x0e}, /* 2 */
500 {0x0e, 0x02, 0x06, 0x0e}, /* 3 */
501 {0x08, 0x0c, 0x0e, 0x04}, /* 4 */
502 {0x0e, 0x0c, 0x02, 0x0c}, /* 5 */
503 {0x0e, 0x08, 0x0e, 0x0e}, /* 6 */
504 {0x0e, 0x02, 0x04, 0x08}, /* 7 */
505 {0x0e, 0x0e, 0x0a, 0x0e}, /* 8 */
506 {0x0e, 0x0e, 0x02, 0x0e}, /* 9 */
509 struct wps_state
*state
= gwps
->state
;
510 struct screen
*display
= gwps
->display
;
511 struct wps_data
*data
= gwps
->data
;
512 unsigned char progress_pattern
[7];
522 if (LIKELY(state
->id3
))
524 elapsed
= state
->id3
->elapsed
;
525 length
= state
->id3
->length
;
533 if (buf_size
< 34) /* worst case: 11x UTF-8 char + \0 */
536 time
= elapsed
+ state
->ff_rewind_count
;
538 pos
= 55 * time
/ length
;
540 memset(timestr
, 0, sizeof(timestr
));
541 format_time(timestr
, sizeof(timestr
)-2, time
);
542 timestr
[strlen(timestr
)] = ':'; /* always safe */
544 for (i
= 0; i
< 11; i
++, pos
-= 5)
547 memset(progress_pattern
, 0, sizeof(progress_pattern
));
549 if ((digit
= timestr
[time_idx
]))
554 if (timestr
[time_idx
+ 1] == ':') /* ones, left aligned */
556 memcpy(progress_pattern
, numbers
[digit
], 4);
559 else /* tens, shifted right */
561 for (j
= 0; j
< 4; j
++)
562 progress_pattern
[j
] = numbers
[digit
][j
] >> 1;
564 if (time_idx
> 0) /* not the first group, add colon in front */
566 progress_pattern
[1] |= 0x10u
;
567 progress_pattern
[3] |= 0x10u
;
573 progress_pattern
[5] = progress_pattern
[6] = 0x1fu
;
576 if (pos
> 0 && pos
< 5)
579 progress_pattern
[5] = progress_pattern
[6] = (~0x1fu
>> pos
) & 0x1fu
;
582 if (softchar
&& pat_idx
< 8)
584 display
->define_pattern(data
->wps_progress_pat
[pat_idx
],
586 buf
= utf8encode(data
->wps_progress_pat
[pat_idx
], buf
);
590 buf
= utf8encode(' ', buf
);
592 buf
= utf8encode(0xe115, buf
); /* 2/7 _ */
597 #endif /* HAVE_LCD_CHARCELL */
599 /* Return the index to the end token for the conditional token at index.
600 The conditional token can be either a start token or a separator
603 static int find_conditional_end(struct wps_data
*data
, int index
)
606 while (data
->tokens
[ret
].type
!= WPS_TOKEN_CONDITIONAL_END
)
607 ret
= data
->tokens
[ret
].value
.i
;
609 /* ret now is the index to the end token for the conditional. */
613 /* Evaluate the conditional that is at *token_index and return whether a skip
614 has ocurred. *token_index is updated with the new position.
616 static bool evaluate_conditional(struct gui_wps
*gwps
, int *token_index
)
621 struct wps_data
*data
= gwps
->data
;
624 int cond_index
= *token_index
;
627 unsigned char num_options
= data
->tokens
[cond_index
].value
.i
& 0xFF;
628 unsigned char prev_val
= (data
->tokens
[cond_index
].value
.i
& 0xFF00) >> 8;
630 /* treat ?xx<true> constructs as if they had 2 options. */
634 int intval
= num_options
;
635 /* get_token_value needs to know the number of options in the enum */
636 value
= get_token_value(gwps
, &data
->tokens
[cond_index
+ 1],
637 result
, sizeof(result
), &intval
);
639 /* intval is now the number of the enum option we want to read,
640 starting from 1. If intval is -1, we check if value is empty. */
642 intval
= (value
&& *value
) ? 1 : num_options
;
643 else if (intval
> num_options
|| intval
< 1)
644 intval
= num_options
;
646 data
->tokens
[cond_index
].value
.i
= (intval
<< 8) + num_options
;
648 /* skip to the appropriate enum case */
649 int next
= cond_index
+ 2;
650 for (i
= 1; i
< intval
; i
++)
652 next
= data
->tokens
[next
].value
.i
;
656 if (prev_val
== intval
)
658 /* Same conditional case as previously. Return without clearing the
663 cond_end
= find_conditional_end(data
, cond_index
+ 2);
664 for (i
= cond_index
+ 3; i
< cond_end
; i
++)
666 #ifdef HAVE_LCD_BITMAP
667 /* clear all pictures in the conditional and nested ones */
668 if (data
->tokens
[i
].type
== WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
)
669 clear_image_pos(gwps
, find_image(data
->tokens
[i
].value
.i
&0xFF, data
));
670 else if (data
->tokens
[i
].type
== WPS_TOKEN_VOLUMEBAR
||
671 data
->tokens
[i
].type
== WPS_TOKEN_PROGRESSBAR
||
672 data
->tokens
[i
].type
== WPS_TOKEN_BATTERY_PERCENTBAR
)
674 struct progressbar
*bar
= (struct progressbar
*)data
->tokens
[i
].value
.data
;
677 else if (data
->tokens
[i
].type
== WPS_TOKEN_PEAKMETER
)
679 data
->peak_meter_enabled
= false;
683 if (data
->albumart
&& data
->tokens
[i
].type
== WPS_TOKEN_ALBUMART_DISPLAY
)
686 playback_current_aa_hid(data
->playback_aa_slot
), true);
687 data
->albumart
->draw
= false;
696 /* Read a (sub)line to the given alignment format buffer.
697 linebuf is the buffer where the data is actually stored.
698 align is the alignment format that'll be used to display the text.
699 The return value indicates whether the line needs to be updated.
701 static bool get_line(struct gui_wps
*gwps
,
702 struct skin_subline
*subline
,
703 struct align_pos
*align
,
706 unsigned refresh_mode
)
708 struct wps_data
*data
= gwps
->data
;
711 char *buf
= linebuf
; /* will always point to the writing position */
712 char *linebuf_end
= linebuf
+ linebuf_size
- 1;
715 (void)refresh_mode
; /* silence warning on charcell */
717 /* alignment-related variables */
719 char* cur_align_start
;
720 cur_align_start
= buf
;
721 cur_align
= WPS_ALIGN_LEFT
;
723 align
->center
= NULL
;
725 /* Process all tokens of the desired subline */
726 for (i
= subline
->first_token_idx
;
727 i
<= subline
->last_token_idx
; i
++)
729 switch(data
->tokens
[i
].type
)
731 case WPS_TOKEN_CONDITIONAL
:
732 /* place ourselves in the right conditional case */
733 update
|= evaluate_conditional(gwps
, &i
);
736 case WPS_TOKEN_CONDITIONAL_OPTION
:
737 /* we've finished in the curent conditional case,
738 skip to the end of the conditional structure */
739 i
= find_conditional_end(data
, i
);
742 #ifdef HAVE_LCD_BITMAP
743 case WPS_TOKEN_PEAKMETER
:
744 data
->peak_meter_enabled
= true;
746 case WPS_TOKEN_VOLUMEBAR
:
747 case WPS_TOKEN_BATTERY_PERCENTBAR
:
748 case WPS_TOKEN_PROGRESSBAR
:
750 struct progressbar
*bar
= (struct progressbar
*)data
->tokens
[i
].value
.data
;
754 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
:
756 char n
= data
->tokens
[i
].value
.i
& 0xFF;
757 int subimage
= data
->tokens
[i
].value
.i
>> 8;
758 struct gui_img
*img
= find_image(n
, data
);
760 if (img
&& img
->loaded
)
761 img
->display
= subimage
;
764 case WPS_TOKEN_DRAW_INBUILTBAR
:
765 gui_statusbar_draw(&(statusbars
.statusbars
[gwps
->display
->screen_type
]),
766 refresh_mode
== WPS_REFRESH_ALL
,
767 data
->tokens
[i
].value
.data
);
771 case WPS_TOKEN_ALIGN_LEFT
:
772 case WPS_TOKEN_ALIGN_LEFT_RTL
:
773 case WPS_TOKEN_ALIGN_CENTER
:
774 case WPS_TOKEN_ALIGN_RIGHT
:
775 case WPS_TOKEN_ALIGN_RIGHT_RTL
:
776 /* remember where the current aligned text started */
780 align
->left
= cur_align_start
;
783 case WPS_ALIGN_CENTER
:
784 align
->center
= cur_align_start
;
787 case WPS_ALIGN_RIGHT
:
788 align
->right
= cur_align_start
;
791 /* start a new alignment */
792 switch (data
->tokens
[i
].type
)
794 case WPS_TOKEN_ALIGN_LEFT
:
795 cur_align
= WPS_ALIGN_LEFT
;
797 case WPS_TOKEN_ALIGN_LEFT_RTL
:
798 cur_align
= lang_is_rtl() ? WPS_ALIGN_RIGHT
:
801 case WPS_TOKEN_ALIGN_CENTER
:
802 cur_align
= WPS_ALIGN_CENTER
;
804 case WPS_TOKEN_ALIGN_RIGHT
:
805 cur_align
= WPS_ALIGN_RIGHT
;
807 case WPS_TOKEN_ALIGN_RIGHT_RTL
:
808 cur_align
= lang_is_rtl() ? WPS_ALIGN_LEFT
:
815 cur_align_start
= buf
;
817 case WPS_VIEWPORT_ENABLE
:
819 char label
= data
->tokens
[i
].value
.i
;
820 char temp
= VP_DRAW_HIDEABLE
;
821 /* viewports are allowed to share id's so find and enable
823 struct skin_token_list
*list
= data
->viewports
;
826 struct skin_viewport
*vp
=
827 (struct skin_viewport
*)list
->token
->value
.data
;
828 if (vp
->label
== label
)
830 if (vp
->hidden_flags
&VP_DRAW_WASHIDDEN
)
831 temp
|= VP_DRAW_WASHIDDEN
;
832 vp
->hidden_flags
= temp
;
838 #ifdef HAVE_LCD_BITMAP
839 case WPS_TOKEN_UIVIEWPORT_ENABLE
:
840 sb_set_info_vp(gwps
->display
->screen_type
,
841 data
->tokens
[i
].value
.i
|VP_INFO_LABEL
);
843 case WPS_VIEWPORT_CUSTOMLIST
:
844 draw_playlist_viewer_list(gwps
, data
->tokens
[i
].value
.data
);
849 /* get the value of the tag and copy it to the buffer */
850 const char *value
= get_token_value(gwps
, &data
->tokens
[i
],
851 temp_buf
, sizeof(temp_buf
), NULL
);
855 while (*value
&& (buf
< linebuf_end
))
863 /* close the current alignment */
867 align
->left
= cur_align_start
;
870 case WPS_ALIGN_CENTER
:
871 align
->center
= cur_align_start
;
874 case WPS_ALIGN_RIGHT
:
875 align
->right
= cur_align_start
;
881 static void get_subline_timeout(struct gui_wps
*gwps
, struct skin_subline
*subline
)
883 struct wps_data
*data
= gwps
->data
;
885 subline
->time_mult
= DEFAULT_SUBLINE_TIME_MULTIPLIER
;
887 for (i
= subline
->first_token_idx
;
888 i
<= subline
->last_token_idx
; i
++)
890 switch(data
->tokens
[i
].type
)
892 case WPS_TOKEN_CONDITIONAL
:
893 /* place ourselves in the right conditional case */
894 evaluate_conditional(gwps
, &i
);
897 case WPS_TOKEN_CONDITIONAL_OPTION
:
898 /* we've finished in the curent conditional case,
899 skip to the end of the conditional structure */
900 i
= find_conditional_end(data
, i
);
903 case WPS_TOKEN_SUBLINE_TIMEOUT
:
904 subline
->time_mult
= data
->tokens
[i
].value
.i
;
913 /* Calculates which subline should be displayed for the specified line
914 Returns true iff the subline must be refreshed */
915 static bool update_curr_subline(struct gui_wps
*gwps
, struct skin_line
*line
)
917 /* shortcut this whole thing if we need to reset the line completly */
918 if (line
->curr_subline
== NULL
)
920 line
->subline_expire_time
= current_tick
;
921 line
->curr_subline
= &line
->sublines
;
922 if (!line
->curr_subline
->next
)
924 line
->subline_expire_time
+= 100*HZ
;
928 get_subline_timeout(gwps
, line
->curr_subline
);
929 line
->subline_expire_time
+= TIMEOUT_UNIT
*line
->curr_subline
->time_mult
;
933 /* if time to advance to next sub-line */
934 if (TIME_AFTER(current_tick
, line
->subline_expire_time
- 1))
936 /* if there is only one subline, there is no need to search for a new one */
937 if (&line
->sublines
== line
->curr_subline
&&
938 line
->curr_subline
->next
== NULL
)
940 line
->subline_expire_time
+= 100 * HZ
;
943 if (line
->curr_subline
->next
)
944 line
->curr_subline
= line
->curr_subline
->next
;
946 line
->curr_subline
= &line
->sublines
;
947 get_subline_timeout(gwps
, line
->curr_subline
);
948 line
->subline_expire_time
= current_tick
+ TIMEOUT_UNIT
*line
->curr_subline
->time_mult
;
954 /* Display a line appropriately according to its alignment format.
955 format_align contains the text, separated between left, center and right.
956 line is the index of the line on the screen.
957 scroll indicates whether the line is a scrolling one or not.
959 static void write_line(struct screen
*display
,
960 struct align_pos
*format_align
,
964 int left_width
= 0, left_xpos
;
965 int center_width
= 0, center_xpos
;
966 int right_width
= 0, right_xpos
;
972 /* calculate different string sizes and positions */
973 display
->getstringsize((unsigned char *)" ", &space_width
, &string_height
);
974 if (format_align
->left
!= 0) {
975 display
->getstringsize((unsigned char *)format_align
->left
,
976 &left_width
, &string_height
);
979 if (format_align
->right
!= 0) {
980 display
->getstringsize((unsigned char *)format_align
->right
,
981 &right_width
, &string_height
);
984 if (format_align
->center
!= 0) {
985 display
->getstringsize((unsigned char *)format_align
->center
,
986 ¢er_width
, &string_height
);
990 right_xpos
= (display
->getwidth() - right_width
);
991 center_xpos
= (display
->getwidth() + left_xpos
- center_width
) / 2;
993 scroll_width
= display
->getwidth() - left_xpos
;
995 /* Checks for overlapping strings.
996 If needed the overlapping strings will be merged, separated by a
999 /* CASE 1: left and centered string overlap */
1000 /* there is a left string, need to merge left and center */
1001 if ((left_width
!= 0 && center_width
!= 0) &&
1002 (left_xpos
+ left_width
+ space_width
> center_xpos
)) {
1003 /* replace the former separator '\0' of left and
1004 center string with a space */
1005 *(--format_align
->center
) = ' ';
1006 /* calculate the new width and position of the merged string */
1007 left_width
= left_width
+ space_width
+ center_width
;
1008 /* there is no centered string anymore */
1011 /* there is no left string, move center to left */
1012 if ((left_width
== 0 && center_width
!= 0) &&
1013 (left_xpos
+ left_width
> center_xpos
)) {
1014 /* move the center string to the left string */
1015 format_align
->left
= format_align
->center
;
1016 /* calculate the new width and position of the string */
1017 left_width
= center_width
;
1018 /* there is no centered string anymore */
1022 /* CASE 2: centered and right string overlap */
1023 /* there is a right string, need to merge center and right */
1024 if ((center_width
!= 0 && right_width
!= 0) &&
1025 (center_xpos
+ center_width
+ space_width
> right_xpos
)) {
1026 /* replace the former separator '\0' of center and
1027 right string with a space */
1028 *(--format_align
->right
) = ' ';
1029 /* move the center string to the right after merge */
1030 format_align
->right
= format_align
->center
;
1031 /* calculate the new width and position of the merged string */
1032 right_width
= center_width
+ space_width
+ right_width
;
1033 right_xpos
= (display
->getwidth() - right_width
);
1034 /* there is no centered string anymore */
1037 /* there is no right string, move center to right */
1038 if ((center_width
!= 0 && right_width
== 0) &&
1039 (center_xpos
+ center_width
> right_xpos
)) {
1040 /* move the center string to the right string */
1041 format_align
->right
= format_align
->center
;
1042 /* calculate the new width and position of the string */
1043 right_width
= center_width
;
1044 right_xpos
= (display
->getwidth() - right_width
);
1045 /* there is no centered string anymore */
1049 /* CASE 3: left and right overlap
1050 There is no center string anymore, either there never
1051 was one or it has been merged in case 1 or 2 */
1052 /* there is a left string, need to merge left and right */
1053 if ((left_width
!= 0 && center_width
== 0 && right_width
!= 0) &&
1054 (left_xpos
+ left_width
+ space_width
> right_xpos
)) {
1055 /* replace the former separator '\0' of left and
1056 right string with a space */
1057 *(--format_align
->right
) = ' ';
1058 /* calculate the new width and position of the string */
1059 left_width
= left_width
+ space_width
+ right_width
;
1060 /* there is no right string anymore */
1063 /* there is no left string, move right to left */
1064 if ((left_width
== 0 && center_width
== 0 && right_width
!= 0) &&
1065 (left_width
> right_xpos
)) {
1066 /* move the right string to the left string */
1067 format_align
->left
= format_align
->right
;
1068 /* calculate the new width and position of the string */
1069 left_width
= right_width
;
1070 /* there is no right string anymore */
1074 ypos
= (line
* string_height
);
1077 if (scroll
&& ((left_width
> scroll_width
) ||
1078 (center_width
> scroll_width
) ||
1079 (right_width
> scroll_width
)))
1081 display
->puts_scroll(0, line
,
1082 (unsigned char *)format_align
->left
);
1086 #ifdef HAVE_LCD_BITMAP
1087 /* clear the line first */
1088 display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
1089 display
->fillrect(left_xpos
, ypos
, display
->getwidth(), string_height
);
1090 display
->set_drawmode(DRMODE_SOLID
);
1093 /* Nasty hack: we output an empty scrolling string,
1094 which will reset the scroller for that line */
1095 display
->puts_scroll(0, line
, (unsigned char *)"");
1097 /* print aligned strings */
1098 if (left_width
!= 0)
1100 display
->putsxy(left_xpos
, ypos
,
1101 (unsigned char *)format_align
->left
);
1103 if (center_width
!= 0)
1105 display
->putsxy(center_xpos
, ypos
,
1106 (unsigned char *)format_align
->center
);
1108 if (right_width
!= 0)
1110 display
->putsxy(right_xpos
, ypos
,
1111 (unsigned char *)format_align
->right
);
1116 static bool skin_redraw(struct gui_wps
*gwps
, unsigned refresh_mode
)
1118 struct wps_data
*data
= gwps
->data
;
1119 struct screen
*display
= gwps
->display
;
1121 if (!data
|| !display
|| !gwps
->state
)
1125 char linebuf
[MAX_PATH
];
1127 struct align_pos align
;
1129 align
.center
= NULL
;
1133 struct skin_token_list
*viewport_list
;
1135 bool update_line
, new_subline_refresh
;
1137 /* reset to first subline if refresh all flag is set */
1138 if (refresh_mode
== WPS_REFRESH_ALL
)
1140 struct skin_line
*line
;
1141 struct skin_viewport
*skin_viewport
= find_viewport(VP_DEFAULT_LABEL
, data
);
1143 if (!(skin_viewport
->hidden_flags
& VP_NEVER_VISIBLE
))
1145 display
->set_viewport(&skin_viewport
->vp
);
1146 display
->clear_viewport();
1149 for (viewport_list
= data
->viewports
;
1150 viewport_list
; viewport_list
= viewport_list
->next
)
1153 (struct skin_viewport
*)viewport_list
->token
->value
.data
;
1154 for(line
= skin_viewport
->lines
; line
; line
= line
->next
)
1156 line
->curr_subline
= NULL
;
1161 #ifdef HAVE_LCD_CHARCELLS
1163 for (i
= 0; i
< 8; i
++)
1165 if (data
->wps_progress_pat
[i
] == 0)
1166 data
->wps_progress_pat
[i
] = display
->get_locked_pattern();
1170 /* disable any viewports which are conditionally displayed.
1171 * If we are only refreshing the peak meter then don't change the viewport
1172 * enabled flags as this will stop scrolling. viewports cant be
1173 * toggled in this refresh mode anyway (FS#10215)*/
1174 if (refresh_mode
!= WPS_REFRESH_PEAK_METER
)
1176 for (viewport_list
= data
->viewports
;
1177 viewport_list
; viewport_list
= viewport_list
->next
)
1179 struct skin_viewport
*skin_viewport
=
1180 (struct skin_viewport
*)viewport_list
->token
->value
.data
;
1181 if (skin_viewport
->hidden_flags
&VP_NEVER_VISIBLE
)
1185 if (skin_viewport
->hidden_flags
&VP_DRAW_HIDEABLE
)
1187 if (skin_viewport
->hidden_flags
&VP_DRAW_HIDDEN
)
1188 skin_viewport
->hidden_flags
|= VP_DRAW_WASHIDDEN
;
1190 skin_viewport
->hidden_flags
|= VP_DRAW_HIDDEN
;
1194 int viewport_count
= 0;
1195 for (viewport_list
= data
->viewports
;
1196 viewport_list
; viewport_list
= viewport_list
->next
, viewport_count
++)
1198 struct skin_viewport
*skin_viewport
=
1199 (struct skin_viewport
*)viewport_list
->token
->value
.data
;
1200 unsigned vp_refresh_mode
= refresh_mode
;
1202 display
->set_viewport(&skin_viewport
->vp
);
1206 #ifdef HAVE_LCD_BITMAP
1207 /* Set images to not to be displayed */
1208 struct skin_token_list
*imglist
= data
->images
;
1211 struct gui_img
*img
= (struct gui_img
*)imglist
->token
->value
.data
;
1213 imglist
= imglist
->next
;
1216 /* dont redraw the viewport if its disabled */
1217 if (skin_viewport
->hidden_flags
&VP_NEVER_VISIBLE
)
1218 { /* don't draw anything into this one */
1219 vp_refresh_mode
= 0; hidden_vp
= true;
1221 else if ((skin_viewport
->hidden_flags
&VP_DRAW_HIDDEN
))
1223 if (!(skin_viewport
->hidden_flags
&VP_DRAW_WASHIDDEN
))
1224 display
->scroll_stop(&skin_viewport
->vp
);
1225 skin_viewport
->hidden_flags
|= VP_DRAW_WASHIDDEN
;
1228 else if (((skin_viewport
->hidden_flags
&
1229 (VP_DRAW_WASHIDDEN
|VP_DRAW_HIDEABLE
))
1230 == (VP_DRAW_WASHIDDEN
|VP_DRAW_HIDEABLE
)))
1232 vp_refresh_mode
= WPS_REFRESH_ALL
;
1233 skin_viewport
->hidden_flags
= VP_DRAW_HIDEABLE
;
1236 if (vp_refresh_mode
== WPS_REFRESH_ALL
)
1238 display
->clear_viewport();
1241 /* loop over the lines for this viewport */
1242 struct skin_line
*line
;
1245 for (line
= skin_viewport
->lines
; line
; line
= line
->next
, line_count
++)
1247 struct skin_subline
*subline
;
1248 memset(linebuf
, 0, sizeof(linebuf
));
1249 update_line
= false;
1251 /* get current subline for the line */
1252 new_subline_refresh
= update_curr_subline(gwps
, line
);
1253 subline
= line
->curr_subline
;
1254 flags
= line
->curr_subline
->line_type
;
1256 if (vp_refresh_mode
== WPS_REFRESH_ALL
|| (flags
& vp_refresh_mode
)
1257 || new_subline_refresh
|| hidden_vp
)
1259 /* get_line tells us if we need to update the line */
1260 update_line
= get_line(gwps
, subline
, &align
,
1261 linebuf
, sizeof(linebuf
), vp_refresh_mode
);
1263 #ifdef HAVE_LCD_BITMAP
1265 if (flags
& vp_refresh_mode
& WPS_REFRESH_PEAK_METER
)
1267 if (!data
->peak_meter_enabled
)
1269 peak_meter_enable(false);
1273 /* the peakmeter should be alone on its line */
1274 update_line
= false;
1276 int h
= font_get(skin_viewport
->vp
.font
)->height
;
1277 int peak_meter_y
= line_count
* h
;
1279 /* The user might decide to have the peak meter in the last
1280 line so that it is only displayed if no status bar is
1281 visible. If so we neither want do draw nor enable the
1283 if (peak_meter_y
+ h
<= skin_viewport
->vp
.y
+skin_viewport
->vp
.height
) {
1284 peak_meter_enable(true);
1285 peak_meter_screen(gwps
->display
, 0, peak_meter_y
,
1286 MIN(h
, skin_viewport
->vp
.y
+skin_viewport
->vp
.height
- peak_meter_y
));
1291 #else /* HAVE_LCD_CHARCELL */
1294 if (flags
& vp_refresh_mode
& WPS_REFRESH_PLAYER_PROGRESS
)
1296 if (data
->full_line_progressbar
)
1297 draw_player_fullbar(gwps
, linebuf
, sizeof(linebuf
));
1299 draw_player_progress(gwps
);
1303 if (update_line
&& !hidden_vp
&&
1304 /* conditionals clear the line which means if the %Vd is put into the default
1305 viewport there will be a blank line.
1306 To get around this we dont allow any actual drawing to happen in the
1307 deault vp if other vp's are defined */
1308 ((skin_viewport
->label
!= VP_DEFAULT_LABEL
&& viewport_list
->next
) ||
1309 !viewport_list
->next
))
1311 if (flags
& WPS_REFRESH_SCROLL
)
1313 /* if the line is a scrolling one we don't want to update
1314 too often, so that it has the time to scroll */
1315 if ((vp_refresh_mode
& WPS_REFRESH_SCROLL
) || new_subline_refresh
)
1316 write_line(display
, &align
, line_count
, true);
1319 write_line(display
, &align
, line_count
, false);
1322 #ifdef HAVE_LCD_BITMAP
1324 if (vp_refresh_mode
& WPS_REFRESH_PLAYER_PROGRESS
)
1326 struct skin_token_list
*bar
= gwps
->data
->progressbars
;
1329 struct progressbar
*thisbar
= (struct progressbar
*)bar
->token
->value
.data
;
1330 if (thisbar
->vp
== &skin_viewport
->vp
&& thisbar
->draw
)
1332 draw_progressbar(gwps
, thisbar
);
1337 /* Now display any images in this viewport */
1339 wps_display_images(gwps
, &skin_viewport
->vp
);
1343 /* Restore the default viewport */
1344 display
->set_viewport(NULL
);
1351 bool skin_has_sbs(enum screen_type screen
, struct wps_data
*data
)
1356 #ifdef HAVE_LCD_BITMAP
1357 if (data
->wps_sb_tag
)
1358 draw
= data
->show_sb_on_wps
;
1359 else if (statusbar_position(screen
) != STATUSBAR_OFF
)
1365 /* do the button loop as often as required for the peak meters to update
1366 * with a good refresh rate.
1367 * gwps is really gwps[NB_SCREENS]! don't wrap this if FOR_NB_SCREENS()
1369 int skin_wait_for_action(struct gui_wps
*gwps
, int context
, int timeout
)
1371 (void)gwps
; /* silence charcell warning */
1372 int button
= ACTION_NONE
;
1373 #ifdef HAVE_LCD_BITMAP
1375 /* when the peak meter is enabled we want to have a
1376 few extra updates to make it look smooth. On the
1377 other hand we don't want to waste energy if it
1382 if(gwps
[i
].data
->peak_meter_enabled
)
1387 long next_refresh
= current_tick
;
1388 long next_big_refresh
= current_tick
+ timeout
;
1389 button
= BUTTON_NONE
;
1390 while (TIME_BEFORE(current_tick
, next_big_refresh
)) {
1391 button
= get_action(context
,TIMEOUT_NOBLOCK
);
1392 if (button
!= ACTION_NONE
) {
1396 sleep(0); /* Sleep until end of current tick. */
1398 if (TIME_AFTER(current_tick
, next_refresh
)) {
1401 if(gwps
[i
].data
->peak_meter_enabled
)
1402 skin_update(&gwps
[i
], WPS_REFRESH_PEAK_METER
);
1403 next_refresh
+= HZ
/ PEAK_METER_FPS
;
1410 /* The peak meter is disabled
1411 -> no additional screen updates needed */
1415 button
= get_action(context
, timeout
);