[dia] Bug 607570: introduce DiaRenderer::draw_layer() ...



commit 4beb64eab817e48d385dcd107ee819a5d91d09bb
Author: Hans Breuer <hans breuer org>
Date:   Sat Sep 29 20:10:26 2012 +0200

    Bug 607570: introduce DiaRenderer::draw_layer() ...
    
    ... and use it in data_render() if no special ObjRenderer function
    is given. This way it is available to most plug-ins without a
    change there. Bump plug-in API version as this is ABI breaking.

 lib/diagramdata.c |   11 +++++++----
 lib/diarenderer.c |   37 +++++++++++++++++++++++++++++++++++++
 lib/diarenderer.h |    4 +++-
 lib/plug-ins.h    |    8 ++++++--
 4 files changed, 53 insertions(+), 7 deletions(-)
---
diff --git a/lib/diagramdata.c b/lib/diagramdata.c
index 085e8ca..0fa70a4 100644
--- a/lib/diagramdata.c
+++ b/lib/diagramdata.c
@@ -804,8 +804,7 @@ data_emit(DiagramData *data, Layer *layer, DiaObject* obj,
  */
 void
 data_render(DiagramData *data, DiaRenderer *renderer, Rectangle *update,
-	    ObjectRenderer obj_renderer,
-	    gpointer gdata)
+	    ObjectRenderer obj_renderer, gpointer gdata)
 {
   Layer *layer;
   guint i, active_layer;
@@ -816,8 +815,12 @@ data_render(DiagramData *data, DiaRenderer *renderer, Rectangle *update,
   for (i=0; i<data->layers->len; i++) {
     layer = (Layer *) g_ptr_array_index(data->layers, i);
     active_layer = (layer == data->active_layer);
-    if (layer->visible)
-      layer_render(layer, renderer, update, obj_renderer, gdata, active_layer);
+    if (layer->visible) {
+      if (obj_renderer)
+        layer_render(layer, renderer, update, obj_renderer, gdata, active_layer);
+      else
+        (DIA_RENDERER_GET_CLASS(renderer)->draw_layer)(renderer, layer, active_layer, update);
+    }
   }
   
   if (!renderer->is_interactive) 
diff --git a/lib/diarenderer.c b/lib/diarenderer.c
index 7e52540..da3f5ee 100644
--- a/lib/diarenderer.c
+++ b/lib/diarenderer.c
@@ -202,6 +202,42 @@ dia_renderer_get_type (void)
   return object_type;
 }
 
+/*! 
+ * \brief Render all the visible object in the layer
+ * @param renderer explicit this pointer
+ * @param layer    layer to draw
+ * @param active   TRUE if it is the currently active layer
+ * @param update   the update rectangle, NULL for unlimited
+ * Given an update rectangle the default implementation calls the draw_object()
+ * member only for intersected objects. This method does _not_ care for layer
+ * visibility, though. If an exporter wants to 'see' also invisible
+ * layers this method needs to be overwritten. Also it does not pass any
+ * matrix to draw_object().
+ * \memberof DiaRenderer
+ */
+static void
+draw_layer (DiaRenderer *renderer,
+	    Layer       *layer,
+	    gboolean     active,
+	    Rectangle   *update)
+{
+  GList *list = layer->objects;
+  void (*func) (DiaRenderer*, DiaObject *, DiaMatrix *);
+
+  g_return_if_fail (layer != NULL);
+
+  func = DIA_RENDERER_GET_CLASS(renderer)->draw_object;
+  /* Draw all objects  */
+  while (list!=NULL) {
+    DiaObject *obj = (DiaObject *) list->data;
+
+    if (update==NULL || rectangle_intersects(update, dia_object_get_enclosing_box(obj))) {
+      (*func)(renderer, obj, NULL);
+    }
+    list = g_list_next(list);
+  }
+}
+
 static void
 draw_object (DiaRenderer *renderer,
 	     DiaObject   *object,
@@ -261,6 +297,7 @@ dia_renderer_class_init (DiaRendererClass *klass)
 
   renderer_class->get_width_pixels  = get_width_pixels;
   renderer_class->get_height_pixels = get_height_pixels;
+  renderer_class->draw_layer = draw_layer;
   renderer_class->draw_object = draw_object;
   renderer_class->get_text_width = get_text_width;
 
diff --git a/lib/diarenderer.h b/lib/diarenderer.h
index d9f3ae0..e20390e 100644
--- a/lib/diarenderer.h
+++ b/lib/diarenderer.h
@@ -87,7 +87,9 @@ struct _DiaRendererClass
   int (*get_width_pixels) (DiaRenderer*);
   /*! return width in pixels, only for interactive renderers */
   int (*get_height_pixels) (DiaRenderer*);
-  /*! Calls the objects draw function, which calls this again 
+  /*! \brief Render all the visible object in the layer */
+  void (*draw_layer) (DiaRenderer*, Layer *, gboolean, Rectangle *);
+  /*! Calls the objects draw function, which calls the renderer again 
    *  Affine transforamtion is mostly done on the renderer side for matrix!=NULL */
   void (*draw_object) (DiaRenderer*, DiaObject*, DiaMatrix*);
   /*! Returns the EXACT width of text in cm, using the current font.
diff --git a/lib/plug-ins.h b/lib/plug-ins.h
index d999929..9cf44d5 100644
--- a/lib/plug-ins.h
+++ b/lib/plug-ins.h
@@ -28,7 +28,9 @@
 
 G_BEGIN_DECLS
 
-/*
+/*!
+ * \brief Plug-in API version for breaking binary compatibility
+ *
  * The api version to ensure dia core and the plug-ins agree on
  * talking about the same thing. If some incompatible change is 
  * made to the interface between plug-ins and core it needs to
@@ -47,8 +49,10 @@ G_BEGIN_DECLS
  *    could have been avoided this way)
  * The list is by no means complete. If in doubt about your change
  * please ask on dia-list or alternative increment ;-)      --hb
+ *
+ * \ingroup Plugins
  */
-#define DIA_PLUGIN_API_VERSION 17
+#define DIA_PLUGIN_API_VERSION 18
 
 typedef enum {
   DIA_PLUGIN_INIT_OK,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]