Allow "tapping" when using the Select Rectangle and Select Region tools (#1980)

* Allow "tapping" when using the Select Rectangle and Select Region tools (in a similar way to tapping when drawing)

* Changed the implemetation of "tapping" selection to allow use with a stylus (that generates many more events than a mouse)

Co-authored-by: Luca Citi <lciti@ieee.org>
presentation
lciti 6 years ago committed by GitHub
parent 10a63500cb
commit c4abdf4632
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/control/tools/Selection.cpp
  2. 4
      src/control/tools/Selection.h
  3. 5
      src/gui/PageView.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<RegionPoint*>(this->points->data);
for (GList* l = this->points; l != nullptr; l = l->next) {
auto* p = static_cast<RegionPoint*>(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;
}

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

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

Loading…
Cancel
Save