comparison examples/menu/filebrowser.c @ 344:ab7f3c00fd05

Implement PMNG viewer
author wycc
date Sun, 08 Mar 2009 11:46:09 +0800
parents 740844ee48c4
children d04085404583
comparison
equal deleted inserted replaced
342:5465ff071b47 344:ab7f3c00fd05
63 63
64 MyApp_fillDirInfo(myApp, path); 64 MyApp_fillDirInfo(myApp, path);
65 } 65 }
66 66
67 67
68 void mypreview(MyAppData *data, char *path)
69 {
70 mb_img_data_t *img = MB_IMG_LDR_LOAD(rdman_img_ldr(MBAPP_RDMAN(myApp)), path);
71 shape_t *obj = (shape_t *) MB_SPRITE_GET_OBJ(myApp->rootsprite, "previewimg");
72
73 printf("Preview %s\n",path);
74 if (img) {
75 printf("image %d %d\n",img->w,img->h);
76 sh_image_set_img_data(obj,img,0,0,img->w,img->h);
77 sh_image_transform(obj);
78 rdman_shape_changed(MBAPP_RDMAN(myApp),obj);
79 rdman_redraw_changed(MBAPP_RDMAN(myApp));
80 }
81 }
82
83 int endWith(char *path, char *ext)
84 {
85 int i;
86 char *s;
87
88 s = path+strlen(path)-1;
89 for(i=strlen(ext)-1;i>=0;i--) {
90 if (*s != ext[i]) return 0;
91 s--;
92 if (s < path) return 0;
93 }
94 return 1;
95 }
96
97 void myupdate(mb_animated_menu_t *m, int select)
98 {
99 MyAppData *data = MBAPP_DATA(myApp,MyAppData);
100 char *s = data->titles[select];
101 char path[1024];
102
103 printf("check %s\n",s);
104
105 if (endWith(s,".jpg") || endWith(s,".png")) {
106 snprintf(path,1024,"%s%s", data->curDir,data->titles[select]);
107 mypreview(data,path);
108 }
109 }
110
111
112
68 struct fileinfo *fileinfo_new() 113 struct fileinfo *fileinfo_new()
69 { 114 {
70 struct fileinfo *f = (struct fileinfo *) malloc(sizeof(struct fileinfo)); 115 struct fileinfo *f = (struct fileinfo *) malloc(sizeof(struct fileinfo));
71 116
72 f->width = 0; 117 f->width = 0;
150 int i; 195 int i;
151 mb_sprite_t *sprite=myApp->rootsprite; 196 mb_sprite_t *sprite=myApp->rootsprite;
152 197
153 data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",NULL); 198 data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",NULL);
154 mb_animated_menu_set_callback(data->m, myselect); 199 mb_animated_menu_set_callback(data->m, myselect);
200 mb_animated_menu_set_update_callback(data->m, myupdate);
155 data->curDir = NULL; 201 data->curDir = NULL;
156 data->nFiles=0; 202 data->nFiles=0;
157 MyApp_fillDirInfo(myApp,dir); 203 MyApp_fillDirInfo(myApp,dir);
158 mb_animated_menu_set_speed(data->m,300); 204 mb_animated_menu_set_speed(data->m,300);
159 } 205 }