Fixed tighter looping scroll.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@977 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Björn Stenberg 2002-06-12 15:15:51 +00:00
parent 8169c8f5bd
commit 4b422aaa36

View file

@ -103,9 +103,9 @@
struct scrollinfo { struct scrollinfo {
char text[128]; char text[128];
char line[32];
int textlen; int textlen;
char offset; char offset;
char xpos;
char startx; char startx;
char starty; char starty;
char space; char space;
@ -113,7 +113,9 @@ struct scrollinfo {
static void scroll_thread(void); static void scroll_thread(void);
static char scroll_stack[0x100]; static char scroll_stack[0x100];
static char scroll_speed = 5; /* updates per second */ static char scroll_speed = 8; /* updates per second */
static char scroll_spacing = 3; /* spaces between end and start of text */
static struct scrollinfo scroll; /* only one scroll line at the moment */ static struct scrollinfo scroll; /* only one scroll line at the moment */
static int scroll_count = 0; static int scroll_count = 0;
@ -766,17 +768,18 @@ void lcd_puts_scroll(int x, int y, char* string )
#else #else
int width, height; int width, height;
lcd_getfontsize(font, &width, &height); lcd_getfontsize(font, &width, &height);
s->space = (LCD_WIDTH - xmargin - x) / width; s->space = (LCD_WIDTH - xmargin - x*width) / width;
#endif #endif
lcd_puts(x,y,string); lcd_puts(x,y,string);
s->textlen = strlen(string); s->textlen = strlen(string);
if ( s->textlen > s->space ) { if ( s->textlen > s->space ) {
s->offset=0; s->offset=s->space;
s->xpos=x;
s->startx=x; s->startx=x;
s->starty=y; s->starty=y;
strncpy(s->text,string,sizeof s->text); strncpy(s->text,string,sizeof s->text);
s->text[sizeof s->text - 1] = 0; s->text[sizeof s->text - 1] = 0;
strncpy(s->line,string,sizeof s->line);
s->line[sizeof s->line - 1] = 0;
scroll_count = 1; scroll_count = 1;
} }
} }
@ -801,31 +804,34 @@ void lcd_scroll_speed(int speed)
static void scroll_thread(void) static void scroll_thread(void)
{ {
struct scrollinfo* s = &scroll; struct scrollinfo* s = &scroll;
while ( 1 ) { while ( 1 ) {
if ( !scroll_count ) { if ( !scroll_count ) {
yield(); yield();
continue; continue;
} }
/* wait 1s before starting scroll */ /* wait 0.5s before starting scroll */
if ( scroll_count < scroll_speed ) if ( scroll_count < scroll_speed/2 )
scroll_count++; scroll_count++;
else { else {
lcd_puts(s->xpos,s->starty,s->text + s->offset); int i;
if ( s->textlen - s->offset < s->space ) for ( i=0; i<s->space-1; i++ )
lcd_puts(s->startx + s->textlen - s->offset, s->starty," "); s->line[i] = s->line[i+1];
lcd_update();
if ( s->offset < s->textlen ) {
if ( s->xpos > s->startx ) s->line[s->space - 1] = s->text[s->offset];
s->xpos--;
else
s->offset++; s->offset++;
if (s->offset >= s->textlen) {
lcd_puts(s->startx + s->textlen - s->offset, s->starty," ");
scroll_count = scroll_speed; /* prevent wrap */
s->offset=0;
s->xpos = s->space-1;
} }
else {
s->line[s->space - 1] = ' ';
if ( s->offset < s->textlen + scroll_spacing - 1 )
s->offset++;
else
s->offset = 0;
}
lcd_puts(s->startx,s->starty,s->line);
lcd_update();
} }
sleep(HZ/scroll_speed); sleep(HZ/scroll_speed);
} }