diff options
author | Pierre-Luc Beaudoin <pierre-luc@pierlux.com> | 2010-01-15 10:28:46 -0500 |
---|---|---|
committer | Pierre-Luc Beaudoin <pierre-luc@pierlux.com> | 2010-01-16 15:45:21 -0500 |
commit | 54c8632053cfcded178badb8afbb17f5f278fa80 (patch) | |
tree | 0c8784d890ec5132a7420e87f1d7d97fdfc39b97 | |
parent | 2b5640543b18036118420d69dc97dd91b9fb4bd0 (diff) | |
download | libchamplain-54c8632053cfcded178badb8afbb17f5f278fa80.tar.gz |
Don't do everything everytime the user moves
Instead, do it only when there's a 100px difference
or when he stops moving. Things that are delayed:
- Loading of tiles
- Redrawing of polygons
- Updating of the scale
-rw-r--r-- | champlain/champlain-view.c | 105 | ||||
-rw-r--r-- | tidy/tidy-finger-scroll.c | 17 |
2 files changed, 85 insertions, 37 deletions
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index fee49ae..320d30f 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -210,6 +210,7 @@ static void connect_marker_notify_cb (ChamplainMarker *marker, static gboolean finger_scroll_button_press_cb (ClutterActor *actor, ClutterButtonEvent *event, ChamplainView *view); static void update_license (ChamplainView *view); +static void update_scale (ChamplainView *view); static void view_load_visible_tiles (ChamplainView *view); static void view_position_tile (ChamplainView* view, ChamplainTile* tile); static void view_tiles_reposition (ChamplainView* view); @@ -277,6 +278,64 @@ viewport_get_current_latitude (ChamplainViewPrivate *priv) priv->viewport_size.height / 2.0); } +/* Updates the internals after the viewport changed */ +static void +update_viewport (ChamplainView *view, + gfloat x, + gfloat y) +{ + ChamplainViewPrivate *priv = view->priv; + + ChamplainFloatPoint old_anchor; + + old_anchor.x = priv->anchor.x; + old_anchor.y = priv->anchor.y; + + view_update_anchor (view, + x + priv->anchor.x + priv->viewport_size.width / 2.0, + y + priv->anchor.y + priv->viewport_size.height / 2.0); + + if (priv->anchor.x - old_anchor.x != 0) + { + ChamplainFloatPoint diff; + + diff.x = priv->anchor.x - old_anchor.x; + diff.y = priv->anchor.y - old_anchor.y; + + DEBUG("Relocating the viewport by %f, %f", diff.x, diff.y); + tidy_viewport_set_origin (TIDY_VIEWPORT (priv->viewport), + x - diff.x, y - diff.y, 0); + return; + } + + priv->viewport_size.x = x; + priv->viewport_size.y = y; + + view_load_visible_tiles (view); + view_tiles_reposition (view); + marker_reposition (view); + update_scale (view); + + view_update_polygons (view); + priv->longitude = viewport_get_current_longitude (priv); + priv->latitude = viewport_get_current_latitude (priv); + + g_object_notify (G_OBJECT (view), "longitude"); + g_object_notify (G_OBJECT (view), "latitude"); +} + +static void +panning_completed (TidyFingerScroll *scroll, + ChamplainView *view) +{ + gfloat x, y; + + tidy_viewport_get_origin (TIDY_VIEWPORT (view->priv->viewport), &x, &y, + NULL); + + update_viewport (view, x, y); +} + static gboolean scroll_event (ClutterActor *actor, ClutterScrollEvent *event, @@ -1397,6 +1456,8 @@ champlain_view_init (ChamplainView *view) g_signal_connect (priv->finger_scroll, "scroll-event", G_CALLBACK (scroll_event), view); + g_signal_connect (priv->finger_scroll, "panning-completed", + G_CALLBACK (panning_completed), view); clutter_container_add_actor (CLUTTER_CONTAINER (priv->finger_scroll), priv->viewport); @@ -1450,50 +1511,20 @@ viewport_pos_changed_cb (GObject *gobject, { ChamplainViewPrivate *priv = view->priv; - ChamplainFloatPoint rect; - ChamplainFloatPoint old_anchor; + gfloat x, y; - tidy_viewport_get_origin (TIDY_VIEWPORT (priv->viewport), &rect.x, &rect.y, + tidy_viewport_get_origin (TIDY_VIEWPORT (priv->viewport), &x, &y, NULL); - if (rect.x == priv->viewport_size.x && - rect.y == priv->viewport_size.y) + if (x == priv->viewport_size.x && + y == priv->viewport_size.y) return; - old_anchor.x = priv->anchor.x; - old_anchor.y = priv->anchor.y; - - view_update_anchor (view, - rect.x + priv->anchor.x + priv->viewport_size.width / 2.0, - rect.y + priv->anchor.y + priv->viewport_size.height / 2.0); - - if (priv->anchor.x - old_anchor.x != 0) - { - ChamplainFloatPoint diff; - - diff.x = priv->anchor.x - old_anchor.x; - diff.y = priv->anchor.y - old_anchor.y; - - DEBUG("Relocating the viewport by %f, %f", diff.x, diff.y); - tidy_viewport_set_origin (TIDY_VIEWPORT (priv->viewport), - rect.x - diff.x, rect.y - diff.y, 0); + if (fabs (x - priv->viewport_size.x) < 100 && + fabs (y - priv->viewport_size.y) < 100) return; - } - - priv->viewport_size.x = rect.x; - priv->viewport_size.y = rect.y; - - view_load_visible_tiles (view); - view_tiles_reposition (view); - marker_reposition (view); - view_update_polygons (view); - update_scale (view); - priv->longitude = viewport_get_current_longitude (priv); - priv->latitude = viewport_get_current_latitude (priv); - - g_object_notify (G_OBJECT (view), "longitude"); - g_object_notify (G_OBJECT (view), "latitude"); + update_viewport (view, x, y); } /** diff --git a/tidy/tidy-finger-scroll.c b/tidy/tidy-finger-scroll.c index a1159e0..32c8e58 100644 --- a/tidy/tidy-finger-scroll.c +++ b/tidy/tidy-finger-scroll.c @@ -63,6 +63,15 @@ enum { PROP_BUFFER, }; +enum +{ + /* normal signals */ + PANNING_COMPLETED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0, }; + static void tidy_finger_scroll_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) @@ -177,6 +186,11 @@ tidy_finger_scroll_class_init (TidyFingerScrollClass *klass) "events to buffer", 1, G_MAXUINT, 3, G_PARAM_READWRITE)); + + signals[PANNING_COMPLETED] = + g_signal_new ("panning-completed", G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } static gboolean @@ -294,6 +308,8 @@ deceleration_completed_cb (ClutterTimeline *timeline, clamp_adjustments (scroll); g_object_unref (timeline); scroll->priv->deceleration_timeline = NULL; + + g_signal_emit_by_name (scroll, "panning-completed", NULL); } static void @@ -545,6 +561,7 @@ button_release_event_cb (ClutterActor *actor, if (!decelerating) { clamp_adjustments (scroll); + g_signal_emit_by_name (scroll, "panning-completed", NULL); } /* Pass through events to children. |