# HG changeset patch # User Thinker K.F. Li # Date 1221389476 -28800 # Node ID e4e47d2cdbcd669331fec6f5d34b32ab71d59f05 # Parent 1d74eb3861b715edd95bbdbc70b522cdc51b5ff3 Tank diff -r 1d74eb3861b7 -r e4e47d2cdbcd Doxyfile --- a/Doxyfile Sun Sep 14 09:42:07 2008 +0800 +++ b/Doxyfile Sun Sep 14 18:51:16 2008 +0800 @@ -591,7 +591,7 @@ # directories that contain example code fragments that are included (see # the \include command). -EXAMPLE_PATH = +EXAMPLE_PATH = examples/ # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp diff -r 1d74eb3861b7 -r e4e47d2cdbcd dox/first_program.h --- a/dox/first_program.h Sun Sep 14 09:42:07 2008 +0800 +++ b/dox/first_program.h Sun Sep 14 18:51:16 2008 +0800 @@ -27,5 +27,7 @@ * and initialize a 'foo' instance. An instance is released by calling * foo_free(). * - * - \subpage svg2code_ex + * \dontinclude examples/svg2code_ex/main.c + * \skip main + * \until } */ diff -r 1d74eb3861b7 -r e4e47d2cdbcd examples/svg2code_ex/main.c --- a/examples/svg2code_ex/main.c Sun Sep 14 09:42:07 2008 +0800 +++ b/examples/svg2code_ex/main.c Sun Sep 14 18:51:16 2008 +0800 @@ -1,4 +1,4 @@ -/*! \page svg2code_ex +/*! \file * * svg2code_ex is an example that show programmers how to create a * menu with MadButterfly. diff -r 1d74eb3861b7 -r e4e47d2cdbcd examples/tank/tank_main.c --- a/examples/tank/tank_main.c Sun Sep 14 09:42:07 2008 +0800 +++ b/examples/tank/tank_main.c Sun Sep 14 18:51:16 2008 +0800 @@ -35,7 +35,8 @@ struct _tank_rt { tank1_t *tank1; tank2_t *tank2; - tank_en_t *tank_en; + int n_enemy; + tank_en_t *tank_enemies[10]; void *map[12][16]; X_MB_runtime_t *mb_rt; }; @@ -88,10 +89,14 @@ } tank_rt->tank1 = tank1_new(rdman); + CHANGE_POS(tank_rt->tank1, 5 * 50, 11 * 50); tank_rt->tank2 = tank2_new(rdman); - CHANGE_POS(tank_rt->tank2, 50, 0); - tank_rt->tank_en = tank_en_new(rdman); - CHANGE_POS(tank_rt->tank_en, 100, 0); + CHANGE_POS(tank_rt->tank2, 10 * 50, 11 * 50); + for(i = 0; i < 3; i++) { + tank_rt->tank_enemies[i] = tank_en_new(rdman); + CHANGE_POS(tank_rt->tank_enemies[i], (2 + i * 3) * 50, 0); + } + tank_rt->n_enemy = i; } int diff -r 1d74eb3861b7 -r e4e47d2cdbcd img/core.gaphor --- a/img/core.gaphor Sun Sep 14 09:42:07 2008 +0800 +++ b/img/core.gaphor Sun Sep 14 18:51:16 2008 +0800 @@ -1,2 +1,3 @@ -111(1.0, 0.0, 0.0, 1.0, 309.0, 118.0)100.050.0111(1.0, 0.0, 0.0, 1.0, 249.0, 237.0)100.051.8125111(1.0, 0.0, 0.0, 1.0, 420.0, 225.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 344.0, 168.0)00[(0.0, 0.0), (-57.0, 69.0)]0(1.0, 0.0, 0.0, 1.0, 374.0, 168.0)00[(0.0, 0.0), (110.0, 57.0)]0111(1.0, 0.0, 0.0, 1.0, 248.0, 334.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 297.0, 288.8125)00[(0.0, 0.0), (-1.0, 45.1875)]0(1.0, 0.0, 0.0, 1.0, 348.0, 334.0)00[(0.0, 0.0), (72.0, -60.0)]0111(1.0, 0.0, 0.0, 1.0, 427.0, 334.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 348.0, 360.0)00[(0.0, 0.0), (79.0, 1.0)]0111(1.0, 0.0, 0.0, 1.0, 430.0, 423.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 430.0, 449.0)00[(0.0, 0.0), (-82.0, -63.1875)]0(1.0, 0.0, 0.0, 1.0, 477.0, 385.8125)00[(0.0, 0.0), (-1.0, 37.1875)]0(1.0, 0.0, 0.0, 1.0, 348.0, 377.0)00[(0.0, 0.0), (79.0, 0.0)]0 \ No newline at end of file +111(1.0, 0.0, 0.0, 1.0, 309.0, 118.0)100.050.0111(1.0, 0.0, 0.0, 1.0, 249.0, 237.0)100.051.8125111(1.0, 0.0, 0.0, 1.0, 420.0, 225.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 344.0, 168.0)00[(0.0, 0.0), (-57.0, 69.0)]0(1.0, 0.0, 0.0, 1.0, 374.0, 168.0)00[(0.0, 0.0), (110.0, 57.0)]0111(1.0, 0.0, 0.0, 1.0, 248.0, 334.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 297.0, 288.8125)00[(0.0, 0.0), (-1.0, 45.1875)]0(1.0, 0.0, 0.0, 1.0, 348.0, 334.0)00[(0.0, 0.0), (72.0, -60.0)]0111(1.0, 0.0, 0.0, 1.0, 427.0, 334.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 348.0, 360.0)00[(0.0, 0.0), (79.0, 1.0)]0111(1.0, 0.0, 0.0, 1.0, 430.0, 423.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 430.0, 447.0)00[(0.0, 0.0), (-83.0, -61.1875)]0(1.0, 0.0, 0.0, 1.0, 477.0, 385.8125)00[(0.0, 0.0), (-1.0, 37.1875)]0(1.0, 0.0, 0.0, 1.0, 348.0, 377.0)00[(0.0, 0.0), (79.0, 0.0)]0111(1.0, 0.0, 0.0, 1.0, 65.0, 72.0)100.051.8125111(1.0, 0.0, 0.0, 1.0, 61.0, 167.0)105.077.8125111(1.0, 0.0, 0.0, 1.0, 65.0, 293.0)100.051.8125(1.0, 0.0, 0.0, 1.0, 116.0, 123.8125)00[(0.0, 0.0), (0.0, 43.1875)]0(1.0, 0.0, 0.0, 1.0, 115.0, 244.8125)00[(0.0, 0.0), (0.0, 48.1875)]0(1.0, 0.0, 0.0, 1.0, 345.0, 196.0)00[(0.0, 0.0), (133.0, -2.0)](1.0, 0.0, 0.0, 1.0, 256.0, 168.0)00[(0.0, 0.0), (89.0, 0.0)](1.0, 0.0, 0.0, 1.0, 557.0, 65.0)100.050.0301.0(1.0, 0.0, 0.0, 1.0, 428.0, 63.0)100.050.0298.0(1.0, 0.0, 0.0, 1.0, 295.0, 63.0)100.050.0310.0(1.0, 0.0, 0.0, 1.0, 478.0, 217.0)00[(0.0, 0.0), (129.0, -1.0)](1.0, 0.0, 0.0, 1.0, 345.0, 255.0)00[(0.0, 0.0), (133.0, 0.0)](1.0, 0.0, 0.0, 1.0, 478.0, 273.0)00[(0.0, 0.0), (129.0, 0.0)](1.0, 0.0, 0.0, 1.0, 345.0, 316.0)00[(0.0, 0.0), (133.0, -1.0)](1.0, 0.0, 0.0, 1.0, 478.0, 331.0)00[(0.0, 0.0), (129.0, -1.0)](1.0, 0.0, 0.0, 1.0, 345.0, 365.0)00[(0.0, 0.0), (133.0, 0.0)](1.0, 0.0, 0.0, 1.0, 478.0, 379.0)00[(0.0, 0.0), (129.0, -1.0)](1.0, 0.0, 0.0, 1.0, 318.0, 234.0)341.0108.0(1.0, 0.0, 0.0, 1.0, 142.0, 373.0)180.042.0(1.0, 0.0, 0.0, 1.0, 236.0, 373.0)00[(0.0, 0.0), (83.0, -56.0)] \ No newline at end of file diff -r 1d74eb3861b7 -r e4e47d2cdbcd img/core.png Binary file img/core.png has changed diff -r 1d74eb3861b7 -r e4e47d2cdbcd img/program.png Binary file img/program.png has changed diff -r 1d74eb3861b7 -r e4e47d2cdbcd src/Makefile --- a/src/Makefile Sun Sep 14 09:42:07 2008 +0800 +++ b/src/Makefile Sun Sep 14 18:51:16 2008 +0800 @@ -1,7 +1,7 @@ SRCS = coord.c geo.c shape_path.c shape_text.c shape_rect.c \ redraw_man.c timer.c animate.c paint.c event.c observer.c \ X_supp.c timertool.c tools.c shift.c chgcolor.c \ - visibility.c + visibility.c rotate.c OBJS = ${SRCS:C/(.*)\.c/\1.o/g} TESTCASE_OBJS = ${SRCS:C/(.*)\.c/testcase-\1.o/g} CFLAGS+= -Wall -I/usr/local/include `pkg-config --cflags cairo` diff -r 1d74eb3861b7 -r e4e47d2cdbcd src/animate.c --- a/src/animate.c Sun Sep 14 09:42:07 2008 +0800 +++ b/src/animate.c Sun Sep 14 18:51:16 2008 +0800 @@ -1,10 +1,15 @@ /*! \file * \brief Animation tools. * - * \sa ani + * \sa \ref ani */ /*! \page ani What is Animation? * + * Animation is a program to move, resize, rotate, ..., changing + * graphics on the output screen. + * + * \image html program.png + * * XXX: Program is a sequence of actions duration a perior. * Actions are grouped into words. A program defines * the order and time of playing of words. A word @@ -22,7 +27,43 @@ * with timer for periodic running. \ref mb_tman_t is timer of * MadButterfly. The update frequence is 10fps by default, now. * - * \sa animate.c + * \section use_progm How to Use Animation Program? + * Following code block creates a program with 2 words. First word is + * started immediately after the program been started. It is consisted + * for 1 second. Second word is started 1 second after the program been + * started. It is consisted for 2 seconds. There are 2 action in + * first word, they shift graphics managed by coord1 & coord2 by (50,50) and + * (-50,50) pixels, respectly. The shifting is performed incrementally + * in 1 second. Second word shifts coord1 and coord2, too. And, graphics + * managed by coord3 are hidden at end of the word. At end of code in the + * block, mb_progm_start() starts the program. 3rd argument of + * mb_progm_start() must be current wall time. + * + * \code + * progm = mb_progm_new(10, &rdman); + * + * MB_TIMEVAL_SET(&start, 0, 0); + * MB_TIMEVAL_SET(&playing, 1, 0); + * word = mb_progm_next_word(progm, &start, &playing); + * + * act = mb_shift_new(50, 50, coord1, word); + * act = mb_shift_new(-50, 50, coord2, word); + * + * MB_TIMEVAL_SET(&start, 1, 0); + * MB_TIMEVAL_SET(&playing, 2, 0); + * word = mb_progm_next_word(progm, &start, &playing); + * + * act = mb_shift_new(0, 20, coord1, word); + * act = mb_shift_new(0, -20, coord2, word); + * act = mb_visibility_new(VIS_HIDDEN, coord3, word); + * + * gettimeofday(&tv, NULL); + * MB_TIMEVAL_SET(&mbtv, tv.tv_sec, tv.tv_usec); + * mb_progm_start(progm, tman, &mbtv); + * \endcode + * + * + * \sa \ref animate.c */ #include #include diff -r 1d74eb3861b7 -r e4e47d2cdbcd src/animate.h --- a/src/animate.h Sun Sep 14 09:42:07 2008 +0800 +++ b/src/animate.h Sun Sep 14 18:51:16 2008 +0800 @@ -5,19 +5,7 @@ #include "mb_timer.h" #include "paint.h" -/*! \defgroup anim Animation - * \brief Animation is a set of functions to make graph moving. - * @{ - */ -typedef struct _mb_progm mb_progm_t; -typedef struct _mb_word mb_word_t; -typedef struct _mb_action mb_action_t; -typedef struct _mb_progm_state mb_progm_state_t; - -/*! \defgroup act_support Action Supports. - * @{ - */ -/*! \brief Basic class of nnimation actions. +/*! \page def_action How to Define An Action? * * A action must implement following 4 functions. * \li start, @@ -31,6 +19,22 @@ * It also means *_new() must have an argument with type of * (mb_word_t *). */ + +/*! \defgroup anim Animation + * \brief Animation is a set of functions to make graph moving. + * @{ + */ +typedef struct _mb_progm mb_progm_t; +typedef struct _mb_word mb_word_t; +typedef struct _mb_action mb_action_t; + +/*! \defgroup act_support Action Supports. + * @{ + */ +/*! \brief Basic class of nnimation actions. + * + * \sa \ref def_action + */ struct _mb_action { void (*start)(mb_action_t *act, const mb_timeval_t *now, @@ -63,6 +67,8 @@ extern mb_action_t *mb_chgcolor_new(co_comp_t r, co_comp_t g, co_comp_t b, co_comp_t a, paint_t *paint, mb_word_t *word); +extern mb_action_t *mb_rotate_new(float angle1, float angle2, + coord_t *coord, mb_word_t *word); enum { VIS_VISIBLE, VIS_HIDDEN }; extern mb_action_t *mb_visibility_new(int visib, coord_t *coord, diff -r 1d74eb3861b7 -r e4e47d2cdbcd src/rotate.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/rotate.c Sun Sep 14 18:51:16 2008 +0800 @@ -0,0 +1,119 @@ +#include +#include +#include +#include +#include "animate.h" + +static float comp_mb_timeval_ratio(const mb_timeval_t *a, + const mb_timeval_t *b) { + float ratio; + + ratio = (float)MB_TIMEVAL_SEC(a) * 1000000.0 + (float)MB_TIMEVAL_USEC(a); + ratio /= (float)MB_TIMEVAL_SEC(b) * 1000000.0 + (float)MB_TIMEVAL_USEC(b); + return ratio; +} + +/*! \brief Animation action to rotate a coordinate. + */ +struct _mb_rotate { + mb_action_t action; + + co_aix angle1, angle2; + coord_t *coord; + + mb_timeval_t start_time; + const mb_timeval_t *playing_time; +}; +typedef struct _mb_rotate mb_rotate_t; + +static void mb_rotate_start(mb_action_t *act, + const mb_timeval_t *now, + const mb_timeval_t *playing_time, + redraw_man_t *rdman) { + mb_rotate_t *rotate = (mb_rotate_t *)act; + co_aix *matrix; + float _sin, _cos; + + _sin = sinf(rotate->angle1); + _cos = cosf(rotate->angle1); + + matrix = rotate->coord->matrix; + memset(matrix, 0, sizeof(co_aix) * 6); + matrix[0] = _cos; + matrix[1] = -_sin; + matrix[3] = _sin; + matrix[4] = _cos; + rdman_coord_changed(rdman, rotate->coord); + + MB_TIMEVAL_CP(&rotate->start_time, now); + rotate->playing_time = playing_time; +} + +static void mb_rotate_step(mb_action_t *act, const mb_timeval_t *now, + redraw_man_t *rdman) { + mb_rotate_t *rotate = (mb_rotate_t *)act; + mb_timeval_t diff; + co_aix *matrix; + float ratio; + float angle; + float _sin, _cos; + + MB_TIMEVAL_CP(&diff, now); + MB_TIMEVAL_DIFF(&diff, &rotate->start_time); + ratio = comp_mb_timeval_ratio(&diff, rotate->playing_time); + + angle = rotate->angle1 * (1 - ratio) + rotate->angle2 * ratio; + _sin = sinf(angle); + _cos = cosf(angle); + + matrix = rotate->coord->matrix; + matrix[0] = _cos; + matrix[1] = -_sin; + matrix[3] = _sin; + matrix[4] = _cos; + rdman_coord_changed(rdman, rotate->coord); +} + +static void mb_rotate_stop(mb_action_t *act, const mb_timeval_t *now, + redraw_man_t *rdman) { + mb_rotate_t *rotate = (mb_rotate_t *)act; + co_aix *matrix; + float _sin, _cos; + + _sin = sinf(rotate->angle2); + _cos = cosf(rotate->angle2); + + matrix = rotate->coord->matrix; + matrix[0] = _cos; + matrix[1] = -_sin; + matrix[3] = _sin; + matrix[4] = _cos; + rdman_coord_changed(rdman, rotate->coord); +} + +static void mb_rotate_free(mb_action_t *act) { + free(act); +} + +mb_action_t *mb_rotate_new(float angle1, float angle2, + coord_t *coord, + mb_word_t *word) { + mb_rotate_t *rotate; + + rotate = (mb_rotate_t *)malloc(sizeof(mb_rotate_t)); + if(rotate == NULL) + return NULL; + + rotate->angle1 = angle1; + rotate->angle2 = angle2; + rotate->coord = coord; + + rotate->action.start = mb_rotate_start; + rotate->action.step = mb_rotate_step; + rotate->action.stop = mb_rotate_stop; + rotate->action.free = mb_rotate_free; + + mb_word_add_action(word, (mb_action_t *)rotate); + + return (mb_action_t *)rotate; +} diff -r 1d74eb3861b7 -r e4e47d2cdbcd src/shift.c --- a/src/shift.c Sun Sep 14 09:42:07 2008 +0800 +++ b/src/shift.c Sun Sep 14 18:51:16 2008 +0800 @@ -13,7 +13,7 @@ } typedef struct _mb_shift mb_shift_t; -/*! \brief Animation action for shift a coordination. */ +/*! \brief Animation action for relative shift a coordination. */ struct _mb_shift { mb_action_t action; @@ -95,5 +95,3 @@ return (mb_action_t *)shift; } - -