annotate examples/menu/filebrowser.c @ 1234:0f597a2073eb

Enter the group after insert/extend a key frame
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 10 Jan 2011 11:45:12 +0800
parents e030c9d4b79b
children
rev   line source
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
1 /*! \file
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
2 *
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
3 * This is the demo program for the animated menu. We will use to test the MBAF API.
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
4 * We need to have group item1-item9 in the SVG file. Initially, we will show
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
5 * item1-item8 only. When a up/down key is pressed, we will draw the next item in item9 and
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
6 * add two words to move item1-item9 smoothly. The first word move items to the 3/4 position
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
7 * fastly. The second will move it from 3/4 to the final position slowly to make retard effect.
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
8 *
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
9 * If we press another key before the second words finish, we will delete the word and replace
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
10 * it with a word to move it fastly to the final position and then we will repeat the procedure
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
11 * to add another two words to move it to the next position.
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
12 */
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
13 #include <stdio.h>
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
14 #include <mb.h>
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
15 #include <string.h>
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
16 #include <dirent.h>
325
4453ea44a83d Remove the menu.h
root@localhost.localdomain
parents: 309
diff changeset
17 //#include "menu.h"
456
26c302b47de1 Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
18 #include "mb_af.h"
26c302b47de1 Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents: 454
diff changeset
19 #include <mb_ani_menu.h>
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
20
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
21
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
22
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
23 struct fileinfo {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
24 int height;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
25 int width;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
26 int depth;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
27 int bitrate;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
28 int duration;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
29 int year;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
30 char *comment;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
31 };
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
32 #define MAX_ENTRY 1000
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
33 typedef struct {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
34 mb_animated_menu_t *m;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
35 char *curDir;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
36 struct fileinfo *files[MAX_ENTRY];
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
37 char *titles[MAX_ENTRY];
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
38 int nFiles;
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
39 }app_data_t;
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
40
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
41 mbaf_t *app;
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
42
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
43
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
44
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
45 void myselect(mb_animated_menu_t *m, int select)
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
46 {
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
47 app_data_t *data = MBAF_DATA(app,app_data_t);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
48 char path[1024];
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
49 int len,i;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
50
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
51 if (strcmp(data->titles[select],"..")==0) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
52 strcpy(path, data->curDir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
53 len = strlen(path);
602
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
54 for(i=len-2;i>0;i--) {
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
55 if (path[i] == '/') {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
56 path[i] = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
57 break;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
58 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
59 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
60 } else {
602
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
61 snprintf(path,1024,"%s%s", data->curDir,data->titles[select]);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
62 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
63
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
64 MyApp_fillDirInfo(app, path);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
65 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
66
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
67
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
68 void mypreview(app_data_t *data, char *path)
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
69 {
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
70 redraw_man_t *rdman = MBAF_RDMAN(app);
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
71 paint_t *paint, *old_paint;
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
72 shape_t *obj = (shape_t *) MB_SPRITE_GET_OBJ(app->rootsprite, "previewimg");
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
73 int w, h;
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
74
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
75 printf("Preview %s\n",path);
542
d7f224b97b7f Fix the wrong way of getting the paint of an image.
Thinker K.F. Li <thinker@branda.to>
parents: 456
diff changeset
76 paint = rdman_img_ldr_load_paint(rdman, path); /* return a cached
d7f224b97b7f Fix the wrong way of getting the paint of an image.
Thinker K.F. Li <thinker@branda.to>
parents: 456
diff changeset
77 * paint if the
d7f224b97b7f Fix the wrong way of getting the paint of an image.
Thinker K.F. Li <thinker@branda.to>
parents: 456
diff changeset
78 * path was loaded
d7f224b97b7f Fix the wrong way of getting the paint of an image.
Thinker K.F. Li <thinker@branda.to>
parents: 456
diff changeset
79 * before */
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
80 if (paint) {
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
81 paint_image_get_size(paint, &w, &h);
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
82 printf("image %d %d\n",w, h);
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
83 old_paint = sh_get_fill(obj);
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
84 rdman_paint_fill(rdman, paint, obj);
542
d7f224b97b7f Fix the wrong way of getting the paint of an image.
Thinker K.F. Li <thinker@branda.to>
parents: 456
diff changeset
85 if(old_paint != paint)
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
86 rdman_paint_free(rdman, old_paint);
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
87
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
88 rdman_shape_changed(MBAF_RDMAN(app),obj);
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
89 rdman_redraw_changed(MBAF_RDMAN(app));
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
90 }
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
91 }
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
92
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
93 int endWith(char *path, char *ext)
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
94 {
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
95 int i;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
96 char *s;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
97
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
98 s = path+strlen(path)-1;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
99 for(i=strlen(ext)-1;i>=0;i--) {
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
100 if (*s != ext[i]) return 0;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
101 s--;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
102 if (s < path) return 0;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
103 }
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
104 return 1;
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
105 }
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
106
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
107 void myupdate(mb_animated_menu_t *m, int select)
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
108 {
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
109 app_data_t *data = MBAF_DATA(app,app_data_t);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
110 char *s = data->titles[select];
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
111 char path[1024];
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
112
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
113 printf("check %s\n",s);
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
114
601
8863d23cea4b Load images with Imlib2.
Thinker K.F. Li <thinker@branda.to>
parents: 542
diff changeset
115 if (endWith(s,".png") || endWith(s, ".jpg") ||
8863d23cea4b Load images with Imlib2.
Thinker K.F. Li <thinker@branda.to>
parents: 542
diff changeset
116 endWith(s, ".PNG") || endWith(s, ".JPG")) {
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
117 snprintf(path,1024,"%s%s", data->curDir,data->titles[select]);
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
118 mypreview(data,path);
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
119 }
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
120 }
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
121
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
122
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
123
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
124 struct fileinfo *fileinfo_new()
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
125 {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
126 struct fileinfo *f = (struct fileinfo *) malloc(sizeof(struct fileinfo));
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
127
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
128 f->width = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
129 f->height = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
130 f->depth = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
131 f->bitrate = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
132 f->duration = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
133 f->year = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
134 f->comment = NULL;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
135 return f;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
136 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
137
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
138 void fileinfo_free(struct fileinfo *f)
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
139 {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
140 free(f);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
141 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
142
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
143
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
144 MyApp_fillDirInfo(mbaf_t *app,char *curdir)
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
145 {
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
146 app_data_t *data = MBAF_DATA(app,app_data_t);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
147 DIR *dir;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
148 struct dirent *e;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
149 struct fileinfo *f;
602
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
150 char *path;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
151 int sz;
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
152 int i;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
153
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
154 dir = opendir(curdir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
155 if (dir == NULL) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
156 printf("We can not open the direftory %s\n", curdir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
157 return;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
158 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
159
329
740844ee48c4 Update position of light-bar after update menu item
Thinker K.F. Li <thinker@branda.to>
parents: 325
diff changeset
160 if (data->curDir)
740844ee48c4 Update position of light-bar after update menu item
Thinker K.F. Li <thinker@branda.to>
parents: 325
diff changeset
161 free(data->curDir);
602
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
162
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
163 sz = strlen(curdir);
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
164 if(curdir[sz - 1] != '/')
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
165 sz++;
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
166 data->curDir = (char *)malloc(sz + 1);
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
167 strcpy(data->curDir, curdir);
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
168 if(curdir[sz - 1] == '\0')
ac2e6468a22a Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
Thinker K.F. Li <thinker@branda.to>
parents: 601
diff changeset
169 strcat(data->curDir, "/");
329
740844ee48c4 Update position of light-bar after update menu item
Thinker K.F. Li <thinker@branda.to>
parents: 325
diff changeset
170
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
171 if (data->files) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
172 for(i=0;i<data->nFiles;i++) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
173 fileinfo_free(data->files[i]);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
174 free(data->titles[i]);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
175 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
176 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
177 data->nFiles = 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
178 while(e = readdir(dir)) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
179 if (strcmp(e->d_name,".")==0) continue;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
180 if (e->d_type == DT_DIR) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
181 if (data->nFiles < MAX_ENTRY) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
182 f = fileinfo_new();
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
183 data->files[data->nFiles] = f;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
184 data->titles[data->nFiles++] = strdup(e->d_name);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
185 printf("%s\n", e->d_name);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
186 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
187 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
188 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
189
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
190 closedir(dir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
191 dir = opendir(curdir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
192 while(e = readdir(dir)) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
193 if (strcmp(e->d_name,".")==0) continue;
1121
e030c9d4b79b Display the file which is symbolic link
wycc
parents: 602
diff changeset
194 printf("e->d_type=%d %d name=%s\n",e->d_type,DT_REG,e->d_name);
e030c9d4b79b Display the file which is symbolic link
wycc
parents: 602
diff changeset
195 if (e->d_type == DT_REG || e->d_type == DT_LNK) {
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
196 if (data->nFiles < MAX_ENTRY) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
197 f = fileinfo_new();
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
198 data->files[data->nFiles] = f;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
199 data->titles[data->nFiles++] = strdup(e->d_name);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
200 printf("%s\n", e->d_name);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
201 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
202 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
203 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
204 closedir(dir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
205 data->titles[data->nFiles] = NULL;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
206 mb_animated_menu_set_titles(data->m,data->titles);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
207 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
208
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
209
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
210 MyApp_InitContent(char *dir)
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
211 {
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
212 app_data_t *data = MBAF_DATA(app,app_data_t);
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
213 subject_t *key = MBAF_KB_SUBJECT(app);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
214 char name[255];
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
215 coord_t *l;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
216 int i;
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
217 mb_sprite_t *sprite=app->rootsprite;
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
218
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
219 data->m = mb_animated_menu_new(app,app->rootsprite,"item",NULL);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
220 mb_animated_menu_set_callback(data->m, myselect);
344
ab7f3c00fd05 Implement PMNG viewer
wycc
parents: 329
diff changeset
221 mb_animated_menu_set_update_callback(data->m, myupdate);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
222 data->curDir = NULL;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
223 data->nFiles=0;
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
224 MyApp_fillDirInfo(app,dir);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
225 mb_animated_menu_set_speed(data->m,300);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
226 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
227
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
228 int main(int argc, char * const argv[]) {
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
229 subject_t *subject;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
230 mb_obj_t *button;
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
231 app_data_t data;
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
232 mb_timeval_t tmo,interval;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
233 char *dir;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
234
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
235 if (argc > 1)
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
236 dir = argv[1];
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
237 else
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
238 dir ="/tmp";
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
239 app = mbaf_init("browser", ".libs");
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
240 mbaf_set_data(app,&data);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
241 MyApp_InitContent(dir);
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
242
454
9b8dda201ccb Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 453
diff changeset
243 mbaf_loop(app);
309
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
244
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
245 return 0;
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
246 }
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
247
4dfb850dee92 Add filebrowser program and SVG file.
wycc
parents:
diff changeset
248 /* vim: set ts=4 */