diff options
author | William Wilgus <wilgus.william@gmail.com> | 2022-10-09 00:47:44 -0400 |
---|---|---|
committer | William Wilgus <wilgus.william@gmail.com> | 2022-10-09 08:46:51 -0400 |
commit | d73aaf3d9ec0f232c733f9330d38cdec55d9264d (patch) | |
tree | b124e48be4feb16e5d5c551a63714975869eb8a3 /apps | |
parent | e57b4f909901ccc04b596ea817a98100b5f7b33b (diff) | |
download | rockbox-d73aaf3d9ec0f232c733f9330d38cdec55d9264d.tar.gz rockbox-d73aaf3d9ec0f232c733f9330d38cdec55d9264d.zip |
add splash_progress
the loading track splash flashes and is ugly
add a function to display a progressbar along with the splash message
spruce up database commit message as well
Change-Id: I2749b958c1ee5dad2631a5f999a4b00ddca7f225
Diffstat (limited to 'apps')
-rw-r--r-- | apps/gui/splash.c | 112 | ||||
-rw-r--r-- | apps/gui/splash.h | 9 | ||||
-rw-r--r-- | apps/main.c | 10 | ||||
-rw-r--r-- | apps/onplay.c | 5 | ||||
-rw-r--r-- | apps/playlist.c | 7 | ||||
-rw-r--r-- | apps/root_menu.c | 16 |
6 files changed, 113 insertions, 46 deletions
diff --git a/apps/gui/splash.c b/apps/gui/splash.c index b85e4693aa..bf9647cff1 100644 --- a/apps/gui/splash.c +++ b/apps/gui/splash.c | |||
@@ -30,17 +30,18 @@ | |||
30 | #include "splash.h" | 30 | #include "splash.h" |
31 | #include "viewport.h" | 31 | #include "viewport.h" |
32 | #include "strtok_r.h" | 32 | #include "strtok_r.h" |
33 | #include "scrollbar.h" | ||
33 | 34 | ||
34 | #define MAXLINES (LCD_HEIGHT/6) | 35 | #define MAXLINES (LCD_HEIGHT/6) |
35 | #define MAXBUFFER 512 | 36 | #define MAXBUFFER 512 |
36 | #define RECT_SPACING 2 | 37 | #define RECT_SPACING 2 |
37 | #define SPLASH_MEMORY_INTERVAL (HZ) | 38 | #define SPLASH_MEMORY_INTERVAL (HZ) |
38 | 39 | ||
39 | static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | 40 | static bool splash_internal(struct screen * screen, const char *fmt, va_list ap, |
41 | struct viewport *vp, int addl_lines) | ||
40 | { | 42 | { |
41 | char splash_buf[MAXBUFFER]; | 43 | char splash_buf[MAXBUFFER]; |
42 | char *lines[MAXLINES]; | 44 | char *lines[MAXLINES]; |
43 | |||
44 | char *next; | 45 | char *next; |
45 | char *lastbreak = NULL; | 46 | char *lastbreak = NULL; |
46 | char *store = NULL; | 47 | char *store = NULL; |
@@ -48,15 +49,12 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | |||
48 | int x = 0; | 49 | int x = 0; |
49 | int y, i; | 50 | int y, i; |
50 | int space_w, w, h; | 51 | int space_w, w, h; |
51 | struct viewport vp; | 52 | |
52 | int width, height; | 53 | int width, height; |
53 | int maxw = 0; | 54 | int maxw = 0; |
54 | 55 | ||
55 | viewport_set_defaults(&vp, screen->screen_type); | ||
56 | struct viewport *last_vp = screen->set_viewport(&vp); | ||
57 | |||
58 | screen->getstringsize(" ", &space_w, &h); | 56 | screen->getstringsize(" ", &space_w, &h); |
59 | y = h; | 57 | y = h + (addl_lines * h); |
60 | 58 | ||
61 | vsnprintf(splash_buf, sizeof(splash_buf), fmt, ap); | 59 | vsnprintf(splash_buf, sizeof(splash_buf), fmt, ap); |
62 | va_end(ap); | 60 | va_end(ap); |
@@ -65,7 +63,7 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | |||
65 | 63 | ||
66 | next = strtok_r(splash_buf, " ", &store); | 64 | next = strtok_r(splash_buf, " ", &store); |
67 | if (!next) | 65 | if (!next) |
68 | goto end; /* nothing to display */ | 66 | return false; /* nothing to display */ |
69 | 67 | ||
70 | lines[0] = next; | 68 | lines[0] = next; |
71 | while (true) | 69 | while (true) |
@@ -73,12 +71,13 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | |||
73 | screen->getstringsize(next, &w, NULL); | 71 | screen->getstringsize(next, &w, NULL); |
74 | if (lastbreak) | 72 | if (lastbreak) |
75 | { | 73 | { |
76 | if (x + (next - lastbreak) * space_w + w | 74 | int next_w = (next - lastbreak) * space_w; |
77 | > vp.width - RECT_SPACING*2) | 75 | |
76 | if (x + next_w + w > vp->width - RECT_SPACING*2) | ||
78 | { /* too wide, wrap */ | 77 | { /* too wide, wrap */ |
79 | if (x > maxw) | 78 | if (x > maxw) |
80 | maxw = x; | 79 | maxw = x; |
81 | if ((y + h > vp.height) || (line >= (MAXLINES-1))) | 80 | if ((y + h > vp->height) || (line >= (MAXLINES-1))) |
82 | break; /* screen full or out of lines */ | 81 | break; /* screen full or out of lines */ |
83 | x = 0; | 82 | x = 0; |
84 | y += h; | 83 | y += h; |
@@ -88,7 +87,7 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | |||
88 | { | 87 | { |
89 | /* restore & calculate spacing */ | 88 | /* restore & calculate spacing */ |
90 | *lastbreak = ' '; | 89 | *lastbreak = ' '; |
91 | x += (next - lastbreak) * space_w; | 90 | x += next_w; |
92 | } | 91 | } |
93 | } | 92 | } |
94 | x += w; | 93 | x += w; |
@@ -111,39 +110,39 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | |||
111 | width = maxw + 2*RECT_SPACING; | 110 | width = maxw + 2*RECT_SPACING; |
112 | height = y + 2*RECT_SPACING; | 111 | height = y + 2*RECT_SPACING; |
113 | 112 | ||
114 | if (width > vp.width) | 113 | if (width > vp->width) |
115 | width = vp.width; | 114 | width = vp->width; |
116 | if (height > vp.height) | 115 | if (height > vp->height) |
117 | height = vp.height; | 116 | height = vp->height; |
118 | 117 | ||
119 | vp.x += (vp.width - width) / 2; | 118 | vp->x += (vp->width - width) / 2; |
120 | vp.y += (vp.height - height) / 2; | 119 | vp->y += (vp->height - height) / 2; |
121 | vp.width = width; | 120 | vp->width = width; |
122 | vp.height = height; | 121 | vp->height = height; |
123 | 122 | ||
124 | vp.flags |= VP_FLAG_ALIGN_CENTER; | 123 | vp->flags |= VP_FLAG_ALIGN_CENTER; |
125 | #if LCD_DEPTH > 1 | 124 | #if LCD_DEPTH > 1 |
126 | if (screen->depth > 1) | 125 | if (screen->depth > 1) |
127 | { | 126 | { |
128 | vp.drawmode = DRMODE_FG; | 127 | vp->drawmode = DRMODE_FG; |
129 | /* can't do vp.fg_pattern here, since set_foreground does a bit more on | 128 | /* can't do vp->fg_pattern here, since set_foreground does a bit more on |
130 | * greyscale */ | 129 | * greyscale */ |
131 | screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_LIGHTGRAY)); | 130 | screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_LIGHTGRAY)); |
132 | } | 131 | } |
133 | else | 132 | else |
134 | #endif | 133 | #endif |
135 | vp.drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID); | 134 | vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID); |
136 | 135 | ||
137 | screen->fill_viewport(); | 136 | screen->fill_viewport(); |
138 | 137 | ||
139 | #if LCD_DEPTH > 1 | 138 | #if LCD_DEPTH > 1 |
140 | if (screen->depth > 1) | 139 | if (screen->depth > 1) |
141 | /* can't do vp.fg_pattern here, since set_foreground does a bit more on | 140 | /* can't do vp->fg_pattern here, since set_foreground does a bit more on |
142 | * greyscale */ | 141 | * greyscale */ |
143 | screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_BLACK)); | 142 | screen->set_foreground(SCREEN_COLOR_TO_NATIVE(screen, LCD_BLACK)); |
144 | else | 143 | else |
145 | #endif | 144 | #endif |
146 | vp.drawmode = DRMODE_SOLID; | 145 | vp->drawmode = DRMODE_SOLID; |
147 | 146 | ||
148 | screen->draw_border_viewport(); | 147 | screen->draw_border_viewport(); |
149 | 148 | ||
@@ -155,9 +154,7 @@ static void splash_internal(struct screen * screen, const char *fmt, va_list ap) | |||
155 | { | 154 | { |
156 | screen->putsxy(0, y, lines[i]); | 155 | screen->putsxy(0, y, lines[i]); |
157 | } | 156 | } |
158 | screen->update_viewport(); | 157 | return true; /* needs update */ |
159 | end: | ||
160 | screen->set_viewport(last_vp); | ||
161 | } | 158 | } |
162 | 159 | ||
163 | void splashf(int ticks, const char *fmt, ...) | 160 | void splashf(int ticks, const char *fmt, ...) |
@@ -169,9 +166,17 @@ void splashf(int ticks, const char *fmt, ...) | |||
169 | fmt = P2STR((unsigned char *)fmt); | 166 | fmt = P2STR((unsigned char *)fmt); |
170 | FOR_NB_SCREENS(i) | 167 | FOR_NB_SCREENS(i) |
171 | { | 168 | { |
169 | struct screen * screen = &(screens[i]); | ||
170 | struct viewport vp; | ||
171 | viewport_set_defaults(&vp, screen->screen_type); | ||
172 | struct viewport *last_vp = screen->set_viewport(&vp); | ||
173 | |||
172 | va_start(ap, fmt); | 174 | va_start(ap, fmt); |
173 | splash_internal(&(screens[i]), fmt, ap); | 175 | if (splash_internal(screen, fmt, ap, &vp, 0)) |
176 | screen->update_viewport(); | ||
174 | va_end(ap); | 177 | va_end(ap); |
178 | |||
179 | screen->set_viewport(last_vp); | ||
175 | } | 180 | } |
176 | if (ticks) | 181 | if (ticks) |
177 | sleep(ticks); | 182 | sleep(ticks); |
@@ -189,3 +194,50 @@ void splash(int ticks, const char *str) | |||
189 | #endif | 194 | #endif |
190 | splashf(ticks, "%s", P2STR((const unsigned char*)str)); | 195 | splashf(ticks, "%s", P2STR((const unsigned char*)str)); |
191 | } | 196 | } |
197 | |||
198 | /* splash a progress meter */ | ||
199 | void splash_progress(int current, int total, const char *fmt, ...) | ||
200 | { | ||
201 | int vp_flag = VP_FLAG_VP_DIRTY; | ||
202 | /* progress update tick */ | ||
203 | static long next_tick = 0; | ||
204 | long now = current_tick; | ||
205 | |||
206 | if (current < total) | ||
207 | { | ||
208 | if(TIME_BEFORE(now, next_tick)) | ||
209 | return; | ||
210 | /* limit to 20fps */ | ||
211 | next_tick = now + HZ/20; | ||
212 | vp_flag = 0; /* don't mark vp dirty to prevent flashing */ | ||
213 | } | ||
214 | |||
215 | va_list ap; | ||
216 | |||
217 | /* If fmt is a lang ID then get the corresponding string (which | ||
218 | still might contain % place holders). */ | ||
219 | fmt = P2STR((unsigned char *)fmt); | ||
220 | FOR_NB_SCREENS(i) | ||
221 | { | ||
222 | struct screen * screen = &(screens[i]); | ||
223 | struct viewport vp; | ||
224 | viewport_set_defaults(&vp, screen->screen_type); | ||
225 | struct viewport *last_vp = screen->set_viewport_ex(&vp, vp_flag); | ||
226 | |||
227 | va_start(ap, fmt); | ||
228 | if (splash_internal(screen, fmt, ap, &vp, 1)) | ||
229 | { | ||
230 | int size = screen->getcharheight(); | ||
231 | int y = vp.height - size - RECT_SPACING; | ||
232 | int w = vp.width - RECT_SPACING * 2; | ||
233 | |||
234 | gui_scrollbar_draw(screen, RECT_SPACING, y, w, size, | ||
235 | total, 0, current, HORIZONTAL | FOREGROUND); | ||
236 | |||
237 | screen->update_viewport(); | ||
238 | } | ||
239 | va_end(ap); | ||
240 | |||
241 | screen->set_viewport(last_vp); | ||
242 | } | ||
243 | } | ||
diff --git a/apps/gui/splash.h b/apps/gui/splash.h index 76b4c16d0c..4002af5296 100644 --- a/apps/gui/splash.h +++ b/apps/gui/splash.h | |||
@@ -39,4 +39,13 @@ extern void splashf(int ticks, const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); | |||
39 | * it will be voiced | 39 | * it will be voiced |
40 | */ | 40 | */ |
41 | extern void splash(int ticks, const char *str); | 41 | extern void splash(int ticks, const char *str); |
42 | |||
43 | /* | ||
44 | * Puts a splash message centered on all the screens with a progressbar | ||
45 | * - current : current progress increment | ||
46 | * - total : total increments | ||
47 | * - fmt : what to say *printf style | ||
48 | * updates limited internally to 20 fps - call repeatedly to update progress | ||
49 | */ | ||
50 | extern void splash_progress(int current, int total, const char *fmt, ...) ATTRIBUTE_PRINTF(3, 4); | ||
42 | #endif /* _GUI_ICON_H_ */ | 51 | #endif /* _GUI_ICON_H_ */ |
diff --git a/apps/main.c b/apps/main.c index 59932d6185..6360267243 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -288,13 +288,15 @@ static void init_tagcache(void) | |||
288 | #endif | 288 | #endif |
289 | if (lang_is_rtl()) | 289 | if (lang_is_rtl()) |
290 | { | 290 | { |
291 | splashf(0, "[%d/%d] %s", ret, tagcache_get_max_commit_step(), | 291 | splash_progress(ret, tagcache_get_max_commit_step(), |
292 | str(LANG_TAGCACHE_INIT)); | 292 | "[%d/%d] %s", ret, tagcache_get_max_commit_step(), |
293 | str(LANG_TAGCACHE_INIT)); | ||
293 | } | 294 | } |
294 | else | 295 | else |
295 | { | 296 | { |
296 | splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT), ret, | 297 | splash_progress(ret, tagcache_get_max_commit_step(), |
297 | tagcache_get_max_commit_step()); | 298 | "%s [%d/%d]", str(LANG_TAGCACHE_INIT), ret, |
299 | tagcache_get_max_commit_step()); | ||
298 | } | 300 | } |
299 | clear = true; | 301 | clear = true; |
300 | } | 302 | } |
diff --git a/apps/onplay.c b/apps/onplay.c index e4e2a7b3b8..bb93d204e0 100644 --- a/apps/onplay.c +++ b/apps/onplay.c | |||
@@ -382,8 +382,9 @@ static bool playing_time(void) | |||
382 | although playback continues forward. */ | 382 | although playback continues forward. */ |
383 | for (i = 0; i < pti.nb_tracks; i++) { | 383 | for (i = 0; i < pti.nb_tracks; i++) { |
384 | /* Show a splash while we are loading. */ | 384 | /* Show a splash while we are loading. */ |
385 | splashf(0, str(LANG_LOADING_PERCENT), | 385 | splash_progress(i, pti.nb_tracks, |
386 | i*100/pti.nb_tracks, str(LANG_OFF_ABORT)); | 386 | "%s (%s)", str(LANG_WAIT), str(LANG_OFF_ABORT)); |
387 | |||
387 | /* Voice equivalent */ | 388 | /* Voice equivalent */ |
388 | if (TIME_AFTER(current_tick, talked_tick+5*HZ)) { | 389 | if (TIME_AFTER(current_tick, talked_tick+5*HZ)) { |
389 | talked_tick = current_tick; | 390 | talked_tick = current_tick; |
diff --git a/apps/playlist.c b/apps/playlist.c index 70a1a0823e..837e9d7f44 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -2201,12 +2201,11 @@ int playlist_resume(void) | |||
2201 | 2201 | ||
2202 | for(count=0; count<nread && !exit_loop && !useraborted; count++,p++) | 2202 | for(count=0; count<nread && !exit_loop && !useraborted; count++,p++) |
2203 | { | 2203 | { |
2204 | /* So a splash while we are loading. */ | 2204 | /* Show a splash while we are loading. */ |
2205 | splash_progress((total_read + count), control_file_size, | ||
2206 | "%s (%s)", str(LANG_WAIT), str(LANG_OFF_ABORT)); | ||
2205 | if (TIME_AFTER(current_tick, last_tick + HZ/4)) | 2207 | if (TIME_AFTER(current_tick, last_tick + HZ/4)) |
2206 | { | 2208 | { |
2207 | splashf(0, str(LANG_LOADING_PERCENT), | ||
2208 | (total_read+count)*100/control_file_size, | ||
2209 | str(LANG_OFF_ABORT)); | ||
2210 | if (action_userabort(TIMEOUT_NOBLOCK)) | 2209 | if (action_userabort(TIMEOUT_NOBLOCK)) |
2211 | { | 2210 | { |
2212 | useraborted = true; | 2211 | useraborted = true; |
diff --git a/apps/root_menu.c b/apps/root_menu.c index 80a84d9d49..95524e1ba3 100644 --- a/apps/root_menu.c +++ b/apps/root_menu.c | |||
@@ -241,15 +241,19 @@ static int browser(void* param) | |||
241 | { | 241 | { |
242 | if (lang_is_rtl()) | 242 | if (lang_is_rtl()) |
243 | { | 243 | { |
244 | splashf(0, "[%d/%d] %s", stat->commit_step, | 244 | splash_progress(stat->commit_step, |
245 | tagcache_get_max_commit_step(), | 245 | tagcache_get_max_commit_step(), |
246 | str(LANG_TAGCACHE_INIT)); | 246 | "[%d/%d] %s", stat->commit_step, |
247 | tagcache_get_max_commit_step(), | ||
248 | str(LANG_TAGCACHE_INIT)); | ||
247 | } | 249 | } |
248 | else | 250 | else |
249 | { | 251 | { |
250 | splashf(0, "%s [%d/%d]", str(LANG_TAGCACHE_INIT), | 252 | splash_progress(stat->commit_step, |
251 | stat->commit_step, | 253 | tagcache_get_max_commit_step(), |
252 | tagcache_get_max_commit_step()); | 254 | "%s [%d/%d]", str(LANG_TAGCACHE_INIT), |
255 | stat->commit_step, | ||
256 | tagcache_get_max_commit_step()); | ||
253 | } | 257 | } |
254 | } | 258 | } |
255 | else | 259 | else |