From e372967cdea53d68417b10a39711103e4eb0b0af Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 8 Aug 2017 14:31:27 -0300 Subject: [PATCH] Fix bug using brush size on selection+snap to grid Discussion: https://community.aseprite.org/t/snap-to-grid-problem/292 --- src/app/ui/context_bar.cpp | 17 ++++++++++++++--- src/app/ui/context_bar.h | 14 ++++++++------ src/app/ui/editor/tool_loop_impl.cpp | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index 70675145d..09741ebe2 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -1879,11 +1879,22 @@ void ContextBar::setActiveBrush(const doc::BrushRef& brush) updateForActiveTool(); } -doc::BrushRef ContextBar::activeBrush(tools::Tool* tool) const +doc::BrushRef ContextBar::activeBrush(tools::Tool* tool, + tools::Ink* ink) const { - if ((!tool) || + if (ink == nullptr) + ink = (tool ? tool->getInk(0): nullptr); + + // Selection tools use a brush with size = 1 (always) + if (ink && ink->isSelection()) { + doc::BrushRef brush; + brush.reset(new Brush(kCircleBrushType, 1, 0)); + return brush; + } + + if ((tool == nullptr) || (tool == App::instance()->activeTool()) || - (tool->getInk(0)->isPaint() && + (ink && ink->isPaint() && m_activeBrush->type() == kImageBrushType)) { m_activeBrush->setPattern(Preferences::instance().brush.pattern()); return m_activeBrush; diff --git a/src/app/ui/context_bar.h b/src/app/ui/context_bar.h index 7f9fe978f..ef50f9c82 100644 --- a/src/app/ui/context_bar.h +++ b/src/app/ui/context_bar.h @@ -31,10 +31,6 @@ namespace render { class DitheringMatrix; } -namespace tools { - class Tool; -} - namespace ui { class Box; class Button; @@ -44,6 +40,11 @@ namespace ui { namespace app { + namespace tools { + class Ink; + class Tool; + } + class BrushSlot; class DitheringSelector; @@ -58,13 +59,14 @@ namespace app { void updateForTool(tools::Tool* tool); void updateForMovingPixels(); void updateForSelectingBox(const std::string& text); - void updateToolLoopModifiersIndicators(app::tools::ToolLoopModifiers modifiers); + void updateToolLoopModifiersIndicators(tools::ToolLoopModifiers modifiers); void updateAutoSelectLayer(bool state); bool isAutoSelectLayer() const; void setActiveBrush(const doc::BrushRef& brush); void setActiveBrushBySlot(tools::Tool* tool, int slot); - doc::BrushRef activeBrush(tools::Tool* tool = nullptr) const; + doc::BrushRef activeBrush(tools::Tool* tool = nullptr, + tools::Ink* ink = nullptr) const; void discardActiveBrush(); BrushSlot createBrushSlotFromPreferences(); diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index 9cdfa1738..a5b9aed95 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -104,7 +104,7 @@ public: const app::Color& bgColor) : m_editor(editor) , m_tool(tool) - , m_brush(App::instance()->contextBar()->activeBrush(m_tool)) + , m_brush(App::instance()->contextBar()->activeBrush(m_tool, ink)) , m_document(document) , m_sprite(editor->sprite()) , m_layer(layer)