changeset 81:13fdf205047b

Hide shapes and groups
author Thinker K.F. Li <thinker@branda.to>
date Thu, 21 Aug 2008 13:52:23 +0800
parents e548221c04eb
children 4bb6451ef036
files src/X_supp.c src/mb_types.h tools/mb_c_header.m4 tools/mb_c_source.m4 tools/svg2code.py
diffstat 5 files changed, 70 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/X_supp.c	Thu Aug 21 00:27:36 2008 +0800
+++ b/src/X_supp.c	Thu Aug 21 13:52:23 2008 +0800
@@ -76,7 +76,12 @@
     XEvent evt;
     XMotionEvent *mevt;
     XButtonEvent *bevt;
-    co_aix x, y;
+    XExposeEvent *eevt;
+    co_aix x, y, w, h;
+
+    int eflag = 0;
+    int ex1, ey1, ex2, ey2;
+
     unsigned int state, button;
     int r;
 
@@ -118,12 +123,35 @@
 	    break;
 
 	case Expose:
-	    rdman_redraw_area(rdman, evt.xexpose.x, evt.xexpose.y,
-			      evt.xexpose.width, evt.xexpose.height);
+	    eevt = &evt.xexpose;
+	    x = eevt->x;
+	    y = eevt->y;
+	    w = eevt->width;
+	    h = eevt->height;
+
+	    if(eflag) {
+		if(x < ex1)
+		    ex1 = x;
+		if(y < ey1)
+		    ey1 = y;
+		if((x + w) > ex2)
+		    ex2 = x + w;
+		if((y + h) > ey2)
+		    ey2 = y + h;
+	    } else {
+		ex1 = x;
+		ey1 = y;
+		ex2 = x + w;
+		ey2 = y + h;
+		eflag = 1;
+	    }
 	    break;
 	}
     }
-    rdman_redraw_changed(rdman);
+    if(eflag) {
+	rdman_redraw_area(rdman, ex1, ey1, (ex2 - ex1), (ey2 - ey1));
+	eflag = 0;
+    }
     XFlush(display);
 }
 
--- a/src/mb_types.h	Thu Aug 21 00:27:36 2008 +0800
+++ b/src/mb_types.h	Thu Aug 21 13:52:23 2008 +0800
@@ -151,6 +151,8 @@
     } while(0)
 #define sh_get_geo(sh) ((sh)->geo)
 #define sh_get_mouse_event_subject(sh) ((sh)->geo->mouse_event)
+#define sh_hide(sh) do { (sh)->geo->flags |= GEF_HIDDEN; } while(0)
+#define sh_show(sh) do { (sh)->geo->flags &= ~GEF_HIDDEN; } while(0)
 extern void sh_attach_coord(shape_t *sh, coord_t *coord);
 extern void sh_detach_coord(shape_t *sh);
 
--- a/tools/mb_c_header.m4	Thu Aug 21 00:27:36 2008 +0800
+++ b/tools/mb_c_header.m4	Thu Aug 21 13:52:23 2008 +0800
@@ -30,6 +30,9 @@
 define([FILL_SHAPE_WITH_PAINT],)
 define([STROKE_SHAPE_WITH_PAINT],)
 define([STROKE_WIDTH],)
+define([GROUP_HIDE],)
+define([PATH_HIDE],)
+define([RECT_HIDE],)
 
 define([MADBUTTERFLY],[dnl
 [#ifndef __$1_H_
--- a/tools/mb_c_source.m4	Thu Aug 21 00:27:36 2008 +0800
+++ b/tools/mb_c_source.m4	Thu Aug 21 13:52:23 2008 +0800
@@ -42,6 +42,9 @@
 define([FILL_SHAPE_WITH_PAINT])
 define([STROKE_SHAPE_WITH_PAINT])
 define([STROKE_WIDTH])
+define([GROUP_HIDE],)
+define([RECT_HIDE],)
+define([PATH_HIDE],)
 divert[]])
 
 define([S_ADD_LINEAR_PAINT],[
@@ -112,6 +115,18 @@
 [    obj->$1->stroke_width = $2;
 ]])
 
+define([S_GROUP_HIDE],[dnl
+[    coord_hide(obj->$1);
+]])
+
+define([S_RECT_HIDE],[dnl
+[    sh_hide(obj->$1);
+]])
+
+define([S_PATH_HIDE],[dnl
+[    sh_hide(obj->$1);
+]])
+
 define([SETUP_VARS],[divert([-1])
 define([SIMPORT],[IMPORT(]QUOTE($[]1)[,[S_])])
 SIMPORT([ADD_LINEAR_PAINT])
@@ -126,7 +141,10 @@
 SIMPORT([STROKE_SHAPE])
 SIMPORT([FILL_SHAPE_WITH_PAINT])
 SIMPORT([STROKE_SHAPE_WITH_PAINT])
-SIMPORT([STROKE_WIDTH],)
+SIMPORT([STROKE_WIDTH])
+SIMPORT([GROUP_HIDE])
+SIMPORT([RECT_HIDE])
+SIMPORT([PATH_HIDE])
 divert[]])
 
 define([F_ADD_LINEAR_PAINT],[[
@@ -172,6 +190,9 @@
 define([FILL_SHAPE_WITH_PAINT])
 define([STROKE_SHAPE_WITH_PAINT])
 define([STROKE_WIDTH])
+define([GROUP_HIDE],)
+define([RECT_HIDE],)
+define([PATH_HIDE],)
 divert[]])
 
 define([MADBUTTERFLY],[dnl
--- a/tools/svg2code.py	Thu Aug 21 00:27:36 2008 +0800
+++ b/tools/svg2code.py	Thu Aug 21 13:52:23 2008 +0800
@@ -99,7 +99,7 @@
         int(code[3:5], 16) / 255.0, \
         int(code[5:7], 16) / 255.0
 
-def translate_style(node, coord_id, codefo, doc):
+def translate_style(node, coord_id, codefo, doc, prefix):
     node_id = node.getAttribute('id')
     style_str = node.getAttribute('style')
     prop_strs = [s.strip() for s in style_str.split(';')]
@@ -153,6 +153,13 @@
         print >> codefo, 'STROKE_WIDTH([%s], %f)dnl' % (
             node_id, stroke_width)
         pass
+
+    if prop_map.has_key('display'):
+        display = prop_map['display'].strip().lower()
+        if display == 'none':
+            print >> codefo, '%sHIDE([%s])dnl' % (prefix, node_id)
+            pass
+        pass
     pass
 
 def translate_path(path, coord_id, codefo, doc):
@@ -160,7 +167,7 @@
     d = path.getAttribute('d')
     print >> codefo, 'dnl'
     print >> codefo, 'ADD_PATH([%s], [%s], [%s])dnl' % (path_id, d, coord_id)
-    translate_style(path, coord_id, codefo, doc)
+    translate_style(path, coord_id, codefo, doc, 'PATH_')
     pass
 
 def translate_rect(rect, coord_id, codefo, doc):
@@ -180,13 +187,14 @@
     print >> codefo, 'dnl'
     print >> codefo, 'ADD_RECT([%s], %f, %f, %f, %f, %f, %f, [%s])dnl' % (
         rect_id, x, y, width, height, rx, ry, coord_id)
-    translate_style(rect, coord_id, codefo, doc)
+    translate_style(rect, coord_id, codefo, doc, 'RECT_')
     pass
 
 def translate_group(group, parent_id, codefo, doc):
     group_id = group.getAttribute('id')
     print >> codefo, 'dnl'
     print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id)
+    translate_style(group, group_id, codefo, doc, 'GROUP_')
     for node in group.childNodes:
         if node.namespaceURI != svgns:
             continue