]> err.no Git - libchamplain/commitdiff
Fix bug 570314: Zoom-in zooms at the wrong place if actor is not positioned at 0,0
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Tue, 3 Feb 2009 06:10:54 +0000 (08:10 +0200)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Tue, 3 Feb 2009 06:10:54 +0000 (08:10 +0200)
Also fixed for get_coods

champlain/champlain-view.c
demos/launcher.c

index 3e03807f69bb6bd54dc9553200f87652324ec9a0..e0197e6d42b40f1905fbcb054032b33b1b69f9f6 100644 (file)
@@ -205,16 +205,22 @@ scroll_event (ClutterActor *actor,
   gboolean success = FALSE;
   gdouble lon, lat;
   gint x_diff, y_diff;
+  gint actor_x, actor_y;
+  gint rel_x, rel_y;
+
+  clutter_actor_get_transformed_position (priv->finger_scroll, &actor_x, &actor_y);
+  rel_x = event->x - actor_x;
+  rel_y = event->y - actor_y;
 
   /* Keep the lon, lat where the mouse is */
   lon = viewport_get_longitude_at (priv,
-    priv->viewport_size.x + event->x + priv->map->current_level->anchor.x);
+    priv->viewport_size.x + rel_x + priv->map->current_level->anchor.x);
   lat = viewport_get_latitude_at (priv,
-    priv->viewport_size.y + event->y + priv->map->current_level->anchor.y);
+    priv->viewport_size.y + rel_y + priv->map->current_level->anchor.y);
 
   /* How far was it from the center of the viewport (in px) */
-  x_diff = priv->viewport_size.width / 2 - event->x;
-  y_diff = priv->viewport_size.height / 2 - event->y;
+  x_diff = priv->viewport_size.width / 2 - rel_x;
+  y_diff = priv->viewport_size.height / 2 - rel_y;
 
   if (event->direction == CLUTTER_SCROLL_UP)
     success = map_zoom_in (priv->map);
@@ -858,16 +864,23 @@ finger_scroll_button_press_cb (ClutterActor *actor,
 
   if (event->button == 1 && event->click_count == 2)
     {
+      gint actor_x, actor_y;
+      gint rel_x, rel_y;
+
+      clutter_actor_get_transformed_position (priv->finger_scroll, &actor_x, &actor_y);
+      rel_x = event->x - actor_x;
+      rel_y = event->y - actor_y;
+
       ClutterActor *group = priv->map->current_level->group;
       /* Keep the lon, lat where the mouse is */
       gdouble lon = viewport_get_longitude_at (priv,
-        priv->viewport_size.x + event->x + priv->map->current_level->anchor.x);
+        priv->viewport_size.x + rel_x + priv->map->current_level->anchor.x);
       gdouble lat = viewport_get_latitude_at (priv, 
-        priv->viewport_size.y + event->y + priv->map->current_level->anchor.y);
+        priv->viewport_size.y + rel_y + priv->map->current_level->anchor.y);
 
       /* How far was it from the center of the viewport (in px) */
-      gint x_diff = priv->viewport_size.width / 2 - event->x;
-      gint y_diff = priv->viewport_size.height / 2 - event->y;
+      gint x_diff = priv->viewport_size.width / 2 - rel_x;
+      gint y_diff = priv->viewport_size.height / 2 - rel_y;
 
       if (map_zoom_in (priv->map))
         {
@@ -1102,6 +1115,10 @@ champlain_view_get_coords_from_event (ChamplainView *view,
 
   ChamplainViewPrivate *priv = GET_PRIVATE (view);
   guint x, y;
+  gint actor_x, actor_y;
+  gint rel_x, rel_y;
+
+  clutter_actor_get_transformed_position (priv->finger_scroll, &actor_x, &actor_y);
 
   switch (clutter_event_type (event))
     {
@@ -1139,12 +1156,15 @@ champlain_view_get_coords_from_event (ChamplainView *view,
         return FALSE;
     }
 
+  rel_x = x - actor_x;
+  rel_y = y - actor_y;
+
   if (latitude)
     *latitude = viewport_get_latitude_at (priv,
-        priv->viewport_size.y + y + priv->map->current_level->anchor.y);
+        priv->viewport_size.y + rel_y + priv->map->current_level->anchor.y);
   if (longitude)
     *longitude = viewport_get_longitude_at (priv,
-        priv->viewport_size.x + x + priv->map->current_level->anchor.x);
+        priv->viewport_size.x + rel_x + priv->map->current_level->anchor.x);
 
   return TRUE;
 }
index d94122ccc1792000cae1fc8334bc14577afc996d..0d565bc389246a8816e41894b1f01233be5518e3 100644 (file)
@@ -101,7 +101,8 @@ main (int argc,
   g_signal_connect_after (actor, "button-release-event",
       G_CALLBACK (map_view_button_release_cb), actor);
 
-  champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600);
+  champlain_view_set_size (CHAMPLAIN_VIEW (actor), 700, 500);
+  clutter_actor_set_position (actor, 50, 50);
 
   layer = create_marker_layer (actor);
   champlain_view_add_layer(CHAMPLAIN_VIEW (actor), layer);