From 078f3285445bbc9d7da1db70ac70595eb6cc7208 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 18 Mar 2003 16:04:58 +0000 Subject: [PATCH] When you use splash() and a centered output, it will now put the text in a centered "box" on the screen and will not clear the rest of the screen. This makes a neat "windows-effect", as can be seen on these demo-shots: http://www.contactor.se/~dast/splash3.png http://www.contactor.se/~dast/splash2.png http://www.contactor.se/~dast/splash.png Needless to say, current code that "pops-up" information should be moved to use splash() instead... git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3476 a1c6a512-1295-4272-9138-f99709370657 --- apps/screens.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/apps/screens.c b/apps/screens.c index f7ee443f4b..37b2f5e426 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -469,7 +469,7 @@ bool f3_screen(void) #endif #ifdef HAVE_LCD_BITMAP -#define SPACE 4 /* pixels between words */ +#define SPACE 3 /* pixels between words */ #define MAXLETTERS 128 /* 16*8 */ #define MAXLINES 10 #else @@ -499,13 +499,15 @@ void splash(int ticks, /* how long */ unsigned char widths[MAXLINES]; int line=0; bool first=true; +#ifdef HAVE_LCD_BITMAP + int maxw=0; +#endif va_start( ap, fmt ); vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap ); - lcd_clear_display(); - if(center) { + /* first a pass to measure sizes */ next = strtok_r(splash_buf, " ", &store); while (next) { @@ -513,11 +515,11 @@ void splash(int ticks, /* how long */ lcd_getstringsize(next, &w, &h); #else w = strlen(next); - h = 1; + h = 1; /* store height in characters */ #endif if(!first) { if(x+w> LCD_WIDTH) { - /* too wide */ + /* Too wide, wrap */ y+=h; line++; if((y > (LCD_HEIGHT-h)) || (line > MAXLINES)) @@ -535,6 +537,11 @@ void splash(int ticks, /* how long */ x += w+SPACE; widths[line]=x-SPACE; /* don't count the trailing space */ +#ifdef HAVE_LCD_BITMAP + /* store the widest line */ + if(widths[line]>maxw) + maxw = widths[line]; +#endif next = strtok_r(NULL, " ", &store); } #ifdef HAVE_LCD_BITMAP @@ -545,14 +552,37 @@ void splash(int ticks, /* how long */ #else y = 0; /* vertical center on 2 lines would be silly */ #endif - line=0; first=true; + + /* Now recreate the string again since the strtok_r() above has ruined + the one we already have! Here's room for improvements! */ vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap ); } va_end( ap ); if(center) x = (LCD_WIDTH-widths[0])/2; + +#ifdef HAVE_LCD_BITMAP + /* If we center the display and it wouldn't cover the full screen, + then just clear the box we need and put a nice little frame and + put the text in there! */ + if(center && (y > 2)) { + if(maxw < (LCD_WIDTH -4)) { + int xx = (LCD_WIDTH-maxw)/2 - 2; + lcd_clearrect(xx, y-2, maxw+4, LCD_HEIGHT-y*2+4); + lcd_drawrect(xx, y-2, maxw+4, LCD_HEIGHT-y*2+4); + } + else { + lcd_clearrect(0, y-2, LCD_WIDTH, LCD_HEIGHT-y*2+4); + lcd_drawline(0, y-2, LCD_WIDTH, y-2); + lcd_drawline(0, LCD_HEIGHT-y+2, LCD_WIDTH, LCD_HEIGHT-y+2); + } + } + else +#endif + lcd_clear_display(); + line=0; next = strtok_r(splash_buf, " ", &store); while (next) { #ifdef HAVE_LCD_BITMAP