[libchamplain/libchamplain-0-4] Display a significant value
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libchamplain/libchamplain-0-4] Display a significant value
- Date: Tue, 5 Jan 2010 19:01:46 +0000 (UTC)
commit 9c8a19f540d24346d9a5ece397c77d8afd875e47
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date: Tue Dec 15 11:54:14 2009 -0500
Display a significant value
champlain/champlain-view.c | 24 +++++++++++++++++++++---
1 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index f508d0b..1f3d475 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -230,7 +230,6 @@ static void champlain_view_go_to_with_duration (ChamplainView *view,
#define SCALE_HEIGHT 20
#define SCALE_WIDTH 100
#define SCALE_PADDING 10
-#define SCALE_LINE_WIDTH 4.0
static gdouble
viewport_get_longitude_at (ChamplainViewPrivate *priv, gint x)
@@ -1009,6 +1008,8 @@ update_scale (ChamplainView *view)
gfloat scale_width = SCALE_WIDTH;
gchar *label;
cairo_t *cr;
+ gint base;
+ gfloat factor;
if (! priv || !priv->map || !priv->map->current_level)
return;
@@ -1024,11 +1025,23 @@ update_scale (ChamplainView *view)
}
m_per_pixel = champlain_map_source_get_meters_per_pixel (priv->map_source,
- priv->zoom_level, priv->latitude, priv->longitude) * scale_width;
- label = g_strdup_printf ("%.2f km", m_per_pixel / 1000);
+ priv->zoom_level, priv->latitude, priv->longitude);
+ /* Keep the closest power of 10 */
+ base = floor (log (m_per_pixel * scale_width) / log (10));
+ base = pow (10, base);
+
+ /* How many times can it be fitted in our max scale width */
+ scale_width /= m_per_pixel * scale_width / base;
+ factor = floor (SCALE_WIDTH / scale_width);
+ base *= factor;
+ scale_width *= factor;
+
+ label = g_strdup_printf ("%d km", base / 1000);
text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (priv->scale_actor), "scale-label");
clutter_text_set_text (CLUTTER_TEXT (text), label);
+
+ /* Center the label */
clutter_actor_get_size (text, &width, &height);
clutter_actor_set_position (text, (scale_width - width) / 2, -height / 2);
@@ -1049,6 +1062,11 @@ update_scale (ChamplainView *view)
cairo_line_to (cr, scale_width, SCALE_HEIGHT / 2);
cairo_stroke (cr);
+ /* Middle tick */
+ cairo_move_to (cr, scale_width / 2, 3 * SCALE_HEIGHT / 8);
+ cairo_line_to (cr, scale_width / 2, 5 * SCALE_HEIGHT / 8);
+ cairo_stroke (cr);
+
/* Last tick */
cairo_move_to (cr, scale_width, SCALE_HEIGHT / 4);
cairo_line_to (cr, scale_width, 3 * SCALE_HEIGHT / 4);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]