diff options
Diffstat (limited to 'libview')
-rw-r--r-- | libview/ev-view-private.h | 4 | ||||
-rw-r--r-- | libview/ev-view.c | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h index 1d1220f3..eef79f92 100644 --- a/libview/ev-view-private.h +++ b/libview/ev-view-private.h @@ -214,6 +214,10 @@ struct _EvView { GtkGesture *zoom_gesture; gdouble prev_zoom_gesture_scale; EvPanAction pan_action; + + /* Current zoom center */ + gdouble zoom_center_x; + gdouble zoom_center_y; }; struct _EvViewClass { diff --git a/libview/ev-view.c b/libview/ev-view.c index c9d97f44..3a5fefdd 100644 --- a/libview/ev-view.c +++ b/libview/ev-view.c @@ -555,6 +555,7 @@ view_set_adjustment_values (EvView *view, gdouble upper; double factor; gint new_value; + gdouble zoom_center; gtk_widget_get_allocation (widget, &allocation); @@ -562,10 +563,12 @@ view_set_adjustment_values (EvView *view, req_size = view->requisition.width; alloc_size = allocation.width; adjustment = view->hadjustment; + zoom_center = view->zoom_center_x; } else { req_size = view->requisition.height; alloc_size = allocation.height; adjustment = view->vadjustment; + zoom_center = view->zoom_center_y; } if (!adjustment) @@ -575,6 +578,8 @@ view_set_adjustment_values (EvView *view, value = gtk_adjustment_get_value (adjustment); upper = gtk_adjustment_get_upper (adjustment); page_size = gtk_adjustment_get_page_size (adjustment); + if (zoom_center < 0) + zoom_center = page_size * 0.5; switch (view->pending_scroll) { case SCROLL_TO_KEEP_POSITION: @@ -584,7 +589,7 @@ view_set_adjustment_values (EvView *view, case SCROLL_TO_PAGE_POSITION: break; case SCROLL_TO_CENTER: - factor = (value + page_size * 0.5) / upper; + factor = (value + zoom_center) / upper; break; } @@ -610,8 +615,11 @@ view_set_adjustment_values (EvView *view, ev_view_scroll_to_page_position (view, orientation); break; case SCROLL_TO_CENTER: - new_value = CLAMP (upper * factor - page_size * 0.5 + 0.5, - 0, upper - page_size); + new_value = CLAMP (upper * factor - zoom_center + 0.5, 0, upper - page_size); + if (orientation == GTK_ORIENTATION_HORIZONTAL) + view->zoom_center_x = -1.0; + else + view->zoom_center_y = -1.0; gtk_adjustment_set_value (adjustment, (int)new_value); break; } @@ -3286,6 +3294,8 @@ ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) if (state == GDK_CONTROL_MASK) { ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE); + view->zoom_center_x = event->x; + view->zoom_center_y = event->y; if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_LEFT) { if (ev_view_can_zoom_in (view)) { @@ -5005,6 +5015,8 @@ zoom_gesture_scale_changed_cb (GtkGestureZoom *gesture, view->prev_zoom_gesture_scale = scale; ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE); + gtk_gesture_get_bounding_box_center (GTK_GESTURE (gesture), &view->zoom_center_x, &view->zoom_center_y); + if ((factor < 1.0 && ev_view_can_zoom_out (view)) || (factor >= 1.0 && ev_view_can_zoom_in (view))) ev_view_zoom (view, factor); @@ -5057,6 +5069,8 @@ ev_view_init (EvView *view) view->pending_scroll = SCROLL_TO_KEEP_POSITION; view->jump_to_find_result = TRUE; view->highlight_find_results = FALSE; + view->zoom_center_x = -1; + view->zoom_center_y = -1; g_signal_connect (view, "notify::scale-factor", G_CALLBACK (on_notify_scale_factor), NULL); |