diff options
author | Shachar Liberman <lshachar@hotmail.com> | 2006-10-02 23:54:28 +0000 |
---|---|---|
committer | Shachar Liberman <lshachar@hotmail.com> | 2006-10-02 23:54:28 +0000 |
commit | f5452c0bded3147dfc91dc89580e65a879bc50e8 (patch) | |
tree | 02902f222ce45b1f47f3533ebcf0d72adb34f22a /apps/gui/splash.c | |
parent | c9d7f76ae5dea14acdbacf4b06212be958f37b47 (diff) | |
download | rockbox-f5452c0bded3147dfc91dc89580e65a879bc50e8.tar.gz rockbox-f5452c0bded3147dfc91dc89580e65a879bc50e8.zip |
Improved code for the splash function: spare some calculation, fix a bug for screens wider then 255 (ipod 5g), fix FS#5775 by displaying complete lines instead of word by word.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11113 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/splash.c')
-rw-r--r-- | apps/gui/splash.c | 151 |
1 files changed, 58 insertions, 93 deletions
diff --git a/apps/gui/splash.c b/apps/gui/splash.c index d04ef015b9..0b2045b2e1 100644 --- a/apps/gui/splash.c +++ b/apps/gui/splash.c | |||
@@ -25,13 +25,11 @@ | |||
25 | 25 | ||
26 | #ifdef HAVE_LCD_BITMAP | 26 | #ifdef HAVE_LCD_BITMAP |
27 | 27 | ||
28 | #define SPACE 3 /* pixels between words */ | ||
29 | #define MAXLETTERS 128 /* 16*8 */ | 28 | #define MAXLETTERS 128 /* 16*8 */ |
30 | #define MAXLINES 10 | 29 | #define MAXLINES 10 |
31 | 30 | ||
32 | #else | 31 | #else |
33 | 32 | ||
34 | #define SPACE 1 /* one letter space */ | ||
35 | #define MAXLETTERS 22 /* 11 * 2 */ | 33 | #define MAXLETTERS 22 /* 11 * 2 */ |
36 | #define MAXLINES 2 | 34 | #define MAXLINES 2 |
37 | 35 | ||
@@ -42,93 +40,80 @@ static void splash(struct screen * screen, | |||
42 | { | 40 | { |
43 | char *next; | 41 | char *next; |
44 | char *store=NULL; | 42 | char *store=NULL; |
45 | int x=0; | 43 | int x = 0; |
46 | int y=0; | ||
47 | int w, h; | 44 | int w, h; |
48 | unsigned char splash_buf[MAXLETTERS]; | 45 | unsigned char splash_buf[MAXLETTERS]; |
49 | unsigned char widths[MAXLINES]; | 46 | unsigned short widths[MAXLINES]; |
50 | int line=0; | 47 | unsigned char *text = splash_buf; |
48 | int line = 0, i_line = 0; | ||
51 | bool first=true; | 49 | bool first=true; |
52 | #ifdef HAVE_LCD_BITMAP | 50 | #ifdef HAVE_LCD_BITMAP |
53 | int maxw=0; | 51 | int maxw=0; |
52 | int space; | ||
53 | int y; | ||
54 | screen->getstringsize(" ", &space, &y); | ||
54 | #if LCD_DEPTH > 1 | 55 | #if LCD_DEPTH > 1 |
55 | unsigned prevbg = LCD_DEFAULT_BG; | 56 | unsigned prevbg = LCD_DEFAULT_BG; |
56 | unsigned prevfg = LCD_DEFAULT_FG; | 57 | unsigned prevfg = LCD_DEFAULT_FG; |
57 | #endif | 58 | #endif |
58 | #endif | 59 | #else |
59 | 60 | screen->double_height (false); /* HAVE_LCD_CHARCELLS */ | |
60 | #ifdef HAVE_LCD_CHARCELLS | 61 | int space = 1; |
61 | screen->double_height (false); | 62 | int y = 0; |
62 | #endif | 63 | #endif |
63 | screen->stop_scroll(); | 64 | screen->stop_scroll(); |
64 | vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap ); | 65 | vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap ); |
65 | 66 | va_end( ap ); | |
66 | if(center) { | 67 | |
67 | /* first a pass to measure sizes */ | 68 | /* measure sizes & concatenates tokenise words into lines. */ |
68 | next = strtok_r(splash_buf, " ", &store); | 69 | next = strtok_r(splash_buf, " ", &store); |
69 | while (next) { | 70 | while (next) { |
70 | #ifdef HAVE_LCD_BITMAP | 71 | #ifdef HAVE_LCD_BITMAP |
71 | screen->getstringsize(next, &w, &h); | 72 | screen->getstringsize(next, &w, &h); |
72 | #else | 73 | #else |
73 | w = strlen(next); | 74 | w = strlen(next); |
74 | h = 1; /* store height in characters */ | 75 | h = 1; /* store height in characters */ |
75 | #endif | 76 | #endif |
76 | if(!first) { | 77 | if(!first) { |
77 | if(x+w> screen->width) { | 78 | if(x + w > screen->width) { /* Too wide, wrap */ |
78 | /* Too wide, wrap */ | 79 | y += h; |
79 | y+=h; | 80 | line++; |
80 | line++; | 81 | x = 0; |
81 | if((y > (screen->height-h)) || (line > screen->nb_lines)) | 82 | if((y > (screen->height-h)) || (line > screen->nb_lines)) |
82 | /* STOP */ | 83 | /* STOP */ |
83 | break; | 84 | break; |
84 | x=0; | ||
85 | first=true; | ||
86 | } | ||
87 | } | 85 | } |
88 | else | 86 | else |
89 | first = false; | 87 | next[-1] = ' '; /* re-concatenate string */ |
90 | 88 | } | |
91 | /* think of it as if the text was written here at position x,y | 89 | else |
92 | being w pixels/chars wide and h high */ | 90 | first = false; |
93 | 91 | ||
94 | x += w+SPACE; | 92 | x += w + space; |
95 | widths[line]=x-SPACE; /* don't count the trailing space */ | 93 | widths[line] = x - space; /* don't count the trailing space */ |
96 | #ifdef HAVE_LCD_BITMAP | 94 | #ifdef HAVE_LCD_BITMAP |
97 | /* store the widest line */ | 95 | /* store the widest line */ |
98 | if(widths[line]>maxw) | 96 | if(widths[line]>maxw) |
99 | maxw = widths[line]; | 97 | maxw = widths[line]; |
100 | #endif | 98 | #endif |
101 | next = strtok_r(NULL, " ", &store); | 99 | next = strtok_r(NULL, " ", &store); |
102 | } | 100 | } |
103 | 101 | ||
102 | if(center) { | ||
104 | #ifdef HAVE_LCD_BITMAP | 103 | #ifdef HAVE_LCD_BITMAP |
105 | /* Start displaying the message at position y. The reason for the | 104 | /* Start displaying the message at position y. */ |
106 | added h here is that it isn't added until the end of lines in the | 105 | y = (screen->height - y)/2; |
107 | loop above and we always break the loop in the middle of a line. */ | ||
108 | y = (screen->height - (y+h) )/2; | ||
109 | #else | 106 | #else |
110 | y = 0; /* vertical center on 2 lines would be silly */ | 107 | y = 0; /* vertical center on 2 lines would be silly */ |
111 | #endif | 108 | #endif |
112 | first=true; | 109 | } else |
113 | 110 | y = 0; | |
114 | /* Now recreate the string again since the strtok_r() above has ruined | ||
115 | the one we already have! Here's room for improvements! */ | ||
116 | vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap ); | ||
117 | } | ||
118 | va_end( ap ); | ||
119 | |||
120 | if(center) | ||
121 | { | ||
122 | x = (screen->width-widths[0])/2; | ||
123 | if(x < 0) | ||
124 | x = 0; | ||
125 | } | ||
126 | 111 | ||
127 | #ifdef HAVE_LCD_BITMAP | ||
128 | /* If we center the display, then just clear the box we need and put | 112 | /* If we center the display, then just clear the box we need and put |
129 | a nice little frame and put the text in there! */ | 113 | a nice little frame and put the text in there! */ |
114 | #ifdef HAVE_LCD_BITMAP | ||
130 | if(center && (y > 2)) { | 115 | if(center && (y > 2)) { |
131 | int xx = (screen->width-maxw)/2 - 2; | 116 | int xx = (screen->width - maxw)/2 - 2; |
132 | /* The new graphics routines handle clipping, so no need to check */ | 117 | /* The new graphics routines handle clipping, so no need to check */ |
133 | #if LCD_DEPTH > 1 | 118 | #if LCD_DEPTH > 1 |
134 | if(screen->depth>1) { | 119 | if(screen->depth>1) { |
@@ -146,43 +131,23 @@ static void splash(struct screen * screen, | |||
146 | else | 131 | else |
147 | #endif | 132 | #endif |
148 | screen->clear_display(); | 133 | screen->clear_display(); |
149 | line=0; | 134 | |
150 | next = strtok_r(splash_buf, " ", &store); | 135 | /* print the message to screen */ |
151 | while (next) { | 136 | while(line-- >= 0) { |
137 | if (center) { | ||
138 | x = (screen->width-widths[i_line++])/2; | ||
139 | if(x < 0) | ||
140 | x = 0; | ||
141 | } else | ||
142 | x = 0; | ||
152 | #ifdef HAVE_LCD_BITMAP | 143 | #ifdef HAVE_LCD_BITMAP |
153 | screen->getstringsize(next, &w, &h); | 144 | screen->putsxy(x, y, text); |
154 | #else | 145 | #else |
155 | w = strlen(next); | 146 | screen->puts(x, y, text); |
156 | h = 1; | ||
157 | #endif | 147 | #endif |
158 | if(!first) { | 148 | text += strlen(text) + 1; |
159 | if(x+w> screen->width) { | 149 | y +=h; |
160 | /* too wide */ | ||
161 | y+=h; | ||
162 | line++; /* goto next line */ | ||
163 | first=true; | ||
164 | if(y > (screen->height-h)) | ||
165 | /* STOP */ | ||
166 | break; | ||
167 | if(center) { | ||
168 | x = (screen->width-widths[line])/2; | ||
169 | if(x < 0) | ||
170 | x = 0; | ||
171 | } | ||
172 | else | ||
173 | x=0; | ||
174 | } | ||
175 | } | 150 | } |
176 | else | ||
177 | first=false; | ||
178 | #ifdef HAVE_LCD_BITMAP | ||
179 | screen->putsxy(x, y, next); | ||
180 | #else | ||
181 | screen->puts(x, y, next); | ||
182 | #endif | ||
183 | x += w+SPACE; /* pixels space! */ | ||
184 | next = strtok_r(NULL, " ", &store); | ||
185 | } | ||
186 | 151 | ||
187 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH > 1) | 152 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH > 1) |
188 | if(screen->depth > 1) { | 153 | if(screen->depth > 1) { |