From 8870c90774dfe183322b1b82372af62a1ba0c925 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 29 Nov 2016 18:36:08 -0300 Subject: [PATCH] Fix several issues with "auto select layer" indicator --- src/app/ui/context_bar.cpp | 8 +++++--- src/app/ui/context_bar.h | 1 + src/app/ui/editor/editor.cpp | 20 ++++++++++++-------- src/app/ui/editor/editor.h | 3 +-- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index 391c979b4..fdbdbb2ad 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -1750,12 +1750,14 @@ void ContextBar::updateToolLoopModifiersIndicators(tools::ToolLoopModifiers modi void ContextBar::updateAutoSelectLayer(bool state) { - if (!m_autoSelectLayer->isVisible()) - return; - m_autoSelectLayer->setSelected(state); } +bool ContextBar::isAutoSelectLayer() const +{ + return m_autoSelectLayer->isSelected(); +} + void ContextBar::setActiveBrushBySlot(tools::Tool* tool, int slot) { ASSERT(tool); diff --git a/src/app/ui/context_bar.h b/src/app/ui/context_bar.h index 9d9d7aad8..a2432b109 100644 --- a/src/app/ui/context_bar.h +++ b/src/app/ui/context_bar.h @@ -53,6 +53,7 @@ namespace app { void updateForSelectingBox(const std::string& text); void updateToolLoopModifiersIndicators(app::tools::ToolLoopModifiers modifiers); void updateAutoSelectLayer(bool state); + bool isAutoSelectLayer() const; void setActiveBrush(const doc::BrushRef& brush); void setActiveBrushBySlot(tools::Tool* tool, int slot); diff --git a/src/app/ui/editor/editor.cpp b/src/app/ui/editor/editor.cpp index 2992eba9b..af4b4dcb0 100644 --- a/src/app/ui/editor/editor.cpp +++ b/src/app/ui/editor/editor.cpp @@ -158,7 +158,6 @@ Editor::Editor(Document* document, EditorFlags flags) , m_brushPreview(this) , m_lastDrawingPosition(-1, -1) , m_toolLoopModifiers(tools::ToolLoopModifiers::kNone) - , m_autoSelectLayer(false) , m_padding(0, 0) , m_antsTimer(100, this) , m_antsOffset(0) @@ -991,6 +990,11 @@ tools::Ink* Editor::getCurrentEditorInk() return App::instance()->activeToolManager()->activeInk(); } +bool Editor::isAutoSelectLayer() const +{ + return App::instance()->contextBar()->isAutoSelectLayer(); +} + gfx::Point Editor::screenToEditor(const gfx::Point& pt) { View* view = View::getView(this); @@ -1122,7 +1126,8 @@ void Editor::updateToolByTipProximity(ui::PointerType pointerType) void Editor::updateToolLoopModifiersIndicators() { int modifiers = int(tools::ToolLoopModifiers::kNone); - bool autoSelectLayer = Preferences::instance().editor.autoSelectLayer(); + const bool autoSelectLayer = isAutoSelectLayer(); + bool newAutoSelectLayer = autoSelectLayer; KeyAction action; if (m_customizationDelegate) { @@ -1134,7 +1139,6 @@ void Editor::updateToolLoopModifiersIndicators() (int(tools::ToolLoopModifiers::kReplaceSelection) | int(tools::ToolLoopModifiers::kAddSelection) | int(tools::ToolLoopModifiers::kSubtractSelection))); - autoSelectLayer = m_autoSelectLayer; // Shape tools (line, curves, rectangles, etc.) action = m_customizationDelegate->getPressedKeyAction(KeyContext::ShapeTool); @@ -1163,7 +1167,9 @@ void Editor::updateToolLoopModifiersIndicators() // For move tool action = m_customizationDelegate->getPressedKeyAction(KeyContext::MoveTool); if (int(action & KeyAction::AutoSelectLayer)) - autoSelectLayer = true; + newAutoSelectLayer = true; + else + newAutoSelectLayer = Preferences::instance().editor.autoSelectLayer(); } } @@ -1180,10 +1186,8 @@ void Editor::updateToolLoopModifiersIndicators() } } - if (m_autoSelectLayer != autoSelectLayer) { - m_autoSelectLayer = autoSelectLayer; - ctxBar->updateAutoSelectLayer(autoSelectLayer); - } + if (autoSelectLayer != newAutoSelectLayer) + ctxBar->updateAutoSelectLayer(newAutoSelectLayer); } app::Color Editor::getColorByPosition(const gfx::Point& mousePos) diff --git a/src/app/ui/editor/editor.h b/src/app/ui/editor/editor.h index f467cf686..d1f7dc1f2 100644 --- a/src/app/ui/editor/editor.h +++ b/src/app/ui/editor/editor.h @@ -177,7 +177,7 @@ namespace app { tools::Ink* getCurrentEditorInk(); tools::ToolLoopModifiers getToolLoopModifiers() const { return m_toolLoopModifiers; } - bool isAutoSelectLayer() const { return m_autoSelectLayer; } + bool isAutoSelectLayer() const; bool isSecondaryButton() const { return m_secondaryButton; } gfx::Point lastDrawingPosition() const { return m_lastDrawingPosition; } @@ -289,7 +289,6 @@ namespace app { gfx::Point m_lastDrawingPosition; tools::ToolLoopModifiers m_toolLoopModifiers; - bool m_autoSelectLayer; // Extra space around the sprite. gfx::Point m_padding;