expanded the browser with a little cursor to move

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@331 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2002-04-30 13:37:28 +00:00
parent 5ab87aa978
commit 25ca8f2a56
2 changed files with 50 additions and 8 deletions

View file

@ -88,10 +88,7 @@ void app_main(void)
menu_init();
break;
case (LINE_BROWSE * LINE_HEIGHT):
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
dirbrowse("/");
lcd_update();
while((!button_get()));
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
menu_init();
break;

View file

@ -19,30 +19,75 @@
#include <dir.h>
#include <types.h>
#include <lcd.h>
#include <button.h>
#define TREE_MAX_LEN 15
#define TREE_MAX_ON_SCREEN 7
int dircursor=0;
bool dirbrowse(char *root)
{
DIR *dir = opendir(root);
int i;
struct dirent *entry;
char buffer[20];
char buffer[TREE_MAX_ON_SCREEN][20];
if(!dir)
return TRUE; /* failure */
lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
lcd_puts(0,0, "[Browse]", 0);
i=0;
while((entry = readdir(dir))) {
strncpy(buffer, entry->d_name, TREE_MAX_LEN);
buffer[TREE_MAX_LEN]=0;
lcd_puts(0, i*8, buffer, 0);
strncpy(buffer[i], entry->d_name, TREE_MAX_LEN);
buffer[i][TREE_MAX_LEN]=0;
lcd_puts(6, 8+i*8, buffer[i], 0);
if(++i > 8)
if(++i > TREE_MAX_ON_SCREEN)
break;
}
closedir(dir);
lcd_puts(0, 8+dircursor, "-", 0);
lcd_update();
while(1) {
int key = button_get();
if(!key) {
sleep(1);
continue;
}
switch(key) {
case BUTTON_OFF:
case BUTTON_LEFT:
return FALSE;
break;
case BUTTON_UP:
if(dircursor) {
lcd_puts(0, 8+dircursor, " ", 0);
dircursor -= 8;
lcd_puts(0, 8+dircursor, "-", 0);
lcd_update();
}
break;
case BUTTON_DOWN:
if(dircursor < (8 * TREE_MAX_ON_SCREEN)) {
lcd_puts(0, 8+dircursor, " ", 0);
dircursor += 8;
lcd_puts(0, 8+dircursor, "-", 0);
lcd_update();
}
break;
}
}
return FALSE;
}