]> err.no Git - libchamplain/commitdiff
Redraw polygons when their properties change and points are changed
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 14 Jun 2009 17:47:30 +0000 (13:47 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 14 Jun 2009 17:47:30 +0000 (13:47 -0400)
champlain/champlain-polygon.c
champlain/champlain-view.c

index 7cb316ee1b91dc1d32a123c17c4e498803c455f8..c592c8d308abc037db2cb64e583e8f88b1d32d86 100644 (file)
@@ -320,6 +320,7 @@ champlain_polygon_append_point (ChamplainPolygon *self,
   ChamplainPoint *point = champlain_point_new (lat, lon);
 
   self->priv->points = g_list_append (self->priv->points, point);
+  g_object_notify (G_OBJECT (self), "visible");
   return point;
 }
 
@@ -347,6 +348,7 @@ champlain_polygon_insert_point (ChamplainPolygon *self,
   ChamplainPoint *point = champlain_point_new (lat, lon);
 
   self->priv->points = g_list_insert (self->priv->points, point, pos);
+  g_object_notify (G_OBJECT (self), "visible");
   return point;
 }
 
@@ -370,6 +372,7 @@ champlain_polygon_clear_points (ChamplainPolygon *self)
     next = g_list_next (next);
   }
   g_list_free (self->priv->points);
+  g_object_notify (G_OBJECT (self), "visible");
 }
 
 /**
index 84f3fb372c6c631f96bcf62a8ae2c01619e9217f..95109bb869c0a3ec87ecc8dcbf56d39f437c6bf2 100644 (file)
@@ -115,6 +115,11 @@ typedef struct {
   gdouble from_longitude;
 } GoToContext;
 
+typedef struct {
+  ChamplainView *view;
+  ChamplainPolygon *polygon;
+} PolygonRedrawContext;
+
 struct _ChamplainViewPrivate
 {
   ClutterActor *stage;
@@ -156,6 +161,9 @@ struct _ChamplainViewPrivate
   /* champlain_view_go_to's context, kept for stop_go_to */
   GoToContext *goto_context;
 
+  /* notify_polygon_cb's context, kept for idle cb */
+  guint polygon_redraw_id;
+
   /* Lines and shapes */
   GList *polygons;
   ClutterActor *polygon_layer;  /* Contains the polygons */
@@ -427,12 +435,31 @@ draw_polygon (ChamplainView *view, ChamplainPolygon *polygon)
   cairo_destroy (cr);
 }
 
+static gboolean
+redraw_polygon_on_idle (PolygonRedrawContext *ctx)
+{
+  draw_polygon (ctx->view, ctx->polygon);
+  ctx->view->priv->polygon_redraw_id = 0;
+  // ctx is freed by g_idle_add_full
+  return FALSE;
+}
+
 static void
-notify_polygon_visible_cb (ChamplainPolygon *polygon,
+notify_polygon_cb (ChamplainPolygon *polygon,
     GParamSpec *arg1,
     ChamplainView *view)
 {
-  draw_polygon (view, polygon);
+  PolygonRedrawContext *ctx;
+
+  if (view->priv->polygon_redraw_id != 0)
+    return;
+
+  ctx = g_new0 (PolygonRedrawContext, 1);
+  ctx->view = view;
+  ctx->polygon = polygon;
+
+  view->priv->polygon_redraw_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+      (GSourceFunc) redraw_polygon_on_idle, ctx, g_free);
 }
 
 static void
@@ -939,6 +966,7 @@ champlain_view_init (ChamplainView *view)
   priv->longitude = 0.0f;
   priv->goto_context = NULL;
   priv->map = NULL;
+  priv->polygon_redraw_id = 0;
 
   /* Setup viewport */
   priv->viewport = g_object_ref (tidy_viewport_new ());
@@ -2363,8 +2391,8 @@ champlain_view_add_polygon (ChamplainView *view,
 
   view->priv->polygons = g_list_append (view->priv->polygons, g_object_ref (polygon));
 
-  g_signal_connect (polygon, "notify::visible",
-      G_CALLBACK (notify_polygon_visible_cb), view);
+  g_signal_connect (polygon, "notify",
+      G_CALLBACK (notify_polygon_cb), view);
 
   if (view->priv->viewport_size.width == 0 ||
       view->priv->viewport_size.height == 0)