forked from len0rd/rockbox
first implementation of directory scrolling - partly by Stefan Meyer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@481 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f830e3827f
commit
04fdc1eb83
1 changed files with 43 additions and 5 deletions
|
|
@ -33,7 +33,7 @@
|
||||||
#define TREE_MAX_FILENAMELEN 64
|
#define TREE_MAX_FILENAMELEN 64
|
||||||
#define TREE_MAX_ON_SCREEN 7
|
#define TREE_MAX_ON_SCREEN 7
|
||||||
#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
|
#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
|
||||||
|
|
||||||
void browse_root(void) {
|
void browse_root(void) {
|
||||||
dirbrowse("/");
|
dirbrowse("/");
|
||||||
}
|
}
|
||||||
|
|
@ -61,9 +61,10 @@ bool is_dir(char* path)
|
||||||
}
|
}
|
||||||
|
|
||||||
int static
|
int static
|
||||||
showdir(char *path, struct entry *buffer, int start)
|
showdir(char *path, struct entry *buffer, int start, int scrollpos, int* at_end)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int j=0;
|
||||||
DIR *dir = opendir(path);
|
DIR *dir = opendir(path);
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
|
||||||
|
|
@ -71,6 +72,7 @@ showdir(char *path, struct entry *buffer, int start)
|
||||||
return -1; /* not a directory */
|
return -1; /* not a directory */
|
||||||
|
|
||||||
i=start;
|
i=start;
|
||||||
|
*at_end=0; /* Have we displayed the last directory entry? */
|
||||||
while((entry = readdir(dir))) {
|
while((entry = readdir(dir))) {
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
|
@ -78,6 +80,9 @@ showdir(char *path, struct entry *buffer, int start)
|
||||||
/* skip names starting with a dot */
|
/* skip names starting with a dot */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if(j++ < scrollpos)
|
||||||
|
continue ;
|
||||||
|
|
||||||
len = strlen(entry->d_name);
|
len = strlen(entry->d_name);
|
||||||
if(len < TREE_MAX_FILENAMELEN)
|
if(len < TREE_MAX_FILENAMELEN)
|
||||||
/* strncpy() is evil, we memcpy() instead, +1 includes the
|
/* strncpy() is evil, we memcpy() instead, +1 includes the
|
||||||
|
|
@ -101,6 +106,15 @@ showdir(char *path, struct entry *buffer, int start)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entry==0) {
|
||||||
|
*at_end=1;
|
||||||
|
} else {
|
||||||
|
*at_end=(readdir(dir)==0);
|
||||||
|
}
|
||||||
|
j = i ;
|
||||||
|
while (j++ < TREE_MAX_ON_SCREEN) {
|
||||||
|
lcd_puts(LINE_X, LINE_Y+j*LINE_HEIGTH," ", 0);
|
||||||
|
}
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
@ -116,6 +130,8 @@ bool dirbrowse(char *root)
|
||||||
char currdir[255];
|
char currdir[255];
|
||||||
int dircursor=0;
|
int dircursor=0;
|
||||||
int i;
|
int i;
|
||||||
|
int start=0;
|
||||||
|
int at_end=0;
|
||||||
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
|
|
@ -123,7 +139,7 @@ bool dirbrowse(char *root)
|
||||||
lcd_puts(0,0, "[Browse]", 0);
|
lcd_puts(0,0, "[Browse]", 0);
|
||||||
memcpy(currdir,root,sizeof(currdir));
|
memcpy(currdir,root,sizeof(currdir));
|
||||||
|
|
||||||
numentries = showdir(root, buffer, 0);
|
numentries = showdir(root, buffer, 0, start, &at_end);
|
||||||
|
|
||||||
if (numentries == -1) return -1; /* root is not a directory */
|
if (numentries == -1) return -1; /* root is not a directory */
|
||||||
|
|
||||||
|
|
@ -155,10 +171,12 @@ bool dirbrowse(char *root)
|
||||||
|
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
lcd_puts(0,0, "[Browse]", 0);
|
lcd_puts(0,0, "[Browse]", 0);
|
||||||
numentries = showdir(currdir, buffer, 0);
|
numentries = showdir(currdir, buffer, 0, 0, &at_end);
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
|
start=0;
|
||||||
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
|
||||||
(strcmp(buffer[dircursor].name,buf)!=0)) dircursor++;
|
(strcmp(buffer[dircursor].name,buf)!=0)) dircursor++;
|
||||||
|
if (dircursor==TREE_MAX_ON_SCREEN) dircursor=0;
|
||||||
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
||||||
lcd_update();
|
lcd_update();
|
||||||
}
|
}
|
||||||
|
|
@ -176,13 +194,14 @@ bool dirbrowse(char *root)
|
||||||
if (is_dir(buf)) {
|
if (is_dir(buf)) {
|
||||||
memcpy(currdir,buf,sizeof(currdir));
|
memcpy(currdir,buf,sizeof(currdir));
|
||||||
dircursor=0;
|
dircursor=0;
|
||||||
|
start=0;
|
||||||
} else {
|
} else {
|
||||||
playtune(currdir, buffer[dircursor].name);
|
playtune(currdir, buffer[dircursor].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
lcd_clear_display();
|
lcd_clear_display();
|
||||||
lcd_puts(0,0, "[Browse]", 0);
|
lcd_puts(0,0, "[Browse]", 0);
|
||||||
numentries = showdir(currdir, buffer, 0);
|
numentries = showdir(currdir, buffer, 0, 0, &at_end);
|
||||||
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
||||||
lcd_update();
|
lcd_update();
|
||||||
break;
|
break;
|
||||||
|
|
@ -193,6 +212,15 @@ bool dirbrowse(char *root)
|
||||||
dircursor--;
|
dircursor--;
|
||||||
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
||||||
lcd_update();
|
lcd_update();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (start) {
|
||||||
|
lcd_clear_display();
|
||||||
|
lcd_puts(0,0, "[Browse]", 0);
|
||||||
|
numentries = showdir(currdir, buffer, 0, --start, &at_end);
|
||||||
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
||||||
|
lcd_update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_DOWN:
|
case BUTTON_DOWN:
|
||||||
|
|
@ -201,6 +229,16 @@ bool dirbrowse(char *root)
|
||||||
dircursor++;
|
dircursor++;
|
||||||
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
||||||
lcd_update();
|
lcd_update();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (!at_end) {
|
||||||
|
lcd_clear_display();
|
||||||
|
lcd_puts(0,0, "[Browse]", 0);
|
||||||
|
numentries = showdir(currdir, buffer, 0, ++start, &at_end);
|
||||||
|
|
||||||
|
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
|
||||||
|
lcd_update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue