30 #ifndef PT_GFX_BRUSH_H
31 #define PT_GFX_BRUSH_H
33 #include <Pt/Gfx/Image.h>
34 #include <Pt/SmartPtr.h>
45 ColorStop(
float position,
const Color& color)
50 float position()
const
53 const Color& color()
const
72 {
return _stops.empty(); }
74 std::size_t size()
const
75 {
return _stops.size(); }
82 void add(
float position,
const Color& color)
83 { _stops.push_back( ColorStop(position, color) ); }
85 const ColorStop& operator[] (std::size_t n)
const
88 const ColorStop& front()
const
89 {
return _stops.front(); }
91 const ColorStop& back()
const
92 {
return _stops.back(); }
94 void calculateInterpolatedColor(Color& res,
const float position)
const;
98 std::vector<ColorStop> _stops;
102 class PT_GFX_API Brush
131 Brush(
const Color& color);
135 static Brush verticalGradient(
const Color& from,
const Color& to);
137 static Brush horizontalGradient(
const Color& from,
const Color& to);
139 static Brush verticalGradient(
const ColorStops& colorStops);
141 static Brush horizontalGradient(
const ColorStops& colorStops);
145 static Brush linearGradient(
const PointF& begin,
const PointF& end,
146 const ColorStops& colorStops);
150 static Brush linearGradient(
float beginX,
float beginY,
151 float endX,
float endY,
152 const ColorStops& colorStops);
156 static Brush radialGradient(
const PointF& begin,
float beginRadius,
157 const PointF& end,
float endRadius,
158 const ColorStops& colorStops);
162 static Brush radialGradient(
float beginX,
float beginY,
float beginRadius,
163 float endX,
float endY,
float endRadius,
164 const ColorStops& colorStops);
168 FillStyle fillStyle()
const;
170 PositionMode positionMode()
const;
172 void setColor(
const Color& color);
174 const Color& color()
const;
178 GradientStyle gradient()
const;
181 const Color& gradientColor()
const;
185 const ColorStops& gradientStops()
const;
189 const PointF& gradientBegin()
const;
193 float gradientBeginRadius()
const;
197 const PointF& gradientEnd()
const;
201 float gradientEndRadius()
const;
203 void setTexture(
const Image& texture,
206 const Image& texture()
const;
215 bool isGradient()
const;
217 bool isTexture()
const;
222 Brush(BrushData* data);
225 SmartPtr<BrushData> _brushData;
234 , _fillStyle(Brush::Solid)
236 , _gradient(Brush::Horizontal)
239 BrushData(
const Color& color)
241 , _fillStyle(Brush::Solid)
243 , _gradient(Brush::Horizontal)
246 BrushData(
const Image& texture,
250 BrushData(
const Color& from,
const Color& to,
251 Brush::GradientStyle g);
256 Brush::FillStyle fillStyle()
const
257 {
return _fillStyle; }
259 Brush::PositionMode positionMode()
const
260 {
return _positionMode; }
262 void setSolid(
const Color& color);
264 const Color& color()
const
265 {
return _gradientStops.empty() ? _color : _gradientStops.front().color(); }
268 void set1DGradient(Brush::GradientStyle g,
const ColorStops& colorStops);
271 void setLinearGradient(
const PointF& begin,
const PointF& end,
272 const ColorStops& colorStops);
275 void setLinearGradient(
float beginX,
float beginY,
276 float endX,
float endY,
277 const ColorStops& colorStops);
281 void setRadialGradient(
const PointF& begin,
float beginRadius,
282 const PointF& end,
float endRadius,
283 const ColorStops& colorStops);
286 void setRadialGradient(
float beginX,
float beginY,
float beginRadius,
287 float endX,
float endY,
float endRadius,
288 const ColorStops& colorStops);
290 Brush::GradientStyle gradient()
const
291 {
return _gradient; }
294 const Color& gradientColor()
const
295 {
return _gradientStops.empty() ? _color : _gradientStops.back().color(); }
297 const ColorStops& gradientStops()
const
298 {
return _gradientStops; }
300 const PointF& gradientBegin()
const
301 {
return _gradientBegin; }
303 float gradientBeginRadius()
const
304 {
return _gradientBeginRadius; }
306 const PointF& gradientEnd()
const
307 {
return _gradientEnd; }
309 float gradientEndRadius()
const
310 {
return _gradientEndRadius; }
312 void setTexture(
const Image& texture,
315 const Image& texture()
const
324 bool isGradient()
const
325 {
return _fillStyle == Brush::Gradient; }
327 bool isTexture()
const
328 {
return _fillStyle == Brush::Texture; }
335 Brush::FillStyle _fillStyle;
336 Brush::PositionMode _positionMode;
339 Brush::GradientStyle _gradient;
340 ColorStops _gradientStops;
341 PointF _gradientBegin;
342 float _gradientBeginRadius;
344 float _gradientEndRadius;
int_type int32_t
Signed 32-bit integer type.
Definition: Types.h:36