mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 21:33:12 +00:00
Prefer LayerGroup::layers() instead of iterators
This commit is contained in:
parent
f1f3dc91de
commit
58f8ed6476
@ -394,9 +394,9 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
|
||||
LayerList layers = sprite->root()->layers();
|
||||
|
||||
// Remove all other layers
|
||||
for (LayerIterator it=layers.begin(), end=layers.end(); it!=end; ++it) {
|
||||
if (*it != resultLayer)
|
||||
api.removeLayer(*it);
|
||||
for (Layer* child : layers) {
|
||||
if (child != resultLayer)
|
||||
api.removeLayer(child);
|
||||
}
|
||||
|
||||
// Change the number of frames
|
||||
|
@ -168,11 +168,8 @@ int NewLayerCommand::getMaxLayerNum(const Layer* layer) const
|
||||
max = std::strtol(layer->name().c_str()+prefix.size(), NULL, 10);
|
||||
|
||||
if (layer->isGroup()) {
|
||||
auto it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
auto end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
int tmp = getMaxLayerNum(*it);
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers()) {
|
||||
int tmp = getMaxLayerNum(child);
|
||||
max = MAX(tmp, max);
|
||||
}
|
||||
}
|
||||
|
@ -328,11 +328,7 @@ void Document::copyLayerContent(const Layer* sourceLayer0, Document* destDoc, La
|
||||
const LayerGroup* sourceLayer = static_cast<const LayerGroup*>(sourceLayer0);
|
||||
LayerGroup* destLayer = static_cast<LayerGroup*>(destLayer0);
|
||||
|
||||
LayerConstIterator it = sourceLayer->getLayerBegin();
|
||||
LayerConstIterator end = sourceLayer->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
Layer* sourceChild = *it;
|
||||
for (Layer* sourceChild : sourceLayer->layers()) {
|
||||
base::UniquePtr<Layer> destChild(NULL);
|
||||
|
||||
if (sourceChild->isImage()) {
|
||||
|
@ -290,11 +290,8 @@ void DocumentApi::moveFrameLayer(Layer* layer, frame_t frame, frame_t beforeFram
|
||||
}
|
||||
|
||||
case ObjectType::LayerGroup: {
|
||||
LayerIterator it = static_cast<LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerIterator end = static_cast<LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it)
|
||||
moveFrameLayer(*it, frame, beforeFrame);
|
||||
for (Layer* child : static_cast<LayerGroup*>(layer)->layers())
|
||||
moveFrameLayer(child, frame, beforeFrame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -392,12 +392,9 @@ bool AseFormat::onSave(FileOp* fop)
|
||||
|
||||
// Write extra chunks in the first frame
|
||||
if (frame == fop->roi().fromFrame()) {
|
||||
LayerIterator it = sprite->root()->getLayerBegin();
|
||||
LayerIterator end = sprite->root()->getLayerEnd();
|
||||
|
||||
// Write layer chunks
|
||||
for (; it != end; ++it)
|
||||
ase_file_write_layers(f, &frame_header, *it);
|
||||
for (Layer* child : sprite->root()->layers())
|
||||
ase_file_write_layers(f, &frame_header, child);
|
||||
|
||||
// Writer frame tags
|
||||
if (sprite->frameTags().size() > 0)
|
||||
@ -581,11 +578,8 @@ static void ase_file_write_layers(FILE* f, ASE_FrameHeader* frame_header, const
|
||||
ase_file_write_user_data_chunk(f, frame_header, &layer->userData());
|
||||
|
||||
if (layer->isGroup()) {
|
||||
auto it = static_cast<const LayerGroup*>(layer)->getLayerBegin(),
|
||||
end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it)
|
||||
ase_file_write_layers(f, frame_header, *it);
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers())
|
||||
ase_file_write_layers(f, frame_header, child);
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,11 +607,8 @@ static void ase_file_write_cels(FILE* f, ASE_FrameHeader* frame_header,
|
||||
}
|
||||
|
||||
if (layer->isGroup()) {
|
||||
auto it = static_cast<const LayerGroup*>(layer)->getLayerBegin(),
|
||||
end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it)
|
||||
ase_file_write_cels(f, frame_header, sprite, *it, frame, firstFrame);
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers())
|
||||
ase_file_write_cels(f, frame_header, sprite, child, frame, firstFrame);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,8 @@ static bool has_cels(const Layer* layer, frame_t frame)
|
||||
return (layer->cel(frame) ? true: false);
|
||||
|
||||
case ObjectType::LayerGroup: {
|
||||
LayerConstIterator it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerConstIterator end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
if (has_cels(*it, frame))
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers()) {
|
||||
if (has_cels(child, frame))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
@ -54,12 +54,8 @@ void ImagesCollector::collectFromLayer(Layer* layer, frame_t frame)
|
||||
}
|
||||
|
||||
case ObjectType::LayerGroup: {
|
||||
LayerIterator it = static_cast<LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerIterator end = static_cast<LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it)
|
||||
collectFromLayer(*it, frame);
|
||||
|
||||
for (Layer* child : static_cast<LayerGroup*>(layer)->layers())
|
||||
collectFromLayer(child, frame);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2001-2015 David Capello
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
@ -44,39 +44,39 @@ int Layer::getMemSize() const
|
||||
|
||||
Layer* Layer::getPrevious() const
|
||||
{
|
||||
if (m_parent != NULL) {
|
||||
LayerConstIterator it =
|
||||
std::find(m_parent->getLayerBegin(),
|
||||
m_parent->getLayerEnd(), this);
|
||||
if (m_parent) {
|
||||
auto it =
|
||||
std::find(m_parent->layers().begin(),
|
||||
m_parent->layers().end(), this);
|
||||
|
||||
if (it != m_parent->getLayerEnd() &&
|
||||
it != m_parent->getLayerBegin()) {
|
||||
if (it != m_parent->layers().end() &&
|
||||
it != m_parent->layers().begin()) {
|
||||
it--;
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Layer* Layer::getNext() const
|
||||
{
|
||||
if (m_parent != NULL) {
|
||||
LayerConstIterator it =
|
||||
std::find(m_parent->getLayerBegin(),
|
||||
m_parent->getLayerEnd(), this);
|
||||
if (m_parent) {
|
||||
auto it =
|
||||
std::find(m_parent->layers().begin(),
|
||||
m_parent->layers().end(), this);
|
||||
|
||||
if (it != m_parent->getLayerEnd()) {
|
||||
if (it != m_parent->layers().end()) {
|
||||
it++;
|
||||
if (it != m_parent->getLayerEnd())
|
||||
if (it != m_parent->layers().end())
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Cel* Layer::cel(frame_t frame) const
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@ -279,24 +279,16 @@ LayerGroup::~LayerGroup()
|
||||
|
||||
void LayerGroup::destroyAllLayers()
|
||||
{
|
||||
LayerIterator it = getLayerBegin();
|
||||
LayerIterator end = getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
Layer* layer = *it;
|
||||
for (Layer* layer : m_layers)
|
||||
delete layer;
|
||||
}
|
||||
m_layers.clear();
|
||||
}
|
||||
|
||||
int LayerGroup::getMemSize() const
|
||||
{
|
||||
int size = sizeof(LayerGroup);
|
||||
LayerConstIterator it = getLayerBegin();
|
||||
LayerConstIterator end = getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
const Layer* layer = *it;
|
||||
for (const Layer* layer : m_layers) {
|
||||
size += layer->getMemSize();
|
||||
}
|
||||
|
||||
@ -305,11 +297,8 @@ int LayerGroup::getMemSize() const
|
||||
|
||||
void LayerGroup::getCels(CelList& cels) const
|
||||
{
|
||||
LayerConstIterator it = getLayerBegin();
|
||||
LayerConstIterator end = getLayerEnd();
|
||||
|
||||
for (; it != end; ++it)
|
||||
(*it)->getCels(cels);
|
||||
for (const Layer* layer : m_layers)
|
||||
layer->getCels(cels);
|
||||
}
|
||||
|
||||
void LayerGroup::addLayer(Layer* layer)
|
||||
@ -320,7 +309,7 @@ void LayerGroup::addLayer(Layer* layer)
|
||||
|
||||
void LayerGroup::removeLayer(Layer* layer)
|
||||
{
|
||||
LayerIterator it = std::find(m_layers.begin(), m_layers.end(), layer);
|
||||
auto it = std::find(m_layers.begin(), m_layers.end(), layer);
|
||||
ASSERT(it != m_layers.end());
|
||||
m_layers.erase(it);
|
||||
|
||||
@ -333,12 +322,12 @@ void LayerGroup::stackLayer(Layer* layer, Layer* after)
|
||||
if (layer == after)
|
||||
return;
|
||||
|
||||
LayerIterator it = std::find(m_layers.begin(), m_layers.end(), layer);
|
||||
auto it = std::find(m_layers.begin(), m_layers.end(), layer);
|
||||
ASSERT(it != m_layers.end());
|
||||
m_layers.erase(it);
|
||||
|
||||
if (after) {
|
||||
LayerIterator after_it = std::find(m_layers.begin(), m_layers.end(), after);
|
||||
auto after_it = std::find(m_layers.begin(), m_layers.end(), after);
|
||||
ASSERT(after_it != m_layers.end());
|
||||
after_it++;
|
||||
m_layers.insert(after_it, layer);
|
||||
|
@ -167,11 +167,7 @@ namespace doc {
|
||||
|
||||
virtual int getMemSize() const override;
|
||||
|
||||
const LayerList& layers() { return m_layers; }
|
||||
LayerIterator getLayerBegin() { return m_layers.begin(); }
|
||||
LayerIterator getLayerEnd() { return m_layers.end(); }
|
||||
LayerConstIterator getLayerBegin() const { return m_layers.begin(); }
|
||||
LayerConstIterator getLayerEnd() const { return m_layers.end(); }
|
||||
const LayerList& layers() const { return m_layers; }
|
||||
int layersCount() const { return (int)m_layers.size(); }
|
||||
|
||||
void addLayer(Layer* layer);
|
||||
|
@ -88,14 +88,11 @@ void write_layer(std::ostream& os, const Layer* layer)
|
||||
}
|
||||
|
||||
case ObjectType::LayerGroup: {
|
||||
LayerConstIterator it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerConstIterator end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
// Number of sub-layers
|
||||
write16(os, static_cast<const LayerGroup*>(layer)->layersCount());
|
||||
|
||||
for (; it != end; ++it)
|
||||
write_layer(os, *it);
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers())
|
||||
write_layer(os, child);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite Document Library
|
||||
// Copyright (c) 2001-2015 David Capello
|
||||
// Copyright (c) 2001-2016 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -15,8 +15,6 @@ namespace doc {
|
||||
class Layer;
|
||||
|
||||
typedef std::vector<Layer*> LayerList;
|
||||
typedef LayerList::iterator LayerIterator;
|
||||
typedef LayerList::const_iterator LayerConstIterator;
|
||||
|
||||
} // namespace doc
|
||||
|
||||
|
@ -203,7 +203,7 @@ int Sprite::getMemSize() const
|
||||
LayerImage* Sprite::backgroundLayer() const
|
||||
{
|
||||
if (root()->layersCount() > 0) {
|
||||
Layer* bglayer = *root()->getLayerBegin();
|
||||
Layer* bglayer = root()->layers().front();
|
||||
|
||||
if (bglayer->isBackground()) {
|
||||
ASSERT(bglayer->isImage());
|
||||
@ -251,11 +251,8 @@ LayerIndex Sprite::layerToIndex(const Layer* layer) const
|
||||
void Sprite::getLayersList(std::vector<Layer*>& layers) const
|
||||
{
|
||||
// TODO support subgroups
|
||||
LayerConstIterator it = m_root->getLayerBegin();
|
||||
LayerConstIterator end = m_root->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
layers.push_back(*it);
|
||||
for (Layer* child : m_root->layers()) {
|
||||
layers.push_back(child);
|
||||
}
|
||||
}
|
||||
|
||||
@ -573,11 +570,8 @@ static Layer* index2layer(const Layer* layer, const LayerIndex& index, int* inde
|
||||
if (layer->isGroup()) {
|
||||
Layer *found;
|
||||
|
||||
LayerConstIterator it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerConstIterator end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
if ((found = index2layer(*it, index, index_count)))
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers()) {
|
||||
if ((found = index2layer(child, index, index_count)))
|
||||
return found;
|
||||
}
|
||||
}
|
||||
@ -596,11 +590,8 @@ static LayerIndex layer2index(const Layer* layer, const Layer* find_layer, int*
|
||||
if (layer->isGroup()) {
|
||||
int found;
|
||||
|
||||
LayerConstIterator it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerConstIterator end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
if ((found = layer2index(*it, find_layer, index_count)) >= 0)
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers()) {
|
||||
if ((found = layer2index(child, find_layer, index_count)) >= 0)
|
||||
return LayerIndex(found);
|
||||
}
|
||||
}
|
||||
|
@ -803,12 +803,9 @@ void Render::renderLayer(
|
||||
}
|
||||
|
||||
case ObjectType::LayerGroup: {
|
||||
LayerConstIterator it = static_cast<const LayerGroup*>(layer)->getLayerBegin();
|
||||
LayerConstIterator end = static_cast<const LayerGroup*>(layer)->getLayerEnd();
|
||||
|
||||
for (; it != end; ++it) {
|
||||
for (const Layer* child : static_cast<const LayerGroup*>(layer)->layers()) {
|
||||
renderLayer(
|
||||
*it, image,
|
||||
child, image,
|
||||
area, frame,
|
||||
scaled_func,
|
||||
render_background,
|
||||
|
Loading…
x
Reference in New Issue
Block a user