[libchamplain/libchamplain-0-4] Add max-scale-width property to view



commit 149180b9ed6a977155973023ab2c49ac833e2bec
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date:   Tue Dec 15 15:16:36 2009 -0500

    Add max-scale-width property to view

 champlain/champlain-view.c |   82 +++++++++++++++++++++++++++++++++++++++++---
 champlain/champlain-view.h |    2 +
 2 files changed, 79 insertions(+), 5 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index cb35071..d2a8355 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -97,6 +97,7 @@ enum
   PROP_STATE,
   PROP_SHOW_SCALE,
   PROP_SCALE_UNIT,
+  PROP_MAX_SCALE_WIDTH,
 };
 
 #define PADDING 10
@@ -161,6 +162,7 @@ struct _ChamplainViewPrivate
   ClutterActor *scale_actor;
   gboolean show_scale;
   ChamplainUnit scale_unit;
+  guint max_scale_width;
 
   ChamplainState state; /* View's global state */
 
@@ -230,7 +232,6 @@ static void champlain_view_go_to_with_duration (ChamplainView *view,
     guint duration);
 
 #define SCALE_HEIGHT  20
-#define SCALE_WIDTH   100
 #define SCALE_PADDING 10
 #define SCALE_INSIDE_PADDING 10
 #define SCALE_LINE_WIDTH 2
@@ -602,6 +603,9 @@ champlain_view_get_property (GObject *object,
       case PROP_SHOW_SCALE:
         g_value_set_boolean (value, priv->show_scale);
         break;
+      case PROP_MAX_SCALE_WIDTH:
+        g_value_set_uint (value, priv->max_scale_width);
+        break;
       case PROP_SCALE_UNIT:
         g_value_set_enum (value, priv->scale_unit);
         break;
@@ -666,6 +670,9 @@ champlain_view_set_property (GObject *object,
     case PROP_SHOW_SCALE:
       champlain_view_set_show_scale (view, g_value_get_boolean (value));
       break;
+    case PROP_MAX_SCALE_WIDTH:
+      champlain_view_set_max_scale_width (view, g_value_get_uint (value));
+      break;
     case PROP_SCALE_UNIT:
       champlain_view_set_scale_unit (view, g_value_get_enum (value));
       break;
@@ -968,6 +975,24 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass)
            G_PARAM_READWRITE));
 
   /**
+  * ChamplainView:max-scale-width:
+  *
+  * The size of the map scale on screen in pixels.
+  *
+  * Since: 0.4.3
+  */
+  g_object_class_install_property (object_class,
+       PROP_MAX_SCALE_WIDTH,
+       g_param_spec_uint ("max-scale-width",
+           "The width of the scale",
+           "The max width of the scale"
+           "on screen",
+           1,
+           2000,
+           100,
+           G_PARAM_READWRITE));
+
+  /**
   * ChamplainView:scale-unit:
   *
   * The scale's units.
@@ -1032,7 +1057,7 @@ update_scale (ChamplainView *view)
   gfloat width;
   ChamplainViewPrivate *priv = view->priv;
   gfloat m_per_pixel;
-  gfloat scale_width = SCALE_WIDTH;
+  gfloat scale_width = priv->max_scale_width;
   gchar *label;
   cairo_t *cr;
   gfloat base;
@@ -1070,7 +1095,7 @@ update_scale (ChamplainView *view)
 
       /* 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);
+      factor = floor (priv->max_scale_width / scale_width);
       base *= factor;
       scale_width *= factor;
 
@@ -1158,9 +1183,17 @@ create_scale (ChamplainView *view)
   ClutterActor *scale, *text;
   gfloat width;
   ChamplainViewPrivate *priv = view->priv;
+
+  if (priv->scale_actor)
+    {
+      g_object_unref (priv->scale_actor);
+      clutter_container_remove_actor (CLUTTER_CONTAINER (priv->stage), priv->scale_actor);
+    }
+
   priv->scale_actor = g_object_ref (clutter_group_new());
+  clutter_container_add_actor (CLUTTER_CONTAINER (priv->stage), priv->scale_actor);
 
-  scale = clutter_cairo_texture_new (SCALE_WIDTH + 2 * SCALE_INSIDE_PADDING, SCALE_HEIGHT + 2 * SCALE_INSIDE_PADDING);
+  scale = clutter_cairo_texture_new (priv->max_scale_width + 2 * SCALE_INSIDE_PADDING, SCALE_HEIGHT + 2 * SCALE_INSIDE_PADDING);
   clutter_actor_set_name (scale, "scale-line");
 
   text = clutter_text_new_with_text ("Sans 9", "X km");
@@ -1218,6 +1251,7 @@ champlain_view_init (ChamplainView *view)
   priv->polygon_redraw_id = 0;
   priv->show_scale = TRUE;
   priv->scale_unit = CHAMPLAIN_UNIT_KM;
+  priv->max_scale_width = 100;
 
   /* Setup viewport */
   priv->viewport = g_object_ref (tidy_viewport_new ());
@@ -1230,7 +1264,6 @@ champlain_view_init (ChamplainView *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));
@@ -2450,6 +2483,28 @@ champlain_view_set_show_scale (ChamplainView *view,
 }
 
 /**
+* champlain_view_set_max_scale_width:
+* @view: a #ChamplainView
+* @value: a #guint in pixels
+*
+* Sets the maximum width of the scale on the screen in pixels
+*
+* Since: 0.4.3
+*/
+void
+champlain_view_set_max_scale_width (ChamplainView *view,
+    guint value)
+{
+  g_return_if_fail (CHAMPLAIN_IS_VIEW (view));
+
+  ChamplainViewPrivate *priv = view->priv;
+
+  priv->max_scale_width = value;
+  create_scale (view);
+  update_scale (view);
+}
+
+/**
 * champlain_view_set_scale_unit:
 * @view: a #ChamplainView
 * @unit: a #ChamplainUnit
@@ -2856,6 +2911,23 @@ champlain_view_get_show_scale (ChamplainView *view)
 }
 
 /**
+ * champlain_view_get_max_scale_width:
+ * @view: The view
+ *
+ * Returns: The max scale width in pixels.
+ *
+ * Since: 0.4.3
+ */
+guint
+champlain_view_get_max_scale_width (ChamplainView *view)
+{
+  g_return_val_if_fail (CHAMPLAIN_IS_VIEW (view), FALSE);
+
+  ChamplainViewPrivate *priv = view->priv;
+  return priv->max_scale_width;
+}
+
+/**
  * champlain_view_get_scale_unit:
  * @view: The view
  *
diff --git a/champlain/champlain-view.h b/champlain/champlain-view.h
index 8c3017c..3e422e8 100644
--- a/champlain/champlain-view.h
+++ b/champlain/champlain-view.h
@@ -115,6 +115,7 @@ void champlain_view_set_keep_center_on_resize (ChamplainView *view,
 void champlain_view_set_show_license (ChamplainView *view, gboolean value);
 void champlain_view_set_show_scale (ChamplainView *view, gboolean value);
 void champlain_view_set_scale_unit (ChamplainView *view, ChamplainUnit unit);
+void champlain_view_set_max_scale_width (ChamplainView *view, guint value);
 void champlain_view_set_zoom_on_double_click (ChamplainView *view,
     gboolean value);
 
@@ -143,6 +144,7 @@ ChamplainScrollMode champlain_view_get_scroll_mode (ChamplainView *view);
 gboolean champlain_view_get_keep_center_on_resize (ChamplainView *view);
 gboolean champlain_view_get_show_license (ChamplainView *view);
 gboolean champlain_view_get_show_scale (ChamplainView *view);
+guint champlain_view_get_max_scale_width (ChamplainView *view);
 ChamplainUnit champlain_view_get_scale_unit (ChamplainView *view);
 gboolean champlain_view_get_zoom_on_double_click (ChamplainView *view);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]