changeset 196:c234ee745ceb

Start moving to mb_obj_t
author Thinker K.F. Li <thinker@branda.to>
date Tue, 09 Dec 2008 17:34:10 +0800
parents 5235aded379c
children 75ec0124202a
files include/mb_types.h src/coord.c src/event.c src/redraw_man.c src/shape_path.c src/shape_rect.c src/shape_text.c
diffstat 7 files changed, 37 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/include/mb_types.h	Wed Nov 19 20:54:27 2008 +0800
+++ b/include/mb_types.h	Tue Dec 09 17:34:10 2008 +0800
@@ -11,9 +11,27 @@
 typedef struct _area area_t;
 typedef struct _shnode shnode_t;
 typedef struct _paint paint_t;
+typedef struct _mb_obj mb_obj_t;
 
 struct _redraw_man;
 
+struct _mb_obj {
+    int obj_type;
+};
+
+enum { MBO_DUMMY,
+       MBO_COORD,
+       MBO_SHAPES=0x1000,
+       MBO_PATH,
+       MBO_TEXT,
+       MBO_RECT
+};
+#define MBO_CLASS_MASK 0xf000
+#define MBO_CLASS(x) (((mb_obj_t *)(x))->obj_type & MBO_CLASS_MASK)
+#define MBO_TYPE(x) (((mb_obj_t *)(x))->obj_type)
+#define IS_MBO_SHAPES(obj) (MBO_CLASS(obj) == MBO_SHAPES)
+#define IS_MBO_COORD(obj) (MBO_TYPE(obj) == MB_COORD)
+
 /*! \brief Base of paint types.
  *
  * Paints should be freed by users by calling rdman_paint_free() of
@@ -93,6 +111,7 @@
  * \enddot
  */
 typedef struct _coord {
+    mb_obj_t obj;
     unsigned int order;
     unsigned int flags;
     co_aix opacity;
@@ -161,7 +180,7 @@
  * \enddot
  */
 struct _shape {
-    int sh_type;
+    mb_obj_t obj;
     geo_t *geo;
     coord_t *coord;
     paint_t *fill, *stroke;
@@ -171,7 +190,7 @@
     struct _shape *sh_next;	/*!< Link all shapes of a rdman together. */
     void (*free)(shape_t *shape);
 };
-enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT };
+/* enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT, SHT_RECT }; */
 
 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event)
 #define sh_hide(sh)			     \
--- a/src/coord.c	Wed Nov 19 20:54:27 2008 +0800
+++ b/src/coord.c	Tue Dec 09 17:34:10 2008 +0800
@@ -90,6 +90,7 @@
 	co->parent = parent;
 	STAILQ_INS_TAIL(parent->children, coord_t, sibling, co);
     }
+    MBO_TYPE(co) = MBO_COORD;
     co->matrix[0] = 1;
     co->matrix[4] = 1;
     co->aggr_matrix[0] = 1;
--- a/src/event.c	Wed Nov 19 20:54:27 2008 +0800
+++ b/src/event.c	Tue Dec 09 17:34:10 2008 +0800
@@ -52,14 +52,14 @@
 }
 
 static void draw_shape_path(shape_t *shape, cairo_t *cr) {
-    switch(shape->sh_type) {
-    case SHT_PATH:
+    switch(MBO_TYPE(shape)) {
+    case MBO_PATH:
 	sh_path_draw(shape, cr);
 	break;
-    case SHT_TEXT:
+    case MBO_TEXT:
 	sh_text_draw(shape, cr);
 	break;
-    case SHT_RECT:
+    case MBO_RECT:
 	sh_rect_draw(shape, cr);
 	break;
     }
--- a/src/redraw_man.c	Wed Nov 19 20:54:27 2008 +0800
+++ b/src/redraw_man.c	Tue Dec 09 17:34:10 2008 +0800
@@ -750,14 +750,14 @@
 }
 
 static void clean_shape(shape_t *shape) {
-    switch(shape->sh_type) {
-    case SHT_PATH:
+    switch(MBO_TYPE(shape)) {
+    case MBO_PATH:
 	sh_path_transform(shape);
 	break;
-    case SHT_TEXT:
+    case MBO_TEXT:
 	sh_text_transform(shape);
 	break;
-    case SHT_RECT:
+    case MBO_RECT:
 	sh_rect_transform(shape);
 	break;
 #ifdef UNITTEST
@@ -950,14 +950,14 @@
      *	operators for them.
      */
     if(shape->fill || shape->stroke) {
-	switch(shape->sh_type) {
-	case SHT_PATH:
+	switch(MBO_TYPE(shape)) {
+	case MBO_PATH:
 	    sh_path_draw(shape, cr);
 	    break;
-	case SHT_TEXT:
+	case MBO_TEXT:
 	    sh_text_draw(shape, cr);
 	    break;
-	case SHT_RECT:
+	case MBO_RECT:
 	    sh_rect_draw(shape, cr);
 	    break;
 #ifdef UNITTEST
--- a/src/shape_path.c	Wed Nov 19 20:54:27 2008 +0800
+++ b/src/shape_path.c	Tue Dec 09 17:34:10 2008 +0800
@@ -682,7 +682,7 @@
     path = (sh_path_t *)malloc(sizeof(sh_path_t));
     /*! \todo Remove this memset()? */
     memset(&path->shape, 0, sizeof(shape_t));
-    path->shape.sh_type = SHT_PATH;
+    MBO_TYPE(path) = MBO_PATH;
     path->cmd_len = cmd_cnt;
     path->arg_len = arg_cnt;
     path->fix_arg_len = fix_arg_cnt;
--- a/src/shape_rect.c	Wed Nov 19 20:54:27 2008 +0800
+++ b/src/shape_rect.c	Tue Dec 09 17:34:10 2008 +0800
@@ -27,7 +27,7 @@
 
     memset(rect, 0, sizeof(sh_rect_t));
 
-    rect->shape.sh_type = SHT_RECT;
+    MBO_TYPE(rect) = MBO_RECT;
     rect->x = x;
     rect->y = y;
     rect->w = w;
--- a/src/shape_text.c	Wed Nov 19 20:54:27 2008 +0800
+++ b/src/shape_text.c	Tue Dec 09 17:34:10 2008 +0800
@@ -42,7 +42,7 @@
 	return NULL;
 
     memset(text, 0, sizeof(sh_text_t));
-    text->shape.sh_type = SHT_TEXT;
+    MBO_TYPE(text) = MBO_TEXT;
     text->data = strdup(txt);
     if(text->data == NULL) {
 	free(text);