1 | // Aseprite Document Library |
---|---|
2 | // Copyright (c) 2001-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 | #ifndef DOC_CELS_RANGE_H_INCLUDED |
8 | #define DOC_CELS_RANGE_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "doc/frame.h" |
12 | #include "doc/object_id.h" |
13 | #include "doc/selected_frames.h" |
14 | |
15 | #include <set> |
16 | |
17 | namespace doc { |
18 | |
19 | class Cel; |
20 | class Layer; |
21 | class SelectedFrames; |
22 | class Sprite; |
23 | |
24 | class CelsRange { |
25 | public: |
26 | enum Flags { |
27 | ALL, |
28 | UNIQUE, |
29 | }; |
30 | |
31 | CelsRange(const Sprite* sprite, |
32 | const SelectedFrames& selFrames, |
33 | const Flags flags = ALL); |
34 | |
35 | class iterator { |
36 | public: |
37 | typedef Cel* value_type; |
38 | typedef std::ptrdiff_t difference_type; |
39 | typedef Cel** pointer; |
40 | typedef Cel*& reference; |
41 | typedef std::forward_iterator_tag iterator_category; |
42 | |
43 | iterator(const SelectedFrames& selFrames); |
44 | iterator(const Sprite* sprite, |
45 | const SelectedFrames& selFrames, |
46 | const Flags flags); |
47 | |
48 | bool operator==(const iterator& other) const { |
49 | return m_cel == other.m_cel; |
50 | } |
51 | |
52 | bool operator!=(const iterator& other) const { |
53 | return !operator==(other); |
54 | } |
55 | |
56 | Cel* operator*() const { |
57 | return m_cel; |
58 | } |
59 | |
60 | iterator& operator++(); |
61 | |
62 | private: |
63 | Cel* m_cel; |
64 | const SelectedFrames& m_selFrames; |
65 | SelectedFrames::const_iterator m_frameIterator; |
66 | Flags m_flags; |
67 | std::set<ObjectId> m_visited; |
68 | }; |
69 | |
70 | iterator begin() { return m_begin; } |
71 | iterator end() { return m_end; } |
72 | |
73 | int size() { |
74 | int count = 0; |
75 | for (auto it=begin(), e=end(); it!=e; ++it) |
76 | ++count; |
77 | return count; |
78 | } |
79 | |
80 | private: |
81 | SelectedFrames m_selFrames; |
82 | iterator m_begin, m_end; |
83 | }; |
84 | |
85 | } // namespace doc |
86 | |
87 | #endif |
88 |