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
#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
#include <clutter/clutter.h>
#include <glib.h>
#include <glib-object.h>
-#include <gtk-clutter-embed.h>
#include <cairo.h>
#include <math.h>
#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>
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
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);
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);
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);
{
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 &&
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 };
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 ();
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();
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);
}
/**
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;
#include <champlain/champlain_defines.h>
#include <glib.h>
#include <glib-object.h>
-#include <gtk/gtk.h>
#include <clutter/clutter.h>
/**
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);
void champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer);
+void champlain_view_set_size (ChamplainView *view, gint width, gint height);
+
#endif
#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 ()
{
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;
}
}
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;
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);
#include "tile.h"
#include "map.h"
+#include "champlain_private.h"
#include <math.h>
#include <errno.h>
#include <glib.h>
#include <clutter/clutter.h>
-#include <gdk/gdk.h>
+#include "champlain_private.h"
typedef struct
{
GPtrArray *tiles;
ClutterActor* group;
- GdkPoint anchor;
+ ChamplainPoint anchor;
} ZoomLevel;
guint zoom_level_get_width(ZoomLevel *level);
# 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)
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,
AC_OUTPUT
echo ""
-echo " Champlain $VERSION"
+echo " libchamplain $VERSION"
echo ""
echo " Prefix: ${prefix}"
echo " Compiler flags: ${CPPFLAGS}"