From: Pierre-Luc Beaudoin Date: Wed, 10 Jun 2009 02:49:06 +0000 (-0400) Subject: Have each ChamplainPolygon have their ClutterActor X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf2c24db4a63ac5d7301b39442588247d80c2bf6;p=libchamplain Have each ChamplainPolygon have their ClutterActor --- diff --git a/champlain/champlain-polygon.c b/champlain/champlain-polygon.c index 1105411..2a8d978 100644 --- a/champlain/champlain-polygon.c +++ b/champlain/champlain-polygon.c @@ -35,6 +35,7 @@ #include "champlain-private.h" #include +#include #include 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); } /** diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h index 37fa6c6..65e94e9 100644 --- a/champlain/champlain-private.h +++ b/champlain/champlain-private.h @@ -45,6 +45,7 @@ struct _ChamplainPolygonPrivate { ClutterColor *fill_color; gboolean stroke; gdouble stroke_width; + ClutterActor *actor; }; typedef struct diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index f27b836..d204f62 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -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); }