1 | // Aseprite Document Library |
2 | // Copyright (c) 2020 Igara Studio S.A. |
3 | // Copyright (c) 2001-2015 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_MASK_BOUNDARIES_H_INCLUDED |
9 | #define DOC_MASK_BOUNDARIES_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "gfx/path.h" |
13 | #include "gfx/rect.h" |
14 | |
15 | #include <vector> |
16 | |
17 | namespace doc { |
18 | class Image; |
19 | |
20 | class MaskBoundaries { |
21 | public: |
22 | class Segment { |
23 | public: |
24 | Segment(bool open, const gfx::Rect& bounds) |
25 | : m_open(open), m_bounds(bounds) { } |
26 | |
27 | // Returns true if this segment enters into the boundaries. |
28 | bool open() const { return m_open; } |
29 | |
30 | const gfx::Rect& bounds() const { return m_bounds; } |
31 | void offset(int x, int y) { m_bounds.offset(x, y); } |
32 | bool vertical() const { return m_bounds.w == 0; } |
33 | bool horizontal() const { return m_bounds.h == 0; } |
34 | |
35 | private: |
36 | bool m_open; |
37 | gfx::Rect m_bounds; |
38 | |
39 | friend class MaskBoundaries; |
40 | }; |
41 | |
42 | typedef std::vector<Segment> list_type; |
43 | typedef list_type::iterator iterator; |
44 | typedef list_type::const_iterator const_iterator; |
45 | |
46 | bool isEmpty() const { return m_segs.empty(); } |
47 | void reset(); |
48 | void regen(const Image* bitmap); |
49 | |
50 | const_iterator begin() const { return m_segs.begin(); } |
51 | const_iterator end() const { return m_segs.end(); } |
52 | iterator begin() { return m_segs.begin(); } |
53 | iterator end() { return m_segs.end(); } |
54 | |
55 | void offset(int x, int y); |
56 | gfx::Path& path() { return m_path; } |
57 | |
58 | void createPathIfNeeeded(); |
59 | |
60 | private: |
61 | list_type m_segs; |
62 | gfx::Path m_path; |
63 | }; |
64 | |
65 | } // namespace doc |
66 | |
67 | #endif |
68 | |