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