summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-05-05 10:45:50 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-05-05 10:45:50 +0000
commitc484ae4494c6aab821b70a04ac59cc4e3739f44f (patch)
tree350888a23434007a295e2d6ae27c4d08ea6a347e
parent08e2b4917bb46fb1408134808bf946b282c473c3 (diff)
downloadrockbox-c484ae4494c6aab821b70a04ac59cc4e3739f44f.tar.gz
rockbox-c484ae4494c6aab821b70a04ac59cc4e3739f44f.zip
builds with Player LCD too
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@435 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/tree.c111
1 files changed, 86 insertions, 25 deletions
diff --git a/uisimulator/tree.c b/uisimulator/tree.c
index b6342c67f5..74da12e9c7 100644
--- a/uisimulator/tree.c
+++ b/uisimulator/tree.c
@@ -17,18 +17,22 @@
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19
20#include <string.h>
21#include <stdlib.h>
22
20#include <dir.h> 23#include <dir.h>
24#include <file.h>
21#include <types.h> 25#include <types.h>
22#include <lcd.h> 26#include <lcd.h>
23#include <button.h> 27#include <button.h>
24#include "kernel.h" 28#include "kernel.h"
25#include "tree.h" 29#include "tree.h"
26#ifdef WIN32
27#include <windows.h>
28#endif // WIN32
29 30
30#define TREE_MAX_LEN 15 31#include "play.h"
31#define TREE_MAX_ON_SCREEN 7 32
33#define TREE_MAX_FILENAMELEN 64
34#define TREE_MAX_ON_SCREEN 7
35#define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */
32 36
33int dircursor=0; 37int dircursor=0;
34 38
@@ -36,34 +40,80 @@ void browse_root(void) {
36 dirbrowse("/"); 40 dirbrowse("/");
37} 41}
38 42
39bool dirbrowse(char *root) 43struct entry {
44 int file; /* TRUE if file, FALSE if dir */
45 char name[TREE_MAX_FILENAMELEN];
46 int namelen;
47};
48
49#define LINE_Y 8 /* Y position the entry-list starts at */
50#define LINE_X 6 /* X position the entry-list starts at */
51#define LINE_HEIGTH 8 /* pixels for each text line */
52
53#ifdef HAVE_LCD_BITMAP
54
55int static
56showdir(char *path, struct entry *buffer, int start)
40{ 57{
41 DIR *dir = opendir(root);
42 int i; 58 int i;
59 DIR *dir = opendir(path);
43 struct dirent *entry; 60 struct dirent *entry;
44 char buffer[TREE_MAX_ON_SCREEN][20];
45 61
46 if(!dir) 62 if(!dir)
47 return TRUE; /* failure */ 63 return 0; /* no entries */
48 64
49#ifdef HAVE_LCD_BITMAP 65 i=start;
50 lcd_clearrect(0, 0, LCD_WIDTH, LCD_HEIGHT); 66 while((entry = readdir(dir))) {
67 int len;
51 68
52 lcd_puts(0,0, "[Browse]", 0); 69 if(entry->d_name[0] == '.')
70 /* skip names starting with a dot */
71 continue;
53 72
54 i=0; 73 len = strlen(entry->d_name);
55 while((entry = readdir(dir))) { 74 if(len < TREE_MAX_FILENAMELEN)
56 strncpy(buffer[i], entry->d_name, TREE_MAX_LEN); 75 /* strncpy() is evil, we memcpy() instead, +1 includes the
57 buffer[i][TREE_MAX_LEN]=0; 76 trailing zero */
58 lcd_puts(6, 8+i*8, buffer[i], 0); 77 memcpy(buffer[i].name, entry->d_name, len+1);
78 else
79 memcpy(buffer[i].name, "too long", 9);
80
81 buffer[i].file = TRUE; /* files only for now */
82
83 if(len < TREE_MAX_LEN_DISPLAY)
84 lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0);
85 else {
86 char storage = buffer[i].name[TREE_MAX_LEN_DISPLAY];
87 buffer[i].name[TREE_MAX_LEN_DISPLAY]=0;
88 lcd_puts(LINE_X, LINE_Y+i*LINE_HEIGTH, buffer[i].name, 0);
89 buffer[i].name[TREE_MAX_LEN_DISPLAY]=storage;
90 }
59 91
60 if(++i >= TREE_MAX_ON_SCREEN) 92 if(++i >= TREE_MAX_ON_SCREEN)
61 break; 93 break;
62 } 94 }
95 i--; /* number of files on screen */
63 96
64 closedir(dir); 97 closedir(dir);
65 98
66 lcd_puts(0, 8+dircursor, "-", 0); 99 return i;
100}
101
102#endif
103
104bool dirbrowse(char *root)
105{
106 struct entry buffer[TREE_MAX_ON_SCREEN];
107 int numentries;
108
109#ifdef HAVE_LCD_BITMAP
110 lcd_clear_display();
111
112 lcd_puts(0,0, "[Browse]", 0);
113
114 numentries = showdir(root, buffer, 0);
115
116 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
67 117
68 lcd_update(); 118 lcd_update();
69 119
@@ -79,20 +129,31 @@ bool dirbrowse(char *root)
79 case BUTTON_LEFT: 129 case BUTTON_LEFT:
80 return FALSE; 130 return FALSE;
81 break; 131 break;
132
133 case BUTTON_RIGHT:
134 case BUTTON_PLAY:
135 playtune(root, buffer[dircursor].name);
136
137 lcd_clear_display();
138 lcd_puts(0,0, "[Browse]", 0);
139 numentries = showdir(root, buffer, 0);
140 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
141 lcd_update();
142 break;
82 143
83 case BUTTON_UP: 144 case BUTTON_UP:
84 if(dircursor) { 145 if(dircursor) {
85 lcd_puts(0, 8+dircursor, " ", 0); 146 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
86 dircursor -= 8; 147 dircursor--;
87 lcd_puts(0, 8+dircursor, "-", 0); 148 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
88 lcd_update(); 149 lcd_update();
89 } 150 }
90 break; 151 break;
91 case BUTTON_DOWN: 152 case BUTTON_DOWN:
92 if(dircursor < (8 * TREE_MAX_ON_SCREEN)) { 153 if(dircursor < numentries) {
93 lcd_puts(0, 8+dircursor, " ", 0); 154 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, " ", 0);
94 dircursor += 8; 155 dircursor++;
95 lcd_puts(0, 8+dircursor, "-", 0); 156 lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0);
96 lcd_update(); 157 lcd_update();
97 } 158 }
98 break; 159 break;