# HG changeset patch # User wycc # Date 1234658097 -28800 # Node ID f894b30676e996020b424154d0742e630bf54e41 # Parent 8b45e7b374b8d3a47b93d5f60587e29f83734d80 Add MBAF object suport. This is still work in progress yet. However, it won't affect other features. Therefore, it is checked in before it become mature. diff -r 8b45e7b374b8 -r f894b30676e9 include/mb_obj.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mb_obj.h Sun Feb 15 08:34:57 2009 +0800 @@ -0,0 +1,73 @@ +#ifndef __MBOBJ_H +#define __MBOBJ_H +#include "mb_shapes.h" +#include "mb_shapes.h" +/*! \brief Change the location of the object. + * + * The location of the object will be relocated to the new position. This function works for group(coord_t) + * and text shape (shape_text_t). For others, this command will be ignored since we don't know the original + * point of a path. + */ +void mb_obj_set_pos(mb_obj_t *obj, co_aix x, co_aix y); + +/*! \brief Get the position of the object. + * + * Return the position of the object. This works for group and text only. For others, (0,0) will be returned. + */ +void mb_obj_get_pos(mb_obj_t *obj, co_aix *x, co_aix *y); + +/*! \brief set the width of the object. + * + */ +void mb_obj_set_scalex(mb_obj_t *obj, int scale); + +/*! \brief return the scale of width. + */ +int mb_obj_get_scalex(mb_obj_t *obj); + +/*! \brief set the scale of height. + */ +void mb_obj_set_scaley(mb_obj_t *obj, int scale); +/*! \brief return the scale of height + * + */ +int mb_obj_get_scaley(mb_obj_t *obj); + + +/*! \brief Change the rotation degree. + * + */ +void mb_obj_set_rotation(mb_obj_t *obj, int degree); + +/*! \brief Return the rotation degree of an object. + * + */ + +int mb_obj_get_rotation(mb_obj_t *obj); + +/*! \brief set the textformat of the texts inside a group. + * + * If the obj is a group, we will search the first text element inside it. If it is a shape_t, it will be applied to it directly. + * + */ +void mb_obj_set_textstyle(mb_obj_t *obj, mb_textstyle_t *format, int begin, int end); + +/*! \brief return the text format style between 'begin' and 'end'. + * + */ +void mb_obj_get_textstyle(mb_obj_t *, mb_textstyle_t *format,int begin,int end); + +/*! \brief Change the characters of a text field. + * Change the content of a text field. If the obj is a group, we will search for the first text field inside it as the target. + */ +void mb_obj_set_text(mb_obj_t *obj, const char *text); + + +/*! \brief Get the content of a text field. + * + * The 'text' is the data buffer and the 'size' is the size of the buffer. + */ +void mb_obj_get_text(mb_obj_t *obj, char *text, int size); + +#endif + diff -r 8b45e7b374b8 -r f894b30676e9 include/mb_types.h --- a/include/mb_types.h Sun Feb 15 08:33:47 2009 +0800 +++ b/include/mb_types.h Sun Feb 15 08:34:57 2009 +0800 @@ -29,6 +29,11 @@ * * mb_obj_t should be initialized with mb_obj_init() and destroied with * mb_obj_destroy(). + * + * We have defined a set of convienent API which will wrap the coord_t or shape_t API accoridng to its type. + * Please refer to http://www.assembla.com/wiki/show/dFrSMOtDer3BZUab7jnrAJ/MBAF_Object for the details. This + * API is designed for regular programmers which can be used to change some common properties of objects without + * checking its type. */ struct _mb_obj { int obj_type; /*!< \brief Type of a MadButterfly object. */ @@ -218,7 +223,7 @@ */ #define coord_move(co,x,y) do {(co)->matrix[2] = (x); (co)->matrix[5] = (y);} while(0) #define coord_set_scalex(co,sx) do {(co)->matrix[0] = sx;} while(0) -#define coord_set_scaley(co,sy) do {(co)->matrux[3] = sy;} while(0) +#define coord_set_scaley(co,sy) do {(co)->matrix[3] = sy;} while(0) #define coord_scalex(co) ((co)->matrix[0]) #define coord_scaley(co) ((co)->matrix[3]) #define coord_x(co) ((co)->matrix[2]) diff -r 8b45e7b374b8 -r f894b30676e9 src/Makefile.am --- a/src/Makefile.am Sun Feb 15 08:33:47 2009 +0800 +++ b/src/Makefile.am Sun Feb 15 08:34:57 2009 +0800 @@ -3,7 +3,7 @@ lib_LTLIBRARIES = libmbfly.la noinst_PROGRAMS = X_main -MBAF_SOURCES=mbaf/mbapp.c mbaf/mbbutton.c +MBAF_SOURCES=mbaf/mbapp.c mbaf/mbbutton.c mbaf/mbobject.c libmbfly_la_SOURCES = animate.c chgcolor.c coord.c event.c geo.c \ observer.c paint.c redraw_man.c rotate.c shape_path.c \ shape_rect.c shape_text.c shift.c subtree_free.c timer.c \ diff -r 8b45e7b374b8 -r f894b30676e9 src/mbaf/mbobject.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mbaf/mbobject.c Sun Feb 15 08:34:57 2009 +0800 @@ -0,0 +1,132 @@ +#include "mb_types.h" +#include "mb_obj.h" + + +void mb_obj_set_pos(mb_obj_t *obj, co_aix x, co_aix y) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + coord_x(((coord_t *) obj)) = x; + coord_y(((coord_t *) obj)) = y; + } else if (MBO_TYPE(obj) == MBO_TEXT) { + sh_text_set_pos((shape_t *) obj, x, y); + } else { + return; + } + +} + +void mb_obj_get_pos(mb_obj_t *obj, co_aix *x, co_aix *y) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + *x = coord_x((coord_t *) obj); + *y = coord_y((coord_t *) obj); + } else if (MBO_TYPE(obj) == MBO_TEXT) { + sh_text_get_pos((shape_t *) obj, x, y); + } else { + return; + } + +} + +void mb_obj_set_text(mb_obj_t *obj, const char *text) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + geo_t *geo; + shape_t *shape; + coord_t *g = (coord_t *) obj; + + FOR_COORD_MEMBERS(g, geo) { + shape = geo_get_shape(geo); + if(shape->obj.obj_type == MBO_TEXT) { + sh_text_set_text(shape, text); + return; + } + } + } else if (MBO_TYPE(obj) == MBO_TEXT) { + sh_text_set_text((shape_t *) obj,text); + } else { + return; + } + +} + + +void mb_obj_get_text(mb_obj_t *obj, char *text,int size) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + geo_t *geo; + shape_t *shape; + coord_t *g = (coord_t *) obj; + + FOR_COORD_MEMBERS(g, geo) { + shape = geo_get_shape(geo); + if(shape->obj.obj_type == MBO_TEXT) { + sh_text_get_text(shape, text,size); + return; + } + } + } else if (MBO_TYPE(obj) == MBO_TEXT) { + sh_text_get_text((shape_t *) obj,text,size); + } else { + *text = 0; + return; + } +} + +void mb_obj_set_scalex(mb_obj_t *obj,int scale) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + coord_set_scalex((coord_t *) obj, scale); + } else { + } +} + +int mb_obj_get_scalex(mb_obj_t *obj) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + return coord_scalex((coord_t *) obj); + } else { + return 100; + } +} + +void mb_obj_set_scaley(mb_obj_t *obj,int scale) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + coord_set_scaley((coord_t *) obj, scale); + } else { + } +} +int mb_obj_get_scaley(mb_obj_t *obj) +{ + if (MBO_TYPE(obj) == MBO_COORD) { + return coord_scaley((coord_t *) obj); + } else { + return 100; + } +} + +void mb_obj_set_rotation(mb_obj_t *obj, int degree) +{ + printf("%s is not implemented yet\n",__FUNCTION__); +} + +int mb_obj_get_rotation(mb_obj_t *obj) +{ + printf("%s is not implemented yet\n",__FUNCTION__); +} + + + +void mb_obj_set_color(mb_obj_t *obj, int color) +{ + printf("%s is not implemented yet\n",__FUNCTION__); +} + + +int mb_obj_get_color(mb_obj_t *obj) +{ + printf("%s is not implemented yet\n",__FUNCTION__); + return 0; +} + diff -r 8b45e7b374b8 -r f894b30676e9 src/shape_text.c --- a/src/shape_text.c Sun Feb 15 08:33:47 2009 +0800 +++ b/src/shape_text.c Sun Feb 15 08:34:57 2009 +0800 @@ -72,7 +72,28 @@ return (shape_t *)text; } -extern void sh_text_set_text(shape_t *shape, const char *txt) { +void sh_text_set_pos(shape_t *shape, co_aix x, co_aix y) +{ + sh_text_t *text = (sh_text_t *)shape; + text->x = x; + text->y = y; +} + + +void sh_text_get_pos(shape_t *shape, co_aix *x, co_aix *y) +{ + sh_text_t *text = (sh_text_t *)shape; + *x = text->x; + *y = text->y; +} + +void sh_text_get_text(shape_t *shape, char *text,int size) +{ + sh_text_t *t = (sh_text_t *)shape; + strncpy(text,t->data, size); +} + +void sh_text_set_text(shape_t *shape, const char *txt) { sh_text_t *text = (sh_text_t *)shape; char *buf; @@ -230,7 +251,7 @@ } text->layout = pango_cairo_create_layout(cr); desc = pango_font_description_from_string("Sans Bold"); - cairo_set_source_rgb (cr, 0, 0, 0); + //cairo_set_source_rgb (cr, 0, 0, 0); pango_layout_set_font_description (text->layout, desc); pango_layout_set_text(text->layout,text->data,strlen(text->data)); pango_layout_set_attributes(text->layout, text->attrs);