summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarkus Braun <markus.braun@krawel.de>2002-08-15 06:36:25 +0000
committerMarkus Braun <markus.braun@krawel.de>2002-08-15 06:36:25 +0000
commite2a9fe194315508329c8434592edb76cb727c224 (patch)
treef045c684ab93a3e8e07ba8c00e59d1b9be3d0978 /apps
parent3377e9f3025f15ef3b34c1e2b648dd59cf192921 (diff)
downloadrockbox-e2a9fe194315508329c8434592edb76cb727c224.tar.gz
rockbox-e2a9fe194315508329c8434592edb76cb727c224.zip
time/date setting works now with loadable and proportional fonts
code makeup git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1749 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/settings.c241
1 files changed, 197 insertions, 44 deletions
diff --git a/apps/settings.c b/apps/settings.c
index 8c73aab87b..85bd41a55f 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -526,58 +526,208 @@ void set_option(char* string, int* variable, char* options[], int numoptions )
526#define INDEX_X 0 526#define INDEX_X 0
527#define INDEX_Y 1 527#define INDEX_Y 1
528#define INDEX_WIDTH 2 528#define INDEX_WIDTH 2
529char *dayname[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; 529char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
530char *monthname[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; 530char *monthname[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
531char cursor[][3]={{0, 1, 2}, {3, 1, 2}, {6, 1, 2}, {4, 2, 4}, {9, 2, 3}, {13, 2, 2}}; 531 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
532char daysinmonth[]={31,28,31,30,31,30,31,31,30,31,30,31}; 532char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
533 {24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
534char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
533 535
534void set_time(char* string, int timedate[]) 536void set_time(char* string, int timedate[])
535{ 537{
536 bool done = false; 538 bool done = false;
537 int button; 539 int button;
538 int min=0,steps=0; 540 int min = 0, steps = 0;
539 int cursorpos=0; 541 int cursorpos = 0;
540 int lastcursorpos=!cursorpos; 542 int lastcursorpos = !cursorpos;
541 unsigned char buffer[19]; 543 unsigned char buffer[19];
542 int realyear; 544 int realyear;
543 int julianday; 545 int julianday;
544 int i; 546 int i;
547#if defined(LOADABLE_FONTS) || defined(LCD_PROPFONTS)
548 unsigned char reffub[5];
549 unsigned int width, height;
550 unsigned int separator_width, weekday_width;
551 unsigned int line_height, prev_line_height;
552#if defined(LOADABLE_FONTS)
553 unsigned char *font = lcd_getcurrentldfont();
554#endif
555#endif
545 556
546 lcd_clear_display(); 557 lcd_clear_display();
547 lcd_puts_scroll(0,0,string); 558 lcd_puts_scroll(0, 0, string);
548 559
549 while ( !done ) { 560 while ( !done ) {
550 /* calculate the number of days in febuary */ 561 /* calculate the number of days in febuary */
551 realyear=timedate[3]+2000; 562 realyear = timedate[3] + 2000;
552 if((realyear%4==0 && !(realyear%100 == 0)) || realyear%400 == 0) /* for february depends on year */ 563 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
553 daysinmonth[1]=29; 564 daysinmonth[1] = 29;
554 else 565 else
555 daysinmonth[1]=28; 566 daysinmonth[1] = 28;
556 567
557 /* fix day if month or year changed */ 568 /* fix day if month or year changed */
558 timedate[5]=timedate[5]<daysinmonth[timedate[4]-1]?timedate[5]:daysinmonth[timedate[4]-1]; 569 if (timedate[5] > daysinmonth[timedate[4] - 1])
570 timedate[5] = daysinmonth[timedate[4] - 1];
559 571
560 /* calculate day of week */ 572 /* calculate day of week */
561 julianday=0; 573 julianday = 0;
562 for(i=0;i<timedate[4]-1;i++) { 574 for(i = 0; i < timedate[4] - 1; i++) {
563 julianday+=daysinmonth[i]; 575 julianday += daysinmonth[i];
564 } 576 }
565 julianday+=timedate[5]; 577 julianday += timedate[5];
566 timedate[6]=(realyear+julianday+(realyear-1)/4-(realyear-1)/100+(realyear-1)/400+7-1)%7; 578 timedate[6] = (realyear + julianday + (realyear - 1) / 4 -
579 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
567 580
568 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", 581 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ",
569 timedate[0], 582 timedate[0],
570 timedate[1], 583 timedate[1],
571 timedate[2]); 584 timedate[2]);
572 lcd_puts(0,1,buffer); 585 lcd_puts(0, 1, buffer);
586#if defined(LCD_PROPFONTS)
587 /* recalculate the positions and offsets */
588 lcd_getstringsize(string, 0, &width, &prev_line_height);
589 lcd_getstringsize(buffer, 0, &width, &line_height);
590 lcd_getstringsize(":", 0, &separator_width, &height);
591
592 strncpy(reffub, buffer, 2);
593 reffub[2] = '\0';
594 lcd_getstringsize(reffub, 0, &width, &height);
595 cursor[0][INDEX_X] = 0;
596 cursor[0][INDEX_Y] = 1 + prev_line_height + 1;
597 cursor[0][INDEX_WIDTH] = width + strlen(reffub) - 1;
598
599 strncpy(reffub, buffer + 3, 2);
600 reffub[2] = '\0';
601 lcd_getstringsize(reffub, 0, &width, &height);
602 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + 1 + separator_width + 1;
603 cursor[1][INDEX_Y] = 1 + prev_line_height + 1;
604 cursor[1][INDEX_WIDTH] = width + strlen(reffub) - 1;
605
606 strncpy(reffub, buffer + 6, 2);
607 reffub[2] = '\0';
608 lcd_getstringsize(reffub, 0, &width, &height);
609 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + 1 + separator_width + 1 +
610 cursor[1][INDEX_WIDTH] + 1 + separator_width + 1;
611 cursor[2][INDEX_Y] = 1 + prev_line_height + 1;
612 cursor[2][INDEX_WIDTH] = width + strlen(reffub) - 1;
613
614 lcd_getstringsize(buffer, 0, &width, &prev_line_height);
615#elif defined(LOADABLE_FONTS)
616 /* recalculate the positions and offsets */
617 lcd_getstringsize(string, font, &width, &prev_line_height);
618 lcd_getstringsize(buffer, font, &width, &line_height);
619 lcd_getstringsize(":", font, &separator_width, &height);
620
621 strncpy(reffub, buffer, 2);
622 reffub[2] = '\0';
623 lcd_getstringsize(reffub, font, &width, &height);
624 cursor[0][INDEX_X] = 0;
625 cursor[0][INDEX_Y] = prev_line_height;
626 cursor[0][INDEX_WIDTH] = width;
627
628 strncpy(reffub, buffer + 3, 2);
629 reffub[2] = '\0';
630 lcd_getstringsize(reffub, font, &width, &height);
631 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
632 cursor[1][INDEX_Y] = prev_line_height;
633 cursor[1][INDEX_WIDTH] = width;
634
635 strncpy(reffub, buffer + 6, 2);
636 reffub[2] = '\0';
637 lcd_getstringsize(reffub, font, &width, &height);
638 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
639 cursor[1][INDEX_WIDTH] + separator_width;
640 cursor[2][INDEX_Y] = prev_line_height;
641 cursor[2][INDEX_WIDTH] = width;
642
643 lcd_getstringsize(buffer, font, &width, &prev_line_height);
644#endif
573 645
574 snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d", 646 snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d ",
575 dayname[timedate[6]], 647 dayname[timedate[6]],
576 timedate[3], 648 timedate[3],
577 monthname[timedate[4]-1], 649 monthname[timedate[4] - 1],
578 timedate[5]); 650 timedate[5]);
579 lcd_puts(0,2,buffer); 651 lcd_puts(0, 2, buffer);
580 lcd_invertrect(cursor[cursorpos][INDEX_X]*6,cursor[cursorpos][INDEX_Y]*8,cursor[cursorpos][INDEX_WIDTH]*6,8); 652#if defined(LCD_PROPFONTS)
653 /* recalculate the positions and offsets */
654 lcd_getstringsize(buffer, 0, &width, &line_height);
655 strncpy(reffub, buffer, 3);
656 reffub[3] = '\0';
657 lcd_getstringsize(reffub, 0, &weekday_width, &height);
658 weekday_width += strlen(reffub) - 1;
659 lcd_getstringsize(" ", 0, &separator_width, &height);
660
661 strncpy(reffub, buffer + 4, 4);
662 reffub[4] = '\0';
663 lcd_getstringsize(reffub, 0, &width, &height);
664 cursor[3][INDEX_X] = weekday_width + 1 + separator_width + 1;
665 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height + 1;
666 cursor[3][INDEX_WIDTH] = width + strlen(reffub) - 1;
667
668 strncpy(reffub, buffer + 9, 3);
669 reffub[3] = '\0';
670 lcd_getstringsize(reffub, 0, &width, &height);
671 cursor[4][INDEX_X] = weekday_width + 1 + separator_width + 1 +
672 cursor[3][INDEX_WIDTH] + 1 + separator_width + 1;
673 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height + 1;
674 cursor[4][INDEX_WIDTH] = width + strlen(reffub) - 1;
675
676 strncpy(reffub, buffer + 13, 2);
677 reffub[2] = '\0';
678 lcd_getstringsize(reffub, 0, &width, &height);
679 cursor[5][INDEX_X] = weekday_width + 1 + separator_width + 1 +
680 cursor[3][INDEX_WIDTH] + 1 + separator_width + 1 +
681 cursor[4][INDEX_WIDTH] + 1 + separator_width + 1;
682 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height + 1;
683 cursor[5][INDEX_WIDTH] = width + strlen(reffub) - 1;
684
685 lcd_invertrect(cursor[cursorpos][INDEX_X],
686 cursor[cursorpos][INDEX_Y],
687 cursor[cursorpos][INDEX_WIDTH],
688 line_height);
689#elif defined(LOADABLE_FONTS)
690 /* recalculate the positions and offsets */
691 lcd_getstringsize(buffer, font, &width, &line_height);
692 strncpy(reffub, buffer, 3);
693 reffub[3] = '\0';
694 lcd_getstringsize(reffub, font, &weekday_width, &height);
695 lcd_getstringsize(" ", font, &separator_width, &height);
696
697 strncpy(reffub, buffer + 4, 4);
698 reffub[4] = '\0';
699 lcd_getstringsize(reffub, font, &width, &height);
700 cursor[3][INDEX_X] = weekday_width + separator_width;
701 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
702 cursor[3][INDEX_WIDTH] = width;
703
704 strncpy(reffub, buffer + 9, 3);
705 reffub[3] = '\0';
706 lcd_getstringsize(reffub, font, &width, &height);
707 cursor[4][INDEX_X] = weekday_width + separator_width +
708 cursor[3][INDEX_WIDTH] + separator_width;
709 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
710 cursor[4][INDEX_WIDTH] = width;
711
712 strncpy(reffub, buffer + 13, 2);
713 reffub[2] = '\0';
714 lcd_getstringsize(reffub, font, &width, &height);
715 cursor[5][INDEX_X] = weekday_width + separator_width +
716 cursor[3][INDEX_WIDTH] + separator_width +
717 cursor[4][INDEX_WIDTH] + separator_width;
718 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
719 cursor[5][INDEX_WIDTH] = width;
720
721 lcd_invertrect(cursor[cursorpos][INDEX_X],
722 cursor[cursorpos][INDEX_Y],
723 cursor[cursorpos][INDEX_WIDTH],
724 line_height);
725#else
726 lcd_invertrect(cursor[cursorpos][INDEX_X],
727 cursor[cursorpos][INDEX_Y],
728 cursor[cursorpos][INDEX_WIDTH],
729 8);
730#endif
581 lcd_puts(0,4,"ON to set"); 731 lcd_puts(0,4,"ON to set");
582 lcd_puts(0,5,"OFF to revert"); 732 lcd_puts(0,5,"OFF to revert");
583 lcd_update(); 733 lcd_update();
@@ -587,25 +737,25 @@ void set_time(char* string, int timedate[])
587 lastcursorpos=cursorpos; 737 lastcursorpos=cursorpos;
588 switch(cursorpos) { 738 switch(cursorpos) {
589 case 0: /* hour */ 739 case 0: /* hour */
590 min=0; 740 min = 0;
591 steps=24; 741 steps = 24;
592 break; 742 break;
593 case 1: /* minute */ 743 case 1: /* minute */
594 case 2: /* second */ 744 case 2: /* second */
595 min=0; 745 min = 0;
596 steps=60; 746 steps = 60;
597 break; 747 break;
598 case 3: /* year */ 748 case 3: /* year */
599 min=0; 749 min = 0;
600 steps=100; 750 steps = 100;
601 break; 751 break;
602 case 4: /* month */ 752 case 4: /* month */
603 min=1; 753 min = 1;
604 steps=12; 754 steps = 12;
605 break; 755 break;
606 case 5: /* day */ 756 case 5: /* day */
607 min=1; 757 min = 1;
608 steps=daysinmonth[timedate[4]-1]; 758 steps = daysinmonth[timedate[4] - 1];
609 break; 759 break;
610 } 760 }
611 } 761 }
@@ -613,26 +763,29 @@ void set_time(char* string, int timedate[])
613 button = button_get(true); 763 button = button_get(true);
614 switch ( button ) { 764 switch ( button ) {
615 case BUTTON_LEFT: 765 case BUTTON_LEFT:
616 cursorpos=(cursorpos+6-1)%6; 766 cursorpos = (cursorpos + 6 - 1) % 6;
617 break; 767 break;
618 case BUTTON_RIGHT: 768 case BUTTON_RIGHT:
619 cursorpos=(cursorpos+6+1)%6; 769 cursorpos = (cursorpos + 6 + 1) % 6;
620 break; 770 break;
621 case BUTTON_UP: 771 case BUTTON_UP:
622 timedate[cursorpos]=(timedate[cursorpos]+steps-min+1)%steps+min; 772 timedate[cursorpos] = (timedate[cursorpos] + steps - min + 1) % steps + min;
623 if(timedate[cursorpos] == 0) timedate[cursorpos]+=min; 773 if(timedate[cursorpos] == 0)
774 timedate[cursorpos] += min;
624 break; 775 break;
625 case BUTTON_DOWN: 776 case BUTTON_DOWN:
626 timedate[cursorpos]=(timedate[cursorpos]+steps-min-1)%steps+min; 777 timedate[cursorpos]=(timedate[cursorpos]+steps - min - 1) % steps + min;
627 if(timedate[cursorpos] == 0) timedate[cursorpos]+=min; 778 if(timedate[cursorpos] == 0)
779 timedate[cursorpos] += min;
628 break; 780 break;
629 case BUTTON_ON: 781 case BUTTON_ON:
630 done=true; 782 done = true;
631 if (timedate[6] == 0) timedate[6]=7; /* rtc needs 1 .. 7 */ 783 if (timedate[6] == 0) /* rtc needs 1 .. 7 */
784 timedate[6] = 7;
632 break; 785 break;
633 case BUTTON_OFF: 786 case BUTTON_OFF:
634 done=true; 787 done = true;
635 timedate[0]=-1; 788 timedate[0] = -1;
636 break; 789 break;
637 default: 790 default:
638 break; 791 break;