Mercurial > MadButterfly
annotate tools/mb_c_source.m4 @ 83:ea758bb3bbe2
example
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 22 Aug 2008 00:12:04 +0800 |
parents | 13fdf205047b |
children | 42698de1f653 |
rev | line source |
---|---|
63 | 1 changequote(`[', `]')dnl |
2 include([foreach.m4])dnl | |
3 divert([-1]) | |
4 | |
64 | 5 define([UNQUOTE], [$*]) |
6 | |
7 define([QUOTE], [[[$*]]]) | |
63 | 8 |
64 | 9 define([COUNT],[ifelse([$*],[],0,[$#])]) |
63 | 10 |
64 | 11 define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) |
63 | 12 |
64 | 13 define([D_COLOR_STOP],[ |
14 {$6,$2,$3,$4,$5}]) | |
63 | 15 |
16 define([D_ADD_LINEAR_PAINT],[dnl | |
64 | 17 ifelse(COUNT($6),0,,[dnl |
18 static const int n_$1_stops = COUNT($6); | |
19 static const grad_stop_t $1_stops[[]] = {UNQUOTE($6)}; | |
63 | 20 ])dnl |
21 ]) | |
22 | |
23 define([D_ADD_RADIAL_PAINT],[dnl | |
64 | 24 ifelse(COUNT($5),0,,[dnl |
25 static const int n_$1_stops = COUNT($5); | |
26 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)}; | |
63 | 27 ])dnl |
28 ]) | |
29 | |
30 define([DECLARE_VARS], [divert([-1]) | |
64 | 31 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) |
32 DIMPORT([ADD_LINEAR_PAINT]) | |
33 DIMPORT([ADD_RADIAL_PAINT]) | |
34 DIMPORT([COLOR_STOP]) | |
78 | 35 define([REF_STOPS_RADIAL]) |
36 define([REF_STOPS_LINEAR]) | |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
69
diff
changeset
|
37 define([ADD_PATH]) |
64 | 38 define([ADD_RECT]) |
39 define([ADD_COORD]) | |
83 | 40 define([ADD_TEXT],) |
64 | 41 define([FILL_SHAPE]) |
42 define([STROKE_SHAPE]) | |
43 define([FILL_SHAPE_WITH_PAINT]) | |
44 define([STROKE_SHAPE_WITH_PAINT]) | |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
45 define([STROKE_WIDTH]) |
81 | 46 define([GROUP_HIDE],) |
47 define([RECT_HIDE],) | |
48 define([PATH_HIDE],) | |
63 | 49 divert[]]) |
50 | |
51 define([S_ADD_LINEAR_PAINT],[ | |
69
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
52 obj->$1 = paint_linear_new(rdman, $2, $3, $4, $5); |
64 | 53 ifelse(COUNT($6),0,,[dnl |
54 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); | |
55 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); | |
56 paint_linear_stops(obj->$1, n_$1_stops, stops); | |
57 ])dnl | |
63 | 58 ]) |
64 | 59 |
63 | 60 define([S_ADD_RADIAL_PAINT],[ |
69
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
61 obj->$1 = paint_radial_new(rdman, $2, $3, $4); |
64 | 62 ifelse(COUNT($5),0,,[ |
63 stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$1_stops); | |
64 memcpy(stops, $1_stops, sizeof(grad_stop_t) * n_$1_stops); | |
65 paint_radial_stops(obj->$1, n_$1_stops, stops); | |
66 ])dnl | |
63 | 67 ]) |
68 | |
64 | 69 define([S_COLOR_STOP],[]) |
78 | 70 |
71 define([S_REF_STOPS_RADIAL],[dnl | |
64 | 72 [ stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$2_stops); |
73 memcpy(stops, $2_stops, sizeof(grad_stop_t) * n_$2_stops); | |
74 paint_radial_stops(obj->$1, n_$2_stops, stops); | |
75 ]]) | |
76 | |
78 | 77 define([S_REF_STOPS_LINEAR],[dnl |
78 [ stops = (grad_stop_t *)malloc(sizeof(grad_stop_t) * n_$2_stops); | |
79 memcpy(stops, $2_stops, sizeof(grad_stop_t) * n_$2_stops); | |
80 paint_linear_stops(obj->$1, n_$2_stops, stops); | |
81 ]]) | |
82 | |
64 | 83 define([S_ADD_RECT],[[ |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
84 obj->$1 = sh_rect_new($2, $3, $4, $5, $6, $7); |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
85 rdman_add_shape(rdman, obj->$1, obj->$8); |
64 | 86 ]]) |
87 | |
88 define([S_ADD_PATH],[[ | |
89 obj->$1 = sh_path_new("$2"); | |
90 rdman_add_shape(rdman, obj->$1, obj->$3); | |
91 ]]) | |
92 | |
93 define([S_ADD_COORD],[[ | |
66
309f1eefbec0
create new coords from redraw_man
Thinker K.F. Li <thinker@branda.to>
parents:
64
diff
changeset
|
94 obj->$1 = rdman_coord_new(rdman, obj->$2); |
64 | 95 ]]) |
96 | |
83 | 97 define([S_ADD_TEXT],[[ |
98 obj->$1 = sh_text_new("$2", $3, $4, $5, cairo_get_font_face(rdman->cr)); | |
99 rdman_add_shape(rdman, obj->$1, obj->$6); | |
100 ]]) | |
101 | |
64 | 102 define([S_FILL_SHAPE_WITH_PAINT],[dnl |
103 [ rdman_paint_fill(rdman, obj->$2, obj->$1); | |
104 ]]) | |
105 | |
106 define([S_STROKE_SHAPE_WITH_PAINT],[dnl | |
107 [ rdman_paint_stroke(rdman, obj->$2, obj->$1); | |
108 ]]) | |
109 | |
110 define([S_FILL_SHAPE],[dnl | |
111 [ obj->$1_fill = paint_color_new(rdman, $2, $3, $4, $5); | |
112 rdman_paint_fill(rdman, obj->$1_fill, obj->$1); | |
113 ]]) | |
114 | |
115 define([S_STROKE_SHAPE],[dnl | |
116 [ obj->$1_stroke = paint_color_new(rdman, $2, $3, $4, $5); | |
117 rdman_paint_stroke(rdman, obj->$1_stroke, obj->$1); | |
118 ]]) | |
119 | |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
120 define([S_STROKE_WIDTH],[dnl |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
121 [ obj->$1->stroke_width = $2; |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
122 ]]) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
123 |
81 | 124 define([S_GROUP_HIDE],[dnl |
125 [ coord_hide(obj->$1); | |
126 ]]) | |
127 | |
128 define([S_RECT_HIDE],[dnl | |
129 [ sh_hide(obj->$1); | |
130 ]]) | |
131 | |
132 define([S_PATH_HIDE],[dnl | |
133 [ sh_hide(obj->$1); | |
134 ]]) | |
135 | |
63 | 136 define([SETUP_VARS],[divert([-1]) |
64 | 137 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) |
138 SIMPORT([ADD_LINEAR_PAINT]) | |
139 SIMPORT([ADD_RADIAL_PAINT]) | |
140 SIMPORT([COLOR_STOP]) | |
78 | 141 SIMPORT([REF_STOPS_RADIAL]) |
142 SIMPORT([REF_STOPS_LINEAR]) | |
64 | 143 SIMPORT([ADD_PATH],) |
144 SIMPORT([ADD_RECT]) | |
145 SIMPORT([ADD_COORD]) | |
83 | 146 SIMPORT([ADD_TEXT]) |
64 | 147 SIMPORT([FILL_SHAPE]) |
148 SIMPORT([STROKE_SHAPE]) | |
149 SIMPORT([FILL_SHAPE_WITH_PAINT]) | |
150 SIMPORT([STROKE_SHAPE_WITH_PAINT]) | |
81 | 151 SIMPORT([STROKE_WIDTH]) |
152 SIMPORT([GROUP_HIDE]) | |
153 SIMPORT([RECT_HIDE]) | |
154 SIMPORT([PATH_HIDE]) | |
63 | 155 divert[]]) |
156 | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
157 define([F_ADD_LINEAR_PAINT],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
158 stops = paint_linear_stops(obj->$1, 0, NULL); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
159 free(stops); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
160 obj->$1->free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
161 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
162 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
163 define([F_ADD_RADIAL_PAINT],[[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
164 stops = paint_radial_stops(obj->$1, 0, NULL); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
165 free(stops); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
166 obj->$1->free(obj->$1); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
167 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
168 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
169 define([F_ADD_PATH],[[ |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
69
diff
changeset
|
170 obj->$1->free(obj->$1); |
83 | 171 ]]) |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
172 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
173 define([F_ADD_RECT],[[ |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
69
diff
changeset
|
174 obj->$1->free(obj->$1); |
83 | 175 ]]) |
176 | |
177 define([F_ADD_TEXT],[[ | |
178 obj->$1->free(obj->$1); | |
179 ]]) | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
180 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
181 define([F_FILL_SHAPE],[[ |
69
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
182 obj->$1_fill->free(obj->$1_fill); |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
183 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
184 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
185 define([F_STROKE_SHAPE],[[ |
69
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
186 obj->$1_stroke->free(obj->$1_stroke); |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
187 ]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
188 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
189 define([CLEAR_VARS],[divert([-1]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
190 define([FIMPORT],[IMPORT(]QUOTE($[]1)[,[F_])]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
191 FIMPORT([ADD_LINEAR_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
192 FIMPORT([ADD_RADIAL_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
193 define([COLOR_STOP]) |
78 | 194 define([REF_STOPS_RADIAL]) |
195 define([REF_STOPS_LINEAR]) | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
196 FIMPORT([ADD_PATH],) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
197 FIMPORT([ADD_RECT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
198 define([ADD_COORD]) |
83 | 199 FIMPORT([ADD_TEXT]) |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
200 FIMPORT([FILL_SHAPE]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
201 FIMPORT([STROKE_SHAPE]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
202 define([FILL_SHAPE_WITH_PAINT]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
203 define([STROKE_SHAPE_WITH_PAINT]) |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
204 define([STROKE_WIDTH]) |
81 | 205 define([GROUP_HIDE],) |
206 define([RECT_HIDE],) | |
207 define([PATH_HIDE],) | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
208 divert[]]) |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
209 |
63 | 210 define([MADBUTTERFLY],[dnl |
211 [#include <stdio.h> | |
69
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
212 #include <stdlib.h> |
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
213 #include <string.h> |
63 | 214 #include "mb_types.h" |
215 #include "redraw_man.h" | |
216 #include "shapes.h" | |
217 #include "paint.h" | |
218 #include "$1.h" | |
219 | |
69
a6150b4e0667
Fix bug of newing linear & radial paints
Thinker K.F. Li <thinker@branda.to>
parents:
68
diff
changeset
|
220 $1_t *$1_new(redraw_man_t *rdman) { |
64 | 221 $1_t *obj; |
222 grad_stop_t *stops = NULL;]DECLARE_VARS | |
63 | 223 $2[]dnl |
224 [ | |
225 obj = ($1_t *)malloc(sizeof($1_t)); | |
226 if(obj == NULL) return NULL; | |
227 ]SETUP_VARS | |
64 | 228 obj->root_coord = rdman->root_coord; |
63 | 229 $2 |
230 [ return obj; | |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
231 } |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
232 |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
233 void $1_free($1_t *obj) { |
68 | 234 grad_stop_t *stops = NULL; |
67
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
235 ]CLEAR_VARS[]$2[ |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
236 free(obj); |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
237 } |
3f2872a1a2fe
clear objects in *_free() for generated code
Thinker K.F. Li <thinker@branda.to>
parents:
66
diff
changeset
|
238 ]dnl |
63 | 239 ]) |
240 divert[]dnl |