From 4a4785c0e815d78877da8c4148a584063c3c3e9c Mon Sep 17 00:00:00 2001 From: JJones780 Date: Sun, 31 Mar 2019 16:53:54 -0600 Subject: [PATCH] Avoid page dots and scratches but allow successive attempts. --- src/control/tools/StrokeHandler.cpp | 34 +++++++++++++++++++++- src/control/tools/StrokeHandler.h | 5 ++++ src/gui/inputdevices/InputSequence.cpp | 24 ++++++++++----- src/gui/inputdevices/InputSequence.h | 16 +++++++--- src/gui/inputdevices/NewGtkInputDevice.cpp | 12 ++++---- src/gui/inputdevices/PositionInputData.h | 2 ++ 6 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/control/tools/StrokeHandler.cpp b/src/control/tools/StrokeHandler.cpp index 054d7a3c..72852177 100644 --- a/src/control/tools/StrokeHandler.cpp +++ b/src/control/tools/StrokeHandler.cpp @@ -13,6 +13,14 @@ #include #include +#define IGNORE_STROKE_POINTS 8 //this many point in IGNORE_STROKE_TIME_MS will be ignored unless successive - pen input requires larger count +#define IGNORE_STROKE_TIME_MS 300 +#define DO_NOT_IGNORE_SUCCESSIVE_TIME 500 //only ignore once every this ms + +guint32 StrokeHandler::lastIgnorePointTime; //persist for next stroke + + + StrokeHandler::StrokeHandler(XournalView* xournal, XojPageView* redrawable, PageRef page) : InputHandler(xournal, redrawable, page), surfMask(NULL), @@ -143,10 +151,32 @@ void StrokeHandler::onButtonReleaseEvent(const PositionInputData& pos) return; } + int pointCount = stroke->getPointCount(); + + if ( pointCount < IGNORE_STROKE_POINTS && pos.time - this->startStrokeTime < IGNORE_STROKE_TIME_MS) + { + if ( pos.time - this->lastIgnorePointTime < DO_NOT_IGNORE_SUCCESSIVE_TIME ) + { + this->lastIgnorePointTime = pos.time; + g_print("NOT_IGNORED: %d\n",pos.time - startStrokeTime); + } + else + { + this->lastIgnorePointTime = pos.time; + g_print("IGNORED: %d\tlength:%d\n",pos.time - startStrokeTime, pointCount); + //stroke not being added to layer... delete here. + delete stroke; + stroke = NULL; + return; + } + } + + + // Backward compatibility and also easier to handle for me;-) // I cannot draw a line with one point, to draw a visible line I need two points, // twice the same Point is also OK - if (stroke->getPointCount() == 1) + if (pointCount == 1) { ArrayIterator it = stroke->pointIterator(); if (it.hasNext()) @@ -283,6 +313,8 @@ void StrokeHandler::onButtonPressEvent(const PositionInputData& pos) createStroke(Point(x, y)); } + + this->startStrokeTime = pos.time; } void StrokeHandler::destroySurface() diff --git a/src/control/tools/StrokeHandler.h b/src/control/tools/StrokeHandler.h index 802ae1e0..d0f7631f 100644 --- a/src/control/tools/StrokeHandler.h +++ b/src/control/tools/StrokeHandler.h @@ -64,5 +64,10 @@ private: DocumentView view; ShapeRecognizer* reco; + + guint32 startStrokeTime; + + static guint32 lastIgnorePointTime; //persist across strokes - allow us to not ignore persistent dotting. + }; diff --git a/src/gui/inputdevices/InputSequence.cpp b/src/gui/inputdevices/InputSequence.cpp index 2825a555..ba0e13b0 100644 --- a/src/gui/inputdevices/InputSequence.cpp +++ b/src/gui/inputdevices/InputSequence.cpp @@ -30,7 +30,7 @@ InputSequence::~InputSequence() if (inputRunning) { - actionEnd(); + actionEnd(__UINT32_MAX__); } clearAxes(); @@ -109,11 +109,12 @@ void InputSequence::setCurrentRootPosition(double x, double y) /** * Set (mouse)button */ -void InputSequence::setButton(guint button) +void InputSequence::setButton(guint button, guint time) { XOJ_CHECK_TYPE(InputSequence); this->button = button; + this->eventTime = time; } /** @@ -182,13 +183,15 @@ void InputSequence::handleScrollEvent() /** * Mouse / Pen / Touch move */ -bool InputSequence::actionMoved() +bool InputSequence::actionMoved(guint32 time) { XOJ_CHECK_TYPE(InputSequence); GtkXournal* xournal = inputHandler->getXournal(); ToolHandler* h = inputHandler->getToolHandler(); + this->eventTime = time; + changeTool(); if (penDevice) @@ -258,10 +261,12 @@ bool InputSequence::actionMoved() /** * Mouse / Pen down / touch start */ -bool InputSequence::actionStart() +bool InputSequence::actionStart(guint32 time) { XOJ_CHECK_TYPE(InputSequence); + this->eventTime = time; + inputHandler->focusWidget(); checkCanStartInput(); @@ -379,7 +384,7 @@ bool InputSequence::checkStillRunning() // Button is not down, stop input now! // So the new input can start - actionEnd(); + actionEnd(__UINT32_MAX__); return true; } @@ -387,7 +392,7 @@ bool InputSequence::checkStillRunning() /** * Mouse / Pen up / touch end */ -void InputSequence::actionEnd() +void InputSequence::actionEnd(guint32 time) { XOJ_CHECK_TYPE(InputSequence); @@ -396,6 +401,8 @@ void InputSequence::actionEnd() return; } + this->eventTime = time; + // Mouse button not pressed anymore this->button = 0; @@ -452,9 +459,10 @@ PositionInputData InputSequence::getInputDataRelativeToCurrentPage(XojPageView* GtkXournal* xournal = inputHandler->getXournal(); PositionInputData pos; - pos.x = x - page->getX() - xournal->x; - pos.y = y - page->getY() - xournal->y; + pos.x = this->x - page->getX() - xournal->x; + pos.y = this->y - page->getY() - xournal->y; pos.pressure = Point::NO_PRESURE; + pos.time = this->eventTime; if (presureSensitivity) { diff --git a/src/gui/inputdevices/InputSequence.h b/src/gui/inputdevices/InputSequence.h index 15388b3a..d2957354 100644 --- a/src/gui/inputdevices/InputSequence.h +++ b/src/gui/inputdevices/InputSequence.h @@ -31,17 +31,17 @@ public: /** * Mouse / Pen / Touch move */ - bool actionMoved(); + bool actionMoved(guint32 time); /** * Mouse / Pen down / touch start */ - bool actionStart(); + bool actionStart(guint32 time); /** * Mouse / Pen up / touch end */ - void actionEnd(); + void actionEnd(guint32 time); /** * Check if input is still running, or if there an event was missed @@ -85,7 +85,7 @@ public: /** * Set (mouse)button */ - void setButton(guint button); + void setButton(guint button, guint time); /** * Set state flags from GDKevent (Shift down etc.) @@ -229,4 +229,12 @@ private: * The last Mouse Position, for scrolling */ double scrollOffsetY = 0; + + + /** + * event time + */ + guint32 eventTime; + + }; diff --git a/src/gui/inputdevices/NewGtkInputDevice.cpp b/src/gui/inputdevices/NewGtkInputDevice.cpp index e4366ad2..cd9b88d0 100644 --- a/src/gui/inputdevices/NewGtkInputDevice.cpp +++ b/src/gui/inputdevices/NewGtkInputDevice.cpp @@ -247,7 +247,7 @@ bool NewGtkInputDevice::eventHandler(GdkEvent* event) if (input != NULL) { - input->actionEnd(); + input->actionEnd(((GdkEventTouch *)event)->time); } g_hash_table_remove(touchInputList, sequence); @@ -301,7 +301,7 @@ bool NewGtkInputDevice::eventHandler(GdkEvent* event) guint button = 0; if (gdk_event_get_button(event, &button)) { - input->setButton(button); + input->setButton(button, gdk_event_get_time(event) ); } GdkModifierType state = (GdkModifierType)0; @@ -313,7 +313,8 @@ bool NewGtkInputDevice::eventHandler(GdkEvent* event) if (event->type == GDK_MOTION_NOTIFY || event->type == GDK_TOUCH_UPDATE) { input->copyAxes(event); - input->actionMoved(); + guint32 time = event->type == GDK_MOTION_NOTIFY ? ((GdkEventMotion *)event)->time : ((GdkEventTouch *)event)->time; // or call gdk_event_get_time(event) + input->actionMoved(time); Cursor* cursor = view->getControl()->getWindow()->getXournal()->getCursor(); cursor->setInvisible(false); @@ -323,12 +324,13 @@ bool NewGtkInputDevice::eventHandler(GdkEvent* event) else if (event->type == GDK_BUTTON_PRESS || event->type == GDK_TOUCH_BEGIN) { input->copyAxes(event); - input->actionStart(); + guint32 time = event->type == GDK_BUTTON_PRESS ? ((GdkEventButton *)event)->time : ((GdkEventTouch *)event)->time; //or call gdk_event_get_time() + input->actionStart(time); } else if (event->type == GDK_BUTTON_RELEASE) { input->copyAxes(event); - input->actionEnd(); + input->actionEnd( ((GdkEventButton *)event)->time ); } return true; diff --git a/src/gui/inputdevices/PositionInputData.h b/src/gui/inputdevices/PositionInputData.h index 188f0932..89080e54 100644 --- a/src/gui/inputdevices/PositionInputData.h +++ b/src/gui/inputdevices/PositionInputData.h @@ -24,6 +24,8 @@ public: double x; double y; double pressure; + + guint32 time; //event time /** * State flags from GDKevent (Shift down etc.)