diff options
Diffstat (limited to 'apps/gui/skin_engine/skin_tokens.c')
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 148 |
1 files changed, 147 insertions, 1 deletions
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 11200e448c..78d141e743 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c | |||
@@ -554,6 +554,148 @@ static struct mp3entry* get_mp3entry_from_offset(int offset, char **filename) | |||
554 | return pid3; | 554 | return pid3; |
555 | } | 555 | } |
556 | 556 | ||
557 | #ifdef HAVE_LCD_CHARCELLS | ||
558 | void format_player_progress(struct gui_wps *gwps) | ||
559 | { | ||
560 | struct wps_state *state = skin_get_global_state(); | ||
561 | struct screen *display = gwps->display; | ||
562 | unsigned char progress_pattern[7]; | ||
563 | int pos = 0; | ||
564 | int i; | ||
565 | |||
566 | int elapsed, length; | ||
567 | if (LIKELY(state->id3)) | ||
568 | { | ||
569 | elapsed = state->id3->elapsed; | ||
570 | length = state->id3->length; | ||
571 | } | ||
572 | else | ||
573 | { | ||
574 | elapsed = 0; | ||
575 | length = 0; | ||
576 | } | ||
577 | |||
578 | if (length) | ||
579 | pos = 36 * (elapsed + state->ff_rewind_count) / length; | ||
580 | |||
581 | for (i = 0; i < 7; i++, pos -= 5) | ||
582 | { | ||
583 | if (pos <= 0) | ||
584 | progress_pattern[i] = 0x1fu; | ||
585 | else if (pos >= 5) | ||
586 | progress_pattern[i] = 0x00u; | ||
587 | else | ||
588 | progress_pattern[i] = 0x1fu >> pos; | ||
589 | } | ||
590 | |||
591 | display->define_pattern(gwps->data->wps_progress_pat[0], progress_pattern); | ||
592 | } | ||
593 | |||
594 | void format_player_fullbar(struct gui_wps *gwps, char* buf, int buf_size) | ||
595 | { | ||
596 | static const unsigned char numbers[10][4] = { | ||
597 | {0x0e, 0x0a, 0x0a, 0x0e}, /* 0 */ | ||
598 | {0x04, 0x0c, 0x04, 0x04}, /* 1 */ | ||
599 | {0x0e, 0x02, 0x04, 0x0e}, /* 2 */ | ||
600 | {0x0e, 0x02, 0x06, 0x0e}, /* 3 */ | ||
601 | {0x08, 0x0c, 0x0e, 0x04}, /* 4 */ | ||
602 | {0x0e, 0x0c, 0x02, 0x0c}, /* 5 */ | ||
603 | {0x0e, 0x08, 0x0e, 0x0e}, /* 6 */ | ||
604 | {0x0e, 0x02, 0x04, 0x08}, /* 7 */ | ||
605 | {0x0e, 0x0e, 0x0a, 0x0e}, /* 8 */ | ||
606 | {0x0e, 0x0e, 0x02, 0x0e}, /* 9 */ | ||
607 | }; | ||
608 | |||
609 | struct wps_state *state = skin_get_global_state(); | ||
610 | struct screen *display = gwps->display; | ||
611 | struct wps_data *data = gwps->data; | ||
612 | unsigned char progress_pattern[7]; | ||
613 | char timestr[10]; | ||
614 | int time; | ||
615 | int time_idx = 0; | ||
616 | int pos = 0; | ||
617 | int pat_idx = 1; | ||
618 | int digit, i, j; | ||
619 | bool softchar; | ||
620 | |||
621 | int elapsed, length; | ||
622 | if (LIKELY(state->id3)) | ||
623 | { | ||
624 | elapsed = state->id3->elapsed; | ||
625 | length = state->id3->length; | ||
626 | } | ||
627 | else | ||
628 | { | ||
629 | elapsed = 0; | ||
630 | length = 0; | ||
631 | } | ||
632 | |||
633 | if (buf_size < 34) /* worst case: 11x UTF-8 char + \0 */ | ||
634 | return; | ||
635 | |||
636 | time = elapsed + state->ff_rewind_count; | ||
637 | if (length) | ||
638 | pos = 55 * time / length; | ||
639 | |||
640 | memset(timestr, 0, sizeof(timestr)); | ||
641 | format_time(timestr, sizeof(timestr)-2, time); | ||
642 | timestr[strlen(timestr)] = ':'; /* always safe */ | ||
643 | |||
644 | for (i = 0; i < 11; i++, pos -= 5) | ||
645 | { | ||
646 | softchar = false; | ||
647 | memset(progress_pattern, 0, sizeof(progress_pattern)); | ||
648 | |||
649 | if ((digit = timestr[time_idx])) | ||
650 | { | ||
651 | softchar = true; | ||
652 | digit -= '0'; | ||
653 | |||
654 | if (timestr[time_idx + 1] == ':') /* ones, left aligned */ | ||
655 | { | ||
656 | memcpy(progress_pattern, numbers[digit], 4); | ||
657 | time_idx += 2; | ||
658 | } | ||
659 | else /* tens, shifted right */ | ||
660 | { | ||
661 | for (j = 0; j < 4; j++) | ||
662 | progress_pattern[j] = numbers[digit][j] >> 1; | ||
663 | |||
664 | if (time_idx > 0) /* not the first group, add colon in front */ | ||
665 | { | ||
666 | progress_pattern[1] |= 0x10u; | ||
667 | progress_pattern[3] |= 0x10u; | ||
668 | } | ||
669 | time_idx++; | ||
670 | } | ||
671 | |||
672 | if (pos >= 5) | ||
673 | progress_pattern[5] = progress_pattern[6] = 0x1fu; | ||
674 | } | ||
675 | |||
676 | if (pos > 0 && pos < 5) | ||
677 | { | ||
678 | softchar = true; | ||
679 | progress_pattern[5] = progress_pattern[6] = (~0x1fu >> pos) & 0x1fu; | ||
680 | } | ||
681 | |||
682 | if (softchar && pat_idx < 8) | ||
683 | { | ||
684 | display->define_pattern(data->wps_progress_pat[pat_idx], | ||
685 | progress_pattern); | ||
686 | buf = utf8encode(data->wps_progress_pat[pat_idx], buf); | ||
687 | pat_idx++; | ||
688 | } | ||
689 | else if (pos <= 0) | ||
690 | buf = utf8encode(' ', buf); | ||
691 | else | ||
692 | buf = utf8encode(0xe115, buf); /* 2/7 _ */ | ||
693 | } | ||
694 | *buf = '\0'; | ||
695 | } | ||
696 | |||
697 | #endif /* HAVE_LCD_CHARCELLS */ | ||
698 | |||
557 | /* Don't inline this; it was broken out of get_token_value to reduce stack | 699 | /* Don't inline this; it was broken out of get_token_value to reduce stack |
558 | * usage. | 700 | * usage. |
559 | */ | 701 | */ |
@@ -1075,7 +1217,9 @@ const char *get_token_value(struct gui_wps *gwps, | |||
1075 | #ifdef HAVE_LCD_CHARCELLS | 1217 | #ifdef HAVE_LCD_CHARCELLS |
1076 | case SKIN_TOKEN_PROGRESSBAR: | 1218 | case SKIN_TOKEN_PROGRESSBAR: |
1077 | { | 1219 | { |
1078 | char *end = utf8encode(data->wps_progress_pat[0], buf); | 1220 | char *end; |
1221 | format_player_progress(gwps); | ||
1222 | end = utf8encode(data->wps_progress_pat[0], buf); | ||
1079 | *end = '\0'; | 1223 | *end = '\0'; |
1080 | return buf; | 1224 | return buf; |
1081 | } | 1225 | } |
@@ -1086,6 +1230,8 @@ const char *get_token_value(struct gui_wps *gwps, | |||
1086 | /* we need 11 characters (full line) for | 1230 | /* we need 11 characters (full line) for |
1087 | progress-bar */ | 1231 | progress-bar */ |
1088 | strlcpy(buf, " ", buf_size); | 1232 | strlcpy(buf, " ", buf_size); |
1233 | format_player_fullbar(gwps,buf,buf_size); | ||
1234 | DEBUGF("bar='%s'\n",buf); | ||
1089 | } | 1235 | } |
1090 | else | 1236 | else |
1091 | { | 1237 | { |