forked from len0rd/rockbox
rockpaint: change browse_fonts to use dircache and use whole screen. add scrollbar.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28612 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
bd2011bc6a
commit
62b8efe674
1 changed files with 123 additions and 131 deletions
|
|
@ -456,9 +456,8 @@ union buf
|
||||||
char text[MAX_TEXT];
|
char text[MAX_TEXT];
|
||||||
char font[MAX_PATH];
|
char font[MAX_PATH];
|
||||||
char old_font[MAX_PATH];
|
char old_font[MAX_PATH];
|
||||||
int fh_buf[30];
|
int fh_buf[80];
|
||||||
int fw_buf[30];
|
int fw_buf[80];
|
||||||
char fontname_buf[30][MAX_PATH];
|
|
||||||
} text;
|
} text;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -703,19 +702,20 @@ static bool browse( char *dst, int dst_size, const char *start )
|
||||||
struct gui_synclist browse_list;
|
struct gui_synclist browse_list;
|
||||||
int item_count = 0, selected, button;
|
int item_count = 0, selected, button;
|
||||||
struct tree_context backup;
|
struct tree_context backup;
|
||||||
struct entry *dc;
|
struct entry *dc, *e;
|
||||||
bool reload = true;
|
bool reload = true;
|
||||||
int dirfilter = SHOW_ALL;
|
int dirfilter = SHOW_ALL;
|
||||||
int *indexes = (int *) buffer->clipboard;
|
int *indexes = (int *) buffer;
|
||||||
|
size_t bbuf_len, len;
|
||||||
|
|
||||||
char *a;
|
char *a;
|
||||||
|
|
||||||
rb->strcpy( bbuf, start );
|
rb->strcpy( bbuf, start );
|
||||||
a = bbuf+rb->strlen(bbuf)-1;
|
bbuf_len = rb->strlen(bbuf);
|
||||||
if( *a != '/' )
|
if( bbuf[bbuf_len-1] != '/' )
|
||||||
{
|
{
|
||||||
a[1] = '/';
|
bbuf[bbuf_len++] = '/';
|
||||||
a[2] = '\0';
|
bbuf[bbuf_len] = '\0';
|
||||||
}
|
}
|
||||||
bbuf_s[0] = '\0';
|
bbuf_s[0] = '\0';
|
||||||
|
|
||||||
|
|
@ -729,9 +729,8 @@ static bool browse( char *dst, int dst_size, const char *start )
|
||||||
if( *a != '/' )
|
if( *a != '/' )
|
||||||
{
|
{
|
||||||
*++a = '/';
|
*++a = '/';
|
||||||
*++a = '\0';
|
|
||||||
}
|
}
|
||||||
rb->strcpy( a, dc[tree->selected_item].name );
|
rb->strcpy( a+1, dc[tree->selected_item].name );
|
||||||
tree->dirfilter = &dirfilter;
|
tree->dirfilter = &dirfilter;
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
|
@ -743,14 +742,13 @@ static bool browse( char *dst, int dst_size, const char *start )
|
||||||
selected = 0;
|
selected = 0;
|
||||||
for( i = 0; i < tree->filesindir ; i++)
|
for( i = 0; i < tree->filesindir ; i++)
|
||||||
{
|
{
|
||||||
|
e = &dc[i];
|
||||||
/* only displayes directories and .bmp files */
|
/* only displayes directories and .bmp files */
|
||||||
if( ((dc[i].attr & ATTR_DIRECTORY ) &&
|
if( ( e->attr & ATTR_DIRECTORY ) ||
|
||||||
rb->strcmp( dc[i].name, "." ) &&
|
( !(e->attr & ATTR_DIRECTORY) &&
|
||||||
rb->strcmp( dc[i].name, ".." )) ||
|
check_extention( e->name, ".bmp" ) ) )
|
||||||
( !(dc[i].attr & ATTR_DIRECTORY) &&
|
|
||||||
check_extention( dc[i].name, ".bmp" ) ) )
|
|
||||||
{
|
{
|
||||||
if( !rb->strcmp( dc[i].name, bbuf_s ) )
|
if( bbuf_s[0] && !rb->strcmp( e->name, bbuf_s ) )
|
||||||
selected = item_count;
|
selected = item_count;
|
||||||
indexes[item_count++] = i;
|
indexes[item_count++] = i;
|
||||||
}
|
}
|
||||||
|
|
@ -774,40 +772,40 @@ static bool browse( char *dst, int dst_size, const char *start )
|
||||||
rb->set_current_file( backup.currdir );
|
rb->set_current_file( backup.currdir );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
rb->strcpy( bbuf_s, ".." );
|
a = bbuf + bbuf_len - 1;
|
||||||
|
if( a == bbuf ) break;
|
||||||
|
while( *a == '/' ) a--;
|
||||||
|
*(a+1) = '\0';
|
||||||
|
while( *a != '/' ) a--;
|
||||||
|
/* select parent directory */
|
||||||
|
rb->strcpy( bbuf_s, ++a );
|
||||||
|
*a = '\0';
|
||||||
|
bbuf_len = a - bbuf;
|
||||||
|
reload = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case ACTION_STD_OK:
|
case ACTION_STD_OK:
|
||||||
if( button == ACTION_STD_OK )
|
|
||||||
{
|
|
||||||
selected = rb->gui_synclist_get_sel_pos( &browse_list );
|
selected = rb->gui_synclist_get_sel_pos( &browse_list );
|
||||||
if( selected < 0 || selected >= item_count )
|
if( selected < 0 || selected >= item_count )
|
||||||
break;
|
break;
|
||||||
struct entry* e = &dc[indexes[selected]];
|
e = &dc[indexes[selected]];
|
||||||
rb->strlcpy( bbuf_s, e->name, sizeof( bbuf_s ) );
|
|
||||||
if( !( e->attr & ATTR_DIRECTORY ) )
|
if( !( e->attr & ATTR_DIRECTORY ) )
|
||||||
{
|
{
|
||||||
|
rb->snprintf( dst, dst_size, "%s%s", bbuf, e->name );
|
||||||
*tree = backup;
|
*tree = backup;
|
||||||
rb->set_current_file( backup.currdir );
|
rb->set_current_file( backup.currdir );
|
||||||
rb->snprintf( dst, dst_size, "%s%s", bbuf, bbuf_s );
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
len = rb->strlen(e->name);
|
||||||
if( !rb->strcmp( bbuf_s, "." ) ) break;
|
if (bbuf_len + len + 2 < (int)sizeof(bbuf))
|
||||||
a = bbuf+rb->strlen(bbuf);
|
|
||||||
if( !rb->strcmp( bbuf_s, ".." ) )
|
|
||||||
{
|
{
|
||||||
a--;
|
bbuf_s[0] = '\0';
|
||||||
if( a == bbuf ) break;
|
rb->strcpy( bbuf+bbuf_len, e->name );
|
||||||
if( *a == '/' ) a--;
|
bbuf_len += len;
|
||||||
while( *a != '/' ) a--;
|
bbuf[bbuf_len++] = '/';
|
||||||
rb->strcpy( bbuf_s, ++a );
|
bbuf[bbuf_len] = '\0';
|
||||||
/* select parent directory */
|
|
||||||
bbuf_s[rb->strlen(bbuf_s)-1] = '\0';
|
|
||||||
*a = '\0';
|
|
||||||
reload = true;
|
reload = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
rb->snprintf( a, bbuf+sizeof(bbuf)-a, "%s/", bbuf_s );
|
|
||||||
reload = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACTION_STD_MENU:
|
case ACTION_STD_MENU:
|
||||||
|
|
@ -827,13 +825,16 @@ static bool browse( char *dst, int dst_size, const char *start )
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
static bool browse_fonts( char *dst, int dst_size )
|
static bool browse_fonts( char *dst, int dst_size )
|
||||||
{
|
{
|
||||||
#define WIDTH ( LCD_WIDTH - 20 )
|
|
||||||
#define HEIGHT ( LCD_HEIGHT - 20 )
|
|
||||||
#define LINE_SPACE 2
|
#define LINE_SPACE 2
|
||||||
int top, top_inside = 0, left;
|
#define fh_buf buffer->text.fh_buf
|
||||||
|
#define fw_buf buffer->text.fw_buf
|
||||||
|
|
||||||
|
struct tree_context backup;
|
||||||
|
struct entry *dc, *e;
|
||||||
|
int dirfilter = SHOW_FONT;
|
||||||
|
|
||||||
|
int top = 0;
|
||||||
|
|
||||||
DIR *d;
|
|
||||||
struct dirent *de;
|
|
||||||
int fvi = 0; /* first visible item */
|
int fvi = 0; /* first visible item */
|
||||||
int lvi = 0; /* last visible item */
|
int lvi = 0; /* last visible item */
|
||||||
int si = 0; /* selected item */
|
int si = 0; /* selected item */
|
||||||
|
|
@ -844,30 +845,36 @@ static bool browse_fonts( char *dst, int dst_size )
|
||||||
int b_need_redraw = 1; /* Do we need to redraw ? */
|
int b_need_redraw = 1; /* Do we need to redraw ? */
|
||||||
|
|
||||||
int cp = 0; /* current position */
|
int cp = 0; /* current position */
|
||||||
int fh; /* font height */
|
int sp = 0; /* selected position */
|
||||||
|
int fh, fw; /* font height, width */
|
||||||
|
|
||||||
#define fh_buf buffer->text.fh_buf /* 30 might not be enough ... */
|
char *a;
|
||||||
#define fw_buf buffer->text.fw_buf
|
|
||||||
int fw;
|
|
||||||
#define fontname_buf buffer->text.fontname_buf
|
|
||||||
|
|
||||||
rb->snprintf( buffer->text.old_font, MAX_PATH,
|
rb->snprintf( buffer->text.old_font, MAX_PATH,
|
||||||
FONT_DIR "/%s.fnt",
|
FONT_DIR "/%s.fnt",
|
||||||
rb->global_settings->font_file );
|
rb->global_settings->font_file );
|
||||||
|
|
||||||
|
tree = rb->tree_get_context();
|
||||||
|
backup = *tree;
|
||||||
|
dc = tree->dircache;
|
||||||
|
a = backup.currdir+rb->strlen(backup.currdir)-1;
|
||||||
|
if( *a != '/' )
|
||||||
|
{
|
||||||
|
*++a = '/';
|
||||||
|
}
|
||||||
|
rb->strcpy( a+1, dc[tree->selected_item].name );
|
||||||
|
tree->dirfilter = &dirfilter;
|
||||||
|
rb->strcpy( bbuf, FONT_DIR "/" );
|
||||||
|
rb->set_current_file( bbuf );
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
if( !b_need_redraw )
|
if( !b_need_redraw )
|
||||||
{
|
{
|
||||||
/* we don't need to redraw ... but we need to unselect
|
/* we don't need to redraw ... but we need to unselect
|
||||||
* the previously selected item */
|
* 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_set_drawmode(DRMODE_COMPLEMENT);
|
||||||
rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
|
rb->lcd_fillrect( 10, sp, LCD_WIDTH-10, fh_buf[osi-fvi] );
|
||||||
rb->lcd_set_drawmode(DRMODE_SOLID);
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -875,91 +882,77 @@ static bool browse_fonts( char *dst, int dst_size )
|
||||||
{
|
{
|
||||||
b_need_redraw = 0;
|
b_need_redraw = 0;
|
||||||
|
|
||||||
d = rb->opendir( FONT_DIR "/" );
|
|
||||||
if( !d )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
top_inside = draw_window( HEIGHT, WIDTH, &top, &left, "Fonts" );
|
|
||||||
i = 0;
|
|
||||||
li = -1;
|
|
||||||
while( i < fvi )
|
|
||||||
{
|
|
||||||
rb->readdir( d );
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
cp = top_inside+LINE_SPACE;
|
|
||||||
|
|
||||||
rb->lcd_set_foreground(COLOR_BLACK);
|
rb->lcd_set_foreground(COLOR_BLACK);
|
||||||
rb->lcd_set_background(COLOR_LIGHTGRAY);
|
rb->lcd_set_background(COLOR_LIGHTGRAY);
|
||||||
|
rb->lcd_clear_display();
|
||||||
|
|
||||||
while( cp < top+HEIGHT )
|
rb->font_getstringsize( "Fonts", NULL, &fh, FONT_UI );
|
||||||
|
rb->lcd_putsxy( 2, 2, "Fonts" );
|
||||||
|
top = fh + 4 + LINE_SPACE;
|
||||||
|
|
||||||
|
for( i = 0; fvi < lvi && nvih > 0; i++, fvi++ )
|
||||||
{
|
{
|
||||||
de = rb->readdir( d );
|
nvih -= fh_buf[i] + LINE_SPACE;
|
||||||
if( !de )
|
|
||||||
{
|
|
||||||
li = i-1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if( !check_extention( de->d_name, ".fnt" ) )
|
nvih = 0;
|
||||||
continue;
|
i = fvi;
|
||||||
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
|
li = -1;
|
||||||
de->d_name );
|
|
||||||
|
cp = top;
|
||||||
|
while( cp < LCD_HEIGHT && i < tree->filesindir )
|
||||||
|
{
|
||||||
|
e = &dc[i];
|
||||||
|
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", e->name );
|
||||||
rb->font_load(NULL, bbuf );
|
rb->font_load(NULL, bbuf );
|
||||||
rb->font_getstringsize( de->d_name, &fw, &fh, FONT_UI );
|
rb->font_getstringsize( e->name, &fw, &fh, FONT_UI );
|
||||||
if( nvih > 0 )
|
if( cp + fh >= LCD_HEIGHT )
|
||||||
{
|
|
||||||
nvih -= fh;
|
|
||||||
fvi++;
|
|
||||||
if( nvih < 0 ) nvih = 0;
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if( cp + fh >= top+HEIGHT )
|
|
||||||
{
|
{
|
||||||
nvih = fh;
|
nvih = fh;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rb->lcd_putsxy( left+10, cp, de->d_name );
|
rb->lcd_putsxy( 10, cp, e->name );
|
||||||
fh_buf[i-fvi] = fh;
|
fh_buf[i-fvi] = fh;
|
||||||
fw_buf[i-fvi] = fw;
|
fw_buf[i-fvi] = fw;
|
||||||
cp += fh + LINE_SPACE;
|
cp += fh + LINE_SPACE;
|
||||||
rb->strcpy( fontname_buf[i-fvi], bbuf );
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
lvi = i-1;
|
lvi = i-1;
|
||||||
|
if( i >= tree->filesindir )
|
||||||
|
{
|
||||||
|
li = i-1;
|
||||||
|
}
|
||||||
if( li == -1 )
|
if( li == -1 )
|
||||||
{
|
{
|
||||||
if( !(de = rb->readdir( d ) ) )
|
if( !nvih )
|
||||||
{
|
{
|
||||||
li = lvi;
|
e = &dc[i];
|
||||||
}
|
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s", e->name );
|
||||||
else if( !nvih && check_extention( de->d_name, ".fnt" ) )
|
|
||||||
{
|
|
||||||
rb->snprintf( bbuf, MAX_PATH, FONT_DIR "/%s",
|
|
||||||
de->d_name );
|
|
||||||
rb->font_load(NULL, bbuf );
|
rb->font_load(NULL, bbuf );
|
||||||
rb->font_getstringsize( de->d_name, NULL, &fh, FONT_UI );
|
rb->font_getstringsize( e->name, NULL, &fh, FONT_UI );
|
||||||
nvih = fh;
|
nvih = fh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rb->font_load(NULL, buffer->text.old_font );
|
rb->font_load(NULL, buffer->text.old_font );
|
||||||
rb->closedir( d );
|
if( lvi-fvi < tree->filesindir-1 )
|
||||||
|
{
|
||||||
|
rb->gui_scrollbar_draw( rb->screens[SCREEN_MAIN], 0, top,
|
||||||
|
9, cp-LINE_SPACE-top,
|
||||||
|
tree->filesindir-1, fvi, lvi, VERTICAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
|
||||||
cp = top_inside + LINE_SPACE;
|
sp = top;
|
||||||
for( i = 0; i+fvi < si; i++ )
|
for( i = 0; i+fvi < si; i++ )
|
||||||
{
|
{
|
||||||
cp += fh_buf[i] + LINE_SPACE;
|
sp += fh_buf[i] + LINE_SPACE;
|
||||||
}
|
}
|
||||||
rb->lcd_fillrect( left+10, cp, fw_buf[i], fh_buf[i] );
|
rb->lcd_fillrect( 10, sp, LCD_WIDTH-10, fh_buf[si-fvi] );
|
||||||
rb->lcd_set_drawmode(DRMODE_SOLID);
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
||||||
|
|
||||||
rb->lcd_update_rect( left, top, WIDTH, HEIGHT );
|
rb->lcd_update();
|
||||||
|
|
||||||
osi = si;
|
osi = si;
|
||||||
i = fvi;
|
|
||||||
switch( rb->button_get(true) )
|
switch( rb->button_get(true) )
|
||||||
{
|
{
|
||||||
case ROCKPAINT_UP:
|
case ROCKPAINT_UP:
|
||||||
|
|
@ -967,9 +960,11 @@ static bool browse_fonts( char *dst, int dst_size )
|
||||||
if( si > 0 )
|
if( si > 0 )
|
||||||
{
|
{
|
||||||
si--;
|
si--;
|
||||||
if( si<fvi )
|
if( si < fvi )
|
||||||
{
|
{
|
||||||
fvi = si;
|
fvi = si;
|
||||||
|
nvih = 0;
|
||||||
|
b_need_redraw = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -979,32 +974,29 @@ static bool browse_fonts( char *dst, int dst_size )
|
||||||
if( li == -1 || si < li )
|
if( li == -1 || si < li )
|
||||||
{
|
{
|
||||||
si++;
|
si++;
|
||||||
|
if( si > lvi )
|
||||||
|
{
|
||||||
|
b_need_redraw = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ROCKPAINT_LEFT:
|
case ROCKPAINT_LEFT:
|
||||||
case ROCKPAINT_QUIT:
|
case ROCKPAINT_QUIT:
|
||||||
|
*tree = backup;
|
||||||
|
rb->set_current_file( backup.currdir );
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
case ROCKPAINT_RIGHT:
|
case ROCKPAINT_RIGHT:
|
||||||
case ROCKPAINT_DRAW:
|
case ROCKPAINT_DRAW:
|
||||||
rb->snprintf( dst, dst_size, "%s", fontname_buf[si-fvi] );
|
rb->snprintf( dst, dst_size, FONT_DIR "/%s", dc[si].name );
|
||||||
|
*tree = backup;
|
||||||
|
rb->set_current_file( backup.currdir );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i != fvi || si > lvi )
|
|
||||||
{
|
|
||||||
b_need_redraw = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( si<=lvi )
|
|
||||||
{
|
|
||||||
nvih = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#undef fh_buf
|
#undef fh_buf
|
||||||
#undef fw_buf
|
#undef fw_buf
|
||||||
#undef fontname_buf
|
|
||||||
#undef WIDTH
|
#undef WIDTH
|
||||||
#undef HEIGHT
|
#undef HEIGHT
|
||||||
#undef LINE_SPACE
|
#undef LINE_SPACE
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue