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