forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_list.cpp
54 lines (45 loc) · 1.03 KB
/
layer_list.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Aseprite Document Library
// Copyright (c) 2016-2017 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;
}
bool are_layers_adjacent(const LayerList& layers)
{
layer_t count = 0;
Layer* prev = nullptr;
for (auto layer : layers) {
if (prev && prev != layer->getPrevious())
break;
prev = layer;
++count;
}
if (count == layer_t(layers.size()))
return true;
count = 0;
prev = nullptr;
for (auto layer : layers) {
if (prev && prev != layer->getNext())
break;
prev = layer;
++count;
}
if (count == layer_t(layers.size()))
return true;
return false;
}
} // namespace doc