]> err.no Git - libchamplain/commitdiff
Have each ChamplainPolygon have their ClutterActor
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 10 Jun 2009 02:49:06 +0000 (22:49 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 10 Jun 2009 02:49:06 +0000 (22:49 -0400)
champlain/champlain-polygon.c
champlain/champlain-private.h
champlain/champlain-view.c

index 110541119404702aa667399471b6907c13d1ac9d..2a8d978a4f2c3bb3b534e8b1707b111de2d66b9c 100644 (file)
@@ -35,6 +35,7 @@
 #include "champlain-private.h"
 
 #include <clutter/clutter.h>
+#include <clutter-cairo/clutter-cairo.h>
 #include <glib.h>
 
 static ClutterColor DEFAULT_FILL_COLOR = {0xcc, 0x00, 0x00, 0xaa};
@@ -254,6 +255,8 @@ champlain_polygon_init (ChamplainPolygon *self)
 
   self->priv->fill_color = clutter_color_copy (&DEFAULT_FILL_COLOR);
   self->priv->stroke_color = clutter_color_copy (&DEFAULT_STROKE_COLOR);
+  self->priv->actor = g_object_ref (clutter_cairo_new (800, 600));
+  clutter_actor_set_position (self->priv->actor, 0, 0);
 }
 
 /**
index 37fa6c69cd79e68adfd0bbc943e48150d7a423d4..65e94e95a4083b130df3ba048673b2e0292cc766 100644 (file)
@@ -45,6 +45,7 @@ struct _ChamplainPolygonPrivate {
   ClutterColor *fill_color;
   gboolean stroke;
   gdouble stroke_width;
+  ClutterActor *actor;
 };
 
 typedef struct
index f27b8369da780eff7bf6fb00991fa9e12558ccb4..d204f6230482b6674423be8718b7f648b94829ab 100644 (file)
@@ -524,6 +524,7 @@ champlain_view_dispose (GObject *object)
 {
   ChamplainView *view = CHAMPLAIN_VIEW (object);
   ChamplainViewPrivate *priv = view->priv;
+  GList *polygons;
 
   if (priv->factory != NULL)
     {
@@ -579,6 +580,17 @@ champlain_view_dispose (GObject *object)
       priv->map = NULL;
     }
 
+  polygons = priv->polygons;
+  while (polygons != NULL)
+    {
+      ChamplainPolygon *polygon;
+
+      polygon = CHAMPLAIN_POLYGON (polygons->data);
+      polygons = polygons->next;
+      g_object_unref (polygon);
+      priv->polygons = g_list_remove (polygons, polygon);
+    }
+
   if (priv->goto_context != NULL)
     g_free (priv->goto_context);
 
@@ -861,12 +873,11 @@ champlain_view_init (ChamplainView *view)
   priv->polygons = NULL;
 
   /* Setup polygon layer */
-  priv->polygon_layer = g_object_ref (clutter_cairo_new (800, 600));
+  priv->polygon_layer = g_object_ref (clutter_group_new ());
   clutter_actor_show (priv->polygon_layer);
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport),
       priv->polygon_layer);
   clutter_actor_raise (priv->polygon_layer, priv->map_layer);
-  clutter_actor_set_position (priv->polygon_layer, 0, 0);
 
   champlain_view_set_size (view, priv->viewport_size.width,
       priv->viewport_size.height);
@@ -2179,10 +2190,18 @@ champlain_view_get_zoom_on_double_click (ChamplainView *view)
 }
 
 static void
-draw_polygon (ChamplainView *view, cairo_t *cr, ChamplainPolygon *polygon)
+draw_polygon (ChamplainView *view, ChamplainPolygon *polygon)
 {
+  cairo_t *cr;
   ChamplainViewPrivate *priv = view->priv;
 
+  cr = clutter_cairo_create (CLUTTER_CAIRO (polygon->priv->actor));
+
+  /* Clear the drawing area */
+  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+  cairo_rectangle (cr, 0, 0, 800, 600); //XXX
+  cairo_fill (cr);
+
   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
   GList *list = g_list_first (polygon->priv->points);
   while (list != NULL)
@@ -2224,6 +2243,8 @@ draw_polygon (ChamplainView *view, cairo_t *cr, ChamplainPolygon *polygon)
 
   if (polygon->priv->stroke)
     cairo_stroke (cr);
+
+  cairo_destroy (cr);
 }
 
 static void
@@ -2231,26 +2252,18 @@ view_update_polygons (ChamplainView *view)
 {
   ChamplainViewPrivate *priv = view->priv;
   GList *polygons;
-  cairo_t *cr;
   gint x, y;
 
   if (priv->polygons == NULL)
     return;
 
-  cr = clutter_cairo_create (CLUTTER_CAIRO (priv->polygon_layer));
-
-  /* Clear the drawing area */
-  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
-  cairo_rectangle (cr, 0, 0, 800, 600);
-  cairo_fill (cr);
-
   polygons = priv->polygons;
   while (polygons != NULL)
     {
       ChamplainPolygon *polygon;
 
       polygon = CHAMPLAIN_POLYGON (polygons->data);
-      draw_polygon (view, cr, polygon);
+      draw_polygon (view, polygon);
       polygons = polygons->next;
     }
 
@@ -2258,8 +2271,6 @@ view_update_polygons (ChamplainView *view)
   x = priv->viewport_size.x;
   y = priv->viewport_size.y;
 
-  cairo_destroy (cr);
-
   clutter_actor_set_position (priv->polygon_layer, x, y);
 }
 
@@ -2280,6 +2291,8 @@ champlain_view_add_polygon (ChamplainView *view,
   g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
 
   view->priv->polygons = g_list_append (view->priv->polygons, g_object_ref (polygon));
+  clutter_container_add_actor (CLUTTER_CONTAINER (view->priv->polygon_layer),
+      polygon->priv->actor);
 }
 
 /**
@@ -2299,5 +2312,7 @@ champlain_view_remove_polygon (ChamplainView *view,
   g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
 
   view->priv->polygons = g_list_remove (view->priv->polygons, polygon);
+  clutter_container_remove_actor (CLUTTER_CONTAINER (view->priv->polygon_layer),
+      polygon->priv->actor);
   g_object_unref (polygon);
 }