]> err.no Git - libchamplain/commitdiff
Getting the scale to draw
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 26 Aug 2009 04:45:05 +0000 (00:45 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 26 Aug 2009 04:45:05 +0000 (00:45 -0400)
champlain/champlain-view.c

index e1bfaae08f1603987e207c96bbe19a993ac6f194..d77b3014ccde8a3621f48ce2e58bc674178163ad 100644 (file)
@@ -94,7 +94,8 @@ enum
   PROP_KEEP_CENTER_ON_RESIZE,
   PROP_SHOW_LICENSE,
   PROP_ZOOM_ON_DOUBLE_CLICK,
-  PROP_STATE
+  PROP_STATE,
+  PROP_DISPLAY_SCALE,
 };
 
 #define PADDING 10
@@ -150,6 +151,9 @@ struct _ChamplainViewPrivate
   gboolean show_license;
   ClutterActor *license_actor; /* Contains the license info */
 
+  ClutterActor *scale_actor;
+  gboolean display_scale;
+
   ChamplainState state; /* View's global state */
 
   /* champlain_view_go_to's context, kept for stop_go_to */
@@ -214,6 +218,11 @@ static void champlain_view_go_to_with_duration (ChamplainView *view,
     gdouble longitude,
     guint duration);
 
+#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)
 {
@@ -552,6 +561,9 @@ champlain_view_get_property (GObject *object,
       case PROP_SCROLL_MODE:
         g_value_set_enum (value, priv->scroll_mode);
         break;
+      case PROP_DISPLAY_SCALE:
+        g_value_set_boolean (value, priv->display_scale);
+        break;
       case PROP_DECEL_RATE:
         {
           gdouble decel = 0.0;
@@ -610,6 +622,9 @@ champlain_view_set_property (GObject *object,
     case PROP_SCROLL_MODE:
       champlain_view_set_scroll_mode (view, g_value_get_enum (value));
       break;
+    case PROP_DISPLAY_SCALE:
+      priv->display_scale = g_value_get_boolean (value);
+      break;
     case PROP_DECEL_RATE:
       champlain_view_set_decel_rate (view, g_value_get_double (value));
       break;
@@ -892,6 +907,22 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass)
            CHAMPLAIN_STATE_INIT,
            G_PARAM_READABLE));
 
+  /**
+  * ChamplainView:display-scale:
+  *
+  * Display the map scale.
+  *
+  * Since: 0.6
+  */
+  g_object_class_install_property (object_class,
+       PROP_DISPLAY_SCALE,
+       g_param_spec_boolean ("display-scale",
+           "Display the map scale",
+           "Display the map scale "
+           "on the screen",
+           TRUE,
+           G_PARAM_READWRITE));
+
   /**
   * ChamplainView::animation-completed:
   * @view: the #ChamplainView that received the signal
@@ -934,6 +965,40 @@ button_release_cb (ClutterActor *actor,
   return found;
 }
 
+static void
+create_scale (ChamplainView *view)
+{
+  ClutterActor *scale, *text;
+  cairo_t *cr;
+  gfloat width, height;
+  ChamplainViewPrivate *priv = view->priv;
+
+  priv->scale_actor = g_object_ref (clutter_group_new());
+
+  scale = clutter_cairo_texture_new (SCALE_WIDTH, SCALE_HEIGHT);
+  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (scale));
+
+  cairo_set_source_rgb (cr, 0, 0, 0);
+  cairo_move_to (cr, 0, SCALE_HEIGHT / 2);
+  cairo_line_to (cr, 0, SCALE_HEIGHT);
+  cairo_line_to (cr, SCALE_WIDTH, SCALE_HEIGHT);
+  cairo_line_to (cr, SCALE_WIDTH, SCALE_HEIGHT / 2);
+
+  cairo_set_line_width (cr, SCALE_LINE_WIDTH);
+  cairo_stroke (cr);
+  cairo_destroy (cr);
+
+  text = clutter_text_new_with_text ("Sans 9", "100 km");
+  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);
+
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->scale_actor), scale);
+  clutter_actor_set_position (priv->scale_actor, SCALE_PADDING,
+    priv->viewport_size.height - SCALE_HEIGHT - SCALE_PADDING);
+
+  clutter_actor_set_opacity (priv->scale_actor, 150);
+}
 
 static void
 champlain_view_init (ChamplainView *view)
@@ -965,6 +1030,7 @@ champlain_view_init (ChamplainView *view)
   priv->goto_context = NULL;
   priv->map = NULL;
   priv->polygon_redraw_id = 0;
+  priv->display_scale = TRUE;
 
   /* Setup viewport */
   priv->viewport = g_object_ref (tidy_viewport_new ());
@@ -975,6 +1041,10 @@ champlain_view_init (ChamplainView *view)
   g_signal_connect (priv->viewport, "notify::y-origin",
       G_CALLBACK (viewport_pos_changed_cb), view);
 
+  /* Setup scale */
+  create_scale (view);
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->stage), priv->scale_actor);
+
   /* Setup finger scroll */
   priv->finger_scroll = g_object_ref (tidy_finger_scroll_new (priv->scroll_mode));
 
@@ -1024,6 +1094,7 @@ champlain_view_init (ChamplainView *view)
   champlain_view_set_size (view, priv->viewport_size.width,
       priv->viewport_size.height);
 
+  clutter_actor_raise_top (priv->scale_actor);
   resize_viewport (view);
 
   priv->state = CHAMPLAIN_STATE_DONE;
@@ -1074,6 +1145,8 @@ champlain_view_set_size (ChamplainView *view,
   priv->viewport_size.height = height;
 
   license_set_position (view);
+  clutter_actor_set_position (priv->scale_actor, SCALE_PADDING,
+      priv->viewport_size.height - SCALE_HEIGHT - SCALE_PADDING);
   resize_viewport (view);
 
   if (priv->keep_center_on_resize)