diff options
author | Nils Wallménius <nils@rockbox.org> | 2007-07-21 08:28:48 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2007-07-21 08:28:48 +0000 |
commit | aedf68a02f954ae14d8eb7f5d4a4e5295afd54a4 (patch) | |
tree | b1606bb1c2dc4ed902348d99fcdcde8e17937d60 /apps | |
parent | a07b60e58fe81e709d1b92d7efff908452ee5188 (diff) | |
download | rockbox-aedf68a02f954ae14d8eb7f5d4a4e5295afd54a4.tar.gz rockbox-aedf68a02f954ae14d8eb7f5d4a4e5295afd54a4.zip |
Fix 'Set time & date' screen display when the name of the day or month was not 3 letters long (german language uses 2 for days) also fix displaying of unicode and clean up code.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13949 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/screens.c | 100 |
1 files changed, 47 insertions, 53 deletions
diff --git a/apps/screens.c b/apps/screens.c index dddcbc61a9..570c9b197b 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -858,45 +858,42 @@ static void say_time(int cursorpos, const struct tm *tm) | |||
858 | #define INDEX_WIDTH 2 | 858 | #define INDEX_WIDTH 2 |
859 | 859 | ||
860 | #define SEPARATOR ":" | 860 | #define SEPARATOR ":" |
861 | #define MONTHNAME_LEN 3 | ||
862 | #define DAYNAME_LEN 3 | ||
863 | bool set_time_screen(const char* title, struct tm *tm) | 861 | bool set_time_screen(const char* title, struct tm *tm) |
864 | { | 862 | { |
865 | bool done = false; | 863 | bool done = false; |
866 | int button; | 864 | int button; |
867 | int i, s; | 865 | unsigned int i, s; |
868 | int cursorpos = 0; | 866 | unsigned int cursorpos = 0; |
869 | int lastcursorpos = !cursorpos; | 867 | unsigned int lastcursorpos = 1; |
870 | unsigned int julianday; | 868 | unsigned int julianday; |
871 | unsigned int realyear; | 869 | unsigned int realyear; |
870 | unsigned int width; | ||
872 | unsigned int min = 0, steps = 0; | 871 | unsigned int min = 0, steps = 0; |
873 | unsigned int statusbar_height = 0; | 872 | unsigned int statusbar_height = 0; |
874 | unsigned int width, height; | ||
875 | unsigned int separator_width, weekday_width; | 873 | unsigned int separator_width, weekday_width; |
876 | unsigned int line_height, prev_line_height; | 874 | unsigned int line_height, prev_line_height; |
877 | unsigned char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 875 | unsigned char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
878 | unsigned char buffer[25]; | 876 | unsigned char buffer[20]; |
879 | 877 | ||
880 | /* 6 possible cursor possitions, 3 values stored for each: x, y, width */ | 878 | /* 6 possible cursor possitions, 3 values stored for each: x, y, width */ |
881 | unsigned char cursor[6][3]; | 879 | unsigned char cursor[6][3]; |
882 | memset(cursor, 0, sizeof(cursor)); | 880 | memset(cursor, 0, sizeof(cursor)); |
883 | 881 | ||
884 | int *valptr = NULL; | 882 | int *valptr = NULL; |
885 | |||
886 | /* for easy acess in the drawing loop */ | ||
887 | unsigned char *ptr[6]; | 883 | unsigned char *ptr[6]; |
888 | ptr[0] = buffer; /* hours */ | ||
889 | ptr[1] = buffer + 3; /* minutes */ | ||
890 | ptr[2] = buffer + 6; /* seconds */ | ||
891 | ptr[3] = buffer + 10 + DAYNAME_LEN; /* year (dayname is before year in the | ||
892 | buffer but is not drawn in the loop) */ | ||
893 | ptr[4] = buffer + 15 + DAYNAME_LEN; /* monthname */ | ||
894 | ptr[5] = buffer + 16 + DAYNAME_LEN + MONTHNAME_LEN; /* day of month */ | ||
895 | 884 | ||
896 | if(global_settings.statusbar) | 885 | if(global_settings.statusbar) |
897 | statusbar_height = STATUSBAR_HEIGHT; | 886 | statusbar_height = STATUSBAR_HEIGHT; |
898 | 887 | ||
899 | while ( !done ) { | 888 | while ( !done ) { |
889 | /* for easy acess in the drawing loop */ | ||
890 | ptr[0] = buffer; /* hours */ | ||
891 | ptr[1] = buffer + 3; /* minutes */ | ||
892 | ptr[2] = buffer + 6; /* seconds */ | ||
893 | ptr[3] = buffer + 9; /* year */ | ||
894 | ptr[4] = str(monthname[tm->tm_mon]); /* monthname */ | ||
895 | ptr[5] = buffer + 14; /* day of month */ | ||
896 | |||
900 | /* calculate the number of days in febuary */ | 897 | /* calculate the number of days in febuary */ |
901 | realyear = tm->tm_year + 1900; | 898 | realyear = tm->tm_year + 1900; |
902 | if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0) | 899 | if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0) |
@@ -910,29 +907,28 @@ bool set_time_screen(const char* title, struct tm *tm) | |||
910 | 907 | ||
911 | /* calculate day of week */ | 908 | /* calculate day of week */ |
912 | julianday = 0; | 909 | julianday = 0; |
913 | for(i = 0; i < tm->tm_mon; i++) { | 910 | for(i = 0; (int)i < tm->tm_mon; i++) { |
914 | julianday += daysinmonth[i]; | 911 | julianday += daysinmonth[i]; |
915 | } | 912 | } |
916 | julianday += tm->tm_mday; | 913 | julianday += tm->tm_mday; |
917 | tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 - | 914 | tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 - |
918 | (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7; | 915 | (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7; |
919 | 916 | ||
920 | /* copy all the stuff we want from the tm struct to buffer */ | 917 | /* put all the numbers we want from the tm struct into |
918 | an easily printable buffer */ | ||
921 | snprintf(buffer, sizeof(buffer), | 919 | snprintf(buffer, sizeof(buffer), |
922 | "%02d " "%02d " "%02d " "%.3s " "%04d " "%.3s " "%02d", | 920 | "%02d " "%02d " "%02d " "%04d " "%02d", |
923 | tm->tm_hour, tm->tm_min, tm->tm_sec, | 921 | tm->tm_hour, tm->tm_min, tm->tm_sec, |
924 | str(dayname[tm->tm_wday]), tm->tm_year+1900, | 922 | tm->tm_year+1900, tm->tm_mday); |
925 | str(monthname[tm->tm_mon]), tm->tm_mday); | ||
926 | |||
927 | 923 | ||
928 | /* convert spaces in the buffer to \0 to make it possible to work | 924 | /* convert spaces in the buffer to '\0' to make it possible to work |
929 | directly on the buffer */ | 925 | directly on the buffer */ |
930 | buffer[2] = '\0'; | 926 | for(i=0; i < sizeof(buffer); i++) |
931 | buffer[5] = '\0'; | 927 | { |
932 | buffer[8] = '\0'; | 928 | if(buffer[i] == ' ') |
933 | buffer[9 + DAYNAME_LEN] = '\0'; | 929 | buffer[i] = '\0'; |
934 | buffer[14 + DAYNAME_LEN] = '\0'; | 930 | } |
935 | buffer[15 + DAYNAME_LEN + MONTHNAME_LEN] = '\0'; | 931 | |
936 | FOR_NB_SCREENS(s) | 932 | FOR_NB_SCREENS(s) |
937 | { | 933 | { |
938 | /* minimum lines needed is 2 + title line */ | 934 | /* minimum lines needed is 2 + title line */ |
@@ -945,63 +941,61 @@ bool set_time_screen(const char* title, struct tm *tm) | |||
945 | 941 | ||
946 | /* recalculate the positions and offsets */ | 942 | /* recalculate the positions and offsets */ |
947 | if (screens[s].nb_lines >= 3) | 943 | if (screens[s].nb_lines >= 3) |
948 | screens[s].getstringsize(title, &width, &prev_line_height); | 944 | screens[s].getstringsize(title, NULL, &prev_line_height); |
949 | else | 945 | else |
950 | prev_line_height = 0; | 946 | prev_line_height = 0; |
951 | screens[s].getstringsize(buffer, &width, &line_height); | 947 | screens[s].getstringsize(buffer, NULL, &line_height); |
952 | screens[s].getstringsize(SEPARATOR, &separator_width, &height); | 948 | screens[s].getstringsize(SEPARATOR, &separator_width, NULL); |
953 | 949 | ||
950 | |||
951 | /* get width for each string except the last one and put them | ||
952 | in the cursor array */ | ||
953 | for(i=0; i < 5; i++) | ||
954 | { | ||
955 | screens[s].getstringsize(ptr[i], &width, NULL); | ||
956 | cursor[i][INDEX_WIDTH] = width; | ||
957 | } | ||
958 | |||
954 | /* hour */ | 959 | /* hour */ |
955 | screens[s].getstringsize(buffer, &width, &height); | ||
956 | /* cursor[0][INDEX_X] is already 0 because of the memset */ | 960 | /* cursor[0][INDEX_X] is already 0 because of the memset */ |
957 | cursor[0][INDEX_Y] = prev_line_height + statusbar_height; | 961 | cursor[0][INDEX_Y] = prev_line_height + statusbar_height; |
958 | cursor[0][INDEX_WIDTH] = width; | ||
959 | 962 | ||
960 | /* minute */ | 963 | /* minute */ |
961 | screens[s].getstringsize(buffer + 3, &width, &height); | ||
962 | cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width; | 964 | cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width; |
963 | cursor[1][INDEX_Y] = prev_line_height + statusbar_height; | 965 | cursor[1][INDEX_Y] = prev_line_height + statusbar_height; |
964 | cursor[1][INDEX_WIDTH] = width; | ||
965 | 966 | ||
966 | /* second */ | 967 | /* second */ |
967 | screens[s].getstringsize(buffer + 6, &width, &height); | ||
968 | cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width + | 968 | cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width + |
969 | cursor[1][INDEX_WIDTH] + separator_width; | 969 | cursor[1][INDEX_WIDTH] + separator_width; |
970 | cursor[2][INDEX_Y] = prev_line_height + statusbar_height; | 970 | cursor[2][INDEX_Y] = prev_line_height + statusbar_height; |
971 | 971 | ||
972 | /* weekday */ | 972 | /* weekday */ |
973 | screens[s].getstringsize(buffer + 9, &weekday_width, &height); | 973 | screens[s].getstringsize(str(dayname[tm->tm_wday]), &weekday_width, NULL); |
974 | screens[s].getstringsize(" ", &separator_width, &height); | 974 | screens[s].getstringsize(" ", &separator_width, NULL); |
975 | 975 | ||
976 | /* year */ | 976 | /* year */ |
977 | screens[s].getstringsize(buffer + 10 + DAYNAME_LEN, &width, &height); | ||
978 | cursor[3][INDEX_X] = weekday_width + separator_width; | 977 | cursor[3][INDEX_X] = weekday_width + separator_width; |
979 | cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height; | 978 | cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height; |
980 | cursor[3][INDEX_WIDTH] = width; | 979 | |
981 | |||
982 | /* month */ | 980 | /* month */ |
983 | screens[s].getstringsize(buffer + 15 + DAYNAME_LEN, &width, &height); | ||
984 | cursor[4][INDEX_X] = weekday_width + 2 * separator_width + | 981 | cursor[4][INDEX_X] = weekday_width + 2 * separator_width + |
985 | cursor[3][INDEX_WIDTH]; | 982 | cursor[3][INDEX_WIDTH]; |
986 | cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height; | 983 | cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height; |
987 | cursor[4][INDEX_WIDTH] = width; | 984 | |
988 | |||
989 | /* day */ | 985 | /* day */ |
990 | screens[s].getstringsize(buffer + 16 + DAYNAME_LEN + MONTHNAME_LEN, | ||
991 | &width, &height); | ||
992 | cursor[5][INDEX_X] = weekday_width + 3 * separator_width + | 986 | cursor[5][INDEX_X] = weekday_width + 3 * separator_width + |
993 | cursor[3][INDEX_WIDTH] + | 987 | cursor[3][INDEX_WIDTH] + |
994 | cursor[4][INDEX_WIDTH]; | 988 | cursor[4][INDEX_WIDTH]; |
995 | cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height; | 989 | cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height; |
996 | 990 | ||
997 | /* draw the screen */ | 991 | /* draw the screen */ |
998 | screens[s].set_drawmode(DRMODE_SOLID); | 992 | screens[s].set_drawmode(DRMODE_SOLID); |
999 | screens[s].clear_display(); | 993 | screens[s].clear_display(); |
1000 | /* display the screen title */ | 994 | /* display the screen title */ |
1001 | screens[s].puts_scroll(0, 0, title); | 995 | screens[s].puts_scroll(0, 0, title); |
1002 | 996 | ||
1003 | /* these are not selectable, so we draw them outside the loop */ | 997 | /* these are not selectable, so we draw them outside the loop */ |
1004 | screens[s].putsxy(0, cursor[3][INDEX_Y], buffer + 9); /* name of the week day */ | 998 | screens[s].putsxy(0, cursor[3][INDEX_Y], str(dayname[tm->tm_wday])); /* name of the week day */ |
1005 | screens[s].putsxy(cursor[1][INDEX_X] - separator_width, | 999 | screens[s].putsxy(cursor[1][INDEX_X] - separator_width, |
1006 | cursor[0][INDEX_Y], SEPARATOR); | 1000 | cursor[0][INDEX_Y], SEPARATOR); |
1007 | screens[s].putsxy(cursor[2][INDEX_X] - separator_width, | 1001 | screens[s].putsxy(cursor[2][INDEX_X] - separator_width, |