[libchamplain] label, layer, license, marker, scale should inherit from ClutterActor
- From: Jiří Techet <jiritechet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] label, layer, license, marker, scale should inherit from ClutterActor
- Date: Wed, 9 Feb 2011 08:40:10 +0000 (UTC)
commit 8d8614200cc98aebb64a82e8d2e0fcdb308f7842
Author: JiÅ?Ã Techet <techet gmail com>
Date: Sun Feb 6 15:01:41 2011 +0100
label, layer, license, marker, scale should inherit from ClutterActor
Inheriting from ClutterGroup exposes their inner structure outside
which breaks encapsulation.
champlain/champlain-label.c | 155 ++++++++++++++++++++++++++--
champlain/champlain-layer.c | 2 +-
champlain/champlain-layer.h | 4 +-
champlain/champlain-license.c | 144 +++++++++++++++++++++++++--
champlain/champlain-license.h | 4 +-
champlain/champlain-marker-layer.c | 195 +++++++++++++++++++++++++++++++-----
champlain/champlain-marker.c | 2 +-
champlain/champlain-marker.h | 4 +-
champlain/champlain-point.c | 140 ++++++++++++++++++++++++-
champlain/champlain-scale.c | 153 ++++++++++++++++++++++++++--
champlain/champlain-scale.h | 4 +-
champlain/champlain-tile.c | 4 +-
12 files changed, 738 insertions(+), 73 deletions(-)
---
diff --git a/champlain/champlain-label.c b/champlain/champlain-label.c
index 4d88f82..fef9f8e 100644
--- a/champlain/champlain-label.c
+++ b/champlain/champlain-label.c
@@ -103,6 +103,8 @@ struct _ChamplainLabelPrivate
ClutterActor *shadow;
ClutterActor *background;
guint redraw_id;
+
+ ClutterGroup *content_group;
};
G_DEFINE_TYPE (ChamplainLabel, champlain_label, CHAMPLAIN_TYPE_MARKER);
@@ -112,6 +114,23 @@ G_DEFINE_TYPE (ChamplainLabel, champlain_label, CHAMPLAIN_TYPE_MARKER);
static void draw_label (ChamplainLabel *label);
+static void paint (ClutterActor *self);
+static void pick (ClutterActor *self,
+ const ClutterColor *color);
+static void get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p);
+static void get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p);
+static void allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags);
+static void map (ClutterActor *self);
+static void unmap (ClutterActor *self);
+
/**
* champlain_label_set_highlight_color:
* @color: a #ClutterColor
@@ -345,6 +364,12 @@ champlain_label_dispose (GObject *object)
priv->attributes = NULL;
}
+ if (priv->content_group)
+ {
+ clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
+ priv->content_group = NULL;
+ }
+
G_OBJECT_CLASS (champlain_label_parent_class)->dispose (object);
}
@@ -389,17 +414,28 @@ champlain_label_finalize (GObject *object)
static void
-champlain_label_class_init (ChamplainLabelClass *labelClass)
+champlain_label_class_init (ChamplainLabelClass *klass)
{
- g_type_class_add_private (labelClass, sizeof (ChamplainLabelPrivate));
+ ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ChamplainLabelPrivate));
- GObjectClass *object_class = G_OBJECT_CLASS (labelClass);
object_class->finalize = champlain_label_finalize;
object_class->dispose = champlain_label_dispose;
object_class->get_property = champlain_label_get_property;
object_class->set_property = champlain_label_set_property;
- labelClass->draw_label = draw_label;
+ actor_class->get_preferred_width = get_preferred_width;
+ actor_class->get_preferred_height = get_preferred_height;
+ actor_class->allocate = allocate;
+ actor_class->paint = paint;
+ actor_class->pick = pick;
+ actor_class->map = map;
+ actor_class->unmap = unmap;
+
+ klass->draw_label = draw_label;
+
/**
* ChamplainLabel:text:
*
@@ -611,11 +647,11 @@ draw_shadow (ChamplainLabel *label,
clutter_actor_set_position (shadow, 0, height / 2.0);
- clutter_container_add_actor (CLUTTER_CONTAINER (label), shadow);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), shadow);
if (priv->shadow != NULL)
{
- clutter_container_remove_actor (CLUTTER_CONTAINER (label),
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->content_group),
priv->shadow);
g_object_unref (priv->shadow);
}
@@ -667,11 +703,11 @@ draw_background (ChamplainLabel *label,
cairo_stroke (cr);
cairo_destroy (cr);
- clutter_container_add_actor (CLUTTER_CONTAINER (label), bg);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), bg);
if (priv->background != NULL)
{
- clutter_container_remove_actor (CLUTTER_CONTAINER (label),
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->content_group),
priv->background);
g_object_unref (priv->background);
}
@@ -694,7 +730,7 @@ draw_label (ChamplainLabel *label)
total_width = clutter_actor_get_width (priv->image) + 2 * PADDING;
total_height = clutter_actor_get_height (priv->image) + 2 * PADDING;
if (clutter_actor_get_parent (priv->image) == NULL)
- clutter_container_add_actor (CLUTTER_CONTAINER (label), priv->image);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->image);
}
if (priv->text != NULL && strlen (priv->text) > 0)
@@ -735,7 +771,7 @@ draw_label (ChamplainLabel *label)
clutter_text_set_color (CLUTTER_TEXT (priv->text_actor),
(champlain_marker_get_highlighted (marker) ? &SELECTED_TEXT_COLOR : priv->text_color));
if (clutter_actor_get_parent (priv->text_actor) == NULL)
- clutter_container_add_actor (CLUTTER_CONTAINER (label), priv->text_actor);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->text_actor);
}
if (priv->text_actor == NULL && priv->image == NULL)
@@ -755,14 +791,14 @@ draw_label (ChamplainLabel *label)
{
if (priv->background != NULL)
{
- clutter_container_remove_actor (CLUTTER_CONTAINER (label), priv->background);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->content_group), priv->background);
g_object_unref (G_OBJECT (priv->background));
priv->background = NULL;
}
if (priv->shadow != NULL)
{
- clutter_container_remove_actor (CLUTTER_CONTAINER (label), priv->shadow);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->content_group), priv->shadow);
g_object_unref (G_OBJECT (priv->shadow));
priv->shadow = NULL;
}
@@ -862,6 +898,8 @@ champlain_label_init (ChamplainLabel *label)
priv->redraw_id = 0;
priv->shadow = NULL;
priv->text_actor = NULL;
+ priv->content_group = CLUTTER_GROUP (clutter_group_new ());
+ clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (label));
g_signal_connect (label, "notify::highlighted", G_CALLBACK (notify_highlighted), NULL);
}
@@ -883,6 +921,99 @@ champlain_label_new (void)
}
+static void
+paint (ClutterActor *self)
+{
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+pick (ClutterActor *self,
+ const ClutterColor *color)
+{
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_label_parent_class)->pick (self, color);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
+{
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+ for_height,
+ min_width_p,
+ natural_width_p);
+}
+
+
+static void
+get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p)
+{
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+ for_width,
+ min_height_p,
+ natural_height_p);
+}
+
+
+static void
+allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
+{
+ ClutterActorBox child_box;
+
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_label_parent_class)->allocate (self, box, flags);
+
+ child_box.x1 = 0;
+ child_box.x2 = box->x2 - box->x1;
+ child_box.y1 = 0;
+ child_box.y2 = box->y2 - box->y1;
+
+ clutter_actor_allocate (CLUTTER_ACTOR (priv->content_group), &child_box, flags);
+}
+
+
+static void
+map (ClutterActor *self)
+{
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_label_parent_class)->map (self);
+
+ clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+unmap (ClutterActor *self)
+{
+ ChamplainLabelPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_label_parent_class)->unmap (self);
+
+ clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+}
+
+
/**
* champlain_label_new_with_text:
* @text: the text of the text
diff --git a/champlain/champlain-layer.c b/champlain/champlain-layer.c
index 2bff295..ec589a4 100644
--- a/champlain/champlain-layer.c
+++ b/champlain/champlain-layer.c
@@ -18,7 +18,7 @@
#include "champlain-layer.h"
-G_DEFINE_TYPE (ChamplainLayer, champlain_layer, CLUTTER_TYPE_GROUP)
+G_DEFINE_TYPE (ChamplainLayer, champlain_layer, CLUTTER_TYPE_ACTOR)
static void
champlain_layer_dispose (GObject *object)
diff --git a/champlain/champlain-layer.h b/champlain/champlain-layer.h
index 6100b2c..f425ef3 100644
--- a/champlain/champlain-layer.h
+++ b/champlain/champlain-layer.h
@@ -50,12 +50,12 @@ typedef struct _ChamplainLayerClass ChamplainLayerClass;
struct _ChamplainLayer
{
- ClutterGroup parent;
+ ClutterActor parent;
};
struct _ChamplainLayerClass
{
- ClutterGroupClass parent_class;
+ ClutterActorClass parent_class;
void (*set_view)(ChamplainLayer *layer,
ChamplainView *view);
diff --git a/champlain/champlain-license.c b/champlain/champlain-license.c
index 99a18f2..d69cc19 100644
--- a/champlain/champlain-license.c
+++ b/champlain/champlain-license.c
@@ -52,11 +52,12 @@ struct _ChamplainLicensePrivate
{
gchar *extra_text; /* Extra license text */
ClutterActor *license_actor;
+ ClutterGroup *content_group;
ChamplainView *view;
};
-G_DEFINE_TYPE (ChamplainLicense, champlain_license, CLUTTER_TYPE_GROUP);
+G_DEFINE_TYPE (ChamplainLicense, champlain_license, CLUTTER_TYPE_ACTOR);
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_LICENSE, ChamplainLicensePrivate))
@@ -64,6 +65,24 @@ G_DEFINE_TYPE (ChamplainLicense, champlain_license, CLUTTER_TYPE_GROUP);
#define WIDTH_PADDING 10
#define HEIGHT_PADDING 7
+static void paint (ClutterActor *self);
+static void pick (ClutterActor *self,
+ const ClutterColor *color);
+static void get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p);
+static void get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p);
+static void allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags);
+static void map (ClutterActor *self);
+static void unmap (ClutterActor *self);
+
+
static void
champlain_license_get_property (GObject *object,
guint prop_id,
@@ -107,7 +126,13 @@ champlain_license_set_property (GObject *object,
static void
champlain_license_dispose (GObject *object)
{
-// ChamplainLicensePrivate *priv = CHAMPLAIN_LICENSE (object)->priv;
+ ChamplainLicensePrivate *priv = CHAMPLAIN_LICENSE (object)->priv;
+
+ if (priv->content_group)
+ {
+ clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
+ priv->content_group = NULL;
+ }
G_OBJECT_CLASS (champlain_license_parent_class)->dispose (object);
}
@@ -125,16 +150,26 @@ champlain_license_finalize (GObject *object)
static void
-champlain_license_class_init (ChamplainLicenseClass *license_class)
+champlain_license_class_init (ChamplainLicenseClass *klass)
{
- g_type_class_add_private (license_class, sizeof (ChamplainLicensePrivate));
+ ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ChamplainLicensePrivate));
- GObjectClass *object_class = G_OBJECT_CLASS (license_class);
object_class->finalize = champlain_license_finalize;
object_class->dispose = champlain_license_dispose;
object_class->get_property = champlain_license_get_property;
object_class->set_property = champlain_license_set_property;
+ actor_class->get_preferred_width = get_preferred_width;
+ actor_class->get_preferred_height = get_preferred_height;
+ actor_class->allocate = allocate;
+ actor_class->paint = paint;
+ actor_class->pick = pick;
+ actor_class->map = map;
+ actor_class->unmap = unmap;
+
/**
* ChamplainView:license-text:
*
@@ -196,7 +231,7 @@ create_license (ChamplainLicense *license)
clutter_text_set_font_name (CLUTTER_TEXT (priv->license_actor), "sans 8");
clutter_text_set_line_alignment (CLUTTER_TEXT (priv->license_actor), PANGO_ALIGN_RIGHT);
clutter_actor_set_opacity (priv->license_actor, 128);
- clutter_container_add_actor (CLUTTER_CONTAINER (license), priv->license_actor);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->license_actor);
}
@@ -209,7 +244,9 @@ champlain_license_init (ChamplainLicense *license)
priv->extra_text = NULL;
priv->view = NULL;
priv->license_actor = NULL;
-
+ priv->content_group = CLUTTER_GROUP (clutter_group_new ());
+ clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (license));
+
create_license (license);
}
@@ -222,6 +259,99 @@ champlain_license_new (void)
static void
+paint (ClutterActor *self)
+{
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+pick (ClutterActor *self,
+ const ClutterColor *color)
+{
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->pick (self, color);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
+{
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+ for_height,
+ min_width_p,
+ natural_width_p);
+}
+
+
+static void
+get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p)
+{
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+ for_width,
+ min_height_p,
+ natural_height_p);
+}
+
+
+static void
+allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
+{
+ ClutterActorBox child_box;
+
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->allocate (self, box, flags);
+
+ child_box.x1 = 0;
+ child_box.x2 = box->x2 - box->x1;
+ child_box.y1 = 0;
+ child_box.y2 = box->y2 - box->y1;
+
+ clutter_actor_allocate (CLUTTER_ACTOR (priv->content_group), &child_box, flags);
+}
+
+
+static void
+map (ClutterActor *self)
+{
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->map (self);
+
+ clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+unmap (ClutterActor *self)
+{
+ ChamplainLicensePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->unmap (self);
+
+ clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
redraw_license_cb (G_GNUC_UNUSED GObject *gobject,
G_GNUC_UNUSED GParamSpec *arg1,
ChamplainLicense *license)
diff --git a/champlain/champlain-license.h b/champlain/champlain-license.h
index 38144e9..23a67e9 100644
--- a/champlain/champlain-license.h
+++ b/champlain/champlain-license.h
@@ -55,14 +55,14 @@ typedef struct _ChamplainLicenseClass ChamplainLicenseClass;
struct _ChamplainLicense
{
- ClutterGroup parent;
+ ClutterActor parent;
ChamplainLicensePrivate *priv;
};
struct _ChamplainLicenseClass
{
- ClutterGroupClass parent_class;
+ ClutterActorClass parent_class;
};
GType champlain_license_get_type (void);
diff --git a/champlain/champlain-marker-layer.c b/champlain/champlain-marker-layer.c
index 33c0b50..9574a8b 100644
--- a/champlain/champlain-marker-layer.c
+++ b/champlain/champlain-marker-layer.c
@@ -80,8 +80,27 @@ struct _ChamplainMarkerLayerPrivate
gboolean stroke;
gdouble stroke_width;
gboolean visible;
+
+ ClutterGroup *content_group;
};
+static void paint (ClutterActor *self);
+static void pick (ClutterActor *self,
+ const ClutterColor *color);
+static void get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p);
+static void get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p);
+static void allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags);
+static void map (ClutterActor *self);
+static void unmap (ClutterActor *self);
+
static void marker_highlighted_cb (ChamplainMarker *marker,
G_GNUC_UNUSED GParamSpec *arg1,
@@ -210,6 +229,12 @@ champlain_marker_layer_dispose (GObject *object)
set_view (CHAMPLAIN_LAYER (self), NULL);
}
+ if (priv->content_group)
+ {
+ clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
+ priv->content_group = NULL;
+ }
+
G_OBJECT_CLASS (champlain_marker_layer_parent_class)->dispose (object);
}
@@ -230,6 +255,7 @@ champlain_marker_layer_finalize (GObject *object)
static void
champlain_marker_layer_class_init (ChamplainMarkerLayerClass *klass)
{
+ ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ChamplainLayerClass *layer_class = CHAMPLAIN_LAYER_CLASS (klass);
@@ -240,6 +266,14 @@ champlain_marker_layer_class_init (ChamplainMarkerLayerClass *klass)
object_class->get_property = champlain_marker_layer_get_property;
object_class->set_property = champlain_marker_layer_set_property;
+ actor_class->get_preferred_width = get_preferred_width;
+ actor_class->get_preferred_height = get_preferred_height;
+ actor_class->allocate = allocate;
+ actor_class->paint = paint;
+ actor_class->pick = pick;
+ actor_class->map = map;
+ actor_class->unmap = unmap;
+
layer_class->set_view = set_view;
/**
@@ -381,10 +415,13 @@ champlain_marker_layer_init (ChamplainMarkerLayer *self)
priv->fill_color = clutter_color_copy (&DEFAULT_FILL_COLOR);
priv->stroke_color = clutter_color_copy (&DEFAULT_STROKE_COLOR);
+
+ priv->content_group = CLUTTER_GROUP (clutter_group_new ());
+ clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (self));
//TODO destroy + ref()
priv->path_actor = clutter_group_new ();
- clutter_container_add_actor (CLUTTER_CONTAINER (self), priv->path_actor);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->path_actor);
}
@@ -407,15 +444,109 @@ champlain_marker_layer_new_full (ChamplainSelectionMode mode)
static void
+paint (ClutterActor *self)
+{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+pick (ClutterActor *self,
+ const ClutterColor *color)
+{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_marker_layer_parent_class)->pick (self, color);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
+{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+ for_height,
+ min_width_p,
+ natural_width_p);
+}
+
+
+static void
+get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p)
+{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+ for_width,
+ min_height_p,
+ natural_height_p);
+}
+
+
+static void
+allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
+{
+ ClutterActorBox child_box;
+
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_marker_layer_parent_class)->allocate (self, box, flags);
+
+ child_box.x1 = 0;
+ child_box.x2 = box->x2 - box->x1;
+ child_box.y1 = 0;
+ child_box.y2 = box->y2 - box->y1;
+
+ clutter_actor_allocate (CLUTTER_ACTOR (priv->content_group), &child_box, flags);
+}
+
+
+static void
+map (ClutterActor *self)
+{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_marker_layer_parent_class)->map (self);
+
+ clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+unmap (ClutterActor *self)
+{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_marker_layer_parent_class)->unmap (self);
+
+ clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
set_highlighted_all_but_one (ChamplainMarkerLayer *layer,
ChamplainMarker *not_highlighted,
gboolean highlight)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
int i;
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+ ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i);
ChamplainMarker *marker = CHAMPLAIN_MARKER (actor);
if (marker != not_highlighted)
@@ -513,6 +644,8 @@ void
champlain_marker_layer_add_marker (ChamplainMarkerLayer *layer,
ChamplainMarker *marker)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
+
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
@@ -527,7 +660,7 @@ champlain_marker_layer_add_marker (ChamplainMarkerLayer *layer,
g_signal_connect (G_OBJECT (marker), "moved",
G_CALLBACK (marker_move_by_cb), layer);
- clutter_container_add_actor (CLUTTER_CONTAINER (layer), CLUTTER_ACTOR (marker));
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), CLUTTER_ACTOR (marker));
set_marker_position (layer, marker);
redraw_path (layer);
}
@@ -546,6 +679,8 @@ void
champlain_marker_layer_remove_marker (ChamplainMarkerLayer *layer,
ChamplainMarker *marker)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
+
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
g_return_if_fail (CHAMPLAIN_IS_MARKER (marker));
@@ -555,7 +690,7 @@ champlain_marker_layer_remove_marker (ChamplainMarkerLayer *layer,
g_signal_handlers_disconnect_by_func (G_OBJECT (marker),
G_CALLBACK (marker_position_notify), layer);
- clutter_container_remove_actor (CLUTTER_CONTAINER (layer), CLUTTER_ACTOR (marker));
+ clutter_container_remove_actor (CLUTTER_CONTAINER (priv->content_group), CLUTTER_ACTOR (marker));
redraw_path (layer);
}
@@ -571,14 +706,16 @@ champlain_marker_layer_remove_marker (ChamplainMarkerLayer *layer,
void
champlain_marker_layer_animate_in_all_markers (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
+
guint i;
guint delay = 0;
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+ ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i);
ChamplainMarker *marker = CHAMPLAIN_MARKER (actor);
champlain_marker_animate_in_with_delay (marker, delay);
@@ -598,14 +735,16 @@ champlain_marker_layer_animate_in_all_markers (ChamplainMarkerLayer *layer)
void
champlain_marker_layer_animate_out_all_markers (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
+
guint i;
guint delay = 0;
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+ ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i);
ChamplainMarker *marker = CHAMPLAIN_MARKER (actor);
champlain_marker_animate_out_with_delay (marker, delay);
@@ -625,13 +764,14 @@ champlain_marker_layer_animate_out_all_markers (ChamplainMarkerLayer *layer)
void
champlain_marker_layer_show_all_markers (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
guint i;
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ClutterActor *marker = CLUTTER_ACTOR (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+ ClutterActor *marker = CLUTTER_ACTOR (clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i));
clutter_actor_show (marker);
}
@@ -648,13 +788,14 @@ champlain_marker_layer_show_all_markers (ChamplainMarkerLayer *layer)
void
champlain_marker_layer_hide_all_markers (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
guint i;
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ClutterActor *marker = CLUTTER_ACTOR (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+ ClutterActor *marker = CLUTTER_ACTOR (clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i));
clutter_actor_hide (marker);
}
@@ -664,13 +805,14 @@ champlain_marker_layer_hide_all_markers (ChamplainMarkerLayer *layer)
void
champlain_marker_layer_set_all_markers_movable (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
guint i;
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+ ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i));
champlain_marker_set_movable (marker, TRUE);
}
@@ -680,13 +822,14 @@ champlain_marker_layer_set_all_markers_movable (ChamplainMarkerLayer *layer)
void
champlain_marker_layer_set_all_markers_unmovable (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
guint i;
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+ ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i));
champlain_marker_set_movable (marker, FALSE);
}
@@ -708,16 +851,17 @@ champlain_marker_layer_set_all_markers_unmovable (ChamplainMarkerLayer *layer)
GSList *
champlain_marker_layer_get_selected_markers (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
GSList *lst = NULL;
g_return_val_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer), NULL);
gint i, n_children;
- n_children = clutter_group_get_n_children (CLUTTER_GROUP (layer));
+ n_children = clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group));
for (i = 1; i < n_children; i++)
{
- ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+ ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i);
lst = g_slist_prepend (lst, actor);
}
@@ -824,10 +968,10 @@ relocate (ChamplainMarkerLayer *layer)
g_return_if_fail (CHAMPLAIN_IS_VIEW (priv->view));
- n_children = clutter_group_get_n_children (CLUTTER_GROUP (layer));
+ n_children = clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group));
for (i = 1; i < n_children; i++)
{
- ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+ ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i);
ChamplainMarker *marker = CHAMPLAIN_MARKER (actor);
set_marker_position (layer, marker);
@@ -878,10 +1022,10 @@ redraw_path (ChamplainMarkerLayer *layer)
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (cairo_texture));
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- n_children = clutter_group_get_n_children (CLUTTER_GROUP (layer));
+ n_children = clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group));
for (i = 1; i < n_children; i++)
{
- ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (layer), i);
+ ClutterActor *actor = clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i);
ChamplainMarker *marker = CHAMPLAIN_MARKER (actor);
gfloat x, y;
@@ -975,6 +1119,7 @@ set_view (ChamplainLayer *layer,
ChamplainBoundingBox *
champlain_marker_layer_get_bounding_box (ChamplainMarkerLayer *layer)
{
+ ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
gint i = 0;
ChamplainBoundingBox *bbox;
@@ -984,9 +1129,9 @@ champlain_marker_layer_get_bounding_box (ChamplainMarkerLayer *layer)
bbox->bottom = CHAMPLAIN_MAX_LATITUDE;
bbox->top = CHAMPLAIN_MIN_LATITUDE;
- for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (priv->content_group)); i++)
{
- ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
+ ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (priv->content_group), i));
gdouble lat, lon;
g_object_get (G_OBJECT (marker), "latitude", &lat, "longitude", &lon,
diff --git a/champlain/champlain-marker.c b/champlain/champlain-marker.c
index 6aa8050..a3f073d 100644
--- a/champlain/champlain-marker.c
+++ b/champlain/champlain-marker.c
@@ -71,7 +71,7 @@ enum
/* static guint champlain_marker_signals[LAST_SIGNAL] = { 0, }; */
-G_DEFINE_TYPE (ChamplainMarker, champlain_marker, CLUTTER_TYPE_GROUP);
+G_DEFINE_TYPE (ChamplainMarker, champlain_marker, CLUTTER_TYPE_ACTOR);
#define CHAMPLAIN_MARKER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_MARKER, ChamplainMarkerPrivate))
diff --git a/champlain/champlain-marker.h b/champlain/champlain-marker.h
index 2590d3a..0d3a640 100644
--- a/champlain/champlain-marker.h
+++ b/champlain/champlain-marker.h
@@ -56,14 +56,14 @@ typedef struct _ChamplainMarkerClass ChamplainMarkerClass;
struct _ChamplainMarker
{
- ClutterGroup group;
+ ClutterActor parent;
ChamplainMarkerPrivate *priv;
};
struct _ChamplainMarkerClass
{
- ClutterGroupClass parent_class;
+ ClutterActorClass parent_class;
};
GType champlain_marker_get_type (void);
diff --git a/champlain/champlain-point.c b/champlain/champlain-point.c
index e107fc3..2e33560 100644
--- a/champlain/champlain-point.c
+++ b/champlain/champlain-point.c
@@ -57,6 +57,7 @@ struct _ChamplainPointPrivate
{
ClutterColor *color;
gdouble size;
+ ClutterGroup *content_group;
guint redraw_id;
};
@@ -66,6 +67,23 @@ G_DEFINE_TYPE (ChamplainPoint, champlain_point, CHAMPLAIN_TYPE_MARKER);
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_POINT, ChamplainPointPrivate))
+static void paint (ClutterActor *self);
+static void pick (ClutterActor *self,
+ const ClutterColor *color);
+static void get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p);
+static void get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p);
+static void allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags);
+static void map (ClutterActor *self);
+static void unmap (ClutterActor *self);
+
static void draw_point (ChamplainPoint *point);
/**
@@ -155,7 +173,13 @@ champlain_point_set_property (GObject *object,
static void
champlain_point_dispose (GObject *object)
{
-// ChamplainPointPrivate *priv = CHAMPLAIN_POINT (object)->priv;
+ ChamplainPointPrivate *priv = CHAMPLAIN_POINT (object)->priv;
+
+ if (priv->content_group)
+ {
+ clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
+ priv->content_group = NULL;
+ }
G_OBJECT_CLASS (champlain_point_parent_class)->dispose (object);
}
@@ -177,16 +201,26 @@ champlain_point_finalize (GObject *object)
static void
-champlain_point_class_init (ChamplainPointClass *pointClass)
+champlain_point_class_init (ChamplainPointClass *klass)
{
- g_type_class_add_private (pointClass, sizeof (ChamplainPointPrivate));
+ ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ChamplainPointPrivate));
- GObjectClass *object_class = G_OBJECT_CLASS (pointClass);
object_class->finalize = champlain_point_finalize;
object_class->dispose = champlain_point_dispose;
object_class->get_property = champlain_point_get_property;
object_class->set_property = champlain_point_set_property;
+ actor_class->get_preferred_width = get_preferred_width;
+ actor_class->get_preferred_height = get_preferred_height;
+ actor_class->allocate = allocate;
+ actor_class->paint = paint;
+ actor_class->pick = pick;
+ actor_class->map = map;
+ actor_class->unmap = unmap;
+
g_object_class_install_property (object_class, PROP_COLOR,
clutter_param_spec_color ("color", "Color", "The point's color",
&DEFAULT_COLOR, CHAMPLAIN_PARAM_READWRITE));
@@ -207,9 +241,9 @@ draw_point (ChamplainPoint *point)
gdouble radius = size / 2.0;
ClutterColor *color;
- clutter_group_remove_all (CLUTTER_GROUP (point));
+ clutter_group_remove_all (CLUTTER_GROUP (priv->content_group));
cairo_texture = clutter_cairo_texture_new (size, size);
- clutter_container_add_actor (CLUTTER_CONTAINER (point), cairo_texture);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), cairo_texture);
clutter_actor_set_anchor_point (CLUTTER_ACTOR (point), radius, radius);
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (cairo_texture));
@@ -255,6 +289,8 @@ champlain_point_init (ChamplainPoint *point)
priv->color = clutter_color_copy (&DEFAULT_COLOR);
priv->size = 12;
+ priv->content_group = CLUTTER_GROUP (clutter_group_new ());
+ clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (point));
draw_point (point);
@@ -281,6 +317,98 @@ champlain_point_new_full (gdouble size,
return CLUTTER_ACTOR (point);
}
+static void
+paint (ClutterActor *self)
+{
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+pick (ClutterActor *self,
+ const ClutterColor *color)
+{
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_point_parent_class)->pick (self, color);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
+{
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+ for_height,
+ min_width_p,
+ natural_width_p);
+}
+
+
+static void
+get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p)
+{
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+ for_width,
+ min_height_p,
+ natural_height_p);
+}
+
+
+static void
+allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
+{
+ ClutterActorBox child_box;
+
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_point_parent_class)->allocate (self, box, flags);
+
+ child_box.x1 = 0;
+ child_box.x2 = box->x2 - box->x1;
+ child_box.y1 = 0;
+ child_box.y2 = box->y2 - box->y1;
+
+ clutter_actor_allocate (CLUTTER_ACTOR (priv->content_group), &child_box, flags);
+}
+
+
+static void
+map (ClutterActor *self)
+{
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_point_parent_class)->map (self);
+
+ clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+unmap (ClutterActor *self)
+{
+ ChamplainPointPrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_point_parent_class)->unmap (self);
+
+ clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+}
+
void
champlain_point_set_size (ChamplainPoint *point,
diff --git a/champlain/champlain-scale.c b/champlain/champlain-scale.c
index 7a504dd..9cd5fb4 100644
--- a/champlain/champlain-scale.c
+++ b/champlain/champlain-scale.c
@@ -54,11 +54,12 @@ struct _ChamplainScalePrivate
ChamplainUnit scale_unit;
guint max_scale_width;
gfloat text_height;
+ ClutterGroup *content_group;
ChamplainView *view;
};
-G_DEFINE_TYPE (ChamplainScale, champlain_scale, CLUTTER_TYPE_GROUP);
+G_DEFINE_TYPE (ChamplainScale, champlain_scale, CLUTTER_TYPE_ACTOR);
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_SCALE, ChamplainScalePrivate))
@@ -69,6 +70,22 @@ G_DEFINE_TYPE (ChamplainScale, champlain_scale, CLUTTER_TYPE_GROUP);
#define SCALE_INSIDE_PADDING 10
#define SCALE_LINE_WIDTH 2
+static void paint (ClutterActor *self);
+static void pick (ClutterActor *self,
+ const ClutterColor *color);
+static void get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p);
+static void get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p);
+static void allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags);
+static void map (ClutterActor *self);
+static void unmap (ClutterActor *self);
static void
@@ -123,7 +140,13 @@ champlain_scale_set_property (GObject *object,
static void
champlain_scale_dispose (GObject *object)
{
-// ChamplainScalePrivate *priv = CHAMPLAIN_SCALE (object)->priv;
+ ChamplainScalePrivate *priv = CHAMPLAIN_SCALE (object)->priv;
+
+ if (priv->content_group)
+ {
+ clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
+ priv->content_group = NULL;
+ }
G_OBJECT_CLASS (champlain_scale_parent_class)->dispose (object);
}
@@ -139,16 +162,26 @@ champlain_scale_finalize (GObject *object)
static void
-champlain_scale_class_init (ChamplainScaleClass *scale_class)
+champlain_scale_class_init (ChamplainScaleClass *klass)
{
- g_type_class_add_private (scale_class, sizeof (ChamplainScalePrivate));
+ ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ChamplainScalePrivate));
- GObjectClass *object_class = G_OBJECT_CLASS (scale_class);
object_class->finalize = champlain_scale_finalize;
object_class->dispose = champlain_scale_dispose;
object_class->get_property = champlain_scale_get_property;
object_class->set_property = champlain_scale_set_property;
+ actor_class->get_preferred_width = get_preferred_width;
+ actor_class->get_preferred_height = get_preferred_height;
+ actor_class->allocate = allocate;
+ actor_class->paint = paint;
+ actor_class->pick = pick;
+ actor_class->map = map;
+ actor_class->unmap = unmap;
+
/**
* ChamplainScale:max-width:
*
@@ -270,7 +303,7 @@ redraw_scale (ChamplainScale *scale)
}
} while (!final_unit);
- text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (scale), "scale-far-label");
+ text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (priv->content_group), "scale-far-label");
label = g_strdup_printf ("%g", base);
/* Get only digits width for centering */
clutter_text_set_text (CLUTTER_TEXT (text), label);
@@ -285,7 +318,7 @@ redraw_scale (ChamplainScale *scale)
g_free (label);
clutter_actor_set_position (text, (scale_width - width / 2) + SCALE_INSIDE_PADDING, SCALE_INSIDE_PADDING);
- text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (scale), "scale-mid-label");
+ text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (priv->content_group), "scale-mid-label");
label = g_strdup_printf ("%g", base / 2.0);
clutter_text_set_text (CLUTTER_TEXT (text), label);
clutter_actor_get_size (text, &width, &height);
@@ -293,7 +326,7 @@ redraw_scale (ChamplainScale *scale)
g_free (label);
/* Draw the line */
- line = clutter_container_find_child_by_name (CLUTTER_CONTAINER (scale), "scale-line");
+ line = clutter_container_find_child_by_name (CLUTTER_CONTAINER (priv->content_group), "scale-line");
clutter_cairo_texture_clear (CLUTTER_CAIRO_TEXTURE (line));
cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (line));
@@ -336,20 +369,20 @@ create_scale (ChamplainScale *scale)
text = clutter_text_new_with_text ("Sans 9", "X km");
clutter_actor_set_name (text, "scale-far-label");
- clutter_container_add_actor (CLUTTER_CONTAINER (scale), text);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), text);
text = clutter_text_new_with_text ("Sans 9", "X km");
clutter_actor_set_name (text, "scale-mid-label");
- clutter_container_add_actor (CLUTTER_CONTAINER (scale), text);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), text);
text = clutter_text_new_with_text ("Sans 9", "0");
- clutter_container_add_actor (CLUTTER_CONTAINER (scale), text);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), text);
clutter_actor_get_size (text, &width, &priv->text_height);
clutter_actor_set_position (text, SCALE_INSIDE_PADDING - width / 2, SCALE_INSIDE_PADDING);
scale_actor = clutter_cairo_texture_new (priv->max_scale_width + 2 * SCALE_INSIDE_PADDING, SCALE_HEIGHT + priv->text_height + GAP_SIZE + 2*SCALE_INSIDE_PADDING);
clutter_actor_set_name (scale_actor, "scale-line");
- clutter_container_add_actor (CLUTTER_CONTAINER (scale), scale_actor);
+ clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), scale_actor);
clutter_actor_set_opacity (CLUTTER_ACTOR (scale), 200);
}
@@ -365,6 +398,8 @@ champlain_scale_init (ChamplainScale *scale)
priv->scale_unit = CHAMPLAIN_UNIT_KM;
priv->max_scale_width = 100;
priv->view = NULL;
+ priv->content_group = CLUTTER_GROUP (clutter_group_new ());
+ clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (scale));
create_scale (scale);
}
@@ -376,6 +411,100 @@ champlain_scale_new (void)
return CLUTTER_ACTOR (g_object_new (CHAMPLAIN_TYPE_SCALE, NULL));
}
+
+static void
+paint (ClutterActor *self)
+{
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+pick (ClutterActor *self,
+ const ClutterColor *color)
+{
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_scale_parent_class)->pick (self, color);
+
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+get_preferred_width (ClutterActor *self,
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
+{
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+ for_height,
+ min_width_p,
+ natural_width_p);
+}
+
+
+static void
+get_preferred_height (ClutterActor *self,
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p)
+{
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+ for_width,
+ min_height_p,
+ natural_height_p);
+}
+
+
+static void
+allocate (ClutterActor *self,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
+{
+ ClutterActorBox child_box;
+
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_scale_parent_class)->allocate (self, box, flags);
+
+ child_box.x1 = 0;
+ child_box.x2 = box->x2 - box->x1;
+ child_box.y1 = 0;
+ child_box.y2 = box->y2 - box->y1;
+
+ clutter_actor_allocate (CLUTTER_ACTOR (priv->content_group), &child_box, flags);
+}
+
+
+static void
+map (ClutterActor *self)
+{
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_scale_parent_class)->map (self);
+
+ clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+unmap (ClutterActor *self)
+{
+ ChamplainScalePrivate *priv = GET_PRIVATE (self);
+
+ CLUTTER_ACTOR_CLASS (champlain_scale_parent_class)->unmap (self);
+
+ clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+}
+
+
/**
* champlain_scale_set_max_width:
* @scale: a #ChamplainScale
diff --git a/champlain/champlain-scale.h b/champlain/champlain-scale.h
index cfd6e7c..ae15946 100644
--- a/champlain/champlain-scale.h
+++ b/champlain/champlain-scale.h
@@ -67,14 +67,14 @@ typedef enum
struct _ChamplainScale
{
- ClutterGroup parent;
+ ClutterActor parent;
ChamplainScalePrivate *priv;
};
struct _ChamplainScaleClass
{
- ClutterGroupClass parent_class;
+ ClutterActorClass parent_class;
};
GType champlain_scale_get_type (void);
diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c
index f6fbc4a..540a2a9 100644
--- a/champlain/champlain-tile.c
+++ b/champlain/champlain-tile.c
@@ -449,9 +449,11 @@ static void
pick (ClutterActor *self,
const ClutterColor *color)
{
+ ChamplainTilePrivate *priv = GET_PRIVATE (self);
+
CLUTTER_ACTOR_CLASS (champlain_tile_parent_class)->pick (self, color);
- paint (self);
+ clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]