1
0
Fork 0
forked from len0rd/rockbox

Added multiline scroll support.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2729 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Markus Braun 2002-10-21 13:14:25 +00:00
parent f45345edd9
commit bc254fe95f
6 changed files with 308 additions and 81 deletions

View file

@ -530,7 +530,6 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all)
{ {
char buf[MAX_PATH]; char buf[MAX_PATH];
struct format_flags flags; struct format_flags flags;
bool scroll_active = false;
int i; int i;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* to find out wether the peak meter is enabled we /* to find out wether the peak meter is enabled we
@ -602,9 +601,8 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all)
} }
#endif #endif
if (!scroll_active && flags.scroll && !flags.dynamic) if (flags.scroll && !flags.dynamic)
{ {
scroll_active = true;
lcd_puts_scroll(0, i, buf); lcd_puts_scroll(0, i, buf);
} }
else else

View file

@ -700,6 +700,8 @@ int wps_show(void)
status_set_record(false); status_set_record(false);
status_set_audio(false); status_set_audio(false);
#endif #endif
lcd_stop_scroll();
/* set dir browser to current playing song */ /* set dir browser to current playing song */
if (global_settings.browse_current && id3) if (global_settings.browse_current && id3)
set_current_file(id3->path); set_current_file(id3->path);
@ -833,6 +835,8 @@ int wps_show(void)
status_set_record(false); status_set_record(false);
status_set_audio(false); status_set_audio(false);
#endif #endif
lcd_stop_scroll();
/* set dir browser to current playing song */ /* set dir browser to current playing song */
if (global_settings.browse_current && id3) if (global_settings.browse_current && id3)
set_current_file(id3->path); set_current_file(id3->path);

View file

@ -71,7 +71,7 @@ Other Tags:
%> : Display a '>' %> : Display a '>'
%s : Indicate that the line should scroll. Can occur anywhere in %s : Indicate that the line should scroll. Can occur anywhere in
a line (given that the text is displayed; see conditional a line (given that the text is displayed; see conditional
below). Only the first line with a %s will actually scroll. below). You can specify up to 10 scrolling lines.
%s is ignored if combined with %pb, %pc or %pr on the same %s is ignored if combined with %pb, %pc or %pr on the same
line (the result wouldn't be good anyway). line (the result wouldn't be good anyway).

View file

@ -46,9 +46,16 @@
#define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x)))) #define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x))))
#define LCD_ICON(i) ((char)(lcd_iram+i)) #define LCD_ICON(i) ((char)(lcd_iram+i))
#define SCROLLABLE_LINES 2
#define SCROLL_MODE_OFF 0
#define SCROLL_MODE_PAUSE 1
#define SCROLL_MODE_RUN 2
/*** generic code ***/ /*** generic code ***/
struct scrollinfo { struct scrollinfo {
int mode;
char text[MAX_PATH]; char text[MAX_PATH];
char line[32]; char line[32];
int textlen; int textlen;
@ -63,10 +70,10 @@ static char scroll_stack[DEFAULT_STACK_SIZE];
static char scroll_name[] = "scroll"; static char scroll_name[] = "scroll";
static char scroll_speed = 8; /* updates per second */ static char scroll_speed = 8; /* updates per second */
static char scroll_spacing = 3; /* spaces between end and start of text */ static char scroll_spacing = 3; /* spaces between end and start of text */
static long scroll_start_tick;
static struct scrollinfo scroll; /* only one scroll line at the moment */ static struct scrollinfo scroll[SCROLLABLE_LINES];
static int scroll_count = 0;
static const unsigned char new_lcd_ascii[] = { static const unsigned char new_lcd_ascii[] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
@ -272,13 +279,26 @@ void lcd_init (void)
void lcd_puts_scroll(int x, int y, unsigned char* string ) void lcd_puts_scroll(int x, int y, unsigned char* string )
{ {
struct scrollinfo* s = &scroll; struct scrollinfo* s;
int index;
scroll_start_tick = current_tick + HZ/2;
/* search for the next free entry */
for (index = 0; index < SCROLLABLE_LINES; index++) {
s = &scroll[index];
if (s->mode == SCROLL_MODE_OFF) {
break;
}
}
s->space = 11 - x; s->space = 11 - x;
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->mode = SCROLL_MODE_RUN;
s->offset=s->space; s->offset=s->space;
s->startx=x; s->startx=x;
s->starty=y; s->starty=y;
@ -289,31 +309,102 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
s->space > (int)sizeof s->line ? s->space > (int)sizeof s->line ?
(int)sizeof s->line : s->space ); (int)sizeof s->line : s->space );
s->line[sizeof s->line - 1] = 0; s->line[sizeof s->line - 1] = 0;
scroll_count = 1;
} }
} }
void lcd_stop_scroll(void) void lcd_stop_scroll(void)
{ {
if ( scroll_count ) { struct scrollinfo* s;
struct scrollinfo* s = &scroll; int index;
scroll_count = 0;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ||
s->mode == SCROLL_MODE_PAUSE ) {
/* restore scrolled row */ /* restore scrolled row */
lcd_puts(s->startx, s->starty, s->text); lcd_puts(s->startx, s->starty, s->text);
s->mode = SCROLL_MODE_OFF;
}
}
lcd_update(); lcd_update();
} }
void lcd_stop_scroll_line(int line)
{
struct scrollinfo* s;
int index;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->startx == line &&
( s->mode == SCROLL_MODE_RUN ||
s->mode == SCROLL_MODE_PAUSE )) {
/* restore scrolled row */
lcd_puts(s->startx, s->starty, s->text);
s->mode = SCROLL_MODE_OFF;
}
}
lcd_update();
} }
void lcd_scroll_pause(void) void lcd_scroll_pause(void)
{ {
scroll_count = 0; struct scrollinfo* s;
int index;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ) {
s->mode = SCROLL_MODE_PAUSE;
}
}
}
void lcd_scroll_pause_line(int line)
{
struct scrollinfo* s;
int index;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->startx == line &&
s->mode == SCROLL_MODE_RUN ) {
s->mode = SCROLL_MODE_PAUSE;
}
}
} }
void lcd_scroll_resume(void) void lcd_scroll_resume(void)
{ {
scroll_count = 1; struct scrollinfo* s;
int index;
scroll_start_tick = current_tick + HZ/2;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_PAUSE ) {
s->mode = SCROLL_MODE_RUN;
}
}
}
void lcd_scroll_resume_line(int line)
{
struct scrollinfo* s;
int index;
scroll_start_tick = current_tick + HZ/2;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->startx == line &&
s->mode == SCROLL_MODE_PAUSE ) {
s->mode = SCROLL_MODE_RUN;
}
}
} }
void lcd_scroll_speed(int speed) void lcd_scroll_speed(int speed)
@ -323,18 +414,30 @@ void lcd_scroll_speed(int speed)
static void scroll_thread(void) static void scroll_thread(void)
{ {
struct scrollinfo* s = &scroll; struct scrollinfo* s;
int index;
int i;
bool update;
/* initialize scroll struct array */
for (index = 0; index < SCROLLABLE_LINES; index++) {
scroll[index].mode = SCROLL_MODE_OFF;
}
scroll_start_tick = current_tick;
while ( 1 ) { while ( 1 ) {
if ( !scroll_count ) {
yield(); update = false;
continue;
}
/* wait 0.5s before starting scroll */ /* wait 0.5s before starting scroll */
if ( scroll_count < scroll_speed/2 ) if ( TIME_AFTER(current_tick, scroll_start_tick) ) {
scroll_count++;
else { for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
int i; s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ) {
update = true;
for ( i = 0; i < s->space - 1; i++ ) for ( i = 0; i < s->space - 1; i++ )
s->line[i] = s->line[i+1]; s->line[i] = s->line[i+1];
@ -351,8 +454,14 @@ static void scroll_thread(void)
} }
lcd_puts(s->startx,s->starty,s->line); lcd_puts(s->startx,s->starty,s->line);
}
}
if (update) {
lcd_update(); lcd_update();
} }
}
sleep(HZ/scroll_speed); sleep(HZ/scroll_speed);
} }
} }

View file

@ -70,7 +70,14 @@
#define SCROLL_SPACING 3 #define SCROLL_SPACING 3
#define SCROLLABLE_LINES 10
#define SCROLL_MODE_OFF 0
#define SCROLL_MODE_PAUSE 1
#define SCROLL_MODE_RUN 2
struct scrollinfo { struct scrollinfo {
int mode;
char line[MAX_PATH + LCD_WIDTH/2 + SCROLL_SPACING + 2]; char line[MAX_PATH + LCD_WIDTH/2 + SCROLL_SPACING + 2];
int len; /* length of line in chars */ int len; /* length of line in chars */
int width; /* length of line in pixels */ int width; /* length of line in pixels */
@ -84,8 +91,8 @@ static char scroll_stack[DEFAULT_STACK_SIZE];
static char scroll_name[] = "scroll"; static char scroll_name[] = "scroll";
static char scroll_speed = 8; /* updates per second */ static char scroll_speed = 8; /* updates per second */
static char scroll_step = 6; /* pixels per scroll step */ static char scroll_step = 6; /* pixels per scroll step */
static struct scrollinfo scroll; /* only one scroll line at the moment */ static long scroll_start_tick;
static int scroll_count = 0; static struct scrollinfo scroll[SCROLLABLE_LINES];
static int xmargin = 0; static int xmargin = 0;
static int ymargin = 0; static int ymargin = 0;
static int curfont = FONT_SYSFIXED; static int curfont = FONT_SYSFIXED;
@ -658,14 +665,24 @@ void lcd_invertpixel(int x, int y)
void lcd_puts_scroll(int x, int y, unsigned char* string) void lcd_puts_scroll(int x, int y, unsigned char* string)
{ {
struct scrollinfo* s = &scroll; struct scrollinfo* s;
int w, h; int w, h;
int index;
scroll_start_tick = current_tick + HZ/2;
/* search for the next free entry */
for (index = 0; index < SCROLLABLE_LINES; index++) {
s = &scroll[index];
if (s->mode == SCROLL_MODE_OFF) {
break;
}
}
lcd_puts(x,y,string); lcd_puts(x,y,string);
lcd_getstringsize(string, &w, &h); lcd_getstringsize(string, &w, &h);
if (LCD_WIDTH - x*8 - xmargin < w) if (LCD_WIDTH - x * 8 - xmargin < w) {
{
/* prepare scroll line */ /* prepare scroll line */
char *end; char *end;
@ -678,22 +695,24 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
for (end = s->line; *end; end++); for (end = s->line; *end; end++);
strncpy(end, string, LCD_WIDTH/2); strncpy(end, string, LCD_WIDTH/2);
s->mode = SCROLL_MODE_RUN;
s->len = strlen(string); s->len = strlen(string);
s->offset = 0; s->offset = 0;
s->startx = x; s->startx = x;
s->starty = y; s->starty = y;
scroll_count = 1;
} }
} }
void lcd_stop_scroll(void) void lcd_stop_scroll(void)
{ {
if ( scroll_count ) { struct scrollinfo* s;
int w,h; int w,h;
struct scrollinfo* s = &scroll; int index;
scroll_count = 0;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ||
s->mode == SCROLL_MODE_PAUSE ) {
lcd_getstringsize(s->line, &w, &h); lcd_getstringsize(s->line, &w, &h);
lcd_clearrect(xmargin + s->startx * w / s->len, lcd_clearrect(xmargin + s->startx * w / s->len,
ymargin + s->starty * h, ymargin + s->starty * h,
@ -702,18 +721,95 @@ void lcd_stop_scroll(void)
/* restore scrolled row */ /* restore scrolled row */
lcd_puts(s->startx, s->starty, s->line); lcd_puts(s->startx, s->starty, s->line);
s->mode = SCROLL_MODE_OFF;
}
}
lcd_update(); lcd_update();
} }
void lcd_stop_scroll_line(int line)
{
struct scrollinfo* s;
int w,h;
int index;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->startx == line &&
( s->mode == SCROLL_MODE_RUN ||
s->mode == SCROLL_MODE_PAUSE )) {
lcd_getstringsize(s->line, &w, &h);
lcd_clearrect(xmargin + s->startx * w / s->len,
ymargin + s->starty * h,
LCD_WIDTH - xmargin,
h);
/* restore scrolled row */
lcd_puts(s->startx, s->starty, s->line);
s->mode = SCROLL_MODE_OFF;
}
}
lcd_update();
} }
void lcd_scroll_pause(void) void lcd_scroll_pause(void)
{ {
scroll_count = 0; struct scrollinfo* s;
int index;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ) {
s->mode = SCROLL_MODE_PAUSE;
}
}
}
void lcd_scroll_pause_line(int line)
{
struct scrollinfo* s;
int index;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->startx == line &&
s->mode == SCROLL_MODE_RUN ) {
s->mode = SCROLL_MODE_PAUSE;
}
}
} }
void lcd_scroll_resume(void) void lcd_scroll_resume(void)
{ {
scroll_count = 1; struct scrollinfo* s;
int index;
scroll_start_tick = current_tick + HZ/2;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_PAUSE ) {
s->mode = SCROLL_MODE_RUN;
}
}
}
void lcd_scroll_resume_line(int line)
{
struct scrollinfo* s;
int index;
scroll_start_tick = current_tick + HZ/2;
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->startx == line &&
s->mode == SCROLL_MODE_PAUSE ) {
s->mode = SCROLL_MODE_RUN;
}
}
} }
void lcd_scroll_speed(int speed) void lcd_scroll_speed(int speed)
@ -723,19 +819,30 @@ void lcd_scroll_speed(int speed)
static void scroll_thread(void) static void scroll_thread(void)
{ {
struct scrollinfo* s = &scroll; struct scrollinfo* s;
int index;
while ( 1 ) {
if ( !scroll_count ) {
yield();
continue;
}
/* wait 0.5s before starting scroll */
if ( scroll_count < scroll_speed/2 )
scroll_count++;
else {
int w, h; int w, h;
int xpos, ypos; int xpos, ypos;
bool update;
/* initialize scroll struct array */
for (index = 0; index < SCROLLABLE_LINES; index++) {
scroll[index].mode = SCROLL_MODE_OFF;
}
scroll_start_tick = current_tick;
while ( 1 ) {
update = false;
/* wait 0.5s before starting scroll */
if ( TIME_AFTER(current_tick, scroll_start_tick) ) {
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ) {
update = true;
s->offset += scroll_step; s->offset += scroll_step;
@ -748,8 +855,14 @@ static void scroll_thread(void)
lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h); lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h);
lcd_putsxyofs(xpos, ypos, s->offset, s->line); lcd_putsxyofs(xpos, ypos, s->offset, s->line);
}
}
if (update) {
lcd_update(); lcd_update();
} }
}
sleep(HZ/scroll_speed); sleep(HZ/scroll_speed);
} }
} }

View file

@ -31,10 +31,13 @@ extern void lcd_backlight(bool on);
extern void lcd_puts(int x, int y, unsigned char *string); extern void lcd_puts(int x, int y, unsigned char *string);
extern void lcd_putc(int x, int y, unsigned char ch); extern void lcd_putc(int x, int y, unsigned char ch);
extern void lcd_scroll_pause(void); extern void lcd_scroll_pause(void);
extern void lcd_scroll_pause_line(int line);
extern void lcd_scroll_resume(void); extern void lcd_scroll_resume(void);
extern void lcd_scroll_resume_line(int line);
extern void lcd_puts_scroll(int x, int y, unsigned char* string ); extern void lcd_puts_scroll(int x, int y, unsigned char* string );
extern void lcd_icon(int icon, bool enable); extern void lcd_icon(int icon, bool enable);
extern void lcd_stop_scroll(void); extern void lcd_stop_scroll(void);
extern void lcd_stop_scroll_line(int line);
extern void lcd_scroll_speed( int speed ); extern void lcd_scroll_speed( int speed );
extern void lcd_set_contrast(int val); extern void lcd_set_contrast(int val);
extern void lcd_write( bool command, int byte ); extern void lcd_write( bool command, int byte );