1 | // Aseprite Document Library |
---|---|
2 | // Copyright (c) 2016-2017 David Capello |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifdef HAVE_CONFIG_H |
8 | #include "config.h" |
9 | #endif |
10 | |
11 | #include "doc/layer.h" |
12 | #include "doc/layer_list.h" |
13 | |
14 | #include <algorithm> |
15 | |
16 | namespace doc { |
17 | |
18 | layer_t find_layer_index(const LayerList& layers, const Layer* layer) |
19 | { |
20 | auto it = std::find(layers.begin(), layers.end(), layer); |
21 | if (it != layers.end()) |
22 | return it - layers.begin(); |
23 | else |
24 | return 0; |
25 | } |
26 | |
27 | bool are_layers_adjacent(const LayerList& layers) |
28 | { |
29 | layer_t count = 0; |
30 | Layer* prev = nullptr; |
31 | for (auto layer : layers) { |
32 | if (prev && prev != layer->getPrevious()) |
33 | break; |
34 | prev = layer; |
35 | ++count; |
36 | } |
37 | if (count == layer_t(layers.size())) |
38 | return true; |
39 | |
40 | count = 0; |
41 | prev = nullptr; |
42 | for (auto layer : layers) { |
43 | if (prev && prev != layer->getNext()) |
44 | break; |
45 | prev = layer; |
46 | ++count; |
47 | } |
48 | if (count == layer_t(layers.size())) |
49 | return true; |
50 | |
51 | return false; |
52 | } |
53 | |
54 | } // namespace doc |
55 |