1 | // Aseprite Document Library |
---|---|
2 | // Copyright (C) 2019-2020 Igara Studio S.A. |
3 | // Copyright (C) 2017 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifndef DOC_SLICE_H_INCLUDED |
9 | #define DOC_SLICE_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "doc/frame.h" |
13 | #include "doc/keyframes.h" |
14 | #include "doc/with_user_data.h" |
15 | #include "gfx/point.h" |
16 | #include "gfx/rect.h" |
17 | |
18 | #include <string> |
19 | |
20 | namespace doc { |
21 | class Slices; |
22 | class Sprite; |
23 | |
24 | class SliceKey { |
25 | public: |
26 | static const gfx::Point NoPivot; |
27 | |
28 | SliceKey(); |
29 | SliceKey(const gfx::Rect& bounds, |
30 | const gfx::Rect& center = gfx::Rect(), |
31 | const gfx::Point& pivot = SliceKey::NoPivot); |
32 | |
33 | bool isEmpty() const { return m_bounds.isEmpty(); } |
34 | bool hasCenter() const { return !m_center.isEmpty(); } |
35 | bool hasPivot() const { return m_pivot != NoPivot; } |
36 | |
37 | const gfx::Rect& bounds() const { return m_bounds; } |
38 | const gfx::Rect& center() const { return m_center; } |
39 | const gfx::Point& pivot() const { return m_pivot; } |
40 | |
41 | void setBounds(const gfx::Rect& bounds) { m_bounds = bounds; } |
42 | void setCenter(const gfx::Rect& center) { m_center = center; } |
43 | void setPivot(const gfx::Point& pivot) { m_pivot = pivot; } |
44 | |
45 | private: |
46 | gfx::Rect m_bounds; |
47 | gfx::Rect m_center; |
48 | gfx::Point m_pivot; |
49 | }; |
50 | |
51 | class Slice : public WithUserData { |
52 | public: |
53 | typedef Keyframes<SliceKey> List; |
54 | typedef List::iterator iterator; |
55 | typedef List::const_iterator const_iterator; |
56 | |
57 | Slice(); |
58 | Slice(const Slice& other); |
59 | ~Slice(); |
60 | |
61 | int getMemSize() const override; |
62 | |
63 | void insert(const frame_t frame, const SliceKey& key); |
64 | void remove(const frame_t frame); |
65 | |
66 | const SliceKey* getByFrame(const frame_t frame) const; |
67 | iterator getIteratorByFrame(const frame_t frame) const; |
68 | |
69 | iterator begin() { return m_keys.begin(); } |
70 | iterator end() { return m_keys.end(); } |
71 | const_iterator begin() const { return m_keys.begin(); } |
72 | const_iterator end() const { return m_keys.end(); } |
73 | |
74 | std::size_t size() const { return m_keys.size(); } |
75 | bool empty() const { return m_keys.empty(); } |
76 | |
77 | Sprite* sprite() const; |
78 | Slices* owner() const { return m_owner; } |
79 | frame_t fromFrame() const { return m_keys.fromFrame(); } |
80 | frame_t toFrame() const { return m_keys.toFrame(); } |
81 | const std::string& name() const { return m_name; } |
82 | |
83 | void setOwner(Slices* owner); |
84 | void setName(const std::string& name); |
85 | |
86 | List::Range range(const frame_t from, const frame_t to) { |
87 | return m_keys.range(from, to); |
88 | } |
89 | |
90 | private: |
91 | Slices* m_owner; |
92 | std::string m_name; |
93 | List m_keys; |
94 | }; |
95 | |
96 | } // namespace doc |
97 | |
98 | #endif |
99 |