diff --git a/src/control/tools/Selection.cpp b/src/control/tools/Selection.cpp index 695b39fb..e35a8b29 100644 --- a/src/control/tools/Selection.cpp +++ b/src/control/tools/Selection.cpp @@ -84,8 +84,12 @@ void RectSelection::currentPos(double x, double y) { this->ex = x; this->ey = y; + + this->maxDist = std::max({this->maxDist, x - this->sx, this->sx - x, y - this->sy, this->sy - y}); } +auto RectSelection::userTapped(double zoom) -> bool { return this->maxDist < 10 / zoom; } + void RectSelection::paint(cairo_t* cr, GdkRectangle* rect, double zoom) { GtkColorWrapper selectionColor = view->getSelectionColor(); @@ -300,3 +304,15 @@ auto RegionSelect::finalize(PageRef page) -> bool { return !this->selectedElements.empty(); } + +auto RegionSelect::userTapped(double zoom) -> bool { + double maxDist = 10 / zoom; + auto* r0 = static_cast(this->points->data); + for (GList* l = this->points; l != nullptr; l = l->next) { + auto* p = static_cast(l->data); + if (r0->x - p->x > maxDist || p->x - r0->x > maxDist || r0->y - p->y > maxDist || p->y - r0->y > maxDist) { + return false; + } + } + return true; +} diff --git a/src/control/tools/Selection.h b/src/control/tools/Selection.h index 88d5aa9f..4ce2e13a 100644 --- a/src/control/tools/Selection.h +++ b/src/control/tools/Selection.h @@ -30,6 +30,7 @@ public: virtual bool finalize(PageRef page) = 0; virtual void paint(cairo_t* cr, GdkRectangle* rect, double zoom) = 0; virtual void currentPos(double x, double y) = 0; + virtual bool userTapped(double zoom) = 0; private: protected: @@ -55,12 +56,14 @@ public: virtual void paint(cairo_t* cr, GdkRectangle* rect, double zoom); virtual void currentPos(double x, double y); virtual bool contains(double x, double y); + virtual bool userTapped(double zoom); private: double sx; double sy; double ex; double ey; + double maxDist = 0; /** * In zoom coordinates @@ -81,6 +84,7 @@ public: virtual void paint(cairo_t* cr, GdkRectangle* rect, double zoom); virtual void currentPos(double x, double y); virtual bool contains(double x, double y); + virtual bool userTapped(double zoom); private: GList* points; diff --git a/src/gui/PageView.cpp b/src/gui/PageView.cpp index 9de5e3e6..706dc7f6 100644 --- a/src/gui/PageView.cpp +++ b/src/gui/PageView.cpp @@ -534,6 +534,11 @@ auto XojPageView::onButtonReleaseEvent(const PositionInputData& pos) -> bool { delete this->selection; this->selection = nullptr; } else { + double zoom = xournal->getZoom(); + if (this->selection->userTapped(zoom)) { + SelectObject select(this); + select.at(pos.x / zoom, pos.y / zoom); + } delete this->selection; this->selection = nullptr;