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