[libchamplain] Have each ChamplainPolygon have their ClutterActor
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: svn-commits-list gnome org
- Subject: [libchamplain] Have each ChamplainPolygon have their ClutterActor
- Date: Fri, 12 Jun 2009 00:58:18 -0400 (EDT)
commit cf2c24db4a63ac5d7301b39442588247d80c2bf6
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date: Tue Jun 9 22:49:06 2009 -0400
Have each ChamplainPolygon have their ClutterActor
champlain/champlain-polygon.c | 3 ++
champlain/champlain-private.h | 1 +
champlain/champlain-view.c | 43 +++++++++++++++++++++++++++-------------
3 files changed, 33 insertions(+), 14 deletions(-)
---
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 <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);
}
/**
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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]