Add doc::find_layer_index()

It'll be useful to known the index of a layer inside a list (e.g. a list
of all layers, or a list of all browsable layers, etc.).
This commit is contained in:
David Capello 2016-08-11 14:30:44 -03:00
parent 9fd340751f
commit ae91c3d15b
3 changed files with 30 additions and 0 deletions

View File

@ -44,6 +44,7 @@ add_library(doc-lib
layer.cpp
layer_index.cpp
layer_io.cpp
layer_list.cpp
mask.cpp
mask_boundaries.cpp
mask_io.cpp

27
src/doc/layer_list.cpp Normal file
View File

@ -0,0 +1,27 @@
// Aseprite Document Library
// Copyright (c) 2016 David Capello
//
// 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/layer.h"
#include "doc/layer_list.h"
#include <algorithm>
namespace doc {
layer_t find_layer_index(const LayerList& layers, const Layer* layer)
{
auto it = std::find(layers.begin(), layers.end(), layer);
if (it != layers.end())
return it - layers.begin();
else
return 0;
}
} // namespace doc

View File

@ -17,6 +17,8 @@ namespace doc {
typedef std::vector<Layer*> LayerList;
typedef int layer_t;
layer_t find_layer_index(const LayerList& layers, const Layer* layer);
} // namespace doc
#endif // DOC_LAYER_LIST_H_INCLUDED