]> err.no Git - libchamplain/commitdiff
Split gtk+ deps to libchamplain-gtk
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Tue, 16 Sep 2008 11:19:25 +0000 (07:19 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Tue, 16 Sep 2008 11:19:25 +0000 (07:19 -0400)
champlain.pc.in
champlain/champlain_private.h
champlain/champlainmarker.c
champlain/champlainview.c
champlain/champlainview.h
champlain/launcher.c
champlain/map.c
champlain/map.h
champlain/tile.c
champlain/zoomlevel.h
configure.ac

index dc1757011f0c883dddf23a1e1e5b1f9679832ecd..995dd575a53b818062a81caf5289458a32362506 100644 (file)
@@ -3,9 +3,9 @@ exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@
 
-Name: Champlain
-Description: Map View for Gtk+
+Name: libchamplain
+Description: Map View for Clutter
 Version: @VERSION@
 Libs: -L${libdir} -lchamplain-1.0
 Cflags: -I${includedir}/libchamplain-1.0
-Requires: gobject-2.0 clutter-0.8 gtk+-2.0
+Requires: gobject-2.0 clutter-0.8
index b4fe8a221d9648bc0be7f9bddd1431c1c00ba507..4d97f758c9618a174b23e6a628e760adfdc77ef6 100644 (file)
 #define CHAMPLAIN_PRIVATE_H
 
 #include <glib.h>
-#include <gdk/gdk.h>
 
 #define CHAMPLAIN_MARKER_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_MARKER, ChamplainMarkerPrivate))
 
+typedef struct 
+{
+  gint x;
+  gint y;
+  gint z;
+} ChamplainPoint;
+
 struct _ChamplainMarkerPrivate
 {
   gdouble lon;
   gdouble lat;
   
-  GdkPoint anchor;
+  ChamplainPoint anchor;
 };
 
+typedef struct 
+{
+  gint x;
+  gint y;
+  gint width;
+  gint height;
+} ChamplainRectangle;
+
+
 #endif
index 8e494562c44b3a258f1512d42cc4643bf7a7f35f..89a6e642e237327efdf543c6e475dd15bae6a397 100644 (file)
@@ -31,7 +31,6 @@
 #include <clutter/clutter.h>
 #include <glib.h>
 #include <glib-object.h>
-#include <gtk-clutter-embed.h>
 #include <cairo.h>
 #include <math.h>
 
index 8193c388532b056222dfe48820620d5c828aa50a..414195f8d10e79e74342e63ab107346bfec5040e 100644 (file)
@@ -31,7 +31,6 @@
 #include <clutter/clutter.h>
 #include <glib.h>
 #include <glib-object.h>
-#include <gtk-clutter-embed.h>
 #include <math.h>
 #include <tidy-adjustment.h>
 #include <tidy-finger-scroll.h>
@@ -62,7 +61,7 @@ static guint champlain_view_signals[LAST_SIGNAL] = { 0, };
 
 struct _ChamplainViewPrivate
 {
-  GtkWidget *clutter_embed;
+  ClutterActor *stage;
 
   ChamplainMapSource map_source;
   gint zoom_level; // only used when the zoom-level property is set before map is created
@@ -72,19 +71,16 @@ struct _ChamplainViewPrivate
   ClutterActor *map_layer;
   ClutterActor *viewport;
   ClutterActor *finger_scroll;
-  GdkRectangle viewport_size;
+  ChamplainRectangle viewport_size;
 
   ClutterActor *user_layers;
 
   Map *map;
 
-  GdkCursor *cursor_hand_open;
-  GdkCursor *cursor_hand_closed;
-
   gboolean offline;
 };
 
-G_DEFINE_TYPE (ChamplainView, champlain_view, GTK_TYPE_ALIGNMENT);
+G_DEFINE_TYPE (ChamplainView, champlain_view, CLUTTER_TYPE_GROUP);
 
 static gdouble viewport_get_current_longitude(ChamplainViewPrivate *priv);
 static gdouble viewport_get_current_latitude(ChamplainViewPrivate *priv);
@@ -102,7 +98,6 @@ static void champlain_view_finalize (GObject *object);
 static void champlain_view_class_init (ChamplainViewClass *champlainViewClass);
 static void champlain_view_init (ChamplainView *view);
 static void viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *view);
-static void view_size_allocated_cb (GtkWidget *widget, GtkAllocation *allocation, ChamplainView *view);
 static void notify_marker_reposition_cb(ChamplainMarker *marker, GParamSpec *arg1, ChamplainView *view);
 static void layer_add_marker_cb (ClutterGroup *layer, ChamplainMarker *marker, ChamplainView *view);
 static void connect_marker_notify_cb (ChamplainMarker *marker, ChamplainView *view);
@@ -396,7 +391,7 @@ champlain_view_set_property(GObject *object, guint prop_id, const GValue *value,
             priv->map_source = source;
             if (priv->map) {
               gint currentLevel = priv->map->current_level->level;
-              GdkPoint anchor = priv->map->current_level->anchor;
+              ChamplainPoint anchor = priv->map->current_level->anchor;
               map_free(priv->map);
               priv->map = map_new(priv->map_source);
 
@@ -562,7 +557,7 @@ viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *view)
 {
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
 
-  GdkPoint rect;
+  ChamplainPoint rect;
   tidy_viewport_get_origin(TIDY_VIEWPORT(priv->viewport), &rect.x, &rect.y, NULL);
 
   if (rect.x == priv->viewport_size.x &&
@@ -578,42 +573,26 @@ viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *view)
   g_object_notify(G_OBJECT(view), "latitude");
 }
 
-static void
-view_size_allocated_cb (GtkWidget *widget, GtkAllocation *allocation, ChamplainView *view)
+void
+champlain_view_set_size (ChamplainView *view, gint width, gint height)
 {
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
 
-  priv->viewport_size.width = allocation->width;
-  priv->viewport_size.height = allocation->height;
+  priv->viewport_size.width = width;
+  priv->viewport_size.height = height;
 
   resize_viewport(view);
   map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline);
-  
-  // Setup mouse cursor to a hand
-  gdk_window_set_cursor( priv->clutter_embed->window, priv->cursor_hand_open);
-}
-
-static gboolean 
-mouse_button_cb (GtkWidget *widget, GdkEventButton *event, ChamplainView *view)
-{
-  ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
-  
-  if (event->type == GDK_BUTTON_PRESS)
-    gdk_window_set_cursor( priv->clutter_embed->window, priv->cursor_hand_closed);
-  else
-    gdk_window_set_cursor( priv->clutter_embed->window, priv->cursor_hand_open);
-
-  return FALSE;
 }
 
 /**
  * champlain_view_new:
  * @mode: a #ChamplainViewMode, the scrolling mode
- * Returns a new #ChamplainWidget ready to be used as a #GtkWidget.
+ * Returns a new #ChamplainView ready to be used as a #ClutterActor.
  *
  * Since: 0.1
  */
-GtkWidget *
+ClutterActor *
 champlain_view_new (ChamplainViewMode mode)
 {
   ClutterColor stage_color = { 0x34, 0x39, 0x39, 0xff };
@@ -623,32 +602,8 @@ champlain_view_new (ChamplainViewMode mode)
   view = CHAMPLAIN_VIEW (g_object_new (CHAMPLAIN_TYPE_VIEW, NULL));
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view);
 
-  priv->clutter_embed = gtk_clutter_embed_new ();
-  g_signal_connect (priv->clutter_embed,
-                    "size-allocate",
-                    G_CALLBACK (view_size_allocated_cb),
-                    view);
-  g_signal_connect (priv->clutter_embed,
-                    "button-press-event",
-                    G_CALLBACK (mouse_button_cb),
-                    view);
-  g_signal_connect (priv->clutter_embed,
-                    "button-release-event",
-                    G_CALLBACK (mouse_button_cb),
-                    view);
-  // Setup cursors
-  priv->cursor_hand_open = gdk_cursor_new(GDK_HAND1);
-  priv->cursor_hand_closed = gdk_cursor_new(GDK_FLEUR);
+  priv->stage = clutter_group_new ();
   
-  // Setup stage
-  stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->clutter_embed));
-
-  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
-  gtk_container_add (GTK_CONTAINER (view), priv->clutter_embed);
-  g_signal_connect (stage,
-                    "scroll-event",
-                    G_CALLBACK (scroll_event),
-                    view);
 
   // Setup viewport
   priv->viewport = tidy_viewport_new ();
@@ -673,8 +628,14 @@ champlain_view_new (ChamplainViewMode mode)
 
   priv->finger_scroll = tidy_finger_scroll_new(mode);
 
+  g_signal_connect (priv->finger_scroll,
+                    "scroll-event",
+                    G_CALLBACK (scroll_event),
+                    view);
+                    
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->finger_scroll), priv->viewport);
-  clutter_container_add_actor (CLUTTER_CONTAINER (stage), priv->finger_scroll);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->stage), priv->finger_scroll);
+  clutter_container_add_actor (CLUTTER_CONTAINER (view), priv->stage);
 
   // Map Layer
   priv->map_layer = clutter_group_new();
@@ -687,7 +648,7 @@ champlain_view_new (ChamplainViewMode mode)
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->user_layers);
   clutter_actor_raise(priv->user_layers, priv->map_layer);
 
-  return GTK_WIDGET (view);
+  return CLUTTER_ACTOR (view);
 }
 
 /**
@@ -717,7 +678,7 @@ champlain_view_center_on (ChamplainView *view, gdouble longitude, gdouble latitu
   gdouble x, y;
   x = priv->map->longitude_to_x(priv->map, longitude, priv->map->current_level->level);
   y = priv->map->latitude_to_y(priv->map, latitude, priv->map->current_level->level);
-  GdkPoint* anchor = &priv->map->current_level->anchor;
+  ChamplainPoint* anchor = &priv->map->current_level->anchor;
 
   if (priv->map->current_level->level >= 8) {
     anchor->x = x - G_MAXINT16 / 2;
index 0ffef2efb5839e044e6834ef6fe55d80f339c64c..9fd1de043091acb3c118f29ff71779dc1f646b69 100644 (file)
@@ -23,7 +23,6 @@
 #include <champlain/champlain_defines.h>
 #include <glib.h>
 #include <glib-object.h>
-#include <gtk/gtk.h>
 #include <clutter/clutter.h>
 
 /**
@@ -67,20 +66,20 @@ typedef enum {
 
 struct _ChamplainView
 {
-  GtkAlignment bin;
+  ClutterGroup group;
 
   ChamplainViewPrivate *priv;
 };
 
 struct _ChamplainViewClass
 {
-  GtkBinClass parent_class;
+  ClutterGroupClass parent_class;
 
 };
 
 GType champlain_view_get_type (void);
 
-GtkWidget *champlain_view_new (ChamplainViewMode mode);
+ClutterActor *champlain_view_new (ChamplainViewMode mode);
 
 void champlain_view_center_on (ChamplainView *view, gdouble longitude, gdouble latitude);
 
@@ -90,4 +89,6 @@ void champlain_view_zoom_out (ChamplainView *champlainView);
 
 void champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer);
 
+void champlain_view_set_size (ChamplainView *view, gint width, gint height);
+
 #endif
index 46df999155dfcee68f0d66990f4a418596a037b0..8bbd21abc711076c23f8ae195bc213f1fdf31432 100644 (file)
 
 #include <config.h>
 
-#include <gtk/gtk.h>
-
 #include <champlain.h>
 
-#define OSM_MAP "Open Street Map"
-#define OAM_MAP "Open Arial Map"
-#define MFF_MAP "Maps for free - Relief"
-
-/*
- * Terminate the main loop.
- */
-static void
-on_destroy (GtkWidget *widget, gpointer data)
-{
-  gtk_main_quit ();
-}
-
 static ClutterActor*
 create_marker_layer ()
 {
@@ -61,152 +46,30 @@ create_marker_layer ()
   return layer;
 }
 
-static void
-toggle_layer (GtkToggleButton *widget, ClutterActor *layer)
-{
-  if(gtk_toggle_button_get_active(widget))
-    clutter_actor_show_all(layer);
-  else
-    clutter_actor_hide(layer);
-}
-
-static void
-map_source_changed (GtkWidget *widget, ChamplainView *view)
-{
-  gchar* selection = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget));
-  if (g_strcmp0(selection, OSM_MAP) == 0)
-    {
-      g_object_set(G_OBJECT(view), "map-source", CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, NULL);
-    }
-  else if (g_strcmp0(selection, OAM_MAP) == 0)
-    {
-      g_object_set(G_OBJECT(view), "map-source", CHAMPLAIN_MAP_SOURCE_OPENARIALMAP, NULL);
-    }
-  else if (g_strcmp0(selection, MFF_MAP) == 0)
-    {
-      g_object_set(G_OBJECT(view), "map-source", CHAMPLAIN_MAP_SOURCE_MAPSFORFREE_RELIEF, NULL);
-    }
-}
-
-static void 
-zoom_changed (GtkSpinButton *spinbutton, ChamplainView *view)
-{
-  gint zoom = gtk_spin_button_get_value_as_int(spinbutton);
-  g_object_set(G_OBJECT(view), "zoom-level", zoom, NULL);
-}
-
-static void 
-map_zoom_changed (ChamplainView *view, GParamSpec *gobject, GtkSpinButton *spinbutton)
-{
-  gint zoom;
-  g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
-  gtk_spin_button_set_value(spinbutton, zoom);
-}
-
-static void
-zoom_in (GtkWidget *widget, ChamplainView *view)
-{
-  champlain_view_zoom_in(view);
-}
-
-static void
-zoom_out (GtkWidget *widget, ChamplainView *view)
-{
-  champlain_view_zoom_out(view);
-}
-
 int
 main (int argc, char *argv[])
 {
-  GtkWidget *window;
-  GtkWidget *widget, *vbox, *bbox, *button, *viewport;
-  GtkWidget *scrolled;
-  ClutterActor* layer;
+  ClutterActor* actor, *layer, *stage;
   
   g_thread_init (NULL);
-  gtk_clutter_init (&argc, &argv);
-
-  /* create the main, top level, window */
-  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
-  /* give the window a 10px wide border */
-  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
-
-  /* give it the title */
-  gtk_window_set_title (GTK_WINDOW (window), PACKAGE " " VERSION);
-
-  /* Connect the destroy event of the window with our on_destroy function
-   * When the window is about to be destroyed we get a notificaiton and
-   * stop the main GTK loop
-   */
-  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (on_destroy), NULL);
-
-  vbox = gtk_vbox_new(FALSE, 10);
-  
-  widget = champlain_view_new (CHAMPLAIN_VIEW_MODE_KINETIC);
-  g_object_set(G_OBJECT(widget), "zoom-level", 5, NULL);
-  layer = create_marker_layer();
-  champlain_view_add_layer(widget, layer);
-  
-  gtk_widget_set_size_request(widget, 640, 480);
+  clutter_init (&argc, &argv);
   
-  bbox =  gtk_hbox_new (FALSE, 10);
-  button = gtk_button_new_from_stock (GTK_STOCK_ZOOM_IN);
-  g_signal_connect (button,
-                    "clicked",
-                    G_CALLBACK (zoom_in),
-                    widget);
-  gtk_container_add (GTK_CONTAINER (bbox), button);
-  button = gtk_button_new_from_stock (GTK_STOCK_ZOOM_OUT);
-  g_signal_connect (button,
-                    "clicked",
-                    G_CALLBACK (zoom_out),
-                    widget);
-  gtk_container_add (GTK_CONTAINER (bbox), button);
-  button = gtk_toggle_button_new_with_label  ("Markers");
-  g_signal_connect (button,
-                    "toggled",
-                    G_CALLBACK (toggle_layer),
-                    layer);
-  gtk_container_add (GTK_CONTAINER (bbox), button);
+  stage = clutter_stage_get_default ();
+  clutter_actor_set_size (stage, 800, 600);
   
-  button = gtk_combo_box_new_text();
-  gtk_combo_box_append_text(GTK_COMBO_BOX(button), OSM_MAP);
-  gtk_combo_box_append_text(GTK_COMBO_BOX(button), OAM_MAP);
-  gtk_combo_box_append_text(GTK_COMBO_BOX(button), MFF_MAP);
-  gtk_combo_box_set_active(GTK_COMBO_BOX(button), 0);
-  g_signal_connect (button,
-                    "changed",
-                    G_CALLBACK (map_source_changed),
-                    widget);
-  gtk_container_add (GTK_CONTAINER (bbox), button);
+  actor = champlain_view_new (CHAMPLAIN_VIEW_MODE_KINETIC);
   
-  button = gtk_spin_button_new_with_range(0, 20, 1);
-  g_signal_connect (button,
-                    "changed",
-                    G_CALLBACK (zoom_changed),
-                    widget);
-  g_signal_connect (widget,
-                    "notify::zoom-level",
-                    G_CALLBACK (map_zoom_changed),
-                    button);
-  gtk_container_add (GTK_CONTAINER (bbox), button);
+  champlain_view_set_size (actor, 800, 600);
   
-  viewport = gtk_viewport_new (NULL, NULL);
-  gtk_viewport_set_shadow_type (GTK_VIEWPORT(viewport), GTK_SHADOW_ETCHED_IN);
-  gtk_container_add (GTK_CONTAINER (viewport), widget);
-  
-  gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
-  gtk_container_add (GTK_CONTAINER (vbox), viewport);
-
-  /* and insert it into the main window  */
-  gtk_container_add (GTK_CONTAINER (window), vbox);
+  g_object_set(G_OBJECT(actor), "zoom-level", 5, NULL);
+  layer = create_marker_layer();
+  champlain_view_add_layer(actor, layer);
 
-  /* make sure that everything, window and label, are visible */
-  gtk_widget_show_all (window);
-  champlain_view_center_on(CHAMPLAIN_VIEW(widget), -73.75, 45.466);
-  /* start the main loop */
-  gtk_main ();
+  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
+  champlain_view_center_on(CHAMPLAIN_VIEW(actor), -73.75, 45.466);
+  
+  clutter_actor_show (stage);
+  clutter_main ();
 
   return 0;
 }
index 1d7535cabf0ff1bf66c7fff631dbf596abf377c4..77c86b7c3eef5291c579e633c3fbbd05fde77d18 100644 (file)
@@ -67,7 +67,7 @@ map_load_level(Map *map, gint zoom_level)
 }
 
 void
-map_load_visible_tiles (Map *map, GdkRectangle viewport, gboolean offline)
+map_load_visible_tiles (Map *map, ChamplainRectangle viewport, gboolean offline)
 {
   if (viewport.x < 0)
     viewport.x = 0;
index 3e3eb2b8a254bc598979c2ea7e9e32ceea03ccaf..6b1e0203975b3c4c8ba8d372851b8b92b1c5e96f 100644 (file)
@@ -55,7 +55,7 @@ struct _Map
 
 Map *map_new (ChamplainMapSource source);
 
-void map_load_visible_tiles (Map *map, GdkRectangle viewport, gboolean offline);
+void map_load_visible_tiles (Map *map, ChamplainRectangle viewport, gboolean offline);
 
 void map_free (Map *map);
 
index 219f9bb62c1bfc4268c1465d9265307a6e9c3507..550c081cbe635ae30dfb9f3c2c63b9579b9b1545 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "tile.h"
 #include "map.h"
+#include "champlain_private.h"
 
 #include <math.h>
 #include <errno.h>
index ed26c15c850eb0a6ee62232cbde960be30e5963d..e891183ae0ec1d82f00f3b5cdcd0701b152e5ca9 100644 (file)
@@ -22,7 +22,7 @@
 
 #include <glib.h>
 #include <clutter/clutter.h>
-#include <gdk/gdk.h>
+#include "champlain_private.h"
 
 typedef struct
 {
@@ -34,7 +34,7 @@ typedef struct
   GPtrArray  *tiles;
   ClutterActor* group;
 
-  GdkPoint anchor;
+  ChamplainPoint anchor;
 } ZoomLevel;
 
 guint zoom_level_get_width(ZoomLevel *level);
index d2529d33811e6cd8c2e2cf92bbaa28b42ddbdca9..cff72cf1334d3b34da8066ef6e7701d681ff22ec 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.61)
-AC_INIT(champlain, 0.2, pierre-luc@squidy.info)
+AC_INIT(libchamplain, 0.2, pierre-luc@squidy.info)
 AC_CONFIG_SRCDIR([champlain/champlainview.h])
 AC_CONFIG_HEADER([config.h])
 AC_CONFIG_MACRO_DIR(m4)
@@ -27,9 +27,8 @@ AC_SUBST(DEPS_LIBS)
 PKG_CHECK_MODULES(DEPS,
   [   glib-2.0 >= 2.16,
       gobject-2.0 >= 2.10,
-      gtk+-2.0 >= 2.2,
+      gdk-2.0 >= 2.10,
       clutter-0.8 >= 0.8,
-      clutter-gtk-0.8 >= 0.8,
       clutter-cairo-0.8 >= 0.8,
       cairo >= 1.6,
       libsoup-2.4 >= 2.4.1,
@@ -47,7 +46,7 @@ AC_CONFIG_FILES([Makefile
 AC_OUTPUT
 
 echo ""
-echo " Champlain $VERSION"
+echo " libchamplain $VERSION"
 echo ""
 echo "         Prefix: ${prefix}"
 echo " Compiler flags: ${CPPFLAGS}"