forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cels_range.cpp
103 lines (89 loc) · 2.44 KB
/
cels_range.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Aseprite Document Library
// Copyright (c) 2019 Igara Studio S.A.
// Copyright (c) 2001-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/cels_range.h"
#include "doc/cel.h"
#include "doc/layer.h"
#include "doc/sprite.h"
namespace doc {
CelsRange::CelsRange(const Sprite* sprite,
const SelectedFrames& selFrames,
const Flags flags)
: m_selFrames(selFrames)
, m_begin(sprite, m_selFrames, flags)
, m_end(m_selFrames)
{
}
CelsRange::iterator::iterator(const SelectedFrames& selFrames)
: m_cel(nullptr)
, m_selFrames(selFrames)
, m_frameIterator(selFrames.begin())
{
}
CelsRange::iterator::iterator(const Sprite* sprite,
const SelectedFrames& selFrames,
const CelsRange::Flags flags)
: m_cel(nullptr)
, m_selFrames(selFrames)
, m_frameIterator(selFrames.begin())
, m_flags(flags)
{
// Get first cel
Layer* layer = sprite->root()->firstLayerInWholeHierarchy();
while (layer && !m_cel) {
if (layer->isImage()) {
m_frameIterator = m_selFrames.begin();
auto endFrame = m_selFrames.end();
for (; m_frameIterator!=endFrame; ++m_frameIterator) {
m_cel = layer->cel(*m_frameIterator);
if (m_cel)
break;
}
}
if (!m_cel)
layer = layer->getNextInWholeHierarchy();
}
if (m_cel && flags == CelsRange::UNIQUE)
m_visited.insert(m_cel->data()->id());
}
CelsRange::iterator& CelsRange::iterator::operator++()
{
if (!m_cel)
return *this;
auto endFrame = m_selFrames.end();
if (m_frameIterator != endFrame)
++m_frameIterator;
Layer* layer = m_cel->layer();
m_cel = nullptr;
while (layer && !m_cel) {
if (layer->isImage()) {
for (; m_frameIterator!=endFrame; ++m_frameIterator) {
m_cel = layer->cel(*m_frameIterator);
if (m_cel) {
if (m_flags == CelsRange::UNIQUE) {
if (m_visited.find(m_cel->data()->id()) == m_visited.end()) {
m_visited.insert(m_cel->data()->id());
break;
}
else
m_cel = nullptr;
}
else
break;
}
}
}
if (!m_cel) {
layer = layer->getNextInWholeHierarchy();
m_frameIterator = m_selFrames.begin();
}
}
return *this;
}
} // namespace doc