1 | // LAF Gfx Library |
2 | // Copyright (c) 2020 Igara Studio S.A. |
3 | // |
4 | // This file is released under the terms of the MIT license. |
5 | // Read LICENSE.txt for more information. |
6 | |
7 | #ifndef GFX_PATH_SKIA_H_INCLUDED |
8 | #define GFX_PATH_SKIA_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "gfx/matrix.h" |
12 | #include "gfx/point.h" |
13 | #include "gfx/rect.h" |
14 | |
15 | #include "include/core/SkPath.h" |
16 | |
17 | namespace gfx { |
18 | |
19 | // Simple wrapper for SkPath |
20 | // TODO add missing methods for curves |
21 | class Path { |
22 | public: |
23 | Path() { } |
24 | |
25 | Path& reset() { |
26 | m_skPath.reset(); |
27 | return *this; |
28 | } |
29 | |
30 | Path& rewind() { |
31 | m_skPath.rewind(); |
32 | return *this; |
33 | } |
34 | |
35 | bool isEmpty() const { |
36 | return m_skPath.isEmpty(); |
37 | } |
38 | |
39 | Path& moveTo(float x, float y) { |
40 | m_skPath.moveTo(x, y); |
41 | return *this; |
42 | } |
43 | |
44 | Path& moveTo(const Point& p) { |
45 | m_skPath.moveTo(p.x, p.y); |
46 | return *this; |
47 | } |
48 | |
49 | Path& lineTo(float x, float y) { |
50 | m_skPath.lineTo(x, y); |
51 | return *this; |
52 | } |
53 | |
54 | Path& lineTo(const Point& p) { |
55 | m_skPath.lineTo(p.x, p.y); |
56 | return *this; |
57 | } |
58 | |
59 | Path& close() { |
60 | m_skPath.close(); |
61 | return *this; |
62 | } |
63 | |
64 | void offset(float dx, float dy, Path* dst) const { |
65 | m_skPath.offset(dx, dy, &dst->m_skPath); |
66 | } |
67 | |
68 | void offset(float dx, float dy) { |
69 | m_skPath.offset(dx, dy); |
70 | } |
71 | |
72 | void transform(const Matrix& matrix, Path* dst) { |
73 | m_skPath.transform(matrix.skMatrix(), &dst->m_skPath); |
74 | } |
75 | |
76 | void transform(const Matrix& matrix) { |
77 | m_skPath.transform(matrix.skMatrix()); |
78 | } |
79 | |
80 | RectF bounds() const { |
81 | if (isEmpty()) |
82 | return RectF(); |
83 | |
84 | SkRect rc = m_skPath.computeTightBounds(); |
85 | return RectF(rc.x(), rc.y(), rc.width(), rc.height()); |
86 | } |
87 | |
88 | const SkPath& skPath() const { return m_skPath; } |
89 | SkPath& skPath() { return m_skPath; } |
90 | |
91 | private: |
92 | SkPath m_skPath; |
93 | }; |
94 | |
95 | } // namespace gfx |
96 | |
97 | #endif |
98 | |