| 1 | // Aseprite |
| 2 | // Copyright (C) 2019-2021 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2015 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_TOOLS_STROKE_H_INCLUDED |
| 9 | #define APP_TOOLS_STROKE_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/pref/preferences.h" |
| 13 | #include "gfx/point.h" |
| 14 | #include "gfx/rect.h" |
| 15 | |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace app { |
| 19 | namespace tools { |
| 20 | |
| 21 | class Stroke { |
| 22 | public: |
| 23 | struct Pt { |
| 24 | int x = 0; |
| 25 | int y = 0; |
| 26 | float size = 0.0f; |
| 27 | float angle = 0.0f; |
| 28 | float gradient = 0.0f; |
| 29 | gen::SymmetryMode symmetry = gen::SymmetryMode::NONE; |
| 30 | Pt() { } |
| 31 | Pt(const gfx::Point& point) : x(point.x), y(point.y) { } |
| 32 | Pt(int x, int y) : x(x), y(y) { } |
| 33 | gfx::Point toPoint() const { return gfx::Point(x, y); } |
| 34 | bool operator==(const Pt& that) const { return x == that.x && y == that.y; } |
| 35 | bool operator!=(const Pt& that) const { return x != that.x || y != that.y; } |
| 36 | }; |
| 37 | typedef std::vector<Pt> Pts; |
| 38 | typedef Pts::const_iterator const_iterator; |
| 39 | |
| 40 | const_iterator begin() const { return m_pts.begin(); } |
| 41 | const_iterator end() const { return m_pts.end(); } |
| 42 | |
| 43 | bool empty() const { return m_pts.empty(); } |
| 44 | int size() const { return (int)m_pts.size(); } |
| 45 | |
| 46 | const Pt& operator[](int i) const { return m_pts[i]; } |
| 47 | Pt& operator[](int i) { return m_pts[i]; } |
| 48 | |
| 49 | const Pt& firstPoint() const { |
| 50 | ASSERT(!m_pts.empty()); |
| 51 | return m_pts[0]; |
| 52 | } |
| 53 | |
| 54 | const Pt& lastPoint() const { |
| 55 | ASSERT(!m_pts.empty()); |
| 56 | return m_pts[m_pts.size()-1]; |
| 57 | } |
| 58 | |
| 59 | // Clears the whole stroke. |
| 60 | void reset(); |
| 61 | |
| 62 | // Reset the stroke as "n" points in the given point position. |
| 63 | void reset(int n, const Pt& pt); |
| 64 | |
| 65 | // Adds a new point to the stroke. |
| 66 | void addPoint(const Pt& pt); |
| 67 | |
| 68 | // Displaces all X,Y coordinates the given delta. |
| 69 | void offset(const gfx::Point& delta); |
| 70 | |
| 71 | // Erase the point "index". |
| 72 | void erase(int index); |
| 73 | |
| 74 | // Returns the bounds of the stroke (minimum/maximum position). |
| 75 | gfx::Rect bounds() const; |
| 76 | |
| 77 | std::vector<int> toXYInts() const; |
| 78 | |
| 79 | public: |
| 80 | Pts m_pts; |
| 81 | }; |
| 82 | |
| 83 | typedef std::vector<Stroke> Strokes; |
| 84 | |
| 85 | } // namespace tools |
| 86 | } // namespace app |
| 87 | |
| 88 | #endif |
| 89 | |