From c778fc8239475dedd9cc81324ce88eb0c53839f2 Mon Sep 17 00:00:00 2001 From: Andreas Butti Date: Fri, 28 Dec 2018 19:44:02 +0100 Subject: [PATCH] Center on visible part of the page fixes #626 --- src/gui/widgets/XournalWidget.cpp | 21 +++++++++------------ src/gui/widgets/XournalWidget.h | 5 +++++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/gui/widgets/XournalWidget.cpp b/src/gui/widgets/XournalWidget.cpp index c55bf5c1..800083ce 100644 --- a/src/gui/widgets/XournalWidget.cpp +++ b/src/gui/widgets/XournalWidget.cpp @@ -78,6 +78,7 @@ GtkWidget* gtk_xournal_new(XournalView* view, GtkScrollable* parent) { GtkXournal* xoj = GTK_XOURNAL(g_object_new(gtk_xournal_get_type(), NULL)); xoj->view = view; + xoj->parent = parent; xoj->scrollX = 0; xoj->scrollY = 0; xoj->x = 0; @@ -119,25 +120,21 @@ Rectangle* gtk_xournal_get_visible_area(GtkWidget* widget, XojPageView* p) GtkXournal* xournal = GTK_XOURNAL(widget); - GtkAllocation allocation = { 0 }; - gtk_widget_get_allocation(widget, &allocation); - int viewHeight = allocation.height; - int viewWidth = allocation.width; - - GdkRectangle r1; GdkRectangle r2; - GdkRectangle r3 = { 0, 0, 0, 0 }; + GtkAdjustment* vadj = gtk_scrollable_get_vadjustment(xournal->parent); + GtkAdjustment* hadj = gtk_scrollable_get_hadjustment(xournal->parent); + r2.x = (int)gtk_adjustment_get_lower(hadj); + r2.y = (int)gtk_adjustment_get_lower(vadj); + r2.width = (int)gtk_adjustment_get_page_size(hadj); + r2.height = (int)gtk_adjustment_get_page_size(vadj); + GdkRectangle r1; r1.x = p->getX(); r1.y = p->getY(); r1.width = p->getDisplayWidth(); r1.height = p->getDisplayHeight(); - r2.x = xournal->x; - r2.y = xournal->y; - r2.width = viewWidth; - r2.height = viewHeight; - + GdkRectangle r3 = { 0, 0, 0, 0 }; gdk_rectangle_intersect(&r1, &r2, &r3); if (r3.width == 0 && r3.height == 0) diff --git a/src/gui/widgets/XournalWidget.h b/src/gui/widgets/XournalWidget.h index 3fbe41f3..126497d4 100644 --- a/src/gui/widgets/XournalWidget.h +++ b/src/gui/widgets/XournalWidget.h @@ -39,6 +39,11 @@ struct _GtkXournal */ XournalView* view; + /** + * Scrollabel container + */ + GtkScrollable* parent; + /** * Visible area */