| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 |
| 19 | #ifndef VBRUSH_H |
| 20 | #define VBRUSH_H |
| 21 |
| 22 | #include <vector> |
| 23 | #include "vglobal.h" |
| 24 | #include "vmatrix.h" |
| 25 | #include "vpoint.h" |
| 26 | #include "vbitmap.h" |
| 27 |
| 28 | V_BEGIN_NAMESPACE |
| 29 |
| 30 | typedef std::pair<float, VColor> VGradientStop; |
| 31 | typedef std::vector<VGradientStop> VGradientStops; |
| 32 | class VGradient { |
| 33 | public: |
| 34 | enum class Mode { Absolute, Relative }; |
| 35 | enum class Spread { Pad, Repeat, Reflect }; |
| 36 | enum class Type { Linear, Radial }; |
| 37 | VGradient(VGradient::Type type); |
| 38 | void setStops(const VGradientStops &stops); |
| 39 | void setAlpha(float alpha) {mAlpha = alpha;} |
| 40 | float alpha() const {return mAlpha;} |
| 41 | VGradient() = default; |
| 42 |
| 43 | public: |
| 44 | static constexpr int colorTableSize = 1024; |
| 45 | VGradient::Type mType; |
| 46 | VGradient::Spread mSpread; |
| 47 | VGradient::Mode mMode; |
| 48 | VGradientStops mStops; |
| 49 | float mAlpha{1.0}; |
| 50 | union { |
| 51 | struct { |
| 52 | float x1, y1, x2, y2; |
| 53 | } linear; |
| 54 | struct { |
| 55 | float cx, cy, fx, fy, cradius, fradius; |
| 56 | } radial; |
| 57 | }; |
| 58 | VMatrix mMatrix; |
| 59 | }; |
| 60 |
| 61 | class VLinearGradient : public VGradient { |
| 62 | public: |
| 63 | VLinearGradient(const VPointF &start, const VPointF &stop); |
| 64 | VLinearGradient(float xStart, float yStart, float xStop, float yStop); |
| 65 | }; |
| 66 |
| 67 | class VRadialGradient : public VGradient { |
| 68 | public: |
| 69 | VRadialGradient(const VPointF ¢er, float cradius, |
| 70 | const VPointF &focalPoint, float fradius); |
| 71 | VRadialGradient(float cx, float cy, float cradius, float fx, float fy, |
| 72 | float fradius); |
| 73 | }; |
| 74 |
| 75 | class VBrush { |
| 76 | public: |
| 77 | enum class Type { NoBrush, Solid, LinearGradient, RadialGradient, Texture }; |
| 78 | VBrush() = default; |
| 79 | VBrush(const VColor &color); |
| 80 | VBrush(const VGradient *gradient); |
| 81 | VBrush(int r, int g, int b, int a); |
| 82 | VBrush(const VBitmap &texture); |
| 83 | inline VBrush::Type type() const { return mType; } |
| 84 | void setMatrix(const VMatrix &m); |
| 85 | public: |
| 86 | VBrush::Type mType{Type::NoBrush}; |
| 87 | VColor mColor; |
| 88 | const VGradient *mGradient{nullptr}; |
| 89 | VBitmap mTexture; |
| 90 | VMatrix mMatrix; |
| 91 | }; |
| 92 |
| 93 | V_END_NAMESPACE |
| 94 |
| 95 | #endif // VBRUSH_H |
| 96 |