From: Pierre-Luc Beaudoin Date: Sat, 6 Sep 2008 19:19:30 +0000 (-0400) Subject: Fix coding styles X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bab1537f1b5ff99ad5fd993c5d4a4c59bbd20f6c;p=libchamplain Fix coding styles --- diff --git a/champlain/champlainmarker.c b/champlain/champlainmarker.c index d16610d..2318f04 100644 --- a/champlain/champlainmarker.c +++ b/champlain/champlainmarker.c @@ -54,13 +54,13 @@ static guint champlain_marker_signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE (ChamplainMarker, champlain_marker, CLUTTER_TYPE_GROUP); -static void -champlain_marker_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) +static void +champlain_marker_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - ChamplainMarker* marker = CHAMPLAIN_MARKER(object); + ChamplainMarker *marker = CHAMPLAIN_MARKER(object); ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker); - switch(prop_id) + switch(prop_id) { case PROP_LONGITUDE: g_value_set_double(value, priv->lon); @@ -73,13 +73,13 @@ champlain_marker_get_property(GObject* object, guint prop_id, GValue* value, GPa } } -static void -champlain_marker_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec) +static void +champlain_marker_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - ChamplainMarker* marker = CHAMPLAIN_MARKER(object); + ChamplainMarker *marker = CHAMPLAIN_MARKER(object); ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker); - switch(prop_id) + switch(prop_id) { case PROP_LONGITUDE: { @@ -99,7 +99,7 @@ champlain_marker_set_property(GObject* object, guint prop_id, const GValue* valu } static void -champlain_marker_finalize (GObject * object) +champlain_marker_finalize (GObject *object) { ChamplainMarker *marker = CHAMPLAIN_MARKER (object); ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker); @@ -112,11 +112,11 @@ champlain_marker_class_init (ChamplainMarkerClass *champlainMarkerClass) { g_type_class_add_private (champlainMarkerClass, sizeof (ChamplainMarkerPrivate)); - GObjectClass *objectClass = G_OBJECT_CLASS (champlainMarkerClass); - objectClass->finalize = champlain_marker_finalize; - objectClass->get_property = champlain_marker_get_property; - objectClass->set_property = champlain_marker_set_property; - + GObjectClass *object_class = G_OBJECT_CLASS (champlainMarkerClass); + object_class->finalize = champlain_marker_finalize; + object_class->get_property = champlain_marker_get_property; + object_class->set_property = champlain_marker_set_property; + /** * ChamplainMarker:longitude: * @@ -124,14 +124,14 @@ champlain_marker_class_init (ChamplainMarkerClass *champlainMarkerClass) * * Since: 0.2 */ - g_object_class_install_property(objectClass, PROP_LONGITUDE, + g_object_class_install_property(object_class, PROP_LONGITUDE, g_param_spec_double("longitude", - "Longitude", - "The longitude coordonate of the marker", - -180.0f, - 180.0f, - 0.0f, - CHAMPLAIN_PARAM_READWRITE)); + "Longitude", + "The longitude coordonate of the marker", + -180.0f, + 180.0f, + 0.0f, + CHAMPLAIN_PARAM_READWRITE)); /** * ChamplainMarker:latitude: @@ -140,14 +140,14 @@ champlain_marker_class_init (ChamplainMarkerClass *champlainMarkerClass) * * Since: 0.2 */ - g_object_class_install_property(objectClass, PROP_LATITUDE, + g_object_class_install_property(object_class, PROP_LATITUDE, g_param_spec_double("latitude", - "Latitude", - "The latitude coordonate of the marker", - -90.0f, - 90.0f, - 0.0f, - CHAMPLAIN_PARAM_READWRITE)); + "Latitude", + "The latitude coordonate of the marker", + -90.0f, + 90.0f, + 0.0f, + CHAMPLAIN_PARAM_READWRITE)); } @@ -171,10 +171,10 @@ ClutterActor * champlain_marker_new () { ChamplainMarker *marker; - + marker = CHAMPLAIN_MARKER (g_object_new (CHAMPLAIN_TYPE_MARKER, NULL)); ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker); - + return CLUTTER_ACTOR (marker); } @@ -195,12 +195,11 @@ champlain_marker_set_position (ChamplainMarker *champlainMarker, gdouble longitu priv->lon = longitude; priv->lat = latitude; - + g_object_notify(G_OBJECT(champlainMarker), "longitude"); g_object_notify(G_OBJECT(champlainMarker), "latitude"); } - /** * champlain_marker_set_anchor: * @marker: a #ChamplainMarker @@ -211,14 +210,14 @@ champlain_marker_set_position (ChamplainMarker *champlainMarker, gdouble longitu * * Since: 0.2 */ -void +void champlain_marker_set_anchor (ChamplainMarker *champlainMarker, gint x, gint y) { ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (champlainMarker); - + priv->anchor.x = x; priv->anchor.y = y; - + clutter_actor_set_position(CLUTTER_ACTOR(champlainMarker), -x, -y); } @@ -229,14 +228,14 @@ champlain_marker_set_anchor (ChamplainMarker *champlainMarker, gint x, gint y) * @text_color: a #ClutterColor, the color of the text, can be NULL * @marker_color: a #ClutterColor, the color of the marker, can be NULL * - * Returns a new #ChamplainMarker with a drawn marker containing the given text. + * Returns a new #ChamplainMarker with a drawn marker containing the given text. * * Since: 0.2 */ -ClutterActor * -champlain_marker_new_with_label (const gchar *label, - const gchar *font, - ClutterColor *text_color, +ClutterActor * +champlain_marker_new_with_label (const gchar *label, + const gchar *font, + ClutterColor *text_color, ClutterColor *marker_color) { ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new ()); @@ -276,7 +275,7 @@ champlain_marker_new_with_label (const gchar *label, cairo_line_to (cr, 0, text_height + point); cairo_close_path (cr); - cairo_set_source_rgba (cr, + cairo_set_source_rgba (cr, marker_color->red / 255.0, marker_color->green / 255.0, marker_color->blue / 255.0, @@ -291,7 +290,7 @@ champlain_marker_new_with_label (const gchar *label, cairo_line_to (cr, point, text_height); cairo_line_to (cr, 0, text_height + point); cairo_close_path (cr); - cairo_set_source_rgba (cr, + cairo_set_source_rgba (cr, darker_color.red / 255.0, darker_color.green / 255.0, darker_color.blue / 255.0, diff --git a/champlain/champlainmarker.h b/champlain/champlainmarker.h index 17a81fa..1ee4cc3 100644 --- a/champlain/champlainmarker.h +++ b/champlain/champlainmarker.h @@ -54,8 +54,8 @@ void champlain_marker_set_position (ChamplainMarker *marker, gdouble longitude, void champlain_marker_set_anchor (ChamplainMarker *marker, gint x, gint y); -ClutterActor *champlain_marker_new_with_label (const gchar *label, - const gchar *font, - ClutterColor *text_color, +ClutterActor *champlain_marker_new_with_label (const gchar *label, + const gchar *font, + ClutterColor *text_color, ClutterColor *marker_color); #endif diff --git a/champlain/champlainview.c b/champlain/champlainview.c index 0d503f6..baa8d9d 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -38,8 +38,6 @@ #include #include - - enum { /* normal signals */ @@ -65,17 +63,17 @@ static guint champlain_view_signals[LAST_SIGNAL] = { 0, }; struct _ChamplainViewPrivate { GtkWidget *clutter_embed; - + 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; - + ClutterActor *user_layers; - + Map *map; gboolean offline; @@ -87,23 +85,23 @@ G_DEFINE_TYPE (ChamplainView, champlain_view, GTK_TYPE_ALIGNMENT); static gdouble viewport_get_current_longitude(ChamplainViewPrivate *priv) { - return priv->map->x_to_longitude(priv->map, - priv->map->current_level->anchor.x + priv->viewport_size.x + priv->viewport_size.width / 2.0, + return priv->map->x_to_longitude(priv->map, + priv->map->current_level->anchor.x + priv->viewport_size.x + priv->viewport_size.width / 2.0, priv->map->current_level->level); } static gdouble viewport_get_current_latitude(ChamplainViewPrivate *priv) { - return priv->map->y_to_latitude(priv->map, - priv->map->current_level->anchor.y + priv->viewport_size.y + priv->viewport_size.height / 2.0, + return priv->map->y_to_latitude(priv->map, + priv->map->current_level->anchor.y + priv->viewport_size.y + priv->viewport_size.height / 2.0, priv->map->current_level->level); } -static void -marker_reposition_cb (ChamplainMarker *marker, ChamplainView* champlainView) +static void +marker_reposition_cb (ChamplainMarker *marker, ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); ChamplainMarkerPrivate *marker_priv = CHAMPLAIN_MARKER_GET_PRIVATE (marker); gint x, y; @@ -119,42 +117,42 @@ marker_reposition_cb (ChamplainMarker *marker, ChamplainView* champlainView) } } -static void -layer_reposition_cb (ClutterActor *layer, ChamplainView* champlainView) +static void +layer_reposition_cb (ClutterActor *layer, ChamplainView *view) { - clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(marker_reposition_cb), champlainView); + clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(marker_reposition_cb), view); } static void -marker_reposition (ChamplainView* champlainView) +marker_reposition (ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - clutter_container_foreach(CLUTTER_CONTAINER(priv->user_layers), CLUTTER_CALLBACK(layer_reposition_cb), champlainView); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + clutter_container_foreach(CLUTTER_CONTAINER(priv->user_layers), CLUTTER_CALLBACK(layer_reposition_cb), view); } static void -resize_viewport(ChamplainView *champlainView) +resize_viewport(ChamplainView *view) { gdouble lower, upper; TidyAdjustment *hadjust, *vadjust; - - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - + + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + if(!priv->map) { priv->map = map_new(priv->map_source); map_load_level(priv->map, priv->zoom_level); clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - - marker_reposition(champlainView); - - g_object_notify(G_OBJECT(champlainView), "zoom-level"); - g_object_notify(G_OBJECT(champlainView), "map-source"); + + marker_reposition(view); + + g_object_notify(G_OBJECT(view), "zoom-level"); + g_object_notify(G_OBJECT(view), "map-source"); } - + clutter_actor_set_size (priv->finger_scroll, priv->viewport_size.width, priv->viewport_size.height); - - + + tidy_scrollable_get_adjustments (TIDY_SCROLLABLE (priv->viewport), &hadjust, &vadjust); if (priv->map->current_level->level < 8) @@ -172,7 +170,7 @@ resize_viewport(ChamplainView *champlainView) if (priv->map->current_level->level < 8) { - lower = -priv->viewport_size.height / 2; + lower = -priv->viewport_size.height / 2; upper = zoom_level_get_height(priv->map->current_level) - priv->viewport_size.height / 2; } else @@ -184,132 +182,43 @@ resize_viewport(ChamplainView *champlainView) "step-increment", 1.0, "elastic", TRUE, NULL); } -static void -champlain_view_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec) -{ - ChamplainView* view = CHAMPLAIN_VIEW(object); - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); - - switch(prop_id) - { - case PROP_LONGITUDE: - g_value_set_double(value, viewport_get_current_longitude(priv)); - break; - case PROP_LATITUDE: - g_value_set_double(value, viewport_get_current_latitude(priv)); - break; - case PROP_ZOOM_LEVEL: - { - if (priv->map) - { - g_value_set_int(value, priv->map->current_level->level); - } - else - { - g_value_set_int(value, 0); - } - break; - } - case PROP_MAP_SOURCE: - g_value_set_int(value, priv->map_source); - break; - case PROP_OFFLINE: - g_value_set_boolean(value, priv->offline); - break; - case PROP_DECEL_RATE: - { - gdouble decel; - g_object_get (priv->finger_scroll, "decel-rate", decel, NULL); - g_value_set_double(value, decel); - break; - } - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - -static void -champlain_view_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec) +static void +champlain_view_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - ChamplainView* view = CHAMPLAIN_VIEW(object); - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + ChamplainView *view = CHAMPLAIN_VIEW(object); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); - switch(prop_id) + switch(prop_id) { case PROP_LONGITUDE: - { - gdouble lon = g_value_get_double(value); - gdouble lat = viewport_get_current_latitude(priv); - champlain_view_center_on(view, lon, lat); - break; - } + g_value_set_double(value, viewport_get_current_longitude(priv)); + break; case PROP_LATITUDE: - { - gdouble lon = viewport_get_current_longitude(priv); - gdouble lat = g_value_get_double(value); - champlain_view_center_on(view, lon, lat); - break; - } + g_value_set_double(value, viewport_get_current_latitude(priv)); + break; case PROP_ZOOM_LEVEL: { - gint level = g_value_get_int(value); - if (priv->map) + if (priv->map) { - if (level != priv->map->current_level->level) - { - ClutterActor * group = priv->map->current_level->group; - gdouble lon = viewport_get_current_longitude(priv); - gdouble lat = viewport_get_current_latitude(priv); - if (map_zoom_to(priv->map, level)) - { - resize_viewport(view); - clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); - clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - champlain_view_center_on(view, lon, lat); - marker_reposition(view); - } - } + g_value_set_int(value, priv->map->current_level->level); } - else + else { - priv->zoom_level = level; + g_value_set_int(value, 0); } break; } case PROP_MAP_SOURCE: - { - ChamplainMapSource source = g_value_get_int(value); - if (priv->map_source != source) - { - priv->map_source = source; - if (priv->map) { - gint currentLevel = priv->map->current_level->level; - GdkPoint anchor = priv->map->current_level->anchor; - map_free(priv->map); - priv->map = map_new(priv->map_source); - - // Keep same zoom level - if (currentLevel > priv->map->zoom_levels) - currentLevel = priv->map->zoom_levels; - - map_load_level(priv->map, currentLevel); - priv->map->current_level->anchor = anchor; - - map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); - clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - - marker_reposition(view); - } - } - break; - } + g_value_set_int(value, priv->map_source); + break; case PROP_OFFLINE: - priv->offline = g_value_get_boolean(value); + g_value_set_boolean(value, priv->offline); break; case PROP_DECEL_RATE: { - gdouble decel = g_value_get_double(value); - g_object_set (priv->finger_scroll, "decel-rate", decel, NULL); + gdouble decel; + g_object_get (priv->finger_scroll, "decel-rate", decel, NULL); + g_value_set_double(value, decel); break; } default: @@ -318,7 +227,96 @@ champlain_view_set_property(GObject* object, guint prop_id, const GValue* value, } static void -champlain_view_finalize (GObject * object) +champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + ChamplainView *view = CHAMPLAIN_VIEW(object); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + + switch(prop_id) + { + case PROP_LONGITUDE: + { + gdouble lon = g_value_get_double(value); + gdouble lat = viewport_get_current_latitude(priv); + champlain_view_center_on(view, lon, lat); + break; + } + case PROP_LATITUDE: + { + gdouble lon = viewport_get_current_longitude(priv); + gdouble lat = g_value_get_double(value); + champlain_view_center_on(view, lon, lat); + break; + } + case PROP_ZOOM_LEVEL: + { + gint level = g_value_get_int(value); + if (priv->map) + { + if (level != priv->map->current_level->level) + { + ClutterActor *group = priv->map->current_level->group; + gdouble lon = viewport_get_current_longitude(priv); + gdouble lat = viewport_get_current_latitude(priv); + if (map_zoom_to(priv->map, level)) + { + resize_viewport(view); + clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); + clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); + champlain_view_center_on(view, lon, lat); + marker_reposition(view); + } + } + } + else + { + priv->zoom_level = level; + } + break; + } + case PROP_MAP_SOURCE: + { + ChamplainMapSource source = g_value_get_int(value); + if (priv->map_source != source) + { + priv->map_source = source; + if (priv->map) { + gint currentLevel = priv->map->current_level->level; + GdkPoint anchor = priv->map->current_level->anchor; + map_free(priv->map); + priv->map = map_new(priv->map_source); + + // Keep same zoom level + if (currentLevel > priv->map->zoom_levels) + currentLevel = priv->map->zoom_levels; + + map_load_level(priv->map, currentLevel); + priv->map->current_level->anchor = anchor; + + map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); + clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); + + marker_reposition(view); + } + } + break; + } + case PROP_OFFLINE: + priv->offline = g_value_get_boolean(value); + break; + case PROP_DECEL_RATE: + { + gdouble decel = g_value_get_double(value); + g_object_set (priv->finger_scroll, "decel-rate", decel, NULL); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void +champlain_view_finalize (GObject *object) { ChamplainView *view = CHAMPLAIN_VIEW (object); ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); @@ -335,7 +333,7 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) object_class->finalize = champlain_view_finalize; object_class->get_property = champlain_view_get_property; object_class->set_property = champlain_view_set_property; - + /** * ChamplainView:longitude: * @@ -399,7 +397,7 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) 0, CHAMPLAIN_MAP_SOURCE_COUNT, CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, - CHAMPLAIN_PARAM_READWRITE)); + CHAMPLAIN_PARAM_READWRITE)); /** * ChamplainView:offline: @@ -413,7 +411,7 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) "Offline Mode", "If viewer is in offline mode.", FALSE, - CHAMPLAIN_PARAM_READWRITE)); + CHAMPLAIN_PARAM_READWRITE)); /** * ChamplainView:decel-rate: @@ -436,45 +434,45 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) } static void -champlain_view_init (ChamplainView *champlainView) +champlain_view_init (ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); priv->map_source = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP; priv->zoom_level = 3; priv->offline = FALSE; } -static void -viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *champlainView) +static void +viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + GdkPoint rect; tidy_viewport_get_origin(TIDY_VIEWPORT(priv->viewport), &rect.x, &rect.y, NULL); - + if (rect.x == priv->viewport_size.x && rect.y == priv->viewport_size.y) return; priv->viewport_size.x = rect.x; priv->viewport_size.y = rect.y; - + map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); - - g_object_notify(G_OBJECT(champlainView), "longitude"); - g_object_notify(G_OBJECT(champlainView), "latitude"); + + g_object_notify(G_OBJECT(view), "longitude"); + g_object_notify(G_OBJECT(view), "latitude"); } static void -view_size_allocated_cb (GtkWidget *view, GtkAllocation *allocation, ChamplainView *champlainView) +view_size_allocated_cb (GtkWidget *widget, GtkAllocation *allocation, ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + priv->viewport_size.width = allocation->width; priv->viewport_size.height = allocation->height; - - resize_viewport(champlainView); + + resize_viewport(view); map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); } @@ -490,11 +488,11 @@ champlain_view_new (ChamplainViewMode mode) { ClutterColor stage_color = { 0x34, 0x39, 0x39, 0xff }; ChamplainView *view; - ClutterActor *stage; - + ClutterActor *stage; + 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", @@ -503,14 +501,14 @@ champlain_view_new (ChamplainViewMode mode) // 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); - + // Setup viewport priv->viewport = tidy_viewport_new (); g_object_set (G_OBJECT (priv->viewport), "sync-adjustments", FALSE, NULL); - + g_signal_connect (priv->viewport, "notify::x-origin", G_CALLBACK (viewport_x_changed_cb), @@ -537,13 +535,13 @@ champlain_view_new (ChamplainViewMode mode) priv->map_layer = clutter_group_new(); clutter_actor_show(priv->map_layer); clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map_layer); - + // Setup user_layers priv->user_layers = clutter_group_new(); clutter_actor_show(priv->user_layers); clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->user_layers); clutter_actor_raise(priv->user_layers, priv->map_layer); - + return GTK_WIDGET (view); } @@ -559,9 +557,9 @@ champlain_view_new (ChamplainViewMode mode) */ // FIXME: Animate this. Can be done in Tidy-Adjustment (like for elastic effect) void -champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdouble latitude) +champlain_view_center_on (ChamplainView *view, gdouble longitude, gdouble latitude) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); gdouble x, y; x = priv->map->longitude_to_x(priv->map, longitude, priv->map->current_level->level); @@ -582,7 +580,7 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub anchor->x = max; if (anchor->y > max) anchor->y = max; - + x -= anchor->x; y -= anchor->y; } else { @@ -593,7 +591,7 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub int i; for (i = 0; i < priv->map->current_level->tiles->len; i++) { - Tile* tile = g_ptr_array_index(priv->map->current_level->tiles, i); + Tile *tile = g_ptr_array_index(priv->map->current_level->tiles, i); if (!tile->loading) tile_set_position(priv->map, tile); } @@ -602,114 +600,116 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub x - priv->viewport_size.width / 2.0, y - priv->viewport_size.height / 2.0, 0); - - g_object_notify(G_OBJECT(champlainView), "longitude"); - g_object_notify(G_OBJECT(champlainView), "latitude"); - + + g_object_notify(G_OBJECT(view), "longitude"); + g_object_notify(G_OBJECT(view), "latitude"); + map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); } /** * champlain_view_zoom_in: - * @champlainView: a #ChamplainView + * @view: a #ChamplainView * * Zoom in the map by one level. * * Since: 0.1 */ void -champlain_view_zoom_in (ChamplainView *champlainView) +champlain_view_zoom_in (ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - ClutterActor * group = priv->map->current_level->group; + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + ClutterActor *group = priv->map->current_level->group; gdouble lon = viewport_get_current_longitude(priv); gdouble lat = viewport_get_current_latitude(priv); - if(map_zoom_in(priv->map)) + + if(map_zoom_in(priv->map)) { - resize_viewport(champlainView); + resize_viewport(view); clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - champlain_view_center_on(champlainView, lon, lat); - marker_reposition(champlainView); - - g_object_notify(G_OBJECT(champlainView), "zoom-level"); + champlain_view_center_on(view, lon, lat); + marker_reposition(view); + + g_object_notify(G_OBJECT(view), "zoom-level"); } } /** * champlain_view_zoom_out: - * @champlainView: a #ChamplainView + * @view: a #ChamplainView * * Zoom out the map by one level. * * Since: 0.1 */ void -champlain_view_zoom_out (ChamplainView *champlainView) +champlain_view_zoom_out (ChamplainView *view) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); - ClutterActor * group = priv->map->current_level->group; + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + ClutterActor *group = priv->map->current_level->group; gdouble lon = viewport_get_current_longitude(priv); gdouble lat = viewport_get_current_latitude(priv); + if(map_zoom_out(priv->map)) { - resize_viewport(champlainView); + resize_viewport(view); clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - champlain_view_center_on(champlainView, lon, lat); - marker_reposition(champlainView); - - g_object_notify(G_OBJECT(champlainView), "zoom-level"); + champlain_view_center_on(view, lon, lat); + marker_reposition(view); + + g_object_notify(G_OBJECT(view), "zoom-level"); } } static void -notify_marker_reposition_cb(ChamplainMarker *marker, GParamSpec *arg1, ChamplainView *champlainView) +notify_marker_reposition_cb(ChamplainMarker *marker, GParamSpec *arg1, ChamplainView *view) { - marker_reposition_cb(marker, champlainView); + marker_reposition_cb(marker, view); } static void -layer_add_marker (ClutterGroup *layer, ChamplainMarker *marker, ChamplainView *champlainView) +layer_add_marker (ClutterGroup *layer, ChamplainMarker *marker, ChamplainView *view) { g_signal_connect (marker, "notify::longitude", G_CALLBACK (notify_marker_reposition_cb), - champlainView); + view); } -static void -connect_marker_notify_cb (ChamplainMarker *marker, ChamplainView* champlainView) +static void +connect_marker_notify_cb (ChamplainMarker *marker, ChamplainView *view) { g_signal_connect (marker, "notify::longitude", G_CALLBACK (notify_marker_reposition_cb), - champlainView); + view); } /** * champlain_view_add_layer: - * @champlainView: a #ChamplainView + * @view: a #ChamplainView * @layer: a #ClutterActor * * Adds a new layer to the view * * Since: 0.2 */ -void -champlain_view_add_layer (ChamplainView *champlainView, ClutterActor *layer) +void +champlain_view_add_layer (ChamplainView *view, ClutterActor *layer) { - ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView); + ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); clutter_container_add(CLUTTER_CONTAINER(priv->user_layers), layer, NULL); clutter_actor_raise_top(layer); - + if(priv->map) - marker_reposition(champlainView); - + marker_reposition(view); + g_signal_connect (layer, "add", G_CALLBACK (layer_add_marker), - champlainView); + view); - clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(connect_marker_notify_cb), champlainView); + clutter_container_foreach(CLUTTER_CONTAINER(layer), CLUTTER_CALLBACK(connect_marker_notify_cb), view); } diff --git a/champlain/map.c b/champlain/map.c index a68e03f..1d7535c 100644 --- a/champlain/map.c +++ b/champlain/map.c @@ -16,7 +16,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + #include "map.h" #include "zoomlevel.h" #include "sources/osm_mapnik.h" @@ -26,12 +26,12 @@ #include "sources/google_terrain.h" #include -Map* +Map* map_new (ChamplainMapSource source) { - Map* map = g_new0(Map, 1); - - switch(source) + Map *map = g_new0(Map, 1); + + switch(source) { case CHAMPLAIN_MAP_SOURCE_DEBUG: debugmap_init(map); @@ -46,15 +46,15 @@ map_new (ChamplainMapSource source) mff_relief_init(map); break; } - + map->previous_level = NULL; map->current_level = NULL; return map; } -void -map_load_level(Map* map, gint zoom_level) +void +map_load_level(Map *map, gint zoom_level) { if (map->previous_level) zoom_level_free(map->previous_level); @@ -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, GdkRectangle viewport, gboolean offline) { if (viewport.x < 0) viewport.x = 0; @@ -76,10 +76,10 @@ map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline) gint x_count = ceil((float)viewport.width / map->tile_size) + 1; gint y_count = ceil((float)viewport.height / map->tile_size) + 1; - + gint x_first = (map->current_level->anchor.x + viewport.x) / map->tile_size; gint y_first = (map->current_level->anchor.y + viewport.y) / map->tile_size; - + x_count += x_first; y_count += y_first; @@ -89,20 +89,20 @@ map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline) y_count = map->current_level->column_count; //g_print("Tiles: %d, %d to %d, %d\n", x_first, y_first, x_count, y_count); - + int i, j, k; // Get rid of old tiles first for (k = 0; k < map->current_level->tiles->len; k++) { - Tile* tile = g_ptr_array_index(map->current_level->tiles, k); + Tile *tile = g_ptr_array_index(map->current_level->tiles, k); if (tile->x < x_first || tile->x > x_count || tile->y < y_first || tile->y > y_count) { g_ptr_array_remove (map->current_level->tiles, tile); tile_free(tile); } } - + //Load new tiles if needed for (i = x_first; i < x_count; i++) { @@ -111,22 +111,22 @@ map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline) gboolean exist = FALSE; for (k = 0; k < map->current_level->tiles->len && !exist; k++) { - Tile* tile = g_ptr_array_index(map->current_level->tiles, k); + Tile *tile = g_ptr_array_index(map->current_level->tiles, k); if ( tile->x == i && tile->y == j) exist = TRUE; } if(!exist) { - Tile* tile = tile_load(map, map->current_level->level, i, j, offline); + Tile *tile = tile_load(map, map->current_level->level, i, j, offline); g_ptr_array_add (map->current_level->tiles, tile); } } } } -gboolean -map_zoom_in (Map* map) +gboolean +map_zoom_in (Map *map) { gint new_level = map->current_level->level + 1; if(new_level <= map->zoom_levels) @@ -137,8 +137,8 @@ map_zoom_in (Map* map) return FALSE; } -gboolean -map_zoom_out (Map* map) +gboolean +map_zoom_out (Map *map) { gint new_level = map->current_level->level - 1; if(new_level >= 0) @@ -149,16 +149,16 @@ map_zoom_out (Map* map) return FALSE; } -void -map_free (Map* map) +void +map_free (Map *map) { zoom_level_free(map->current_level); } -gboolean -map_zoom_to (Map* map, guint zoomLevel) +gboolean +map_zoom_to (Map *map, guint zoomLevel) { - if(zoomLevel >= 0 && + if(zoomLevel >= 0 && zoomLevel<= map->zoom_levels) { map_load_level(map, zoomLevel); diff --git a/champlain/map.h b/champlain/map.h index 911c197..3e3eb2b 100644 --- a/champlain/map.h +++ b/champlain/map.h @@ -33,32 +33,32 @@ struct _Map { int zoom_levels; - const gchar* name; + const gchar *name; int tile_size; - ZoomLevel* current_level; - ZoomLevel* previous_level; - - guint (* get_row_count) (Map* map, guint zoom_level); - guint (* get_column_count) (Map* map, guint zoom_level); - - gint (* longitude_to_x) (Map* map, gdouble longitude, guint zoom_level); - gint (* latitude_to_y) (Map* map, gdouble latitude, guint zoom_level); - gdouble (* x_to_longitude) (Map* map, gint x, guint zoom_level); - gdouble (* y_to_latitude) (Map* map, gint y, guint zoom_level); - - gchar* (* get_tile_filename) (Map* map, Tile* tile); - gchar* (* get_tile_uri) (Map* map, Tile* tile); + ZoomLevel *current_level; + ZoomLevel *previous_level; + + guint (* get_row_count) (Map *map, guint zoom_level); + guint (* get_column_count) (Map *map, guint zoom_level); + + gint (* longitude_to_x) (Map *map, gdouble longitude, guint zoom_level); + gint (* latitude_to_y) (Map *map, gdouble latitude, guint zoom_level); + gdouble (* x_to_longitude) (Map *map, gint x, guint zoom_level); + gdouble (* y_to_latitude) (Map *map, gint y, guint zoom_level); + + gchar *(* get_tile_filename) (Map *map, Tile *tile); + gchar *(* get_tile_uri) (Map *map, Tile *tile); }; -Map* map_new (ChamplainMapSource source); +Map *map_new (ChamplainMapSource source); -void map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline); +void map_load_visible_tiles (Map *map, GdkRectangle viewport, gboolean offline); -void map_free (Map* map); +void map_free (Map *map); -gboolean map_zoom_to (Map* map, guint zoomLevel); +gboolean map_zoom_to (Map *map, guint zoomLevel); #endif diff --git a/champlain/sources/debugmap.c b/champlain/sources/debugmap.c index bedc265..3ab068a 100644 --- a/champlain/sources/debugmap.c +++ b/champlain/sources/debugmap.c @@ -16,111 +16,111 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + #include "sources/debugmap.h" #include -guint debugmap_row_count(Map* map, guint zoom_level); -guint debugmap_column_count(Map* map, guint zoom_level); -Tile* debugmap_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint debugmap_row_count(Map *map, guint zoom_level); +guint debugmap_column_count(Map *map, guint zoom_level); +Tile *debugmap_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint debugmap_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint debugmap_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble debugmap_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble debugmap_y_to_latitude (Map* map, gint y, guint zoom_level); +gint debugmap_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint debugmap_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble debugmap_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble debugmap_y_to_latitude (Map *map, gint y, guint zoom_level); -void -debugmap_init(Map* map) +void +debugmap_init(Map *map) { map->name = "Debug"; map->zoom_levels = 1; map->tile_size = 256; - + map->get_row_count = debugmap_row_count; map->get_column_count = debugmap_column_count; - + map->longitude_to_x = debugmap_longitude_to_x; map->latitude_to_y = debugmap_latitude_to_y; map->x_to_longitude = debugmap_x_to_longitude; map->y_to_latitude = debugmap_y_to_latitude; } -guint debugmap_row_count(Map* map, guint zoom_level) +guint debugmap_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint debugmap_column_count(Map* map, guint zoom_level) +guint debugmap_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -Tile* debugmap_get_tile (Map* map, guint zoom_level, guint x, guint y) +Tile *debugmap_get_tile (Map *map, guint zoom_level, guint x, guint y) { - Tile* tile = g_new0(Tile, 1); - + Tile *tile = g_new0(Tile, 1); + ClutterColor white; clutter_color_parse ("white", &white); ClutterColor blue; clutter_color_parse ("blue", &blue); - - ClutterColor * color, * textColor; - if ((y + x) % 2) + + ClutterColor *color, *textColor; + if ((y + x) % 2) { color = &blue; textColor = &white; - } - else + } + else { color = &white; textColor = &blue; } - + tile->x = x; tile->y = y; tile->actor = clutter_group_new(); - - ClutterActor* actor = clutter_rectangle_new_with_color (color); + + ClutterActor *actor = clutter_rectangle_new_with_color (color); clutter_actor_set_position (actor, x * map->tile_size, y * map->tile_size); clutter_actor_set_size (actor, map->tile_size, map->tile_size); clutter_actor_show (actor); clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); - + x *= map->tile_size; y *= map->tile_size; - + gdouble lon, lat; lon = debugmap_x_to_longitude(map, x, zoom_level); lat = debugmap_y_to_latitude(map, x, zoom_level); - + actor = clutter_label_new_full ("Arial", g_strdup_printf("%.2f, %.2f", lon, lat), textColor); clutter_actor_set_position (actor, x, y); clutter_container_add_actor (CLUTTER_CONTAINER (tile->actor), actor); - + g_object_ref(tile->actor); // to prevent actors to be destroyed when they are removed from groups - + return tile; } //FIXME: These functions need to be fixed -gint debugmap_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint debugmap_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { - return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; + return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint debugmap_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint debugmap_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { - return ((latitude + 90.0) / 180.0 * pow(2.0, zoom_level)) * map->tile_size; + return ((latitude + 90.0) / 180.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble debugmap_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble debugmap_x_to_longitude (Map *map, gint x, guint zoom_level) { x /= map->tile_size; return x / map->tile_size * pow(2.0, zoom_level) * 360.0 - 180; } -gdouble debugmap_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble debugmap_y_to_latitude (Map *map, gint y, guint zoom_level) { y /= map->tile_size; return y / map->tile_size * pow(2.0, zoom_level) * 180.0 - 90; diff --git a/champlain/sources/google_map.c b/champlain/sources/google_map.c index 3c79c0a..6803654 100644 --- a/champlain/sources/google_map.c +++ b/champlain/sources/google_map.c @@ -16,92 +16,92 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* * WARNING: Using the Google Map Tiles is in viloation of the Terms of Service. * The current code isn't working because the web server is returning Forbiden error message. */ - + #include "sources/google_map.h" #include "map.h" #include #include -guint google_map_row_count(Map* map, guint zoom_level); -guint google_map_column_count(Map* map, guint zoom_level); -Tile* google_map_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint google_map_row_count(Map *map, guint zoom_level); +guint google_map_column_count(Map *map, guint zoom_level); +Tile *google_map_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint google_map_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint google_map_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble google_map_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble google_map_y_to_latitude (Map* map, gint y, guint zoom_level); +gint google_map_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint google_map_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble google_map_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble google_map_y_to_latitude (Map *map, gint y, guint zoom_level); -gchar* google_map_get_tile_filename(Map* map, Tile* tile); -gchar* google_map_get_tile_uri(Map* map, Tile* tile); +gchar *google_map_get_tile_filename(Map *map, Tile *tile); +gchar *google_map_get_tile_uri(Map *map, Tile *tile); void -google_map_init(Map* map) +google_map_init(Map *map) { map->name = "Google Map"; map->zoom_levels = 15; map->tile_size = 256; - + map->get_row_count = google_map_row_count; map->get_column_count = google_map_column_count; - + map->longitude_to_x = google_map_longitude_to_x; map->latitude_to_y = google_map_latitude_to_y; map->x_to_longitude = google_map_x_to_longitude; map->y_to_latitude = google_map_y_to_latitude; - + map->get_tile_filename = google_map_get_tile_filename; map->get_tile_uri = google_map_get_tile_uri; } -guint google_map_row_count(Map* map, guint zoom_level) +guint google_map_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint -google_map_column_count(Map* map, guint zoom_level) +guint +google_map_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -gint -google_map_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint +google_map_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint -google_map_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint +google_map_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble -google_map_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble +google_map_x_to_longitude (Map *map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } -gdouble -google_map_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble +google_map_y_to_latitude (Map *map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* google_map_get_tile_filename(Map* map, Tile* tile) +gchar *google_map_get_tile_filename(Map *map, Tile *tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", map->zoom_levels + 1 - tile->level, tile->y, tile->x), NULL); } -gchar* google_map_get_tile_uri(Map* map, Tile* tile) +gchar *google_map_get_tile_uri(Map *map, Tile *tile) { return g_strdup_printf("http://mt.google.com/mt?n=404&v=w2.99&x=%d&y=%d&zoom=%d", tile->x, tile->y, map->zoom_levels + 1 - tile->level, NULL); } diff --git a/champlain/sources/google_sat.c b/champlain/sources/google_sat.c index 630f2d8..0949fe8 100644 --- a/champlain/sources/google_sat.c +++ b/champlain/sources/google_sat.c @@ -16,92 +16,92 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* * WARNING: Using the Google Map Tiles is in viloation of the Terms of Service. * The current code isn't working because the web server is returning Forbiden error message. */ - + #include "sources/google_sat.h" #include "map.h" #include #include -guint google_sat_row_count(Map* map, guint zoom_level); -guint google_sat_column_count(Map* map, guint zoom_level); -Tile* google_sat_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint google_sat_row_count(Map *map, guint zoom_level); +guint google_sat_column_count(Map *map, guint zoom_level); +Tile *google_sat_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint google_sat_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint google_sat_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble google_sat_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble google_sat_y_to_latitude (Map* map, gint y, guint zoom_level); +gint google_sat_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint google_sat_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble google_sat_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble google_sat_y_to_latitude (Map *map, gint y, guint zoom_level); -gchar* google_sat_get_tile_filename(Map* map, Tile* tile); -gchar* google_sat_get_tile_uri(Map* map, Tile* tile); +gchar *google_sat_get_tile_filename(Map *map, Tile *tile); +gchar *google_sat_get_tile_uri(Map *map, Tile *tile); void -google_sat_init(Map* map) +google_sat_init(Map *map) { map->name = "OpenStreetMap"; map->zoom_levels = 17; map->tile_size = 256; - + map->get_row_count = google_sat_row_count; map->get_column_count = google_sat_column_count; - + map->longitude_to_x = google_sat_longitude_to_x; map->latitude_to_y = google_sat_latitude_to_y; map->x_to_longitude = google_sat_x_to_longitude; map->y_to_latitude = google_sat_y_to_latitude; - + map->get_tile_filename = google_sat_get_tile_filename; map->get_tile_uri = google_sat_get_tile_uri; } -guint google_sat_row_count(Map* map, guint zoom_level) +guint google_sat_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint -google_sat_column_count(Map* map, guint zoom_level) +guint +google_sat_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -gint -google_sat_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint +google_sat_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint -google_sat_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint +google_sat_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble -google_sat_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble +google_sat_x_to_longitude (Map *map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } -gdouble -google_sat_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble +google_sat_y_to_latitude (Map *map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* google_sat_get_tile_filename(Map* map, Tile* tile) +gchar *google_sat_get_tile_filename(Map *map, Tile *tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", map->zoom_levels + 1 - tile->level, tile->y, tile->x), NULL); } -gchar* google_sat_get_tile_uri(Map* map, Tile* tile) +gchar *google_sat_get_tile_uri(Map *map, Tile *tile) { return g_strdup_printf("http://mt.google.com/mt?n=404&v=w2.99&x=%d&y=%d&zoom=%d", tile->x, tile->y, map->zoom_levels + 1 - tile->level, NULL); } diff --git a/champlain/sources/google_terrain.c b/champlain/sources/google_terrain.c index 3bf40f3..13723be 100644 --- a/champlain/sources/google_terrain.c +++ b/champlain/sources/google_terrain.c @@ -16,92 +16,92 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + /* * WARNING: Using the Google Map Tiles is in viloation of the Terms of Service. * The current code isn't working because the web server is returning Forbiden error message. */ - + #include "sources/google_terrain.h" #include "map.h" #include #include -guint google_terrain_row_count(Map* map, guint zoom_level); -guint google_terrain_column_count(Map* map, guint zoom_level); -Tile* google_terrain_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint google_terrain_row_count(Map *map, guint zoom_level); +guint google_terrain_column_count(Map *map, guint zoom_level); +Tile *google_terrain_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint google_terrain_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint google_terrain_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble google_terrain_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble google_terrain_y_to_latitude (Map* map, gint y, guint zoom_level); +gint google_terrain_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint google_terrain_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble google_terrain_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble google_terrain_y_to_latitude (Map *map, gint y, guint zoom_level); -gchar* google_terrain_get_tile_filename(Map* map, Tile* tile); -gchar* google_terrain_get_tile_uri(Map* map, Tile* tile); +gchar *google_terrain_get_tile_filename(Map *map, Tile *tile); +gchar *google_terrain_get_tile_uri(Map *map, Tile *tile); void -google_terrain_init(Map* map) +google_terrain_init(Map *map) { map->name = "OpenStreetMap"; map->zoom_levels = 17; map->tile_size = 256; - + map->get_row_count = google_terrain_row_count; map->get_column_count = google_terrain_column_count; - + map->longitude_to_x = google_terrain_longitude_to_x; map->latitude_to_y = google_terrain_latitude_to_y; map->x_to_longitude = google_terrain_x_to_longitude; map->y_to_latitude = google_terrain_y_to_latitude; - + map->get_tile_filename = google_terrain_get_tile_filename; map->get_tile_uri = google_terrain_get_tile_uri; } -guint google_terrain_row_count(Map* map, guint zoom_level) +guint google_terrain_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint -google_terrain_column_count(Map* map, guint zoom_level) +guint +google_terrain_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -gint -google_terrain_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint +google_terrain_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint -google_terrain_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint +google_terrain_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble -google_terrain_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble +google_terrain_x_to_longitude (Map *map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } -gdouble -google_terrain_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble +google_terrain_y_to_latitude (Map *map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* google_terrain_get_tile_filename(Map* map, Tile* tile) +gchar *google_terrain_get_tile_filename(Map *map, Tile *tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); } -gchar* google_terrain_get_tile_uri(Map* map, Tile* tile) +gchar *google_terrain_get_tile_uri(Map *map, Tile *tile) { return g_strdup_printf("http://tile.openstreetmap.org/%d/%d/%d.png", tile->level, tile->x, tile->y, NULL); } diff --git a/champlain/sources/mff_relief.c b/champlain/sources/mff_relief.c index c346d86..a0f853c 100644 --- a/champlain/sources/mff_relief.c +++ b/champlain/sources/mff_relief.c @@ -16,7 +16,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + #include "sources/mff_relief.h" #include "map.h" #include @@ -25,81 +25,81 @@ //http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames#C.2FC.2B.2B -guint mff_relief_row_count(Map* map, guint zoom_level); -guint mff_relief_column_count(Map* map, guint zoom_level); -Tile* mff_relief_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint mff_relief_row_count(Map *map, guint zoom_level); +guint mff_relief_column_count(Map *map, guint zoom_level); +Tile *mff_relief_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint mff_relief_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint mff_relief_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble mff_relief_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble mff_relief_y_to_latitude (Map* map, gint y, guint zoom_level); +gint mff_relief_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint mff_relief_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble mff_relief_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble mff_relief_y_to_latitude (Map *map, gint y, guint zoom_level); -gchar* mff_relief_get_tile_filename(Map* map, Tile* tile); -gchar* mff_relief_get_tile_uri(Map* map, Tile* tile); +gchar *mff_relief_get_tile_filename(Map *map, Tile *tile); +gchar *mff_relief_get_tile_uri(Map *map, Tile *tile); void -mff_relief_init(Map* map) +mff_relief_init(Map *map) { map->name = "Maps For Free Relief"; map->zoom_levels = 11; map->tile_size = 256; - + map->get_row_count = mff_relief_row_count; map->get_column_count = mff_relief_column_count; - + map->longitude_to_x = mff_relief_longitude_to_x; map->latitude_to_y = mff_relief_latitude_to_y; map->x_to_longitude = mff_relief_x_to_longitude; map->y_to_latitude = mff_relief_y_to_latitude; - + map->get_tile_filename = mff_relief_get_tile_filename; map->get_tile_uri = mff_relief_get_tile_uri; } -guint mff_relief_row_count(Map* map, guint zoom_level) +guint mff_relief_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint -mff_relief_column_count(Map* map, guint zoom_level) +guint +mff_relief_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -gint -mff_relief_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint +mff_relief_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint -mff_relief_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint +mff_relief_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble -mff_relief_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble +mff_relief_x_to_longitude (Map *map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } -gdouble -mff_relief_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble +mff_relief_y_to_latitude (Map *map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* mff_relief_get_tile_filename(Map* map, Tile* tile) +gchar *mff_relief_get_tile_filename(Map *map, Tile *tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); } -gchar* mff_relief_get_tile_uri(Map* map, Tile* tile) +gchar *mff_relief_get_tile_uri(Map *map, Tile *tile) { return g_strdup_printf("http://maps-for-free.com/layer/relief/z%d/row%d/%d_%d-%d.jpg", tile->level, tile->y, tile->level, tile->x, tile->y, NULL); } diff --git a/champlain/sources/oam.c b/champlain/sources/oam.c index 3a9d1a4..2078d00 100644 --- a/champlain/sources/oam.c +++ b/champlain/sources/oam.c @@ -16,87 +16,87 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + #include "sources/oam.h" #include "map.h" #include #include -guint oam_row_count(Map* map, guint zoom_level); -guint oam_column_count(Map* map, guint zoom_level); -Tile* oam_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint oam_row_count(Map *map, guint zoom_level); +guint oam_column_count(Map *map, guint zoom_level); +Tile *oam_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint oam_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint oam_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble oam_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble oam_y_to_latitude (Map* map, gint y, guint zoom_level); +gint oam_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint oam_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble oam_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble oam_y_to_latitude (Map *map, gint y, guint zoom_level); -gchar* oam_get_tile_filename(Map* map, Tile* tile); -gchar* oam_get_tile_uri(Map* map, Tile* tile); +gchar *oam_get_tile_filename(Map *map, Tile *tile); +gchar *oam_get_tile_uri(Map *map, Tile *tile); void -oam_init(Map* map) +oam_init(Map *map) { map->name = "OpenArialMap"; map->zoom_levels = 17; map->tile_size = 256; - + map->get_row_count = oam_row_count; map->get_column_count = oam_column_count; - + map->longitude_to_x = oam_longitude_to_x; map->latitude_to_y = oam_latitude_to_y; map->x_to_longitude = oam_x_to_longitude; map->y_to_latitude = oam_y_to_latitude; - + map->get_tile_filename = oam_get_tile_filename; map->get_tile_uri = oam_get_tile_uri; } -guint oam_row_count(Map* map, guint zoom_level) +guint oam_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint -oam_column_count(Map* map, guint zoom_level) +guint +oam_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -gint -oam_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint +oam_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint -oam_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint +oam_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble -oam_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble +oam_x_to_longitude (Map *map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } -gdouble -oam_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble +oam_y_to_latitude (Map *map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* oam_get_tile_filename(Map* map, Tile* tile) +gchar *oam_get_tile_filename(Map *map, Tile *tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); } -gchar* oam_get_tile_uri(Map* map, Tile* tile) +gchar *oam_get_tile_uri(Map *map, Tile *tile) { return g_strdup_printf("http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/%d/%d/%d.jpg", tile->level, tile->x, tile->y, NULL); } diff --git a/champlain/sources/osm_mapnik.c b/champlain/sources/osm_mapnik.c index d857940..ad1c861 100644 --- a/champlain/sources/osm_mapnik.c +++ b/champlain/sources/osm_mapnik.c @@ -16,7 +16,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ - + #include "sources/osm_mapnik.h" #include "map.h" #include @@ -25,81 +25,81 @@ //http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames#C.2FC.2B.2B -guint osm_mapnik_row_count(Map* map, guint zoom_level); -guint osm_mapnik_column_count(Map* map, guint zoom_level); -Tile* osm_mapnik_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint osm_mapnik_row_count(Map *map, guint zoom_level); +guint osm_mapnik_column_count(Map *map, guint zoom_level); +Tile *osm_mapnik_get_tile (Map *map, guint zoom_level, guint x, guint y); -gint osm_mapnik_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint osm_mapnik_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble osm_mapnik_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble osm_mapnik_y_to_latitude (Map* map, gint y, guint zoom_level); +gint osm_mapnik_longitude_to_x (Map *map, gdouble longitude, guint zoom_level); +gint osm_mapnik_latitude_to_y (Map *map, gdouble latitude, guint zoom_level); +gdouble osm_mapnik_x_to_longitude (Map *map, gint x, guint zoom_level); +gdouble osm_mapnik_y_to_latitude (Map *map, gint y, guint zoom_level); -gchar* osm_mapnik_get_tile_filename(Map* map, Tile* tile); -gchar* osm_mapnik_get_tile_uri(Map* map, Tile* tile); +gchar *osm_mapnik_get_tile_filename(Map *map, Tile *tile); +gchar *osm_mapnik_get_tile_uri(Map *map, Tile *tile); void -osm_mapnik_init(Map* map) +osm_mapnik_init(Map *map) { map->name = "OpenStreetMap"; map->zoom_levels = 17; map->tile_size = 256; - + map->get_row_count = osm_mapnik_row_count; map->get_column_count = osm_mapnik_column_count; - + map->longitude_to_x = osm_mapnik_longitude_to_x; map->latitude_to_y = osm_mapnik_latitude_to_y; map->x_to_longitude = osm_mapnik_x_to_longitude; map->y_to_latitude = osm_mapnik_y_to_latitude; - + map->get_tile_filename = osm_mapnik_get_tile_filename; map->get_tile_uri = osm_mapnik_get_tile_uri; } -guint osm_mapnik_row_count(Map* map, guint zoom_level) +guint osm_mapnik_row_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -guint -osm_mapnik_column_count(Map* map, guint zoom_level) +guint +osm_mapnik_column_count(Map *map, guint zoom_level) { return pow (2, zoom_level); } -gint -osm_mapnik_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +gint +osm_mapnik_longitude_to_x (Map *map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } -gint -osm_mapnik_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +gint +osm_mapnik_latitude_to_y (Map *map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } -gdouble -osm_mapnik_x_to_longitude (Map* map, gint x, guint zoom_level) +gdouble +osm_mapnik_x_to_longitude (Map *map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } -gdouble -osm_mapnik_y_to_latitude (Map* map, gint y, guint zoom_level) +gdouble +osm_mapnik_y_to_latitude (Map *map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* osm_mapnik_get_tile_filename(Map* map, Tile* tile) +gchar *osm_mapnik_get_tile_filename(Map *map, Tile *tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); } -gchar* osm_mapnik_get_tile_uri(Map* map, Tile* tile) +gchar *osm_mapnik_get_tile_uri(Map *map, Tile *tile) { return g_strdup_printf("http://tile.openstreetmap.org/%d/%d/%d.png", tile->level, tile->x, tile->y, NULL); } diff --git a/champlain/tile.c b/champlain/tile.c index 40e5a92..219f9bb 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -36,33 +36,32 @@ typedef struct { static SoupSession * soup_session; void -tile_set_position(Map* map, Tile* tile) +tile_set_position(Map* map, Tile* tile) { - clutter_actor_set_position (tile->actor, - (tile->x * tile->size) - map->current_level->anchor.x, + clutter_actor_set_position (tile->actor, + (tile->x * tile->size) - map->current_level->anchor.x, (tile->y * tile->size) - map->current_level->anchor.y); clutter_actor_set_size (tile->actor, tile->size, tile->size); clutter_actor_show (tile->actor); } void -tile_setup_animation(Tile* tile) +tile_setup_animation(Tile* tile) { ClutterEffectTemplate *etemplate = clutter_effect_template_new_for_duration (250, CLUTTER_ALPHA_SINE_INC); clutter_actor_set_opacity(tile->actor, 0); clutter_effect_fade (etemplate, tile->actor, 255, NULL, NULL); } -static void +static void create_error_tile(Map* map, Tile* tile) { tile->actor = clutter_texture_new_from_file(DATADIR "/champlain/error.svg", NULL); - + tile_set_position(map, tile); - + clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); tile_setup_animation(tile); - } static void @@ -73,11 +72,11 @@ file_loaded_cb (SoupSession *session, GdkPixbufLoader* loader; GError *error = NULL; gchar* path, *filename, *map_filename; - + Tile* tile = ptr->tile; Map* map = ptr->map; - - if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) + + if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { g_warning ("Unable to download tile %d, %d: %s", tile->x, tile->y, soup_status_get_phrase(msg->status_code)); create_error_tile(map, tile); @@ -97,10 +96,10 @@ file_loaded_cb (SoupSession *session, create_error_tile(map, tile); return; } - + g_object_unref (loader); } - + gdk_pixbuf_loader_close (loader, &error); if (error) { @@ -116,7 +115,7 @@ file_loaded_cb (SoupSession *session, CACHE_DIR, map->name, NULL); - + if (g_mkdir_with_parents (path, 0700) == -1) { if (errno != EEXIST) @@ -126,14 +125,14 @@ file_loaded_cb (SoupSession *session, g_object_unref (loader); } } - + map_filename = map->get_tile_filename(map, tile); filename = g_build_filename (g_get_user_cache_dir (), CACHE_DIR, map->name, map_filename, NULL); - + g_file_set_contents (filename, msg->response_body->data, msg->response_body->length, @@ -147,46 +146,46 @@ file_loaded_cb (SoupSession *session, g_free (tile); return; } - + GdkPixbuf* pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); - + tile->actor = clutter_texture_new(); - clutter_texture_set_from_rgb_data(CLUTTER_TEXTURE(tile->actor), + clutter_texture_set_from_rgb_data(CLUTTER_TEXTURE(tile->actor), gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_has_alpha (pixbuf), gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), gdk_pixbuf_get_rowstride (pixbuf), 3, 0, NULL); - + tile_set_position(map, tile); - + clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); tile_setup_animation(tile); - + tile->loading = FALSE; - + g_object_unref (loader); g_free (filename); g_free (map_filename); } } -Tile* +Tile* tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) { gchar* filename, *map_filename; Tile* tile = g_new0(Tile, 1); - + tile->x = x; tile->y = y; tile->level = zoom_level; tile->size = map->tile_size; - + TwoPtr* ptr = g_new0(TwoPtr, 1); ptr->map = map; ptr->tile = tile; - + // Try the cached version first map_filename = map->get_tile_filename(map, tile); filename = g_build_filename (g_get_user_cache_dir (), @@ -194,12 +193,12 @@ tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) map->name, map_filename, NULL); - - if (g_file_test (filename, G_FILE_TEST_EXISTS)) + + if (g_file_test (filename, G_FILE_TEST_EXISTS)) { tile->actor = clutter_texture_new_from_file(filename, NULL); tile_set_position(map, tile); - + clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL); // Do not animate since it is local and fast } @@ -208,20 +207,19 @@ tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline) SoupMessage *msg; if (!soup_session) soup_session = soup_session_async_new (); - + msg = soup_message_new (SOUP_METHOD_GET, map->get_tile_uri(map, tile)); soup_session_queue_message (soup_session, msg, file_loaded_cb, ptr); tile->loading = TRUE; - } + } // If a tile is neither in cache or can be fetched, do nothing, it'll show up as empty - + g_free (filename); g_free (map_filename); return tile; - } void diff --git a/champlain/tile.h b/champlain/tile.h index 16b3b8d..f200ddb 100644 --- a/champlain/tile.h +++ b/champlain/tile.h @@ -30,10 +30,9 @@ typedef struct int y; int size; int level; - + gboolean loading; // TRUE when a callback exist to load the tile, FALSE otherwise gboolean to_destroy; // TRUE when a tile struct should be deleted when loading is done, FALSE otherwise - } Tile; void tile_free(Tile* tile); diff --git a/champlain/zoomlevel.c b/champlain/zoomlevel.c index f8d4a21..0d04560 100644 --- a/champlain/zoomlevel.c +++ b/champlain/zoomlevel.c @@ -22,11 +22,11 @@ #include "map.h" #include -ZoomLevel* +ZoomLevel* zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) { - ZoomLevel* level = g_new0(ZoomLevel, 1); - + ZoomLevel *level = g_new0(ZoomLevel, 1); + level->level = zoom_level; level->row_count = row; level->column_count = column; @@ -35,9 +35,9 @@ zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) //FIXME: this hard coded value means that there can't be more than 16x16 tiles displayed at once level->tiles = g_ptr_array_sized_new (256); level->group = clutter_group_new (); - + g_object_ref(level->group); // so that the group isn't destroyed when removed from the viewport - + level->anchor.x = 0; level->anchor.y = 0; @@ -45,24 +45,24 @@ zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size) } void -zoom_level_free(ZoomLevel* level) +zoom_level_free(ZoomLevel *level) { int i; for (i = 0; i < level->tiles->len; i++) { - Tile* tile = g_ptr_array_index(level->tiles, i); + Tile *tile = g_ptr_array_index(level->tiles, i); tile_free(tile); } } guint -zoom_level_get_width(ZoomLevel* level) +zoom_level_get_width(ZoomLevel *level) { return (level->column_count) * level->tile_size; } guint -zoom_level_get_height(ZoomLevel* level) +zoom_level_get_height(ZoomLevel *level) { return (level->row_count) * level->tile_size; } diff --git a/champlain/zoomlevel.h b/champlain/zoomlevel.h index ee73d0b..ed26c15 100644 --- a/champlain/zoomlevel.h +++ b/champlain/zoomlevel.h @@ -30,19 +30,19 @@ typedef struct int row_count; int column_count; int tile_size; - + GPtrArray *tiles; ClutterActor* group; - GdkPoint anchor; + GdkPoint anchor; } ZoomLevel; -guint zoom_level_get_width(ZoomLevel* level); +guint zoom_level_get_width(ZoomLevel *level); -guint zoom_level_get_height(ZoomLevel* level); +guint zoom_level_get_height(ZoomLevel *level); ZoomLevel* zoom_level_new(gint zoom_level, gint row, gint column, gint tile_size); -void zoom_level_free(ZoomLevel* level); +void zoom_level_free(ZoomLevel *level); #endif