Mercurial > MadButterfly
changeset 346:b391722bf20e
sh_image_t::img_data is managed by paint_image_t.
- sh_image_t should not try to free it.
- call sh_text_P_generate_layout() in sh_text_transform()
- remove calling from other functions.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 08 Mar 2009 14:44:41 +0800 |
parents | d04085404583 |
children | b247beaac4f0 |
files | examples/menu/filebrowser.c src/X_supp.c src/img_ldr.c src/shape_image.c src/shape_text.c |
diffstat | 5 files changed, 43 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/filebrowser.c Sun Mar 08 11:47:14 2009 +0800 +++ b/examples/menu/filebrowser.c Sun Mar 08 14:44:41 2009 +0800 @@ -67,7 +67,9 @@ void mypreview(MyAppData *data, char *path) { - mb_img_data_t *img = MB_IMG_LDR_LOAD(rdman_img_ldr(MBAPP_RDMAN(myApp)), path); + redraw_man_t *rdman = MBAPP_RDMAN(myApp); + mb_img_ldr_t *ldr = rdman_img_ldr(rdman); + mb_img_data_t *img = MB_IMG_LDR_LOAD(ldr, path); shape_t *obj = (shape_t *) MB_SPRITE_GET_OBJ(myApp->rootsprite, "previewimg"); printf("Preview %s\n",path);
--- a/src/X_supp.c Sun Mar 08 11:47:14 2009 +0800 +++ b/src/X_supp.c Sun Mar 08 14:44:41 2009 +0800 @@ -454,7 +454,7 @@ xmb_rt->tman = mb_tman_new(); - img_ldr = simple_mb_img_ldr_new("./"); + img_ldr = simple_mb_img_ldr_new(""); xmb_rt->img_ldr = img_ldr; rdman_set_img_ldr(xmb_rt->rdman, img_ldr);
--- a/src/img_ldr.c Sun Mar 08 11:47:14 2009 +0800 +++ b/src/img_ldr.c Sun Mar 08 14:44:41 2009 +0800 @@ -113,7 +113,7 @@ return NULL; } strcpy((char *)ldr->repo, img_repository); - if(img_repository[sz - 1] != '/') { + if(img_repository[sz - 1] != '/' && strlen(img_repository) != 0) { ((char *)ldr->repo)[sz] = '/'; ((char *)ldr->repo)[sz + 1] = 0; }
--- a/src/shape_image.c Sun Mar 08 11:47:14 2009 +0800 +++ b/src/shape_image.c Sun Mar 08 14:44:41 2009 +0800 @@ -65,6 +65,32 @@ static void sh_image_free(shape_t *shape); +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); + + 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; +} + /*! \brief Creae a new image shape. * * \param img_data is image data whose owner-ship is transfered. @@ -85,7 +111,7 @@ img->rdman = rdman; img->shape.free = sh_image_free; - r = sh_image_set_img_data((shape_t *)img, img_data, x, y, w, h); + 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); @@ -100,7 +126,6 @@ rdman_paint_free(img->rdman, img->paint); mb_obj_destroy(shape); - MB_IMG_DATA_FREE(img->img_data); free(img); } @@ -184,30 +209,10 @@ 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); + int r; - 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; + r = _sh_image_set_img_data(shape, img_data, x, y, w, h); + return r; } mb_img_data_t *sh_image_get_img_data(shape_t *shape) {
--- a/src/shape_text.c Sun Mar 08 11:47:14 2009 +0800 +++ b/src/shape_text.c Sun Mar 08 14:44:41 2009 +0800 @@ -65,8 +65,7 @@ text->layout = NULL; text->attrs = attrs; text->align = TEXTALIGN_START; - sh_text_P_generate_layout(text, rdman->cr); - + rdman_shape_man(rdman, (shape_t *)text); return (shape_t *)text; @@ -207,6 +206,8 @@ void sh_text_transform(shape_t *shape) { sh_text_t *text; + coord_t *coord; + canvas_t *canvas; co_aix x, y; co_aix shw; PangoRectangle extents; @@ -214,8 +215,12 @@ int r; text = (sh_text_t *)shape; - + text->d_font_size = coord_trans_size(shape->coord, text->font_size); + + coord = sh_get_coord(shape); + canvas = _coord_get_canvas(coord); + sh_text_P_generate_layout(text, (cairo_t *)canvas); x = text->x; y = text->y; @@ -259,7 +264,6 @@ printf("text=%s\n",text->data); } static void draw_text(sh_text_t *text, cairo_t *cr) { - sh_text_P_generate_layout(text, cr); cairo_move_to(cr, text->d_x, text->d_y); pango_cairo_layout_path(cr,text->layout); }