From 62802cfbdfbd85edd5a339361de70c36d74925dc Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Mon, 3 Jun 2019 11:54:35 -0300 Subject: [PATCH] Fix outline preview of contour tool. The purpose of this fix is to correct the outline preview of the Contour Tool when: - is used with custom brush, - with alpha content, - and pixel perfect mode OFF. Before this fix, the outline was being printed more than twice in some places (only noticed with alpha content), giving a bad appearance. --- src/app/tools/intertwiners.h | 98 ++++++++++++----------------- src/app/tools/tool_loop_manager.cpp | 4 ++ 2 files changed, 43 insertions(+), 59 deletions(-) diff --git a/src/app/tools/intertwiners.h b/src/app/tools/intertwiners.h index b45a7ec8e..38caa4501 100644 --- a/src/app/tools/intertwiners.h +++ b/src/app/tools/intertwiners.h @@ -68,80 +68,60 @@ public: }; class IntertwineAsLines : public Intertwine { - Stroke m_lastPointPrinted; Stroke m_pts; - void saveLastPointAndDoPointshape(ToolLoop* loop, const Stroke& stroke) { - m_lastPointPrinted = stroke; - doPointshapePoint(stroke[0].x, stroke[0].y, loop); - } - public: bool snapByAngle() override { return true; } + void prepareIntertwine() override { + m_pts.reset(); + } + void joinStroke(ToolLoop* loop, const Stroke& stroke) override { + if (loop->getTracePolicy() == TracePolicy::Last) + m_pts.reset(); + if (stroke.size() == 0) return; - - if (stroke.size() == 1) { - saveLastPointAndDoPointshape(loop, stroke); + else if (stroke.size() == 1) { + if (m_pts.empty()) + m_pts = stroke; + doPointshapePoint(stroke[0].x, stroke[0].y, loop); return; } - else if (stroke.size() >= 2) { - if (stroke.size() == 2 && stroke[0] == stroke[1]) { - if (m_lastPointPrinted.empty()) { - saveLastPointAndDoPointshape(loop, stroke); - return; - } - else { - if (m_lastPointPrinted[0] != stroke[0] || - loop->getTracePolicy() == TracePolicy::Last) { - saveLastPointAndDoPointshape(loop, stroke); - return; - } - } + else { + doc::AlgoLineWithAlgoPixel lineAlgo = getLineAlgo(loop); + for (int c=0; c+1getController()->isFreehand() && - !loop->getFilled() ? 1: 0); + // Don't draw the first point in freehand tools (this is to + // avoid painting above the last pixel of a freehand stroke, + // when we use Shift+click in the Pencil tool to continue the + // old stroke). When filled is true we are talking about the + // contour tool, so we do all the points. + // TODO useful only in the case when brush size = 1px + const int start = + (loop->getController()->isFreehand() && + !loop->getFilled() ? 1: 0); - for (int c=start; cgetFilled() && !loop->getController()->isFreehand()) { + doPointshapeLine(stroke[stroke.size()-1].x, + stroke[stroke.size()-1].y, + stroke[0].x, stroke[0].y, loop); } - m_pts.reset(); - } - - // Closed shape (polygon outline) - // Note: Contour tool was getting into the condition with no need, so - // we add the && !isFreehand to detect this circunstance. - // When this is missing, we have problems previewing the stroke of - // contour tool, with brush type = kImageBrush with alpha content and - // with not Pixel Perfect pencil mode. - if (loop->getFilled() && !loop->getController()->isFreehand()) { - doPointshapeLine(stroke[stroke.size()-1].x, - stroke[stroke.size()-1].y, - stroke[0].x, stroke[0].y, loop); } } diff --git a/src/app/tools/tool_loop_manager.cpp b/src/app/tools/tool_loop_manager.cpp index b5beecd36..3afe49a03 100644 --- a/src/app/tools/tool_loop_manager.cpp +++ b/src/app/tools/tool_loop_manager.cpp @@ -255,6 +255,10 @@ void ToolLoopManager::doLoopStep(bool lastStep) m_toolLoop->validateDstImage(gfx::Region(m_toolLoop->getDstImage()->bounds())); } } + else if (m_toolLoop->getBrush()->type() == kImageBrushType) { + m_toolLoop->invalidateDstImage(); + m_toolLoop->validateDstImage(gfx::Region(m_toolLoop->getDstImage()->bounds())); + } m_toolLoop->validateDstImage(m_dirtyArea);