mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-04 15:40:10 +00:00
Replace brush slots until the user presses the shortcut
We replace brush slots until the user presses its keyboard shortcut, which means he is interested in reusing the brush. In this way, if we want to keep a brush, we can press Ctrl+B, select the brush area, and then Alt+1 to keep the first brush, then the next brush slot will be used/replaced until Alt+2 is pressed, etc.
This commit is contained in:
parent
03faee9ce4
commit
f1d522f548
@ -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<m_brushes.size(); ++i) {
|
||||
if (!m_brushes[i]) {
|
||||
m_brushes[i] = brush;
|
||||
if (!m_brushes[i].locked ||
|
||||
!m_brushes[i].brush) {
|
||||
m_brushes[i].brush = brush;
|
||||
return i+1;
|
||||
}
|
||||
}
|
||||
|
||||
m_brushes.push_back(brush);
|
||||
m_brushes.push_back(BrushSlot(brush));
|
||||
return (int)m_brushes.size(); // Returns the slot
|
||||
}
|
||||
|
||||
@ -1038,24 +1038,39 @@ void ContextBar::removeBrush(int slot)
|
||||
{
|
||||
--slot;
|
||||
if (slot >= 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;
|
||||
|
@ -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<BrushSlot> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user