Avoid page dots and scratches but allow successive attempts.

presentation
JJones780 7 years ago
parent bfbc2891ef
commit 4a4785c0e8
  1. 34
      src/control/tools/StrokeHandler.cpp
  2. 5
      src/control/tools/StrokeHandler.h
  3. 24
      src/gui/inputdevices/InputSequence.cpp
  4. 16
      src/gui/inputdevices/InputSequence.h
  5. 12
      src/gui/inputdevices/NewGtkInputDevice.cpp
  6. 2
      src/gui/inputdevices/PositionInputData.h

@ -13,6 +13,14 @@
#include <gdk/gdk.h>
#include <cmath>
#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<Point> 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()

@ -64,5 +64,10 @@ private:
DocumentView view;
ShapeRecognizer* reco;
guint32 startStrokeTime;
static guint32 lastIgnorePointTime; //persist across strokes - allow us to not ignore persistent dotting.
};

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

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

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

@ -24,6 +24,8 @@ public:
double x;
double y;
double pressure;
guint32 time; //event time
/**
* State flags from GDKevent (Shift down etc.)

Loading…
Cancel
Save