annotate src/sprite.c @ 289:13ce87b6dbf5

Fix bug of sh_text_t that do not update it-self after changes. - It is wrong to compute bounding box. - location of left-top corner is (text->d_x, text->d_y) not (text->x, text->y).
author Thinker K.F. Li <thinker@branda.to>
date Sat, 31 Jan 2009 18:28:50 +0800
parents 25bc0e753b88
children 31b6633e3538
rev   line source
228
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
1 #include <stdio.h>
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
2 #include <stdlib.h>
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
3 #include <string.h>
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
4 #include <cairo.h>
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
5 #include <dlfcn.h>
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
6 #include <sys/stat.h>
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
7 #include "mb_types.h"
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
8 #include "mb_shapes.h"
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
9 #include "mb_tools.h"
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
10 #include "mb_redraw_man.h"
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
11 #include "mb_observer.h"
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
12 #include "mb_prop.h"
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
13
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
14 static char *Sprite_Search_Path=NULL;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
15 static int sprite_search_so(char *path, int len, const char *name)
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
16 {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
17 struct stat st;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
18
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
19 if (Sprite_Search_Path == NULL) {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
20 Sprite_Search_Path = strdup("/usr/share/madbutterffly");
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
21 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
22
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
23 snprintf(path, len, "./%s.so", name);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
24 if (stat(path, &st)==0) {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
25 return 0;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
26 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
27 snprintf(path, len, "%s/%s.so", Sprite_Search_Path, name);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
28 if (stat(path, &st)==0) {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
29 return 0;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
30 } else {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
31 return -1;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
32 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
33 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
34
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
35 void sprite_set_search_path(char *path)
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
36 {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
37 if (Sprite_Search_Path)
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
38 free(Sprite_Search_Path);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
39 Sprite_Search_Path = strdup(path);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
40 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
41
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
42 mb_sprite_t *sprite_load(const char *name, redraw_man_t *rdman, coord_t *root)
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
43 {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
44 char path[1024];
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
45 const char *s;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
46 void *handle;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
47 mb_sprite_t *(*new)(redraw_man_t *, coord_t *);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
48 mb_sprite_t *obj;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
49
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
50 if (sprite_search_so(path, sizeof(path),name)) {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
51 fprintf(stderr," can not find %s in search path\n", name);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
52 return NULL;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
53 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
54 handle = dlopen(path,RTLD_LAZY);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
55 if (handle == NULL) {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
56 fprintf(stderr, "can not load object %s\n", path);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
57 return NULL;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
58 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
59 s = name + strlen(name)-1;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
60 while((s != name) && *s != '/') s--;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
61 snprintf(path,sizeof(path), "%s_new", s);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
62 new = dlsym(handle,path);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
63 if (new == NULL) {
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
64 fprintf(stderr," Can not find symbol %s at module\n", path);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
65 return NULL;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
66 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
67 obj = new(rdman, root);
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
68 return obj;
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
69 }
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
70
25bc0e753b88 Add dynamic loading function
wycc
parents:
diff changeset
71 /* vim: set ts=4 */