From b2dcfd1024a4eca43d1da742ceedacc2337023eb Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Tue, 10 Nov 2009 00:05:00 +0100 Subject: [PATCH] Add initial scaling capabilities --- champlain/champlain-view.c | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 8e1245c..78d7c09 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -995,6 +995,41 @@ button_release_cb (ClutterActor *actor, return found; } +static void +update_scale (ChamplainView *view, + GParamSpec *arg1, + gpointer *p) +{ + ClutterActor *text; + ChamplainViewPrivate *priv = view->priv; + ChamplainZoomLevel *level; + gfloat m_per_pixel; + gchar *label; + ChamplainTile *tile; + + /* Height is in pixels. + m/px = m/° * 180° / height_in_pixels + + We assume that m/° = 60 * average length of arcsecond, aka + nautical mile, so m/° = 111120 m/° + */ + + if (! priv || !priv->map || !priv->map->current_level) { + return; + } + level = priv->map->current_level; + tile = champlain_zoom_level_get_nth_tile(level, 0); + m_per_pixel = 1852 * 60 * 180 / (champlain_tile_get_size (tile) * champlain_zoom_level_get_height (level)); + printf("FOO: %.2f\n", m_per_pixel); + printf("FOO: %d\n", champlain_zoom_level_get_height (level)); + + label = g_strdup_printf("%.2f km", (m_per_pixel * SCALE_WIDTH) / 1000); + printf("FOO2: %s\n", label); + + text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (priv->scale_actor), "scale-label"); + clutter_text_set_text (CLUTTER_TEXT (text), label); +} + static void create_scale (ChamplainView *view) { @@ -1002,9 +1037,11 @@ create_scale (ChamplainView *view) cairo_t *cr; gfloat width, height; ChamplainViewPrivate *priv = view->priv; - priv->scale_actor = g_object_ref (clutter_group_new()); + g_signal_connect (view, "notify::zoom-level", G_CALLBACK (update_scale), + NULL); + scale = clutter_cairo_texture_new (SCALE_WIDTH, SCALE_HEIGHT); cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (scale)); @@ -1018,7 +1055,8 @@ create_scale (ChamplainView *view) cairo_stroke (cr); cairo_destroy (cr); - text = clutter_text_new_with_text ("Sans 9", "100 km"); + text = clutter_text_new_with_text ("Sans 9", "X km"); + clutter_actor_set_name (text, "scale-label"); clutter_actor_get_size (text, &width, &height); clutter_container_add_actor (CLUTTER_CONTAINER (priv->scale_actor), text); clutter_actor_set_position (text, (SCALE_WIDTH - width) / 2, SCALE_HEIGHT - height - SCALE_LINE_WIDTH); -- 2.39.5