summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/gui/gwps-common.c69
1 files changed, 39 insertions, 30 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index d9bcfdc99f..7e38a08615 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -613,39 +613,31 @@ static bool draw_player_progress(struct gui_wps *gwps)
613 return true; 613 return true;
614} 614}
615 615
616static int map_fullbar_char(int ascii_val)
617{
618 if (ascii_val >= '0' && ascii_val <= ':') /* 0123456789: */
619 return ascii_val - '0';
620 else
621 return -1; /* anything besides a number or ':' is blank */
622}
623
624static void draw_player_fullbar(struct gui_wps *gwps, char* buf, int buf_size) 616static void draw_player_fullbar(struct gui_wps *gwps, char* buf, int buf_size)
625{ 617{
626 static const unsigned char numbers[11][4] = { 618 static const unsigned char numbers[10][4] = {
627 {0x1c, 0x14, 0x14, 0x1c}, /* 0 */ 619 {0x0e, 0x0a, 0x0a, 0x0e}, /* 0 */
628 {0x08, 0x18, 0x08, 0x08}, /* 1 */ 620 {0x04, 0x0c, 0x04, 0x04}, /* 1 */
629 {0x1c, 0x04, 0x08, 0x1c}, /* 2 */ 621 {0x0e, 0x02, 0x04, 0x0e}, /* 2 */
630 {0x1c, 0x04, 0x0c, 0x1c}, /* 3 */ 622 {0x0e, 0x02, 0x06, 0x0e}, /* 3 */
631 {0x10, 0x18, 0x1c, 0x08}, /* 4 */ 623 {0x08, 0x0c, 0x0e, 0x04}, /* 4 */
632 {0x1c, 0x18, 0x04, 0x18}, /* 5 */ 624 {0x0e, 0x0c, 0x02, 0x0c}, /* 5 */
633 {0x1c, 0x10, 0x1c, 0x1c}, /* 6 */ 625 {0x0e, 0x08, 0x0e, 0x0e}, /* 6 */
634 {0x1c, 0x04, 0x08, 0x10}, /* 7 */ 626 {0x0e, 0x02, 0x04, 0x08}, /* 7 */
635 {0x1c, 0x1c, 0x14, 0x1c}, /* 8 */ 627 {0x0e, 0x0e, 0x0a, 0x0e}, /* 8 */
636 {0x1c, 0x1c, 0x04, 0x1c}, /* 9 */ 628 {0x0e, 0x0e, 0x02, 0x0e}, /* 9 */
637 {0x00, 0x08, 0x00, 0x08}, /* : */
638 }; 629 };
639 630
640 struct wps_state *state = gwps->state; 631 struct wps_state *state = gwps->state;
641 struct screen *display = gwps->display; 632 struct screen *display = gwps->display;
642 struct wps_data *data = gwps->data; 633 struct wps_data *data = gwps->data;
643 unsigned char progress_pattern[7]; 634 unsigned char progress_pattern[7];
644 char timestr[12]; 635 char timestr[10];
645 int time; 636 int time;
637 int time_idx = 0;
646 int pos = 0; 638 int pos = 0;
647 int pat_idx = 1; 639 int pat_idx = 1;
648 int i, digit; 640 int digit, i, j;
649 bool softchar; 641 bool softchar;
650 642
651 if (!state->id3 || buf_size < 34) /* worst case: 11x UTF-8 char + \0 */ 643 if (!state->id3 || buf_size < 34) /* worst case: 11x UTF-8 char + \0 */
@@ -656,22 +648,41 @@ static void draw_player_fullbar(struct gui_wps *gwps, char* buf, int buf_size)
656 pos = 55 * time / state->id3->length; 648 pos = 55 * time / state->id3->length;
657 649
658 memset(timestr, 0, sizeof(timestr)); 650 memset(timestr, 0, sizeof(timestr));
659 format_time(timestr, sizeof(timestr), time); 651 format_time(timestr, sizeof(timestr)-2, time);
652 timestr[strlen(timestr)] = ':'; /* always safe */
660 653
661 for (i = 0; i < 11; i++, pos -= 5) 654 for (i = 0; i < 11; i++, pos -= 5)
662 { 655 {
663 softchar = false; 656 softchar = false;
664 memset(progress_pattern, 0, sizeof(progress_pattern)); 657 memset(progress_pattern, 0, sizeof(progress_pattern));
665 658
666 digit = map_fullbar_char(timestr[i]); 659 if ((digit = timestr[time_idx]))
667 if (digit >= 0)
668 { 660 {
669 softchar = true; 661 softchar = true;
670 memcpy(progress_pattern, numbers[digit], 4); 662 digit -= '0';
663
664 if (timestr[time_idx + 1] == ':') /* ones, left aligned */
665 {
666 memcpy(progress_pattern, numbers[digit], 4);
667 time_idx += 2;
668 }
669 else /* tens, shifted right */
670 {
671 for (j = 0; j < 4; j++)
672 progress_pattern[j] = numbers[digit][j] >> 1;
673
674 if (time_idx > 0) /* not the first group, add colon in front */
675 {
676 progress_pattern[1] |= 0x10;
677 progress_pattern[3] |= 0x10;
678 }
679 time_idx++;
680 }
671 681
672 if (pos >= 5) 682 if (pos >= 5)
673 progress_pattern[5] = progress_pattern[6] = 0x1f; 683 progress_pattern[5] = progress_pattern[6] = 0x1f;
674 } 684 }
685
675 if (pos > 0 && pos < 5) 686 if (pos > 0 && pos < 5)
676 { 687 {
677 softchar = true; 688 softchar = true;
@@ -687,10 +698,8 @@ static void draw_player_fullbar(struct gui_wps *gwps, char* buf, int buf_size)
687 } 698 }
688 else if (pos <= 0) 699 else if (pos <= 0)
689 buf = utf8encode(' ', buf); 700 buf = utf8encode(' ', buf);
690 else if (pos >= 5) 701 else
691 buf = utf8encode(0xe115, buf); /* 2/7 _ */ 702 buf = utf8encode(0xe115, buf); /* 2/7 _ */
692 else /* in between, but cannot map */
693 buf = utf8encode('_', buf); /* 1/7 _ */
694 } 703 }
695 *buf = '\0'; 704 *buf = '\0';
696} 705}