summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2002-05-06 17:02:57 +0000
committerDave Chapman <dave@dchapman.com>2002-05-06 17:02:57 +0000
commit04fdc1eb8329f4b1dc458447573551c4f8e4c546 (patch)
treeeb2539aa52c5da0d7da8100f79dd463515d03046
parentf830e3827ff542ffb504aa1983ac394d536ca141 (diff)
downloadrockbox-04fdc1eb8329f4b1dc458447573551c4f8e4c546.zip
rockbox-04fdc1eb8329f4b1dc458447573551c4f8e4c546.tar.gz
rockbox-04fdc1eb8329f4b1dc458447573551c4f8e4c546.tar.bz2
rockbox-04fdc1eb8329f4b1dc458447573551c4f8e4c546.tar.xz
first implementation of directory scrolling - partly by Stefan Meyer
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@481 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/tree.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/uisimulator/tree.c b/uisimulator/tree.c
index 98e5c02..de3b71d 100644
--- a/uisimulator/tree.c
+++ b/uisimulator/tree.c
@@ -33,7 +33,7 @@
#define TREE_MAX_FILENAMELEN 64
#define TREE_MAX_ON_SCREEN 7
#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
-
+
void browse_root(void) {
dirbrowse("/");
}
@@ -61,9 +61,10 @@ bool is_dir(char* path)
}
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 j=0;
DIR *dir = opendir(path);
struct dirent *entry;
@@ -71,6 +72,7 @@ showdir(char *path, struct entry *buffer, int start)
return -1; /* not a directory */
i=start;
+ *at_end=0; /* Have we displayed the last directory entry? */
while((entry = readdir(dir))) {
int len;
@@ -78,6 +80,9 @@ showdir(char *path, struct entry *buffer, int start)
/* skip names starting with a dot */
continue;
+ if(j++ < scrollpos)
+ continue ;
+
len = strlen(entry->d_name);
if(len < TREE_MAX_FILENAMELEN)
/* strncpy() is evil, we memcpy() instead, +1 includes the
@@ -101,6 +106,15 @@ showdir(char *path, struct entry *buffer, int start)
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);
return i;
@@ -116,6 +130,8 @@ bool dirbrowse(char *root)
char currdir[255];
int dircursor=0;
int i;
+ int start=0;
+ int at_end=0;
#ifdef HAVE_LCD_BITMAP
lcd_clear_display();
@@ -123,7 +139,7 @@ bool dirbrowse(char *root)
lcd_puts(0,0, "[Browse]", 0);
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 */
@@ -155,10 +171,12 @@ bool dirbrowse(char *root)
lcd_clear_display();
lcd_puts(0,0, "[Browse]", 0);
- numentries = showdir(currdir, buffer, 0);
+ numentries = showdir(currdir, buffer, 0, 0, &at_end);
dircursor=0;
+ start=0;
while ( (dircursor < TREE_MAX_ON_SCREEN) &&
(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_update();
}
@@ -176,13 +194,14 @@ bool dirbrowse(char *root)
if (is_dir(buf)) {
memcpy(currdir,buf,sizeof(currdir));
dircursor=0;
+ start=0;
} else {
playtune(currdir, buffer[dircursor].name);
}
lcd_clear_display();
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_update();
break;
@@ -193,6 +212,15 @@ bool dirbrowse(char *root)
dircursor--;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
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;
case BUTTON_DOWN:
@@ -201,6 +229,16 @@ bool dirbrowse(char *root)
dircursor++;
lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
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;
}