Mercurial > MadButterfly
changeset 1370:bae104d8d247
Add clone functions for shape types
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Sat, 05 Mar 2011 22:00:16 +0800 |
parents | 9ad74b29e011 |
children | 36cbe73813a8 |
files | include/mb_shapes.h include/mb_types.h src/event.c src/shape_image.c src/shape_path.c src/shape_rect.c src/shape_stext.c |
diffstat | 7 files changed, 109 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_shapes.h Fri Mar 04 21:09:49 2011 +0800 +++ b/include/mb_shapes.h Sat Mar 05 22:00:16 2011 +0800 @@ -74,6 +74,8 @@ int pnt_cnt, co_aix *float_args, int float_arg_cnt); +extern shape_t *rdman_shape_path_clone(redraw_man_t *rdman, + const shape_t *src_path); extern void sh_path_transform(shape_t *shape); extern void sh_path_draw(shape_t *shape, mbe_t *cr); /* @} */ @@ -251,6 +253,8 @@ co_aix x, co_aix y, co_aix w, co_aix h, co_aix rx, co_aix ry); +extern shape_t *rdman_shape_rect_clone(redraw_man_t *rdman, + const shape_t *src_rect); extern void sh_rect_transform(shape_t *shape); extern void sh_rect_draw(shape_t *shape, mbe_t *cr); extern void sh_rect_set(shape_t *shape, co_aix x, co_aix y, @@ -263,6 +267,8 @@ extern shape_t *rdman_shape_image_new(redraw_man_t *rdman, co_aix x, co_aix y, co_aix w, co_aix h); +extern shape_t *rdman_shape_image_clone(redraw_man_t *rdman, + const shape_t *src_img); extern void sh_image_transform(shape_t *shape); extern void sh_image_draw(shape_t *shape, mbe_t *cr); extern void sh_image_set_geometry(shape_t *shape, co_aix x, co_aix y, @@ -312,6 +318,8 @@ extern shape_t *rdman_shape_stext_new(redraw_man_t *rdman, const char *txt, co_aix x, co_aix y); +extern shape_t *rdman_shape_stext_clone(redraw_man_t *rdman, + const shape_t *_src_txt); extern void sh_stext_transform(shape_t *shape); extern void sh_stext_draw(shape_t *shape, mbe_t *cr); extern int sh_stext_set_text(shape_t *shape, const char *txt);
--- a/include/mb_types.h Fri Mar 04 21:09:49 2011 +0800 +++ b/include/mb_types.h Sat Mar 05 22:00:16 2011 +0800 @@ -392,5 +392,14 @@ #define sh_get_stroke(sh) ((sh)->stroke) #define sh_set_stroke_width(sh, v) do { (sh)->stroke_width = (v); } while(0) #define sh_get_stroke_width(sh) (sh)->stroke_width +#define sh_copy_style(rdman, sh_src, sh_dst) do { \ + if(sh_get_fill(sh_src)) \ + rdman_paint_fill((rdman), sh_get_fill(sh_src), (sh_dst)); \ + if(sh_get_stroke(sh_src)) \ + rdman_paint_stroke((rdman), sh_get_stroke(sh_src), (sh_dst)); \ + (sh_dst)->stroke_width = (sh_src)->stroke_width; \ + (sh_dst)->stroke_linecap = (sh_src)->stroke_linecap; \ + (sh_dst)->stroke_linejoin = (sh_src)->stroke_linejoin; \ + } while(0) #endif /* __MB_TYPES_H_ */
--- a/src/event.c Fri Mar 04 21:09:49 2011 +0800 +++ b/src/event.c Sat Mar 05 22:00:16 2011 +0800 @@ -15,8 +15,12 @@ #define OK 0 #define ERR -1 +#ifndef FALSE #define FALSE 0 +#endif +#ifndef TRUE #define TRUE 1 +#endif #define ARRAY_EXT_SZ 64
--- a/src/shape_image.c Fri Mar 04 21:09:49 2011 +0800 +++ b/src/shape_image.c Sat Mar 05 22:00:16 2011 +0800 @@ -92,6 +92,22 @@ return (shape_t *)img; } +shape_t * +rdman_shape_image_clone(redraw_man_t *rdman, const shape_t *_src_img) { + const sh_image_t *src_img = (const sh_image_t *)_src_img; + sh_image_t *new_img; + + new_img = (sh_image_t *)rdman_shape_image_new(rdman, + src_img->x, src_img->y, + src_img->w, src_img->h); + if(new_img == NULL) + return NULL; + + sh_copy_style(rdman, (shape_t *)src_img, (shape_t *)new_img); + + return (shape_t *)new_img; +} + void sh_image_free(shape_t *shape) { sh_image_t *img = (sh_image_t *)shape;
--- a/src/shape_path.c Fri Mar 04 21:09:49 2011 +0800 +++ b/src/shape_path.c Sat Mar 05 22:00:16 2011 +0800 @@ -1204,6 +1204,32 @@ return (shape_t *)path; } +shape_t * +rdman_shape_path_clone(redraw_man_t *rdman, const shape_t *_src_path) { + const sh_path_t *src_path = (const sh_path_t *)_src_path; + sh_path_t *new_path; + char *udata; + char *cmds; + co_aix *pnts, *float_args; + + udata = src_path->user_data; + cmds = udata; + pnts = (co_aix *)(udata + src_path->cmd_len); + float_args = pnts + src_path->pnt_len; + new_path = + (sh_path_t *)rdman_shape_path_new_from_binary(rdman, + cmds, + pnts, src_path->pnt_len, + float_args, + src_path->float_arg_len); + if(new_path == NULL) + return NULL; + + sh_copy_style(rdman, (shape_t *)src_path, (shape_t *)new_path); + + return (shape_t *)new_path; +} + /*! \brief Transform a path from user space to device space. *
--- a/src/shape_rect.c Fri Mar 04 21:09:49 2011 +0800 +++ b/src/shape_rect.c Sat Mar 05 22:00:16 2011 +0800 @@ -50,6 +50,23 @@ return (shape_t *)rect; } +shape_t * +rdman_shape_rect_clone(redraw_man_t *rdman, const shape_t *_src_rect) { + const sh_rect_t *src_rect = (const sh_rect_t *)_src_rect; + sh_rect_t *new_rect; + + new_rect = (sh_rect_t *)rdman_shape_rect_new(rdman, + src_rect->x, src_rect->y, + src_rect->w, src_rect->h, + src_rect->rx, src_rect->ry); + if(new_rect == NULL) + return NULL; + + sh_copy_style(rdman, (shape_t *)src_rect, (shape_t *)new_rect); + + return (shape_t *)src_rect; +} + void sh_rect_set(shape_t *shape, co_aix x, co_aix y, co_aix w, co_aix h, co_aix rx, co_aix ry) { sh_rect_t *rect = (sh_rect_t *)shape;
--- a/src/shape_stext.c Fri Mar 04 21:09:49 2011 +0800 +++ b/src/shape_stext.c Sat Mar 05 22:00:16 2011 +0800 @@ -157,7 +157,7 @@ ASSERT(matrix != NULL); scaled_font = mbe_scaled_font_create((mbe_font_face_t *)face, - matrix, &id); + matrix, id); return (mb_scaled_font_t *)scaled_font; } @@ -311,6 +311,34 @@ return (shape_t *)txt_o; } +#ifndef UNITTEST +shape_t * +rdman_shape_stext_clone(redraw_man_t *rdman, const shape_t *_src_txt) { + sh_stext_t *src_txt = (const sh_stext_t *)_src_txt; + sh_stext_t *new_txt; + style_blks_lst_t *style_blks; + int r; + + new_txt = (sh_stext_t *)rdman_shape_stext_new(rdman, src_txt->txt, + src_txt->x, src_txt->y); + if(new_txt == NULL) + return NULL; + + style_blks = &src_txt->style_blks; + if(style_blks->num > 0) { + r = sh_stext_set_style(new_txt, style_blks->ds, style_blks->num); + if(r != OK) { + _rdman_shape_stext_free((shape_t *)new_txt); + return NULL; + } + } + + sh_copy_style(rdman, (shape_t *)src_txt, (shape_t *)new_txt); + + return (shape_t *)new_txt; +} +#endif /* UNITTEST */ + static int compute_utf8_chars_sz(const char *txt, int n_chars) { int i;