1
0
Fork 0
forked from len0rd/rockbox

power-splash, this should be able to replace most cases where we "splash"

messages for a brief period


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3464 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2003-03-17 21:14:46 +00:00
parent 7ab2ff550d
commit 87cd59f7e3
2 changed files with 95 additions and 16 deletions

View file

@ -470,26 +470,44 @@ bool f3_screen(void)
#ifdef HAVE_LCD_BITMAP
#define SPACE 4 /* pixels between words */
#define MAXLETTERS 128 /* 16*8 */
#define MAXLINES 10
#else
#define SPACE 1 /* one letter space */
#undef LCD_WIDTH
#define LCD_WIDTH 11
#undef LCD_HEIGHT
#define LCD_HEIGHT 2
#define MAXLETTERS 22 /* 11 * 2 */
#define MAXLINES 2
#endif
void splash(char *text, /* what to say */
int ticks, /* fow how long */
int keymask) /* what keymask aborts the waiting (if any) */
void splash(int ticks, /* how long */
int keymask, /* what keymask aborts the waiting (if any) */
bool center, /* FALSE means left-justified, TRUE means
horizontal and vertical center */
char *fmt, /* what to say *printf style */
...)
{
char *next;
char *store=NULL;
int x=0;
int y=0;
int w, h;
unsigned char splash_buf[MAXLETTERS];
va_list ap;
unsigned char widths[MAXLINES];
int line=0;
bool first=true;
va_start( ap, fmt );
vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap );
lcd_clear_display();
next = strtok_r(text, " ", &store);
if(center) {
/* first a pass to measure sizes */
next = strtok_r(splash_buf, " ", &store);
while (next) {
#ifdef HAVE_LCD_BITMAP
lcd_getstringsize(next, &w, &h);
@ -497,16 +515,69 @@ void splash(char *text, /* what to say */
w = strlen(next);
h = 1;
#endif
if(x) {
if(!first) {
if(x+w> LCD_WIDTH) {
/* too wide */
y+=h;
if(y > (LCD_HEIGHT-h))
line++;
if((y > (LCD_HEIGHT-h)) || (line > MAXLINES))
/* STOP */
break;
x=0;
first=true;
}
}
else
first = false;
/* think of it as if the text was written here at position x,y
being w pixels/chars wide and h high */
x += w+SPACE;
widths[line]=x-SPACE; /* don't count the trailing space */
next = strtok_r(NULL, " ", &store);
}
#ifdef HAVE_LCD_BITMAP
/* Start displaying the message at position y. The reason for the
added h here is that it isn't added until the end of lines in the
loop above and we always break the loop in the middle of a line. */
y = (LCD_HEIGHT - (y+h) )/2;
#else
y = 0; /* vertical center on 2 lines would be silly */
#endif
line=0;
first=true;
vsnprintf( splash_buf, sizeof(splash_buf), fmt, ap );
}
va_end( ap );
if(center)
x = (LCD_WIDTH-widths[0])/2;
next = strtok_r(splash_buf, " ", &store);
while (next) {
#ifdef HAVE_LCD_BITMAP
lcd_getstringsize(next, &w, &h);
#else
w = strlen(next);
h = 1;
#endif
if(!first) {
if(x+w> LCD_WIDTH) {
/* too wide */
y+=h;
line++; /* goto next line */
first=true;
if(y > (LCD_HEIGHT-h))
/* STOP */
break;
if(center)
x = (LCD_WIDTH-widths[line])/2;
else
x=0;
}
}
else
first=false;
#ifdef HAVE_LCD_BITMAP
lcd_putsxy(x, y, next);
lcd_update(); /* DURING DEBUG ONLY */
@ -519,6 +590,7 @@ void splash(char *text, /* what to say */
lcd_update();
if(ticks) {
if(keymask) {
int start = current_tick;
int done = ticks + current_tick + 1;
while (TIME_BEFORE( current_tick, done)) {
@ -527,4 +599,8 @@ void splash(char *text, /* what to say */
break;
}
}
else
/* unbreakable! */
sleep(ticks);
}
}

View file

@ -28,8 +28,11 @@ bool f2_screen(void);
bool f3_screen(void);
#endif
void splash(char *text, /* what to say */
int ticks, /* fow how long */
int button);/* what keymask aborts the waiting (if any) */
void splash(int ticks, /* how long */
int keymask,/* what keymask aborts the waiting (if any) */
bool center, /* FALSE means left-justified, TRUE means
horizontal and vertical center */
char *fmt, /* what to say *printf style */
...);
#endif