1
0
Fork 0
forked from len0rd/rockbox

Make the font browser a bit more usable on real targets. (The screen is only redrawn when scrolling is needed)

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10300 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Antoine Cellerier 2006-07-23 20:55:55 +00:00
parent 4735e8ed53
commit a096c83689

View file

@ -276,6 +276,9 @@ static union
char text[MAX_TEXT+1];
char font[MAX_PATH+1];
char old_font[MAX_PATH+1];
int fh_buf[30];
int fw_buf[30];
char fontname_buf[30][MAX_PATH];
} text;
} buffer;
@ -780,19 +783,44 @@ static bool browse_fonts( char *dst, int dst_size )
int fvi = 0; /* first visible item */
int lvi = 0; /* last visible item */
int si = 0; /* selected item */
int osi = 0; /* old selected item */
int li = 0; /* last item */
int nvih = 0; /* next visible item height */
int i;
int b_need_redraw = 1; /* Do we need to redraw ? */
int cp = 0; /* current position */
int fh; /* font height */
#define fh_buf buffer.text.fh_buf /* 30 might not be enough ... */
#define fw_buf buffer.text.fw_buf
int fw;
#define fontname_buf buffer.text.fontname_buf
rb->snprintf( old_font, MAX_PATH,
ROCKBOX_DIR FONT_DIR "/%s.fnt",
rb->global_settings->font_file );
while( 1 )
{
if( !b_need_redraw )
{
/* we don't need to redraw ... but we need to unselect
* the previously selected item */
cp = top_inside + LINE_SPACE;
for( i = 0; i+fvi < osi; i++ )
{
cp += fh_buf[i] + LINE_SPACE;
}
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
rb->lcd_set_drawmode(DRMODE_SOLID);
}
if( b_need_redraw )
{
b_need_redraw = 0;
d = rb->PREFIX(opendir)( ROCKBOX_DIR FONT_DIR "/" );
if( !d )
{
@ -807,6 +835,10 @@ static bool browse_fonts( char *dst, int dst_size )
i++;
}
cp = top_inside+LINE_SPACE;
rb->lcd_set_foreground(COLOR_BLACK);
rb->lcd_set_background(COLOR_LIGHTGRAY);
while( cp < top+HEIGHT )
{
de = rb->PREFIX(readdir)( d );
@ -822,7 +854,7 @@ static bool browse_fonts( char *dst, int dst_size )
rb->snprintf( bbuf, MAX_PATH, ROCKBOX_DIR FONT_DIR "/%s",
de->d_name );
rb->font_load( bbuf );
rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
if( nvih > 0 )
{
nvih -= fh;
@ -836,12 +868,11 @@ static bool browse_fonts( char *dst, int dst_size )
nvih = fh;
break;
}
rb->lcd_set_foreground((si==i?COLOR_WHITE:COLOR_BLACK));
rb->lcd_set_background((si==i?COLOR_BLUE:COLOR_LIGHTGRAY));
rb->lcd_putsxy( left+10, cp, de->d_name );
fh_buf[i-fvi] = fh;
fw_buf[i-fvi] = fw;
cp += fh + LINE_SPACE;
if( si == i )
rb->strcpy( bbuf_s, bbuf );
rb->strcpy( fontname_buf[i-fvi], bbuf );
i++;
}
lvi = i-1;
@ -864,9 +895,21 @@ static bool browse_fonts( char *dst, int dst_size )
}
rb->font_load( old_font );
rb->PREFIX(closedir)( d );
}
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
cp = top_inside + LINE_SPACE;
for( i = 0; i+fvi < si; i++ )
{
cp += fh_buf[i] + LINE_SPACE;
}
rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_update_rect( left, top, WIDTH, HEIGHT );
osi = si;
i = fvi;
switch( rb->button_get(true) )
{
case ROCKPAINT_UP:
@ -894,14 +937,23 @@ static bool browse_fonts( char *dst, int dst_size )
case ROCKPAINT_RIGHT:
case ROCKPAINT_DRAW:
rb->snprintf( dst, dst_size, "%s", bbuf_s );
rb->snprintf( dst, dst_size, "%s", fontname_buf[si-fvi] );
return true;
}
if( i != fvi || si > lvi )
{
b_need_redraw = 1;
}
if( si<=lvi )
{
nvih = 0;
}
}
#undef fh_buf
#undef fw_buf
#undef fontname_buf
#undef WIDTH
#undef HEIGHT
#undef LINE_SPACE
@ -1327,7 +1379,6 @@ static void draw_text( int x, int y )
rb->snprintf( buffer.text.old_font, MAX_PATH,
ROCKBOX_DIR FONT_DIR "/%s.fnt",
rb->global_settings->font_file );
DEBUGF( "old font: %s\n", buffer.text.old_font );
while( 1 )
{
int m = TEXT_MENU_TEXT;