Mercurial > MadButterfly
comparison examples/menu/filebrowser.c @ 454:9b8dda201ccb
Make naming convention consistent with MadButterfly.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 06 Aug 2009 09:38:51 +0800 |
parents | 84ce2d4a8c3f |
children | 26c302b47de1 |
comparison
equal
deleted
inserted
replaced
453:84ce2d4a8c3f | 454:9b8dda201ccb |
---|---|
34 mb_animated_menu_t *m; | 34 mb_animated_menu_t *m; |
35 char *curDir; | 35 char *curDir; |
36 struct fileinfo *files[MAX_ENTRY]; | 36 struct fileinfo *files[MAX_ENTRY]; |
37 char *titles[MAX_ENTRY]; | 37 char *titles[MAX_ENTRY]; |
38 int nFiles; | 38 int nFiles; |
39 }MyAppData; | 39 }app_data_t; |
40 | 40 |
41 MBApp *myApp; | 41 mbaf_t *app; |
42 | 42 |
43 | 43 |
44 | 44 |
45 void myselect(mb_animated_menu_t *m, int select) | 45 void myselect(mb_animated_menu_t *m, int select) |
46 { | 46 { |
47 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | 47 app_data_t *data = MBAF_DATA(app,app_data_t); |
48 char path[1024]; | 48 char path[1024]; |
49 int len,i; | 49 int len,i; |
50 | 50 |
51 if (strcmp(data->titles[select],"..")==0) { | 51 if (strcmp(data->titles[select],"..")==0) { |
52 strcpy(path, data->curDir); | 52 strcpy(path, data->curDir); |
59 } | 59 } |
60 } else { | 60 } else { |
61 snprintf(path,1024,"%s/%s", data->curDir,data->titles[select]); | 61 snprintf(path,1024,"%s/%s", data->curDir,data->titles[select]); |
62 } | 62 } |
63 | 63 |
64 MyApp_fillDirInfo(myApp, path); | 64 MyApp_fillDirInfo(app, path); |
65 } | 65 } |
66 | 66 |
67 | 67 |
68 void mypreview(MyAppData *data, char *path) | 68 void mypreview(app_data_t *data, char *path) |
69 { | 69 { |
70 redraw_man_t *rdman = MBAPP_RDMAN(myApp); | 70 redraw_man_t *rdman = MBAF_RDMAN(app); |
71 paint_t *paint, *old_paint; | 71 paint_t *paint, *old_paint; |
72 paint_t *previewimg_paint; | 72 paint_t *previewimg_paint; |
73 shape_t *obj = (shape_t *) MB_SPRITE_GET_OBJ(myApp->rootsprite, "previewimg"); | 73 shape_t *obj = (shape_t *) MB_SPRITE_GET_OBJ(app->rootsprite, "previewimg"); |
74 int w, h; | 74 int w, h; |
75 | 75 |
76 previewimg_paint = | 76 previewimg_paint = |
77 (paint_t *)MB_SPRITE_GET_OBJ(myApp->rootsprite, | 77 (paint_t *)MB_SPRITE_GET_OBJ(app->rootsprite, |
78 "previewimg_paint_img"); | 78 "previewimg_paint_img"); |
79 printf("Preview %s\n",path); | 79 printf("Preview %s\n",path); |
80 paint = rdman_img_ldr_load_paint(rdman, path); | 80 paint = rdman_img_ldr_load_paint(rdman, path); |
81 if (paint) { | 81 if (paint) { |
82 paint_image_get_size(paint, &w, &h); | 82 paint_image_get_size(paint, &w, &h); |
84 old_paint = sh_get_fill(obj); | 84 old_paint = sh_get_fill(obj); |
85 rdman_paint_fill(rdman, paint, obj); | 85 rdman_paint_fill(rdman, paint, obj); |
86 if(old_paint != previewimg_paint) | 86 if(old_paint != previewimg_paint) |
87 rdman_paint_free(rdman, old_paint); | 87 rdman_paint_free(rdman, old_paint); |
88 | 88 |
89 rdman_shape_changed(MBAPP_RDMAN(myApp),obj); | 89 rdman_shape_changed(MBAF_RDMAN(app),obj); |
90 rdman_redraw_changed(MBAPP_RDMAN(myApp)); | 90 rdman_redraw_changed(MBAF_RDMAN(app)); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 int endWith(char *path, char *ext) | 94 int endWith(char *path, char *ext) |
95 { | 95 { |
105 return 1; | 105 return 1; |
106 } | 106 } |
107 | 107 |
108 void myupdate(mb_animated_menu_t *m, int select) | 108 void myupdate(mb_animated_menu_t *m, int select) |
109 { | 109 { |
110 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | 110 app_data_t *data = MBAF_DATA(app,app_data_t); |
111 char *s = data->titles[select]; | 111 char *s = data->titles[select]; |
112 char path[1024]; | 112 char path[1024]; |
113 | 113 |
114 printf("check %s\n",s); | 114 printf("check %s\n",s); |
115 | 115 |
139 { | 139 { |
140 free(f); | 140 free(f); |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 MyApp_fillDirInfo(MBApp *app,char *curdir) | 144 MyApp_fillDirInfo(mbaf_t *app,char *curdir) |
145 { | 145 { |
146 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | 146 app_data_t *data = MBAF_DATA(app,app_data_t); |
147 DIR *dir; | 147 DIR *dir; |
148 struct dirent *e; | 148 struct dirent *e; |
149 struct fileinfo *f; | 149 struct fileinfo *f; |
150 int i; | 150 int i; |
151 | 151 |
197 } | 197 } |
198 | 198 |
199 | 199 |
200 MyApp_InitContent(char *dir) | 200 MyApp_InitContent(char *dir) |
201 { | 201 { |
202 MyAppData *data = MBAPP_DATA(myApp,MyAppData); | 202 app_data_t *data = MBAF_DATA(app,app_data_t); |
203 subject_t *key = MBAPP_keySubject(myApp); | 203 subject_t *key = MBAF_KB_SUBJECT(app); |
204 char name[255]; | 204 char name[255]; |
205 coord_t *l; | 205 coord_t *l; |
206 int i; | 206 int i; |
207 mb_sprite_t *sprite=myApp->rootsprite; | 207 mb_sprite_t *sprite=app->rootsprite; |
208 | 208 |
209 data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",NULL); | 209 data->m = mb_animated_menu_new(app,app->rootsprite,"item",NULL); |
210 mb_animated_menu_set_callback(data->m, myselect); | 210 mb_animated_menu_set_callback(data->m, myselect); |
211 mb_animated_menu_set_update_callback(data->m, myupdate); | 211 mb_animated_menu_set_update_callback(data->m, myupdate); |
212 data->curDir = NULL; | 212 data->curDir = NULL; |
213 data->nFiles=0; | 213 data->nFiles=0; |
214 MyApp_fillDirInfo(myApp,dir); | 214 MyApp_fillDirInfo(app,dir); |
215 mb_animated_menu_set_speed(data->m,300); | 215 mb_animated_menu_set_speed(data->m,300); |
216 } | 216 } |
217 | 217 |
218 int main(int argc, char * const argv[]) { | 218 int main(int argc, char * const argv[]) { |
219 subject_t *subject; | 219 subject_t *subject; |
220 mb_obj_t *button; | 220 mb_obj_t *button; |
221 MyAppData data; | 221 app_data_t data; |
222 mb_timeval_t tmo,interval; | 222 mb_timeval_t tmo,interval; |
223 char *dir; | 223 char *dir; |
224 | 224 |
225 if (argc > 1) | 225 if (argc > 1) |
226 dir = argv[1]; | 226 dir = argv[1]; |
227 else | 227 else |
228 dir ="/tmp"; | 228 dir ="/tmp"; |
229 myApp = MBApp_Init("browser", ".libs"); | 229 app = mbaf_init("browser", ".libs"); |
230 MBApp_setData(myApp,&data); | 230 mbaf_set_data(app,&data); |
231 MyApp_InitContent(dir); | 231 MyApp_InitContent(dir); |
232 | 232 |
233 MBApp_loop(myApp); | 233 mbaf_loop(app); |
234 | 234 |
235 return 0; | 235 return 0; |
236 } | 236 } |
237 | 237 |
238 /* vim: set ts=4 */ | 238 /* vim: set ts=4 */ |