Skip to content

Commit

Permalink
Redraw when scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
bhennion committed Apr 16, 2024
1 parent a9c53d0 commit 713ae8a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/core/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,9 @@ void MainWindow::initXournalWidget() {

gtk_paned_set_end_child(GTK_PANED(this->panedContainerWidget.get()), this->winXournal);

GtkWidget* vpXournal = gtk_viewport_new(nullptr, nullptr);
scrollHandling = std::make_unique<ScrollHandling>(GTK_SCROLLED_WINDOW(winXournal));

gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(winXournal), vpXournal);

scrollHandling = std::make_unique<ScrollHandling>(GTK_SCROLLABLE(vpXournal));

this->xournal = std::make_unique<XournalView>(GTK_VIEWPORT(vpXournal), control, scrollHandling.get());
this->xournal = std::make_unique<XournalView>(GTK_SCROLLED_WINDOW(winXournal), control, scrollHandling.get());

control->getZoomControl()->initZoomHandler(GTK_SCROLLED_WINDOW(winXournal), xournal.get(), control);

Expand Down
15 changes: 13 additions & 2 deletions src/core/gui/XournalView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ std::pair<size_t, size_t> XournalView::preloadPageBounds(size_t page, size_t max
return {lower, upper};
}

XournalView::XournalView(GtkViewport* parent, Control* control, ScrollHandling* scrollHandling):
static void redraw(GtkAdjustment*, gpointer d) { gtk_widget_queue_draw(GTK_WIDGET(d)); }

XournalView::XournalView(GtkScrolledWindow* parent, Control* control, ScrollHandling* scrollHandling):
scrollHandling(scrollHandling), control(control) {
Document* doc = control->getDocument();
doc->lock();
Expand All @@ -74,10 +76,19 @@ XournalView::XournalView(GtkViewport* parent, Control* control, ScrollHandling*
InputContext* inputContext = new InputContext(this, scrollHandling);
this->widget.reset(gtk_xournal_new(this, inputContext), xoj::util::adopt);

gtk_viewport_set_child(parent, this->widget.get());
gtk_scrolled_window_set_child(parent, this->widget.get());

g_signal_connect(getWidget(), "realize", G_CALLBACK(onRealized), this);

// Repaint when scrolling
auto* hadj = gtk_scrolled_window_get_hadjustment(parent);
g_signal_connect_object(hadj, "changed", G_CALLBACK(redraw), this->widget.get(), GConnectFlags(0));
g_signal_connect_object(hadj, "value-changed", G_CALLBACK(redraw), this->widget.get(), GConnectFlags(0));
auto* vadj = gtk_scrolled_window_get_vadjustment(parent);
g_signal_connect_object(vadj, "changed", G_CALLBACK(redraw), this->widget.get(), GConnectFlags(0));
g_signal_connect_object(vadj, "value-changed", G_CALLBACK(redraw), this->widget.get(), GConnectFlags(0));


this->repaintHandler = std::make_unique<RepaintHandler>(this);
this->handRecognition = std::make_unique<HandRecognition>(this->widget.get(), inputContext, control->getSettings());

Expand Down
2 changes: 1 addition & 1 deletion src/core/gui/XournalView.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Rectangle;

class XournalView: public DocumentListener, public ZoomListener {
public:
XournalView(GtkViewport* parent, Control* control, ScrollHandling* scrollHandling);
XournalView(GtkScrolledWindow* parent, Control* control, ScrollHandling* scrollHandling);
~XournalView() override;

public:
Expand Down
4 changes: 2 additions & 2 deletions src/core/gui/scroll/ScrollHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ ScrollHandling::ScrollHandling(GtkAdjustment* adjHorizontal, GtkAdjustment* adjV
adjHorizontal(adjHorizontal), adjVertical(adjVertical) {}


ScrollHandling::ScrollHandling(GtkScrollable* scrollable):
ScrollHandling(gtk_scrollable_get_hadjustment(scrollable), gtk_scrollable_get_vadjustment(scrollable)) {}
ScrollHandling::ScrollHandling(GtkScrolledWindow* win):
ScrollHandling(gtk_scrolled_window_get_hadjustment(win), gtk_scrolled_window_get_vadjustment(win)) {}


ScrollHandling::~ScrollHandling() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/core/gui/scroll/ScrollHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Layout;
class ScrollHandling {
public:
ScrollHandling(GtkAdjustment* adjHorizontal, GtkAdjustment* adjVertical);
ScrollHandling(GtkScrollable* scrollable);
ScrollHandling(GtkScrolledWindow* scrollable);
~ScrollHandling();

public:
Expand Down

0 comments on commit 713ae8a

Please sign in to comment.