Add a number to each new slice that is created (related to #1651)

This commit is contained in:
David Capello 2020-03-06 15:18:10 -03:00
parent 99cb95357a
commit 1fe3c3a4bc

View File

@ -56,6 +56,8 @@
#include "render/render.h"
#include "ui/ui.h"
#include <algorithm>
namespace app {
using namespace ui;
@ -603,6 +605,8 @@ public:
if (!m_editor->selectSliceBox(bounds) &&
(bounds.w > 1 || bounds.h > 1)) {
Slice* slice = new Slice;
slice->setName(getUniqueSliceName());
SliceKey key(bounds);
slice->insert(getFrame(), key);
@ -624,6 +628,21 @@ public:
m_canceled = true;
}
private:
#ifdef ENABLE_UI
std::string getUniqueSliceName() const {
std::string prefix = "Slice";
int max = 0;
for (Slice* slice : m_sprite->slices())
if (std::strncmp(slice->name().c_str(), prefix.c_str(), prefix.size()) == 0)
max = std::max(max, (int)std::strtol(slice->name().c_str()+prefix.size(), nullptr, 10));
return fmt::format("{} {}", prefix, max+1);
}
#endif
};
#ifdef ENABLE_UI