30 #ifndef PT_GFX_BRUSH_H
31 #define PT_GFX_BRUSH_H
33 #include <Pt/Gfx/Color.h>
34 #include <Pt/Gfx/Point.h>
35 #include <Pt/Gfx/Image.h>
36 #include <Pt/SmartPtr.h>
93 {
return _stops.empty(); }
98 {
return _stops.size(); }
110 { _stops.push_back(
ColorStop(position, color) ); }
115 {
return _stops[n]; }
120 {
return _stops.front(); }
125 {
return _stops.back(); }
133 std::vector<ColorStop> _stops;
224 float endX,
float endY,
230 const PointF& end,
float endRadius,
236 float endX,
float endY,
float endRadius,
312 Brush(BrushData* data);
324 , _fillStyle(
Brush::Solid)
325 , _positionMode(
Brush::Relative)
327 , _gradient(
Brush::Horizontal)
328 , _gradientBeginRadius(0.0f)
329 , _gradientEndRadius(0.0f)
330 , _textureMode(
Brush::SourcePixels)
335 BrushData(
const Color& color)
337 , _fillStyle(Brush::Solid)
338 , _positionMode(Brush::Relative)
340 , _gradient(Brush::Horizontal)
341 , _gradientBeginRadius(0.0f)
342 , _gradientEndRadius(0.0f)
343 , _textureMode(Brush::SourcePixels)
348 BrushData(
const Image& texture,
const PointF& textureOrigin);
350 BrushData(
const BrushData& other);
352 BrushData& operator=(
const BrushData& other);
355 BrushData(
const Color& from,
const Color& to,
361 {
return _fillStyle; }
364 {
return _positionMode; }
366 void setSolid(
const Color& color);
368 const Color& color()
const
369 {
return _gradientStops.empty() ? _color : _gradientStops.front().color(); }
375 void setLinearGradient(
const PointF& begin,
const PointF& end,
376 const ColorStops& colorStops);
379 void setLinearGradient(
float beginX,
float beginY,
380 float endX,
float endY,
381 const ColorStops& colorStops);
385 void setRadialGradient(
const PointF& begin,
float beginRadius,
386 const PointF& end,
float endRadius,
387 const ColorStops& colorStops);
390 void setRadialGradient(
float beginX,
float beginY,
float beginRadius,
391 float endX,
float endY,
float endRadius,
392 const ColorStops& colorStops);
395 {
return _gradient; }
398 const Color& gradientColor()
const
399 {
return _gradientStops.empty() ? _color : _gradientStops.back().color(); }
401 const ColorStops& gradientStops()
const
402 {
return _gradientStops; }
404 const PointF& gradientBegin()
const
405 {
return _gradientBegin; }
407 float gradientBeginRadius()
const
408 {
return _gradientBeginRadius; }
410 const PointF& gradientEnd()
const
411 {
return _gradientEnd; }
413 float gradientEndRadius()
const
414 {
return _gradientEndRadius; }
416 void setImageTexture(
const Image& texture,
const PointF& textureOrigin);
418 const Image& texture()
const;
421 {
return _textureMode; }
423 const PointF& textureOrigin()
const
424 {
return _textureOrigin; }
426 bool isGradient()
const
427 {
return _fillStyle == Brush::Gradient; }
429 bool isTexture()
const
430 {
return _fillStyle == Brush::Texture; }
442 ColorStops _gradientStops;
443 PointF _gradientBegin;
444 float _gradientBeginRadius;
446 float _gradientEndRadius;
449 PointF _textureOrigin;
TextureMode
Identifies how image texture coordinates are interpreted.
Definition: Brush.h:177
Core module.
Definition: Allocator.h:33
bool empty() const
Returns true if no stops are stored.
Definition: Brush.h:92
const ColorStops & gradientStops() const
Color stops of a gradient.
bool isNull() const
Returns true if the brush is null.
const Color & color() const
Returns the solid or first gradient color.
static Brush verticalGradient(const Color &from, const Color &to)
Constructs a vertical gradient brush from two colors.
float position() const
Returns the normalized stop position.
Definition: Brush.h:60
static Brush radialGradient(float beginX, float beginY, float beginRadius, float endX, float endY, float endRadius, const ColorStops &colorStops)
Constructs a relative positioned radial gradient.
const ColorStop & operator[](std::size_t n) const
Returns the stop at the given index.
Definition: Brush.h:114
const Color & gradientColor() const
Returns the legacy secondary gradient color.
static Brush imageTexture(const Image &image, const Gfx::PointF &origin=Gfx::PointF())
Constructs an image texture brush.
const Color & color() const
Returns the stop color.
Definition: Brush.h:65
PositionMode
Identifies how brush coordinates are interpreted.
Definition: Brush.h:159
bool isTexture() const
Returns true if the brush uses a texture.
static Brush linearGradient(float beginX, float beginY, float endX, float endY, const ColorStops &colorStops)
Constructs a relative positioned linear gradient.
const ColorStop & front() const
Returns the first stop.
Definition: Brush.h:119
PositionMode positionMode() const
Returns how brush coordinates are interpreted.
~ColorStops()
Destroys the collection.
Definition: Brush.h:87
void clear()
Removes all stored stops.
Definition: Brush.h:102
Brush(const Color &color)
Constructs a solid brush.
static Brush horizontalGradient(const Color &from, const Color &to)
Constructs a horizontal gradient brush from two colors.
float gradientBeginRadius() const
Radius of a radial gradient begin circle.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
const PointF & textureOrigin() const
Returns the texture pattern origin.
static Brush horizontalGradient(const ColorStops &colorStops)
Constructs a horizontal gradient brush from color stops.
void setColor(const Color &color)
Sets the solid fill color.
ColorStop(float position, const Color &color)
Constructs a color stop.
Definition: Brush.h:53
Brush()
Contructs a null brush.
static Brush radialGradient(const PointF &begin, float beginRadius, const PointF &end, float endRadius, const ColorStops &colorStops)
Constructs an absolute positioned radial gradient.
const Image & texture() const
Returns the texture image.
std::size_t size() const
Returns the number of stored stops.
Definition: Brush.h:97
const PointF & gradientBegin() const
Begin of a linear or radial gradient.
GradientStyle gradient() const
Returns the gradient style.
bool isGradient() const
Returns true if the brush uses a gradient.
GradientStyle
Identifies the gradient variant used by the brush.
Definition: Brush.h:167
void calculateInterpolatedColor(Color &res, const float position) const
Calculates the interpolated color for a position.
Basic image.
Definition: Image.h:52
const PointF & gradientEnd() const
End of a linear or radial gradient.
static Brush verticalGradient(const ColorStops &colorStops)
Constructs a vertical gradient brush from color stops.
Standard color type.
Definition: Color.h:47
FillStyle fillStyle() const
Returns the brushes fill style.
Fill description for shapes and text.
Definition: Brush.h:145
ColorStops()
Constructs an empty collection.
Definition: Brush.h:82
FillStyle
Identifies the fill source used by the brush.
Definition: Brush.h:150
void add(float position, const Color &color)
Appends a color stop.
Definition: Brush.h:109
static Brush linearGradient(const PointF &begin, const PointF &end, const ColorStops &colorStops)
Constructs an absolute positioned linear gradient.
float gradientEndRadius() const
Radius of a radial gradient end circle.
const ColorStop & back() const
Returns the last stop.
Definition: Brush.h:124
Ordered collection of gradient color stops.
Definition: Brush.h:78
Color stop for a gradient brush.
Definition: Brush.h:49
TextureMode textureMode() const
Returns how the texture origin is interpreted.