mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 23:09:58 +00:00
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:
parent
9fd340751f
commit
ae91c3d15b
@ -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
27
src/doc/layer_list.cpp
Normal 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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user