From: Pierre-Luc Beaudoin Date: Tue, 3 Feb 2009 06:10:54 +0000 (+0200) Subject: Fix bug 570314: Zoom-in zooms at the wrong place if actor is not positioned at 0,0 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4959fc29a305625b862b3c0d3a2dfc5f973d01be;p=libchamplain Fix bug 570314: Zoom-in zooms at the wrong place if actor is not positioned at 0,0 Also fixed for get_coods --- diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 3e03807..e0197e6 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -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; } diff --git a/demos/launcher.c b/demos/launcher.c index d94122c..0d565bc 100644 --- a/demos/launcher.c +++ b/demos/launcher.c @@ -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);