From: Pierre-Luc Beaudoin Date: Tue, 16 Sep 2008 11:19:25 +0000 (-0400) Subject: Split gtk+ deps to libchamplain-gtk X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29710ffeebfbd6f359b2f01152aff96b255f3ce8;p=libchamplain Split gtk+ deps to libchamplain-gtk --- diff --git a/champlain.pc.in b/champlain.pc.in index dc17570..995dd57 100644 --- a/champlain.pc.in +++ b/champlain.pc.in @@ -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 diff --git a/champlain/champlain_private.h b/champlain/champlain_private.h index b4fe8a2..4d97f75 100644 --- a/champlain/champlain_private.h +++ b/champlain/champlain_private.h @@ -21,16 +21,31 @@ #define CHAMPLAIN_PRIVATE_H #include -#include #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 diff --git a/champlain/champlainmarker.c b/champlain/champlainmarker.c index 8e49456..89a6e64 100644 --- a/champlain/champlainmarker.c +++ b/champlain/champlainmarker.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include diff --git a/champlain/champlainview.c b/champlain/champlainview.c index 8193c38..414195f 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -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; diff --git a/champlain/champlainview.h b/champlain/champlainview.h index 0ffef2e..9fd1de0 100644 --- a/champlain/champlainview.h +++ b/champlain/champlainview.h @@ -23,7 +23,6 @@ #include #include #include -#include #include /** @@ -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 diff --git a/champlain/launcher.c b/champlain/launcher.c index 46df999..8bbd21a 100644 --- a/champlain/launcher.c +++ b/champlain/launcher.c @@ -19,23 +19,8 @@ #include -#include - #include -#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; } diff --git a/champlain/map.c b/champlain/map.c index 1d7535c..77c86b7 100644 --- a/champlain/map.c +++ b/champlain/map.c @@ -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; diff --git a/champlain/map.h b/champlain/map.h index 3e3eb2b..6b1e020 100644 --- a/champlain/map.h +++ b/champlain/map.h @@ -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); diff --git a/champlain/tile.c b/champlain/tile.c index 219f9bb..550c081 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -20,6 +20,7 @@ #include "tile.h" #include "map.h" +#include "champlain_private.h" #include #include diff --git a/champlain/zoomlevel.h b/champlain/zoomlevel.h index ed26c15..e891183 100644 --- a/champlain/zoomlevel.h +++ b/champlain/zoomlevel.h @@ -22,7 +22,7 @@ #include #include -#include +#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); diff --git a/configure.ac b/configure.ac index d2529d3..cff72cf 100644 --- a/configure.ac +++ b/configure.ac @@ -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}"