[libchamplain] Introduce ChamplainCustomMarker implementing ClutterContainer interface



commit 1c6444fdeffdc101ca2d866dd39afc3a614994a6
Author: JiÅ?í Techet <techet gmail com>
Date:   Wed Feb 9 09:27:08 2011 +0100

    Introduce ChamplainCustomMarker implementing ClutterContainer interface

 champlain/Makefile.am               |    2 +
 champlain/champlain-custom-marker.c |  299 +++++++++++++++++++++++++++++++++++
 champlain/champlain-custom-marker.h |   73 +++++++++
 champlain/champlain-marker.c        |   49 ++----
 champlain/champlain-marker.h        |    1 -
 champlain/champlain.h               |    1 +
 demos/animated-marker.c             |    4 +-
 demos/url-marker.c                  |    3 +-
 8 files changed, 392 insertions(+), 40 deletions(-)
---
diff --git a/champlain/Makefile.am b/champlain/Makefile.am
index 0d4b72b..9c0b284 100644
--- a/champlain/Makefile.am
+++ b/champlain/Makefile.am
@@ -15,6 +15,7 @@ libchamplain_headers_public = 				\
 	$(srcdir)/champlain.h 				\
 	$(srcdir)/champlain-defines.h			\
 	$(srcdir)/champlain-point.h			\
+	$(srcdir)/champlain-custom-marker.h			\
 	$(srcdir)/champlain-view.h			\
 	$(srcdir)/champlain-layer.h 			\
 	$(srcdir)/champlain-marker-layer.h 			\
@@ -71,6 +72,7 @@ libchamplain_sources =					\
 	$(srcdir)/champlain-map-source-factory.c	\
 	$(srcdir)/champlain-map-source-desc.c		\
 	$(srcdir)/champlain-point.c			\
+	$(srcdir)/champlain-custom-marker.c			\
 	$(srcdir)/champlain-renderer.c			\
 	$(srcdir)/champlain-image-renderer.c		\
 	$(srcdir)/champlain-error-tile-renderer.c	\
diff --git a/champlain/champlain-custom-marker.c b/champlain/champlain-custom-marker.c
new file mode 100644
index 0000000..d85cc27
--- /dev/null
+++ b/champlain/champlain-custom-marker.c
@@ -0,0 +1,299 @@
+/*
+ * Copyright (C) 2011 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/**
+ * SECTION:champlain-custom-marker
+ * @short_description: #ChamplainCustom marker is a marker implementing the
+ * #ClutterContainer interface. 
+ * 
+ * #ChamplainCustom marker is a marker implementing the #ClutterContainer 
+ * interface. You can insert your custom actors into the container. Don't forget 
+ * to set the anchor position in the marker using #clutter_actor_set_anchor_point.
+ */
+
+#include "config.h"
+
+#include "champlain.h"
+#include "champlain-defines.h"
+#include "champlain-marshal.h"
+#include "champlain-private.h"
+
+#include <clutter/clutter.h>
+#include <glib.h>
+#include <glib-object.h>
+
+
+enum
+{
+  /* normal signals */
+  LAST_SIGNAL
+};
+
+enum
+{
+  PROP_0,
+};
+
+/* static guint champlain_custom_marker_signals[LAST_SIGNAL] = { 0, }; */
+
+struct _ChamplainCustomMarkerPrivate
+{
+  ClutterContainer *content_group;
+};
+
+static void
+clutter_container_iface_init (ClutterContainerIface *iface);
+
+
+G_DEFINE_TYPE_WITH_CODE (ChamplainCustomMarker, champlain_custom_marker, CHAMPLAIN_TYPE_MARKER,
+                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
+                                                clutter_container_iface_init));
+
+
+#define GET_PRIVATE(obj) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CHAMPLAIN_TYPE_CUSTOM_MARKER, ChamplainCustomMarkerPrivate))
+
+
+
+static void
+add_actor (ClutterContainer *container,
+    ClutterActor *actor)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (container);
+  
+  clutter_container_add_actor (priv->content_group, actor);  
+}
+
+static void
+remove_actor (ClutterContainer *container,
+    ClutterActor *actor)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (container);
+  
+  clutter_container_remove_actor (priv->content_group, actor);  
+}
+
+static void
+foreach_actor (ClutterContainer *container,
+    ClutterCallback callback,
+    gpointer user_data)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (container);
+  
+  clutter_container_foreach (priv->content_group, callback, user_data);  
+}
+
+static void
+raise_actor (ClutterContainer *container,
+    ClutterActor *actor,
+    ClutterActor *sibling)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (container);
+  
+  clutter_container_raise_child (priv->content_group, actor, sibling);  
+}
+
+static void
+lower_actor (ClutterContainer *container,
+    ClutterActor *actor,
+    ClutterActor *sibling)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (container);
+  
+  clutter_container_lower_child (priv->content_group, actor, sibling);  
+}
+
+static void
+sort_depth_order (ClutterContainer *container)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (container);
+  
+  clutter_container_sort_depth_order (priv->content_group);  
+}
+
+static void
+clutter_container_iface_init (ClutterContainerIface *iface)
+{
+  iface->add = add_actor;
+  iface->remove = remove_actor;
+  iface->foreach = foreach_actor;
+  iface->raise = raise_actor;
+  iface->lower = lower_actor;
+  iface->sort_depth_order = sort_depth_order;
+}
+
+
+static void
+paint (ClutterActor *actor)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (actor);
+
+  clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+static void
+pick (ClutterActor       *actor,
+                         const ClutterColor *color)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (actor);
+
+  CLUTTER_ACTOR_CLASS (champlain_custom_marker_parent_class)->pick (actor, color);
+
+  clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+}
+
+static void
+get_preferred_width (ClutterActor *actor,
+                                        gfloat        for_height,
+                                        gfloat       *min_width,
+                                        gfloat       *natural_width)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (actor);
+
+  clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+      for_height,
+      min_width,
+      natural_width);
+}
+
+static void
+get_preferred_height (ClutterActor *actor,
+                                         gfloat        for_width,
+                                         gfloat       *min_height,
+                                         gfloat       *natural_height)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (actor);
+
+  clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+      for_width,
+      min_height,
+      natural_height);
+}
+
+static void
+allocate (ClutterActor *actor,
+    const ClutterActorBox *box,
+    ClutterAllocationFlags flags)
+{
+  ClutterActorBox child_box;
+
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (actor);
+
+  CLUTTER_ACTOR_CLASS (champlain_custom_marker_parent_class)->allocate (actor, 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)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (self);
+
+  CLUTTER_ACTOR_CLASS (champlain_custom_marker_parent_class)->map (self);
+
+  clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+unmap (ClutterActor *self)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (self);
+
+  CLUTTER_ACTOR_CLASS (champlain_custom_marker_parent_class)->unmap (self);
+
+  clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+}
+
+
+static void
+champlain_custom_marker_dispose (GObject *object)
+{
+  ChamplainCustomMarkerPrivate *priv = CHAMPLAIN_CUSTOM_MARKER (object)->priv;
+  
+  if (priv->content_group)
+    {
+      clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
+      priv->content_group = NULL;
+    }
+
+  G_OBJECT_CLASS (champlain_custom_marker_parent_class)->dispose (object);
+}
+
+
+static void
+champlain_custom_marker_finalize (GObject *object)
+{
+//  ChamplainCustomMarkerPrivate *priv = CHAMPLAIN_CUSTOM_MARKER (object)->priv;
+
+  G_OBJECT_CLASS (champlain_custom_marker_parent_class)->finalize (object);
+}
+
+
+static void
+champlain_custom_marker_class_init (ChamplainCustomMarkerClass *klass)
+{
+  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  
+  g_type_class_add_private (klass, sizeof (ChamplainCustomMarkerPrivate));
+
+  object_class->finalize = champlain_custom_marker_finalize;
+  object_class->dispose = champlain_custom_marker_dispose;
+
+  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;
+}
+
+
+static void
+champlain_custom_marker_init (ChamplainCustomMarker *custom_marker)
+{
+  ChamplainCustomMarkerPrivate *priv = GET_PRIVATE (custom_marker);
+
+  custom_marker->priv = priv;
+  priv->content_group = CLUTTER_CONTAINER (clutter_group_new ());
+  clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (custom_marker));
+}
+
+
+/**
+ * champlain_custom_marker_new:
+ * 
+ * Creates an instance of #ChamplainCustomMarker.
+ *
+ * Returns: a new #ChamplainCustomMarker.
+ *
+ * Since: 0.10
+ */
+ClutterActor *
+champlain_custom_marker_new (void)
+{
+  return CLUTTER_ACTOR (g_object_new (CHAMPLAIN_TYPE_CUSTOM_MARKER, NULL));
+}
diff --git a/champlain/champlain-custom-marker.h b/champlain/champlain-custom-marker.h
new file mode 100644
index 0000000..89e310d
--- /dev/null
+++ b/champlain/champlain-custom-marker.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2011 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION)
+#error "Only <champlain/champlain.h> can be included directly."
+#endif
+
+#ifndef CHAMPLAIN_CUSTOM_MARKER_H
+#define CHAMPLAIN_CUSTOM_MARKER_H
+
+#include <champlain/champlain-marker.h>
+
+#include <glib-object.h>
+#include <clutter/clutter.h>
+
+G_BEGIN_DECLS
+
+#define CHAMPLAIN_TYPE_CUSTOM_MARKER champlain_custom_marker_get_type ()
+
+#define CHAMPLAIN_CUSTOM_MARKER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHAMPLAIN_TYPE_CUSTOM_MARKER, ChamplainCustomMarker))
+
+#define CHAMPLAIN_CUSTOM_MARKER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), CHAMPLAIN_TYPE_CUSTOM_MARKER, ChamplainCustomMarkerClass))
+
+#define CHAMPLAIN_IS_CUSTOM_MARKER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHAMPLAIN_TYPE_CUSTOM_MARKER))
+
+#define CHAMPLAIN_IS_CUSTOM_MARKER_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), CHAMPLAIN_TYPE_CUSTOM_MARKER))
+
+#define CHAMPLAIN_CUSTOM_MARKER_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), CHAMPLAIN_TYPE_CUSTOM_MARKER, ChamplainCustomMarkerClass))
+
+typedef struct _ChamplainCustomMarkerPrivate ChamplainCustomMarkerPrivate;
+
+typedef struct _ChamplainCustomMarker ChamplainCustomMarker;
+typedef struct _ChamplainCustomMarkerClass ChamplainCustomMarkerClass;
+
+struct _ChamplainCustomMarker
+{
+  ChamplainMarker parent;
+
+  ChamplainCustomMarkerPrivate *priv;  
+};
+
+struct _ChamplainCustomMarkerClass
+{
+  ChamplainMarkerClass parent_class;
+};
+
+GType champlain_custom_marker_get_type (void);
+
+ClutterActor *champlain_custom_marker_new (void);
+
+G_END_DECLS
+
+#endif
diff --git a/champlain/champlain-marker.c b/champlain/champlain-marker.c
index 71a43e2..0cf7ad7 100644
--- a/champlain/champlain-marker.c
+++ b/champlain/champlain-marker.c
@@ -26,12 +26,11 @@
  * #champlainview for the markers to show on the map.
  *
  * A marker is nothing more than a regular #clutteractor. You can draw on
- * it what ever you want. Don't forget to set the anchor position in the 
- * marker using #clutter_actor_set_anchor_point. Set the markers position
+ * it what ever you want.  Set the markers position
  * on the map using #champlain_marker_set_position.
  *
- * champlain has a more evoluted type of markers with text and image support.
- * See #ChamplainMarker.
+ * libchamplain has a more evoluted type of markers with text and image support.
+ * See #ChamplainLabel.
  */
 
 #include "config.h"
@@ -207,7 +206,7 @@ champlain_marker_class_init (ChamplainMarkerClass *marker_class)
    *
    * The longitude coordonate of the map
    *
-   * Since: 0.4
+   * Since: 0.10
    */
   g_object_class_install_property (object_class, PROP_LONGITUDE,
       g_param_spec_double ("longitude", "Longitude",
@@ -219,7 +218,7 @@ champlain_marker_class_init (ChamplainMarkerClass *marker_class)
    *
    * The latitude coordonate of the map
    *
-   * Since: 0.4
+   * Since: 0.10
    */
   g_object_class_install_property (object_class, PROP_LATITUDE,
       g_param_spec_double ("latitude", "Latitude",
@@ -398,26 +397,6 @@ champlain_marker_init (ChamplainMarker *marker)
 
 
 /**
- * champlain_marker_new:
- *
- * Creates a new instance of #ChamplainMarker.
- *
- * Returns: a new #ChamplainMarker ready to be used as a #ClutterActor.
- *
- * Since: 0.4
- */
-ClutterActor *
-champlain_marker_new (void)
-{
-  ChamplainMarker *marker;
-
-  marker = CHAMPLAIN_MARKER (g_object_new (CHAMPLAIN_TYPE_MARKER, NULL));
-
-  return CLUTTER_ACTOR (marker);
-}
-
-
-/**
  * champlain_marker_set_position:
  * @marker: a #ChamplainMarker
  * @latitude: the longitude to center the map at
@@ -425,7 +404,7 @@ champlain_marker_new (void)
  *
  * Positions the marker on the map at the coordinates
  *
- * Since: 0.4
+ * Since: 0.10
  */
 void
 champlain_marker_set_position (ChamplainMarker *marker,
@@ -452,7 +431,7 @@ champlain_marker_set_position (ChamplainMarker *marker,
  *
  * Returns: the latitude of the marker.
  *
- * Since: 0.6
+ * Since: 0.10
  */
 gdouble
 champlain_marker_get_latitude (ChamplainMarker *marker)
@@ -471,7 +450,7 @@ champlain_marker_get_latitude (ChamplainMarker *marker)
  *
  * Returns: the longitude of the marker.
  *
- * Since: 0.6
+ * Since: 0.10
  */
 gdouble
 champlain_marker_get_longitude (ChamplainMarker *marker)
@@ -490,7 +469,7 @@ champlain_marker_get_longitude (ChamplainMarker *marker)
  * Sets the marker as selected or not. This will affect the "Selected" look
  * of the marker.
  *
- * Since: 0.4
+ * Since: 0.10
  */
 void
 champlain_marker_set_selected (ChamplainMarker *marker,
@@ -512,7 +491,7 @@ champlain_marker_set_selected (ChamplainMarker *marker,
  *
  * Returns: the selected or not state of the marker.
  *
- * Since: 0.4
+ * Since: 0.10
  */
 gboolean
 champlain_marker_get_selected (ChamplainMarker *marker)
@@ -607,7 +586,7 @@ champlain_marker_get_movable (ChamplainMarker *marker)
  *
  * Animates the marker as if it were falling from the sky onto the map.
  *
- * Since: 0.4
+ * Since: 0.10
  */
 void
 champlain_marker_animate_in (ChamplainMarker *marker)
@@ -624,7 +603,7 @@ champlain_marker_animate_in (ChamplainMarker *marker)
  * Animates the marker as if it were falling from the sky onto the map after
  * delay.
  *
- * Since: 0.4
+ * Since: 0.10
  */
 void
 champlain_marker_animate_in_with_delay (ChamplainMarker *marker,
@@ -655,7 +634,7 @@ champlain_marker_animate_in_with_delay (ChamplainMarker *marker,
  *
  * Animates the marker as if it were drawn through the sky.
  *
- * Since: 0.4
+ * Since: 0.10
  */
 void
 champlain_marker_animate_out (ChamplainMarker *marker)
@@ -697,7 +676,7 @@ on_animation_completed (G_GNUC_UNUSED ClutterAnimation *animation,
  * Animates the marker as if it were drawn through the sky after
  * delay.
  *
- * Since: 0.4
+ * Since: 0.10
  */
 void
 champlain_marker_animate_out_with_delay (ChamplainMarker *marker,
diff --git a/champlain/champlain-marker.h b/champlain/champlain-marker.h
index f63d4b4..e2255a1 100644
--- a/champlain/champlain-marker.h
+++ b/champlain/champlain-marker.h
@@ -68,7 +68,6 @@ struct _ChamplainMarkerClass
 
 GType champlain_marker_get_type (void);
 
-ClutterActor *champlain_marker_new (void);
 
 void champlain_marker_set_position (ChamplainMarker *marker,
     gdouble latitude,
diff --git a/champlain/champlain.h b/champlain/champlain.h
index ffdff63..8c878ee 100644
--- a/champlain/champlain.h
+++ b/champlain/champlain.h
@@ -32,6 +32,7 @@
 #include "champlain/champlain-layer.h"
 #include "champlain/champlain-marker-layer.h"
 #include "champlain/champlain-point.h"
+#include "champlain/champlain-custom-marker.h"
 #include "champlain/champlain-marker.h"
 #include "champlain/champlain-label.h"
 #include "champlain/champlain-view.h"
diff --git a/demos/animated-marker.c b/demos/animated-marker.c
index 69ada0b..512f5e1 100644
--- a/demos/animated-marker.c
+++ b/demos/animated-marker.c
@@ -35,7 +35,7 @@ create_marker ()
   cairo_t *cr;
 
   /* Create the marker */
-  marker = champlain_marker_new ();
+  marker = champlain_custom_marker_new ();
 
   /* Static filled circle ----------------------------------------------- */
   bg = clutter_cairo_texture_new (MARKER_SIZE, MARKER_SIZE);
@@ -141,7 +141,7 @@ main (int argc, char *argv[])
 
   /* Create a marker */
   marker = create_marker ();
-  clutter_container_add (CLUTTER_CONTAINER (layer), marker, NULL);
+  champlain_marker_layer_add_marker (layer, CHAMPLAIN_MARKER (marker));
 
   /* Finish initialising the map view */
   g_object_set (G_OBJECT (actor), "zoom-level", 12,
diff --git a/demos/url-marker.c b/demos/url-marker.c
index bf7fafa..8d8c1ab 100644
--- a/demos/url-marker.c
+++ b/demos/url-marker.c
@@ -192,8 +192,7 @@ image_downloaded_cb (SoupSession *session,
   texture = NULL;
   champlain_marker_set_position (CHAMPLAIN_MARKER (marker),
       marker_data->latitude, marker_data->longitude);
-  clutter_container_add (CLUTTER_CONTAINER (marker_data->layer), marker, NULL);
-  clutter_actor_show_all (marker);
+  champlain_marker_layer_add_marker (marker_data->layer, CHAMPLAIN_MARKER (marker));
 
 cleanup:
   if (marker_data)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]