Mercurial > MadButterfly
changeset 341:9c006581f0cd
merge
author | wycc |
---|---|
date | Sun, 08 Mar 2009 10:06:23 +0800 |
parents | 6e01d3d7d104 (current diff) 6a1b36738d3d (diff) |
children | 5465ff071b47 |
files | examples/dynamic/mbapp.c examples/dynamic/mbapp.h |
diffstat | 4 files changed, 41 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/dynamic/mbapp.c Sun Mar 08 10:06:01 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#include <mb.h> -#include <mbapp.h> -MBApp *MBApp_Init(char *module) -{ - MBApp *app = (MBApp *) malloc(sizeof(MBApp)); - X_MB_runtime_t *rt; - - rt = X_MB_new(":0.0", 800, 600); - - app->rt = rt; - app->rdman = X_MB_rdman(rt); - app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord); - rdman_attach_backend(app->rdman, rt); - MB_SPRITE_GOTO_SCENE(app->rootsprite, 1); - return app; -} - -void MBApp_setData(MBApp *app,void *data) -{ - app->private = (void *) data; -} - -mb_tman_t *MBApp_getTimer(MBApp *app) -{ - return X_MB_tman(app->rt); -} - -void MBApp_loop(MBApp *en) -{ - /* - * Start handle connections, includes one to X server. - * User start to interact with the application. - */ - X_MB_handle_connection(en->rt); - - /* - * Clean - */ - X_MB_free(en->rt); - free(en); -}
--- a/examples/dynamic/mbapp.h Sun Mar 08 10:06:01 2009 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#ifndef __APP_H -#define __APP_H -typedef struct _mbapp MBApp; -struct _mbapp { - void *rt; - redraw_man_t *rdman; - mb_sprite_t *rootsprite; - mb_obj_t *root; - void *private; -}; -MBApp *MBApp_Init(char *module); -void MBApp_setData(MBApp *app,void *data); -mb_tman_t *MBApp_getTimer(MBApp *app); -void MBApp_loop(MBApp *en); -#define MBAPP_DATA(app,type) ((type *) ((app)->private)) -#define MBAPP_RDMAN(app) (((MBApp *) app)->rdman) - -#include "mbbutton.h" -#endif
--- a/include/mb_shapes.h Sun Mar 08 10:06:01 2009 +0800 +++ b/include/mb_shapes.h Sun Mar 08 10:06:23 2009 +0800 @@ -242,6 +242,8 @@ extern void sh_image_draw(shape_t *shape, cairo_t *cr); extern void sh_image_set_geometry(shape_t *shape, co_aix x, co_aix y, co_aix w, co_aix h); +extern int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, + co_aix x, co_aix y, co_aix w, co_aix h); /* @} */ /* @} */
--- a/src/shape_image.c Sun Mar 08 10:06:01 2009 +0800 +++ b/src/shape_image.c Sun Mar 08 10:06:23 2009 +0800 @@ -74,25 +74,23 @@ sh_image_t *img; cairo_format_t fmt; paint_t *paint; + int r; img = O_ALLOC(sh_image_t); if(img == NULL) return NULL; memset(img, 0, sizeof(sh_image_t)); - + mb_obj_init((mb_obj_t *)img, MBO_IMAGE); + img->rdman = rdman; img->shape.free = sh_image_free; - mb_obj_init((mb_obj_t *)img, MBO_IMAGE); - img->x = x; - img->y = y; - img->w = w; - img->h = h; - img->img_data = img_data; - - paint = rdman_paint_image_new(rdman, img_data); - rdman_paint_fill(rdman, paint, (shape_t *)img); - img->paint = paint; - img->rdman = rdman; + + r = sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h); + if(r != OK) { + mb_obj_destroy((shape_t *)img); + free(img); + return NULL; + } return (shape_t *)img; } @@ -183,3 +181,32 @@ img->w = w; img->h = h; } + +int sh_image_set_img_data(shape_t *shape, mb_img_data_t *img_data, + co_aix x, co_aix y, co_aix w, co_aix h) { + sh_image_t *img = (sh_image_t *)shape; + paint_t *paint; + + ASSERT(img_data != NULL); + ASSERT(shape->obj.obj_type == MBO_IMAGE); + + paint = rdman_paint_image_new(img->rdman, img_data); + if(paint == NULL) + return ERR; + + if(img->paint) { + rdman_paint_free(img->rdman, img->paint); + MB_IMG_DATA_FREE(img->img_data); + } + + img->img_data = img_data; + img->x = x; + img->y = y; + img->w = w; + img->h = h; + img->paint = paint; + rdman_paint_fill(img->rdman, paint, (shape_t *)img); + + return OK; +} +