diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index fb36a6421..13a31a7f5 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -110,8 +110,7 @@ protected: } void onDeleteAllBrushes() override { - while (!m_owner->brushes().empty()) - m_owner->removeBrush(m_owner->brushes().size()); + m_owner->removeAllBrushes(); } private: @@ -130,7 +129,7 @@ private: IBrushSettings* brushSettings = settings->getToolSettings(currentTool)->getBrush(); doc::BrushRef brush = m_owner->activeBrush(); - m_popupWindow.regenerate(getPopupBox(), m_owner->brushes()); + m_popupWindow.regenerate(getPopupBox(), m_owner->getBrushes()); m_popupWindow.setBrush(brush.get()); Region rgn(m_popupWindow.getBounds().createUnion(getBounds())); @@ -1024,13 +1023,14 @@ int ContextBar::addBrush(const doc::BrushRef& brush) { // Use an empty slot for (size_t i=0; i= 0 && slot < (int)m_brushes.size()) { - m_brushes[slot].reset(); + m_brushes[slot].brush.reset(); // Erase empty trailing slots while (!m_brushes.empty() && - !m_brushes[m_brushes.size()-1]) + !m_brushes[m_brushes.size()-1].brush) m_brushes.erase(--m_brushes.end()); } } +void ContextBar::removeAllBrushes() +{ + while (!m_brushes.empty()) + m_brushes.erase(--m_brushes.end()); +} + void ContextBar::setActiveBrushBySlot(int slot) { --slot; if (slot >= 0 && slot < (int)m_brushes.size() && - m_brushes[slot]) { - setActiveBrush(m_brushes[slot]); + m_brushes[slot].brush) { + m_brushes[slot].locked = true; + setActiveBrush(m_brushes[slot].brush); } } +Brushes ContextBar::getBrushes() +{ + Brushes brushes; + for (const auto& slot : m_brushes) + brushes.push_back(slot.brush); + return brushes; +} + void ContextBar::setActiveBrush(const doc::BrushRef& brush) { m_activeBrush = brush; diff --git a/src/app/ui/context_bar.h b/src/app/ui/context_bar.h index dbecb9b4a..ce0532423 100644 --- a/src/app/ui/context_bar.h +++ b/src/app/ui/context_bar.h @@ -53,8 +53,9 @@ namespace app { // is now available. int addBrush(const doc::BrushRef& brush); void removeBrush(int slot); - const doc::Brushes& brushes() const { return m_brushes; } + void removeAllBrushes(); void setActiveBrushBySlot(int slot); + doc::Brushes getBrushes(); static doc::BrushRef createBrushFromSettings( IBrushSettings* brushSettings = nullptr); @@ -72,6 +73,21 @@ namespace app { void onCurrentToolChange(); void onDropPixels(ContextBarObserver::DropAction action); + struct BrushSlot { + // True if the user locked the brush using the shortcut key to + // access it. + bool locked; + + // Can be null if the user deletes the brush. + doc::BrushRef brush; + + BrushSlot(const doc::BrushRef& brush) + : locked(false), brush(brush) { + } + }; + + typedef std::vector BrushSlots; + class BrushTypeField; class BrushAngleField; class BrushSizeField; @@ -114,7 +130,7 @@ namespace app { RotAlgorithmField* m_rotAlgo; DropPixelsField* m_dropPixels; doc::BrushRef m_activeBrush; - doc::Brushes m_brushes; + BrushSlots m_brushes; }; } // namespace app