Mercurial > MadButterfly
comparison tools/mb_c_source.m4 @ 241:104d83378582
Add scene support in svg2code.py.
- Add mb_sprite_t::goto_scene()
- svg2code.py recoganize "scenes" tag in metadata of SVG file.
- tranform scenes into SCENE() macro.
- define SCENE macro in mb_c_*.m4
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 31 Dec 2008 02:08:40 +0800 |
parents | a0a3196b1a05 |
children | d36abace2ce4 |
comparison
equal
deleted
inserted
replaced
240:d347a577a232 | 241:104d83378582 |
---|---|
8 | 8 |
9 define([COUNT],[ifelse([$*],[],0,[$#])]) | 9 define([COUNT],[ifelse([$*],[],0,[$#])]) |
10 | 10 |
11 define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) | 11 define([IMPORT],[define([$1],[$2$1(]$[]@[)])]) |
12 | 12 |
13 define([D_COLOR_STOP],[ | 13 define([DECLARE_EMPTIES], [ |
14 {$6,$2,$3,$4,$5}]) | 14 define([ADD_LINEAR_PAINT]) |
15 | 15 define([ADD_RADIAL_PAINT]) |
16 define([D_ADD_LINEAR_PAINT],[dnl | 16 define([COLOR_STOP]) |
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)}; | |
20 ])dnl | |
21 ]) | |
22 | |
23 define([D_ADD_RADIAL_PAINT],[dnl | |
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)}; | |
27 ])dnl | |
28 ]) | |
29 | |
30 define([DECLARE_VARS], [divert([-1]) | |
31 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) | |
32 DIMPORT([ADD_LINEAR_PAINT]) | |
33 DIMPORT([ADD_RADIAL_PAINT]) | |
34 DIMPORT([COLOR_STOP]) | |
35 define([REF_STOPS_RADIAL]) | 17 define([REF_STOPS_RADIAL]) |
36 define([REF_STOPS_LINEAR]) | 18 define([REF_STOPS_LINEAR]) |
37 define([ADD_PATH]) | 19 define([ADD_PATH]) |
38 define([ADD_RECT]) | 20 define([ADD_RECT]) |
39 define([ADD_COORD]) | 21 define([ADD_COORD]) |
49 define([COORD_TRANSLATE],) | 31 define([COORD_TRANSLATE],) |
50 define([COORD_MATRIX],) | 32 define([COORD_MATRIX],) |
51 define([SHAPE_TRANSLATE],) | 33 define([SHAPE_TRANSLATE],) |
52 define([SHAPE_MATRIX],) | 34 define([SHAPE_MATRIX],) |
53 define([ADD_SYMBOL],) | 35 define([ADD_SYMBOL],) |
36 define([SCENE]) | |
37 ]) | |
38 | |
39 define([D_COLOR_STOP],[ | |
40 {$6,$2,$3,$4,$5}]) | |
41 | |
42 define([D_ADD_LINEAR_PAINT],[dnl | |
43 ifelse(COUNT($6),0,,[dnl | |
44 static const int n_$1_stops = COUNT($6); | |
45 static const grad_stop_t $1_stops[[]] = {UNQUOTE($6)}; | |
46 ])dnl | |
47 ]) | |
48 | |
49 define([D_ADD_RADIAL_PAINT],[dnl | |
50 ifelse(COUNT($5),0,,[dnl | |
51 static const int n_$1_stops = COUNT($5); | |
52 static const grad_stop_t $1_stops[[]] = {UNQUOTE($5)}; | |
53 ])dnl | |
54 ]) | |
55 | |
56 define([DECLARE_VARS], [divert([-1]) | |
57 define([DIMPORT],[IMPORT(]QUOTE($[]1)[,[D_])]) | |
58 DECLARE_EMPTIES | |
59 DIMPORT([ADD_LINEAR_PAINT]) | |
60 DIMPORT([ADD_RADIAL_PAINT]) | |
61 DIMPORT([COLOR_STOP]) | |
54 divert[]]) | 62 divert[]]) |
55 | 63 |
56 define([S_ADD_LINEAR_PAINT],[ | 64 define([S_ADD_LINEAR_PAINT],[ |
57 obj->$1 = rdman_paint_linear_new(rdman, $2, $3, $4, $5); | 65 obj->$1 = rdman_paint_linear_new(rdman, $2, $3, $4, $5); |
58 ifelse(COUNT($6),0,,[dnl | 66 ifelse(COUNT($6),0,,[dnl |
183 rdman_coord_changed(rdman, obj->$1); | 191 rdman_coord_changed(rdman, obj->$1); |
184 ]]) | 192 ]]) |
185 | 193 |
186 define([SETUP_VARS],[divert([-1]) | 194 define([SETUP_VARS],[divert([-1]) |
187 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) | 195 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])]) |
196 DECLARE_EMPTIES | |
188 SIMPORT([ADD_LINEAR_PAINT]) | 197 SIMPORT([ADD_LINEAR_PAINT]) |
189 SIMPORT([ADD_RADIAL_PAINT]) | 198 SIMPORT([ADD_RADIAL_PAINT]) |
190 SIMPORT([COLOR_STOP]) | 199 SIMPORT([COLOR_STOP]) |
191 SIMPORT([REF_STOPS_RADIAL]) | 200 SIMPORT([REF_STOPS_RADIAL]) |
192 SIMPORT([REF_STOPS_LINEAR]) | 201 SIMPORT([REF_STOPS_LINEAR]) |
204 SIMPORT([PATH_HIDE]) | 213 SIMPORT([PATH_HIDE]) |
205 SIMPORT([COORD_TRANSLATE]) | 214 SIMPORT([COORD_TRANSLATE]) |
206 SIMPORT([COORD_MATRIX]) | 215 SIMPORT([COORD_MATRIX]) |
207 SIMPORT([SHAPE_TRANSLATE]) | 216 SIMPORT([SHAPE_TRANSLATE]) |
208 SIMPORT([SHAPE_MATRIX]) | 217 SIMPORT([SHAPE_MATRIX]) |
209 define([ADD_SYMBOL],) | |
210 divert[]]) | 218 divert[]]) |
211 | 219 |
212 define([F_ADD_LINEAR_PAINT],[[ | 220 define([F_ADD_LINEAR_PAINT],[[ |
213 stops = paint_linear_stops(obj->$1, 0, NULL); | 221 stops = paint_linear_stops(obj->$1, 0, NULL); |
214 free(stops); | 222 free(stops); |
241 rdman_paint_free(rdman, obj->$1_stroke); | 249 rdman_paint_free(rdman, obj->$1_stroke); |
242 ]]) | 250 ]]) |
243 | 251 |
244 define([CLEAR_VARS],[divert([-1]) | 252 define([CLEAR_VARS],[divert([-1]) |
245 define([FIMPORT],[IMPORT(]QUOTE($[]1)[,[F_])]) | 253 define([FIMPORT],[IMPORT(]QUOTE($[]1)[,[F_])]) |
254 DECLARE_EMPTIES | |
246 FIMPORT([ADD_LINEAR_PAINT]) | 255 FIMPORT([ADD_LINEAR_PAINT]) |
247 FIMPORT([ADD_RADIAL_PAINT]) | 256 FIMPORT([ADD_RADIAL_PAINT]) |
248 define([COLOR_STOP]) | |
249 define([REF_STOPS_RADIAL]) | |
250 define([REF_STOPS_LINEAR]) | |
251 FIMPORT([ADD_PATH],) | 257 FIMPORT([ADD_PATH],) |
252 FIMPORT([ADD_RECT]) | 258 FIMPORT([ADD_RECT]) |
253 define([ADD_COORD]) | |
254 FIMPORT([ADD_TEXT]) | 259 FIMPORT([ADD_TEXT]) |
255 FIMPORT([FILL_SHAPE]) | 260 FIMPORT([FILL_SHAPE]) |
256 FIMPORT([STROKE_SHAPE]) | 261 FIMPORT([STROKE_SHAPE]) |
257 define([FILL_SHAPE_WITH_PAINT]) | |
258 define([STROKE_SHAPE_WITH_PAINT]) | |
259 define([STROKE_WIDTH]) | |
260 define([GROUP_HIDE],) | |
261 define([RECT_HIDE],) | |
262 define([PATH_HIDE],) | |
263 define([COORD_TRANSLATE],) | |
264 define([COORD_MATRIX],) | |
265 define([SHAPE_TRANSLATE],) | |
266 define([SHAPE_MATRIX],) | |
267 define([ADD_SYMBOL],) | |
268 divert[]]) | 262 divert[]]) |
269 | 263 |
270 define([REVERSE_VARS],[divert([-1]) | 264 define([REVERSE_VARS],[divert([-1]) |
271 define([__REV_VAR],[]) | 265 define([__REV_VAR],[]) |
272 define([PUSH_REV], [ | 266 define([PUSH_REV], [ |
277 popdef([__REV_VAR])[]POP_ALL_REV[]])]) | 271 popdef([__REV_VAR])[]POP_ALL_REV[]])]) |
278 define([RIMPORT], [ | 272 define([RIMPORT], [ |
279 define(]QUOTE($[]1)[, | 273 define(]QUOTE($[]1)[, |
280 [PUSH_REV(]]QUOTE(QUOTE($[]1))[[(]QUOTE($[]@)[))]) | 274 [PUSH_REV(]]QUOTE(QUOTE($[]1))[[(]QUOTE($[]@)[))]) |
281 ]) | 275 ]) |
276 DECLARE_EMPTIES | |
282 RIMPORT([ADD_LINEAR_PAINT]) | 277 RIMPORT([ADD_LINEAR_PAINT]) |
283 RIMPORT([ADD_RADIAL_PAINT]) | 278 RIMPORT([ADD_RADIAL_PAINT]) |
284 RIMPORT([COLOR_STOP]) | 279 RIMPORT([COLOR_STOP]) |
285 RIMPORT([REF_STOPS_RADIAL]) | 280 RIMPORT([REF_STOPS_RADIAL]) |
286 RIMPORT([REF_STOPS_LINEAR]) | 281 RIMPORT([REF_STOPS_LINEAR]) |
298 RIMPORT([PATH_HIDE]) | 293 RIMPORT([PATH_HIDE]) |
299 RIMPORT([COORD_TRANSLATE]) | 294 RIMPORT([COORD_TRANSLATE]) |
300 RIMPORT([COORD_MATRIX]) | 295 RIMPORT([COORD_MATRIX]) |
301 RIMPORT([SHAPE_TRANSLATE]) | 296 RIMPORT([SHAPE_TRANSLATE]) |
302 RIMPORT([SHAPE_MATRIX]) | 297 RIMPORT([SHAPE_MATRIX]) |
303 define([ADD_SYMBOL],) | |
304 divert[]dnl | 298 divert[]dnl |
305 ]) | 299 ]) |
306 | 300 |
307 define([Y_ADD_SYMBOL],[[{"$1", MB_SPRITE_OFFSET($1)},]]) | 301 define([Y_ADD_SYMBOL],[[{"$1", MB_SPRITE_OFFSET($1)},]]) |
308 | 302 |
309 define([DECLARE_SYMS], [divert([-1]) | 303 define([DECLARE_SYMS], [divert([-1]) |
310 define([YIMPORT],[IMPORT(]QUOTE($[]1)[,[Y_])]) | 304 define([YIMPORT],[IMPORT(]QUOTE($[]1)[,[Y_])]) |
311 define([ADD_LINEAR_PAINT]) | 305 DECLARE_EMPTIES |
312 define([ADD_RADIAL_PAINT]) | |
313 define([COLOR_STOP]) | |
314 define([REF_STOPS_RADIAL]) | |
315 define([REF_STOPS_LINEAR]) | |
316 define([ADD_PATH]) | |
317 define([ADD_RECT]) | |
318 define([ADD_COORD]) | |
319 define([ADD_TEXT],) | |
320 define([FILL_SHAPE]) | |
321 define([STROKE_SHAPE]) | |
322 define([FILL_SHAPE_WITH_PAINT]) | |
323 define([STROKE_SHAPE_WITH_PAINT]) | |
324 define([STROKE_WIDTH]) | |
325 define([GROUP_HIDE],) | |
326 define([RECT_HIDE],) | |
327 define([PATH_HIDE],) | |
328 define([COORD_TRANSLATE],) | |
329 define([COORD_MATRIX],) | |
330 define([SHAPE_TRANSLATE],) | |
331 define([SHAPE_MATRIX],) | |
332 YIMPORT([ADD_SYMBOL]) | 306 YIMPORT([ADD_SYMBOL]) |
307 divert[]dnl | |
308 ]) | |
309 | |
310 define([SC_SCENE], [[static const int scene_$1[] = {] | |
311 foreach([GROUP_NAME], ($2), [[ MB_SPRITE_OFFSET(]GROUP_NAME[), | |
312 ]])dnl | |
313 [ 0 | |
314 }; | |
315 ]]) | |
316 | |
317 define([DEFINE_SCENES], [divert([-1]) | |
318 define([SCIMPORT],[IMPORT(]QUOTE($[]1)[,[SC_])]) | |
319 DECLARE_EMPTIES | |
320 SCIMPORT([SCENE]) | |
321 divert[]dnl | |
322 ]) | |
323 | |
324 define([SCA_SCENE], [[ scene_$1, | |
325 ]]) | |
326 | |
327 define([DEFINE_SCENES_ARRAY], [divert([-1]) | |
328 define([SCAIMPORT],[IMPORT(]QUOTE($[]1)[,[SCA_])]) | |
329 DECLARE_EMPTIES | |
330 SCAIMPORT([SCENE]) | |
333 divert[]dnl | 331 divert[]dnl |
334 ]) | 332 ]) |
335 | 333 |
336 define([MADBUTTERFLY],[dnl | 334 define([MADBUTTERFLY],[dnl |
337 [#include <stdio.h> | 335 [#include <stdio.h> |
346 #ifdef MB_SPRITE_OFFSET | 344 #ifdef MB_SPRITE_OFFSET |
347 #undef MB_SPRITE_OFFSET | 345 #undef MB_SPRITE_OFFSET |
348 #endif | 346 #endif |
349 #define MB_SPRITE_OFFSET(x) ((int)&((($1_t *)0)->x)) | 347 #define MB_SPRITE_OFFSET(x) ((int)&((($1_t *)0)->x)) |
350 | 348 |
351 static | |
352 mb_sprite_lsym_entry_t $1_symbols[] = {]DECLARE_SYMS | |
353 $2[ | |
354 }; | |
355 | |
356 #ifndef MB_LSYM_GET_OBJ_WITH_NAME | 349 #ifndef MB_LSYM_GET_OBJ_WITH_NAME |
357 #define MB_LSYM_GET_OBJ_WITH_NAME | 350 #define MB_LSYM_GET_OBJ_WITH_NAME |
358 | 351 |
359 #define MB_SPRITE_OFF_2_PTR(x, off) (((void *)(x)) + (off)) | 352 #define MB_SPRITE_OFF_2_PTR(x, off) (((void *)(x)) + (off)) |
360 | 353 |
370 } | 363 } |
371 return NULL; | 364 return NULL; |
372 } | 365 } |
373 #endif /* MB_LSYM_GET_OBJ_WITH_NAME */ | 366 #endif /* MB_LSYM_GET_OBJ_WITH_NAME */ |
374 | 367 |
368 static | |
369 mb_sprite_lsym_entry_t $1_symbols[] = {]DECLARE_SYMS | |
370 $2[ | |
371 }; | |
372 | |
373 ]DEFINE_SCENES | |
374 $2 | |
375 DEFINE_SCENES_ARRAY | |
376 static const int *$1_scenes[[]] = { | |
377 $2[]dnl | |
378 NULL | |
379 };[ | |
380 | |
381 #define SCENES_NUM ((sizeof($1_scenes) / sizeof(const int *)) - 1) | |
382 | |
383 static | |
384 int $1_goto_scene($1_t *sprite, int scene_no) { | |
385 coord_t *coord; | |
386 const int *p; | |
387 const int *scene; | |
388 | |
389 if(scene_no >= SCENES_NUM || scene_no < -1) | |
390 return 1; | |
391 | |
392 if(sprite->last_scene) { | |
393 p = sprite->last_scene; | |
394 while(*p != 0) { | |
395 coord = (coord_t *)MB_SPRITE_OFF_2_PTR(sprite, *p); | |
396 coord_hide(coord); | |
397 rdman_coord_changed(sprite->rdman, coord); | |
398 p++; | |
399 } | |
400 } | |
401 | |
402 if(scene_no == -1) { | |
403 sprite->last_scene = NULL; | |
404 return 0; | |
405 } | |
406 | |
407 scene = $1_scenes[scene_no]; | |
408 p = scene; | |
409 while(*p != 0) { | |
410 coord = (coord_t *)MB_SPRITE_OFF_2_PTR(sprite, *p); | |
411 coord_show(coord); | |
412 rdman_coord_changed(sprite->rdman, coord); | |
413 p++; | |
414 } | |
415 | |
416 sprite->last_scene = scene; | |
417 | |
418 return 0; | |
419 } | |
420 | |
375 void $1_free($1_t *); | 421 void $1_free($1_t *); |
376 | 422 |
377 $1_t *$1_new(redraw_man_t *rdman, coord_t *parent_coord) { | 423 $1_t *$1_new(redraw_man_t *rdman, coord_t *parent_coord) { |
378 $1_t *obj; | 424 $1_t *obj; |
379 grad_stop_t *stops = NULL;]DECLARE_VARS | 425 grad_stop_t *stops = NULL;]DECLARE_VARS |
380 $2[]dnl | 426 $2[]dnl |
381 [ | 427 [ |
382 obj = ($1_t *)malloc(sizeof($1_t)); | 428 obj = ($1_t *)malloc(sizeof($1_t)); |
383 if(obj == NULL) return NULL; | 429 if(obj == NULL) return NULL; |
384 | 430 |
385 obj->lsym.sprite.free = (void (*)(mb_sprite_t))$1_free; | 431 obj->lsym.sprite.free = (void (*)(mb_sprite_t *))$1_free; |
432 obj->lsym.sprite.goto_scene = (int (*)(mb_sprite_t *, int))$1_goto_scene; | |
386 obj->lsym.sprite.get_obj_with_name = | 433 obj->lsym.sprite.get_obj_with_name = |
387 (mb_obj_t *(*)(mb_sprite_t *, const char *))mb_lsym_get_obj_with_name; | 434 (mb_obj_t *(*)(mb_sprite_t *, const char *))mb_lsym_get_obj_with_name; |
388 obj->lsym.num_entries = | 435 obj->lsym.num_entries = |
389 sizeof($1_symbols) / sizeof(mb_sprite_lsym_entry_t); | 436 sizeof($1_symbols) / sizeof(mb_sprite_lsym_entry_t); |
390 obj->lsym.entries = $1_symbols; | 437 obj->lsym.entries = $1_symbols; |
391 | 438 |
392 obj->rdman = rdman; | 439 obj->rdman = rdman; |
440 obj->last_scene = NULL; | |
393 ]SETUP_VARS[ | 441 ]SETUP_VARS[ |
394 obj->root_coord = rdman_coord_new(rdman, parent_coord);] | 442 obj->root_coord = rdman_coord_new(rdman, parent_coord);] |
395 $2 | 443 $2 |
396 [ return obj; | 444 [ return obj; |
397 } | 445 } |