diff options
author | Dave Chapman <dave@dchapman.com> | 2002-05-06 17:02:57 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2002-05-06 17:02:57 +0000 |
commit | 04fdc1eb8329f4b1dc458447573551c4f8e4c546 (patch) | |
tree | eb2539aa52c5da0d7da8100f79dd463515d03046 | |
parent | f830e3827ff542ffb504aa1983ac394d536ca141 (diff) | |
download | rockbox-04fdc1eb8329f4b1dc458447573551c4f8e4c546.tar.gz rockbox-04fdc1eb8329f4b1dc458447573551c4f8e4c546.zip |
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.c | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/uisimulator/tree.c b/uisimulator/tree.c index 98e5c027aa..de3b71d3f7 100644 --- a/uisimulator/tree.c +++ b/uisimulator/tree.c | |||
@@ -33,7 +33,7 @@ | |||
33 | #define TREE_MAX_FILENAMELEN 64 | 33 | #define TREE_MAX_FILENAMELEN 64 |
34 | #define TREE_MAX_ON_SCREEN 7 | 34 | #define TREE_MAX_ON_SCREEN 7 |
35 | #define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */ | 35 | #define TREE_MAX_LEN_DISPLAY 17 /* max length that fits on screen */ |
36 | 36 | ||
37 | void browse_root(void) { | 37 | void browse_root(void) { |
38 | dirbrowse("/"); | 38 | dirbrowse("/"); |
39 | } | 39 | } |
@@ -61,9 +61,10 @@ bool is_dir(char* path) | |||
61 | } | 61 | } |
62 | 62 | ||
63 | int static | 63 | int static |
64 | showdir(char *path, struct entry *buffer, int start) | 64 | showdir(char *path, struct entry *buffer, int start, int scrollpos, int* at_end) |
65 | { | 65 | { |
66 | int i; | 66 | int i; |
67 | int j=0; | ||
67 | DIR *dir = opendir(path); | 68 | DIR *dir = opendir(path); |
68 | struct dirent *entry; | 69 | struct dirent *entry; |
69 | 70 | ||
@@ -71,6 +72,7 @@ showdir(char *path, struct entry *buffer, int start) | |||
71 | return -1; /* not a directory */ | 72 | return -1; /* not a directory */ |
72 | 73 | ||
73 | i=start; | 74 | i=start; |
75 | *at_end=0; /* Have we displayed the last directory entry? */ | ||
74 | while((entry = readdir(dir))) { | 76 | while((entry = readdir(dir))) { |
75 | int len; | 77 | int len; |
76 | 78 | ||
@@ -78,6 +80,9 @@ showdir(char *path, struct entry *buffer, int start) | |||
78 | /* skip names starting with a dot */ | 80 | /* skip names starting with a dot */ |
79 | continue; | 81 | continue; |
80 | 82 | ||
83 | if(j++ < scrollpos) | ||
84 | continue ; | ||
85 | |||
81 | len = strlen(entry->d_name); | 86 | len = strlen(entry->d_name); |
82 | if(len < TREE_MAX_FILENAMELEN) | 87 | if(len < TREE_MAX_FILENAMELEN) |
83 | /* strncpy() is evil, we memcpy() instead, +1 includes the | 88 | /* strncpy() is evil, we memcpy() instead, +1 includes the |
@@ -101,6 +106,15 @@ showdir(char *path, struct entry *buffer, int start) | |||
101 | break; | 106 | break; |
102 | } | 107 | } |
103 | 108 | ||
109 | if (entry==0) { | ||
110 | *at_end=1; | ||
111 | } else { | ||
112 | *at_end=(readdir(dir)==0); | ||
113 | } | ||
114 | j = i ; | ||
115 | while (j++ < TREE_MAX_ON_SCREEN) { | ||
116 | lcd_puts(LINE_X, LINE_Y+j*LINE_HEIGTH," ", 0); | ||
117 | } | ||
104 | closedir(dir); | 118 | closedir(dir); |
105 | 119 | ||
106 | return i; | 120 | return i; |
@@ -116,6 +130,8 @@ bool dirbrowse(char *root) | |||
116 | char currdir[255]; | 130 | char currdir[255]; |
117 | int dircursor=0; | 131 | int dircursor=0; |
118 | int i; | 132 | int i; |
133 | int start=0; | ||
134 | int at_end=0; | ||
119 | 135 | ||
120 | #ifdef HAVE_LCD_BITMAP | 136 | #ifdef HAVE_LCD_BITMAP |
121 | lcd_clear_display(); | 137 | lcd_clear_display(); |
@@ -123,7 +139,7 @@ bool dirbrowse(char *root) | |||
123 | lcd_puts(0,0, "[Browse]", 0); | 139 | lcd_puts(0,0, "[Browse]", 0); |
124 | memcpy(currdir,root,sizeof(currdir)); | 140 | memcpy(currdir,root,sizeof(currdir)); |
125 | 141 | ||
126 | numentries = showdir(root, buffer, 0); | 142 | numentries = showdir(root, buffer, 0, start, &at_end); |
127 | 143 | ||
128 | if (numentries == -1) return -1; /* root is not a directory */ | 144 | if (numentries == -1) return -1; /* root is not a directory */ |
129 | 145 | ||
@@ -155,10 +171,12 @@ bool dirbrowse(char *root) | |||
155 | 171 | ||
156 | lcd_clear_display(); | 172 | lcd_clear_display(); |
157 | lcd_puts(0,0, "[Browse]", 0); | 173 | lcd_puts(0,0, "[Browse]", 0); |
158 | numentries = showdir(currdir, buffer, 0); | 174 | numentries = showdir(currdir, buffer, 0, 0, &at_end); |
159 | dircursor=0; | 175 | dircursor=0; |
176 | start=0; | ||
160 | while ( (dircursor < TREE_MAX_ON_SCREEN) && | 177 | while ( (dircursor < TREE_MAX_ON_SCREEN) && |
161 | (strcmp(buffer[dircursor].name,buf)!=0)) dircursor++; | 178 | (strcmp(buffer[dircursor].name,buf)!=0)) dircursor++; |
179 | if (dircursor==TREE_MAX_ON_SCREEN) dircursor=0; | ||
162 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); | 180 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); |
163 | lcd_update(); | 181 | lcd_update(); |
164 | } | 182 | } |
@@ -176,13 +194,14 @@ bool dirbrowse(char *root) | |||
176 | if (is_dir(buf)) { | 194 | if (is_dir(buf)) { |
177 | memcpy(currdir,buf,sizeof(currdir)); | 195 | memcpy(currdir,buf,sizeof(currdir)); |
178 | dircursor=0; | 196 | dircursor=0; |
197 | start=0; | ||
179 | } else { | 198 | } else { |
180 | playtune(currdir, buffer[dircursor].name); | 199 | playtune(currdir, buffer[dircursor].name); |
181 | } | 200 | } |
182 | 201 | ||
183 | lcd_clear_display(); | 202 | lcd_clear_display(); |
184 | lcd_puts(0,0, "[Browse]", 0); | 203 | lcd_puts(0,0, "[Browse]", 0); |
185 | numentries = showdir(currdir, buffer, 0); | 204 | numentries = showdir(currdir, buffer, 0, 0, &at_end); |
186 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); | 205 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); |
187 | lcd_update(); | 206 | lcd_update(); |
188 | break; | 207 | break; |
@@ -193,6 +212,15 @@ bool dirbrowse(char *root) | |||
193 | dircursor--; | 212 | dircursor--; |
194 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); | 213 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); |
195 | lcd_update(); | 214 | lcd_update(); |
215 | } else | ||
216 | { | ||
217 | if (start) { | ||
218 | lcd_clear_display(); | ||
219 | lcd_puts(0,0, "[Browse]", 0); | ||
220 | numentries = showdir(currdir, buffer, 0, --start, &at_end); | ||
221 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); | ||
222 | lcd_update(); | ||
223 | } | ||
196 | } | 224 | } |
197 | break; | 225 | break; |
198 | case BUTTON_DOWN: | 226 | case BUTTON_DOWN: |
@@ -201,6 +229,16 @@ bool dirbrowse(char *root) | |||
201 | dircursor++; | 229 | dircursor++; |
202 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); | 230 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); |
203 | lcd_update(); | 231 | lcd_update(); |
232 | } else | ||
233 | { | ||
234 | if (!at_end) { | ||
235 | lcd_clear_display(); | ||
236 | lcd_puts(0,0, "[Browse]", 0); | ||
237 | numentries = showdir(currdir, buffer, 0, ++start, &at_end); | ||
238 | |||
239 | lcd_puts(0, LINE_Y+dircursor*LINE_HEIGTH, "-", 0); | ||
240 | lcd_update(); | ||
241 | } | ||
204 | } | 242 | } |
205 | break; | 243 | break; |
206 | } | 244 | } |