Merge pull request #636 from andreasb242/master

Center on visible part of the page
presentation
andreasb242 7 years ago committed by GitHub
commit 23b73729f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/gui/widgets/XournalWidget.cpp
  2. 5
      src/gui/widgets/XournalWidget.h

@ -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)

@ -39,6 +39,11 @@ struct _GtkXournal
*/
XournalView* view;
/**
* Scrollabel container
*/
GtkScrollable* parent;
/**
* Visible area
*/

Loading…
Cancel
Save