diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-05-10 14:56:52 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-10 14:56:52 +0000 |
commit | c492d24cce70a7a49cc041a9a948f6758e509ef6 (patch) | |
tree | a5232899ae962994e60251b53d5031332db51df8 /uisimulator/tree.c | |
parent | 71cda11e65cf3d7ea6c9363d9505619508c301ba (diff) | |
download | rockbox-c492d24cce70a7a49cc041a9a948f6758e509ef6.tar.gz rockbox-c492d24cce70a7a49cc041a9a948f6758e509ef6.zip |
Adapted to changes in the lcd API.
Added player support to the dir browser.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@541 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/tree.c')
-rw-r--r-- | uisimulator/tree.c | 401 |
1 files changed, 221 insertions, 180 deletions
diff --git a/uisimulator/tree.c b/uisimulator/tree.c index ed7ebad000..0382547590 100644 --- a/uisimulator/tree.c +++ b/uisimulator/tree.c @@ -32,13 +32,8 @@ #include "play.h" -#define TREE_MAX_FILENAMELEN 64 -#define TREE_MAX_ON_SCREEN 7 -#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */ - -void browse_root(void) { - dirbrowse("/"); -} + +#define TREE_MAX_FILENAMELEN 128 struct entry { int file; /* TRUE if file, FALSE if dir */ @@ -46,204 +41,250 @@ struct entry { int namelen; }; -#define LINE_Y 8 /* Y position the entry-list starts at */ -#define LINE_X 12 /* X position the entry-list starts at */ -#define LINE_HEIGTH 8 /* pixels for each text line */ +void browse_root(void) +{ + dirbrowse("/"); +} + #ifdef HAVE_LCD_BITMAP +#define TREE_MAX_ON_SCREEN 7 +#define TREE_MAX_LEN_DISPLAY 16 /* max length that fits on screen */ + +#define MARGIN_Y 8 /* Y pixel margin */ +#define MARGIN_X 12 /* X pixel margin */ +#define LINE_Y 0 /* Y position the entry-list starts at */ +#define LINE_X 2 /* X position the entry-list starts at */ +#define LINE_HEIGTH 8 /* pixels for each text line */ + extern unsigned char bitmap_icons_6x8[LastIcon][6]; extern icons_6x8; +#else /* HAVE_LCD_BITMAP */ + +#define TREE_MAX_ON_SCREEN 2 +#define TREE_MAX_LEN_DISPLAY 11 /* max length that fits on screen */ +#define LINE_Y 0 /* Y position the entry-list starts at */ +#define LINE_X 1 /* X position the entry-list starts at */ + +#endif /* HAVE_LCD_BITMAP */ + int static showdir(char *path, struct entry *buffer, int start, int scrollpos, int* at_end) { - int i; - int j=0; - int icon_type = 0; - DIR *dir = opendir(path); - struct dirent *entry; - - if(!dir) - return -1; /* not a directory */ - - i=start; - *at_end=0; /* Have we displayed the last directory entry? */ - while((entry = readdir(dir))) { - int len; - - if(entry->d_name[0] == '.') - /* 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 - trailing zero */ - memcpy(buffer[i].name, entry->d_name, len+1); - else - memcpy(buffer[i].name, "too long", 9); - - buffer[i].file = !(entry->attribute&ATTR_DIRECTORY); - - buffer[i].file?(icon_type=File):(icon_type=Folder); - lcd_bitmap(bitmap_icons_6x8[icon_type], 6, LINE_Y+i*LINE_HEIGTH, 6, - 8, TRUE); - - if(len < TREE_MAX_LEN_DISPLAY) - lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0); - else { - char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY]; - buffer[i].name[TREE_MAX_LEN_DISPLAY]=0; - lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0); - buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage; - } + int i; + int j=0; + int icon_type = 0; + DIR *dir = opendir(path); + struct dirent *entry; - if(++i >= TREE_MAX_ON_SCREEN) - 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; -} + if(!dir) + return -1; /* not a directory */ + + i=start; + *at_end=0; /* Have we displayed the last directory entry? */ + while((entry = readdir(dir))) { + int len; + if(entry->d_name[0] == '.') + /* 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 + trailing zero */ + memcpy(buffer[i].name, entry->d_name, len+1); + else + memcpy(buffer[i].name, "too long", 9); + + buffer[i].file = !(entry->attribute&ATTR_DIRECTORY); + +#ifdef HAVE_LCD_BITMAP + if ( buffer[i].file ) + icon_type=File; + else + icon_type=Folder; + lcd_bitmap(bitmap_icons_6x8[icon_type], 6, MARGIN_Y+i*LINE_HEIGTH, 6, + 8, TRUE); #endif + if(len < TREE_MAX_LEN_DISPLAY) + lcd_puts(LINE_X, LINE_Y+i, buffer[i].name); + else { + char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY]; + buffer[i].name[TREE_MAX_LEN_DISPLAY]=0; + lcd_puts(LINE_X, LINE_Y+i, buffer[i].name); + buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage; + } + + if(++i >= TREE_MAX_ON_SCREEN) + 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," "); + } + closedir(dir); + + return i; +} + bool dirbrowse(char *root) { - struct entry buffer[TREE_MAX_ON_SCREEN]; - int numentries; - char buf[255]; - char currdir[255]; - int dircursor=0; - int i; - int start=0; - int at_end=0; + struct entry buffer[TREE_MAX_ON_SCREEN]; + int numentries; + char buf[255]; + char currdir[255]; + int dircursor=0; + int i; + int start=0; + int at_end=0; -#ifdef HAVE_LCD_BITMAP - lcd_clear_display(); + lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 0); - memcpy(currdir,root,sizeof(currdir)); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); + lcd_setmargins(0,MARGIN_Y); + lcd_setfont(0); +#endif + memcpy(currdir,root,sizeof(currdir)); - numentries = showdir(root, buffer, 0, start, &at_end); + 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 */ - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); + lcd_puts(0, dircursor, "-"); + lcd_update(); - lcd_update(); + while(1) { + int key = button_get(); - while(1) { - int key = button_get(); + if(!key) { + sleep(1); + continue; + } + switch(key) { + case BUTTON_OFF: + return FALSE; + break; + + case BUTTON_LEFT: + i=strlen(currdir); + if (i==1) { + return FALSE; + } + else { + while (currdir[i-1]!='/') + i--; + strcpy(buf,&currdir[i]); + if (i==1) + currdir[i]=0; + else + currdir[i-1]=0; + + lcd_clear_display(); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + 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, "-"); + lcd_update(); + } + + break; + + case BUTTON_RIGHT: + case BUTTON_PLAY: + if ((currdir[0]=='/') && (currdir[1]==0)) { + sprintf(buf,"%s%s",currdir,buffer[dircursor].name); + } else { + sprintf(buf,"%s/%s",currdir,buffer[dircursor].name); + } + + if (!buffer[dircursor].file) { + memcpy(currdir,buf,sizeof(currdir)); + dircursor=0; + start=0; + } else { + playtune(currdir, buffer[dircursor].name); +#ifdef HAVE_LCD_BITMAP + lcd_setmargins(0, MARGIN_Y); + lcd_setfont(0); +#endif + } - if(!key) { - sleep(1); - continue; - } - switch(key) { - case BUTTON_OFF: - return FALSE; - break; - - case BUTTON_LEFT: - i=strlen(currdir); - if (i==1) { - return FALSE; - } else { - while (currdir[i-1]!='/') i--; - strcpy(buf,&currdir[i]); - if (i==1) currdir[i]=0; - else currdir[i-1]=0; - - lcd_clear_display(); - lcd_puts(0,0, "[Browse]", 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(); - } - - break; - - case BUTTON_RIGHT: - case BUTTON_PLAY: - if ((currdir[0]=='/') && (currdir[1]==0)) { - sprintf(buf,"%s%s",currdir,buffer[dircursor].name); - } else { - sprintf(buf,"%s/%s",currdir,buffer[dircursor].name); - } - - if (!buffer[dircursor].file) { - 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, start, &at_end); - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); - lcd_update(); - break; + lcd_clear_display(); + numentries = showdir(currdir, buffer, 0, start, &at_end); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + break; - case BUTTON_UP: - if(dircursor) { - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0); - 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: - if(dircursor+1 < numentries) { - lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0); - 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(); + case BUTTON_UP: + if(dircursor) { + lcd_puts(0, LINE_Y+dircursor, " "); + dircursor--; + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } else + { + if (start) { + lcd_clear_display(); + start--; + numentries = showdir(currdir, buffer, 0, + start, &at_end); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } + } + break; + case BUTTON_DOWN: + if(dircursor+1 < numentries) { + lcd_puts(0, LINE_Y+dircursor, " "); + dircursor++; + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } else + { + if (!at_end) { + lcd_clear_display(); + start++; + numentries = showdir(currdir, buffer, 0, + start, &at_end); +#ifdef HAVE_LCD_BITMAP + lcd_putsxy(0,0, "[Browse]",0); +#endif + lcd_puts(0, LINE_Y+dircursor, "-"); + lcd_update(); + } + } + break; } - } - break; } - } -#endif - return FALSE; + return FALSE; } |