2014-07-29 03:53:24 +00:00
|
|
|
// Aseprite Document Library
|
2018-10-25 18:23:01 +00:00
|
|
|
// Copyright (C) 2018 Igara Studio S.A.
|
2018-04-18 19:56:02 +00:00
|
|
|
// Copyright (c) 2001-2018 David Capello
|
2014-07-29 03:53:24 +00:00
|
|
|
//
|
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
// Read LICENSE.txt for more information.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "doc/sprites.h"
|
|
|
|
|
|
|
|
#include "doc/sprite.h"
|
2014-10-21 01:21:31 +00:00
|
|
|
#include "doc/cel.h"
|
|
|
|
#include "doc/image.h"
|
|
|
|
#include "doc/layer.h"
|
|
|
|
#include "doc/primitives.h"
|
2014-07-29 03:53:24 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
2018-08-08 20:27:26 +00:00
|
|
|
#include <memory>
|
2014-07-29 03:53:24 +00:00
|
|
|
|
|
|
|
namespace doc {
|
|
|
|
|
|
|
|
Sprites::Sprites(Document* doc)
|
|
|
|
: m_doc(doc)
|
|
|
|
{
|
|
|
|
ASSERT(doc != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprites::~Sprites()
|
|
|
|
{
|
|
|
|
deleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite* Sprites::add(Sprite* spr)
|
|
|
|
{
|
|
|
|
ASSERT(spr != NULL);
|
|
|
|
|
|
|
|
m_sprites.insert(begin(), spr);
|
2015-01-19 01:05:33 +00:00
|
|
|
spr->setDocument(m_doc);
|
2014-07-29 03:53:24 +00:00
|
|
|
|
|
|
|
return spr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::remove(Sprite* spr)
|
|
|
|
{
|
|
|
|
iterator it = std::find(begin(), end(), spr);
|
|
|
|
ASSERT(it != end());
|
|
|
|
|
2015-01-19 01:05:33 +00:00
|
|
|
if (it != end()) {
|
|
|
|
(*it)->setDocument(NULL);
|
2014-07-29 03:53:24 +00:00
|
|
|
m_sprites.erase(it);
|
2015-01-19 01:05:33 +00:00
|
|
|
}
|
2014-07-29 03:53:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::move(Sprite* spr, int index)
|
|
|
|
{
|
|
|
|
remove(spr);
|
|
|
|
|
|
|
|
m_sprites.insert(begin()+index, spr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprites::deleteAll()
|
|
|
|
{
|
|
|
|
std::vector<Sprite*> copy = m_sprites;
|
|
|
|
|
|
|
|
for (iterator it = copy.begin(), end = copy.end(); it != end; ++it) {
|
|
|
|
Sprite* spr = *it;
|
|
|
|
delete spr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_sprites.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace doc
|