From c7dfff9b41300b5e9206016e5b507b39f82d6eb9 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Tue, 16 Apr 2019 17:23:37 -0300 Subject: [PATCH] Fix straight line while drawing on pixel perfect --- src/app/tools/intertwiners.h | 16 +++++++++++++++- src/app/tools/tool_loop_manager.cpp | 23 ++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/app/tools/intertwiners.h b/src/app/tools/intertwiners.h index 8e141b60c..0c14f4f7b 100644 --- a/src/app/tools/intertwiners.h +++ b/src/app/tools/intertwiners.h @@ -384,6 +384,11 @@ class IntertwineAsPixelPerfect : public Intertwine { } } + // It was introduced to know if joinStroke function + // was executed inmediatelly after a "Last" trace policy (i.e. after the + // user confirms a line draw while he is holding down the SHIFT key), so + // we have to ignore printing the first pixel of the line. + bool retainedTracePolicyLast = false; Stroke m_pts; public: @@ -393,6 +398,7 @@ public: void prepareIntertwine() override { m_pts.reset(); + retainedTracePolicyLast = false; } void joinStroke(ToolLoop* loop, const Stroke& stroke) override { @@ -401,8 +407,10 @@ public: // new joinStroke() is like a fresh start. Without this fix, the // first stage on LineFreehand will draw a "star" like pattern // with lines from the first point to the last point. - if (loop->getTracePolicy() == TracePolicy::Last) + if (loop->getTracePolicy() == TracePolicy::Last) { + retainedTracePolicyLast = true; m_pts.reset(); + } if (stroke.size() == 0) return; @@ -435,6 +443,12 @@ public: ++c; } + // We must ignore to print the first point of the line after + // a joinStroke pass with a retained "Last" trace policy + // (i.e. the user confirms draw a line while he is holding + // the SHIFT key)) + if (c == 0 && retainedTracePolicyLast) + continue; doPointshapePoint(m_pts[c].x, m_pts[c].y, loop); } } diff --git a/src/app/tools/tool_loop_manager.cpp b/src/app/tools/tool_loop_manager.cpp index b7915a423..29ccf1635 100644 --- a/src/app/tools/tool_loop_manager.cpp +++ b/src/app/tools/tool_loop_manager.cpp @@ -77,6 +77,16 @@ void ToolLoopManager::pressButton(const Pointer& pointer) { TOOL_TRACE("ToolLoopManager::pressButton", pointer.point()); + // A little patch to memorize initial Trace Policy in the + // current function execution. + // When the initial trace policy is "Last" and then + // changes to different trace policy at the end of + // this function, the user confirms a line draw while he + // is holding the SHIFT key. + bool tracePolicyWasLast = false; + if (m_toolLoop->getTracePolicy() == TracePolicy::Last) + tracePolicyWasLast = true; + m_lastPointer = pointer; if (isCanceled()) @@ -102,7 +112,18 @@ void ToolLoopManager::pressButton(const Pointer& pointer) m_toolLoop->getController()->getStatusBarText(m_toolLoop, m_stroke, statusText); m_toolLoop->updateStatusBar(statusText.c_str()); - doLoopStep(false); + // We evaluate if the trace policy has changed compared with + // the initial trace policy. + if (!(m_toolLoop->getTracePolicy() == TracePolicy::Last) && + tracePolicyWasLast) { + // Do nothing. We do not need execute an additional doLoopStep + // (which it want to accumulate more points in m_pts in function + // joinStroke() from intertwiners.h) + // This avoid double print of a line while the user holds down + // the SHIFT key. + } + else + doLoopStep(false); } bool ToolLoopManager::releaseButton(const Pointer& pointer)