brush.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Mark Page
28 */
29
30 #pragma once
31
32 #include "../../Core/Math/mat3.h"
33 #include "../../Display/2D/color.h"
34 #include "image.h"
35 #include <vector>
36
37 namespace clan
38 {
39 class BrushGradientStop
40 {
41 public:
42 BrushGradientStop() { }
43 BrushGradientStop(const Colorf &color, float position) : color(color), position(position) { }
44
45 Colorf color;
46 float position = 0.0f;
47 };
48
49 enum class BrushType
50 {
51 solid,
52 linear,
53 radial,
54 image
55 };
56
57 enum class BrushWrapMode
58 {
59 clamp,
60 wrap,
61 mirror
62 };
63
64 enum class BrushInterpolateMode
65 {
66 nearest,
67 linear
68 };
69
70 class Brush
71 {
72 public:
73 Brush() { }
74 Brush(const Colorf &color) : color(color) { }
75
76 BrushType type = BrushType::solid;
77
78 // Generic brush properties
79 float opacity = 1.0f;
80 Mat3f transform = Mat3f::identity();
81
82 // Solid color
83 Colorf color;
84
85 // Gradient color stops
86 std::vector<BrushGradientStop> stops;
87
88 // Linear gradient
89 Pointf start_point;
90 Pointf end_point;
91
92 // Radial gradient
93 Pointf center_point;
94 Pointf gradient_origin_offset;
95 float radius_x = 0.0f;
96 float radius_y = 0.0f;
97
98 // Texture
99 Image image;
100 BrushWrapMode wrap_x = BrushWrapMode::wrap;
101 BrushWrapMode wrap_y = BrushWrapMode::wrap;
102 BrushInterpolateMode interpolate = BrushInterpolateMode::linear;
103
104 static Brush solid(float r, float g, float b, float a = 1.0f)
105 {
106 Brush brush;
107 brush.color = Colorf(r, g, b, a);
108 return brush;
109 }
110 static Brush solid(const Colorf &color)
111 {
112 Brush brush;
113 brush.color = color;
114 return brush;
115 }
116 static Brush solid_rgb8(int r, int g, int b)
117 {
118 Brush brush;
119 brush.color = Colorf(r, g, b);
120 return brush;
121 }
122
123 static Brush solid_rgba8(int r, int g, int b, int a)
124 {
125 Brush brush;
126 brush.color = Colorf(r, g, b, a);
127 return brush;
128 }
129 };
130
131 }
clan::Brush::color
Colorf color
Definition: brush.h:83
clan::Mat3< float >::identity
static Mat3< float > identity()
clan::Brush::opacity
float opacity
Definition: brush.h:79
clan
Definition: clanapp.h:35
clan::Colorf
Floating point color description class (for float).
Definition: color.h:660
clan::BrushInterpolateMode
BrushInterpolateMode
Definition: brush.h:64
clan::Brush::solid_rgb8
static Brush solid_rgb8(int r, int g, int b)
Definition: brush.h:116
clan::BrushType::radial
clan::Brush::type
BrushType type
Definition: brush.h:76
clan::Key::g
clan::Brush::wrap_x
BrushWrapMode wrap_x
Definition: brush.h:100
clan::Brush::center_point
Pointf center_point
Definition: brush.h:93
clan::BrushType::image
clan::BrushWrapMode
BrushWrapMode
Definition: brush.h:57
clan::Brush::interpolate
BrushInterpolateMode interpolate
Definition: brush.h:102
clan::BrushWrapMode::wrap
clan::Brush::solid
static Brush solid(float r, float g, float b, float a=1.0f)
Definition: brush.h:104
clan::Brush::solid
static Brush solid(const Colorf &color)
Definition: brush.h:110
clan::BrushInterpolateMode::linear
clan::Brush::end_point
Pointf end_point
Definition: brush.h:90
clan::BrushGradientStop
Definition: brush.h:39
clan::BrushType::solid
clan::Key::r
clan::Key::f
clan::BrushGradientStop::color
Colorf color
Definition: brush.h:45
clan::BrushWrapMode::mirror
clan::Brush
Definition: brush.h:70
clan::Key::a
clan::Mat3< float >
clan::Brush::start_point
Pointf start_point
Definition: brush.h:89
clan::Brush::radius_x
float radius_x
Definition: brush.h:95
clan::Brush::wrap_y
BrushWrapMode wrap_y
Definition: brush.h:101
clan::Brush::stops
std::vector< BrushGradientStop > stops
Definition: brush.h:86
clan::Image
Image class.
Definition: image.h:59
clan::BrushGradientStop::position
float position
Definition: brush.h:46
clan::Brush::solid_rgba8
static Brush solid_rgba8(int r, int g, int b, int a)
Definition: brush.h:123
clan::BrushGradientStop::BrushGradientStop
BrushGradientStop(const Colorf &color, float position)
Definition: brush.h:43
clan::BrushWrapMode::clamp
clan::BrushInterpolateMode::nearest
clan::Brush::Brush
Brush()
Definition: brush.h:73
clan::Brush::transform
Mat3f transform
Definition: brush.h:80
clan::Brush::Brush
Brush(const Colorf &color)
Definition: brush.h:74
clan::Key::b
clan::BrushType::linear
clan::Pointf
2D (x,y) point structure - Float
Definition: point.h:72
clan::Brush::image
Image image
Definition: brush.h:99
clan::BrushGradientStop::BrushGradientStop
BrushGradientStop()
Definition: brush.h:42
clan::BrushType
BrushType
Definition: brush.h:49
clan::Brush::gradient_origin_offset
Pointf gradient_origin_offset
Definition: brush.h:94
clan::Brush::radius_y
float radius_y
Definition: brush.h:96