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;
211 float endX,
float endY,
217 const PointF& end,
float endRadius,
223 float endX,
float endY,
float endRadius,
304 Brush(BrushData* data);
316 , _fillStyle(
Brush::Solid)
318 , _gradient(
Brush::Horizontal)
324 BrushData(
const Color& color)
326 , _fillStyle(Brush::Solid)
328 , _gradient(Brush::Horizontal)
334 BrushData(
const Image& texture,
338 BrushData(
const Color& from,
const Color& to,
344 {
return _fillStyle; }
347 {
return _positionMode; }
349 void setSolid(
const Color& color);
351 const Color& color()
const
352 {
return _gradientStops.empty() ? _color : _gradientStops.front().color(); }
358 void setLinearGradient(
const PointF& begin,
const PointF& end,
359 const ColorStops& colorStops);
362 void setLinearGradient(
float beginX,
float beginY,
363 float endX,
float endY,
364 const ColorStops& colorStops);
368 void setRadialGradient(
const PointF& begin,
float beginRadius,
369 const PointF& end,
float endRadius,
370 const ColorStops& colorStops);
373 void setRadialGradient(
float beginX,
float beginY,
float beginRadius,
374 float endX,
float endY,
float endRadius,
375 const ColorStops& colorStops);
378 {
return _gradient; }
381 const Color& gradientColor()
const
382 {
return _gradientStops.empty() ? _color : _gradientStops.back().color(); }
384 const ColorStops& gradientStops()
const
385 {
return _gradientStops; }
387 const PointF& gradientBegin()
const
388 {
return _gradientBegin; }
390 float gradientBeginRadius()
const
391 {
return _gradientBeginRadius; }
393 const PointF& gradientEnd()
const
394 {
return _gradientEnd; }
396 float gradientEndRadius()
const
397 {
return _gradientEndRadius; }
399 void setTexture(
const Image& texture,
402 const Image& texture()
const;
410 bool isGradient()
const
411 {
return _fillStyle == Brush::Gradient; }
413 bool isTexture()
const
414 {
return _fillStyle == Brush::Texture; }
426 ColorStops _gradientStops;
427 PointF _gradientBegin;
428 float _gradientBeginRadius;
430 float _gradientEndRadius;
Core module.
Definition: pt-gfx-images.dox:14
bool empty() const
Returns true if no stops are stored.
Definition: Brush.h:92
const ColorStops & gradientStops() const
Color stops of a gradient.
Brush(const Image &texture, Pt::int32_t offX=0, Pt::int32_t offY=0)
Constructs a texture brush.
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.
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:45
static Brush horizontalGradient(const ColorStops &colorStops)
Constructs a horizontal gradient brush from color stops.
void setTexture(const Image &texture, Pt::int32_t offX=0, Pt::int32_t offY=0)
Sets the texture image and offset.
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.
Pt::int32_t offsetY() const
Returns the vertical texture offset.
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.
int_type int32_t
Signed 32-bit integer type.
Definition: Types.h:36
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.
Pt::int32_t offsetX() const
Returns the horizontal texture offset.
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