tiny-skia-cpp
A C++20 2D rendering library (port of tiny-skia)
Loading...
Searching...
No Matches
tiny_skia::LinearGradient Class Reference

Two-point linear gradient shader. More...

#include <tiny_skia/shaders/LinearGradient.h>

Static Public Member Functions

static std::optional< std::variant< Color, LinearGradient > > create (Point start, Point end, std::vector< GradientStop > stops, SpreadMode mode, Transform transform)
 Creates a linear gradient between two points. Returns a Color if the gradient degenerates to a single color.
 

Detailed Description

Example
Paint paint;
paint.antiAlias = false;
auto result =
LinearGradient::create(Point::fromXY(100.0f, 100.0f), Point::fromXY(900.0f, 900.0f),
{
GradientStop::create(0.0f, Color::fromRgba8(50, 127, 150, 200)),
GradientStop::create(1.0f, Color::fromRgba8(220, 140, 75, 180)),
},
SpreadMode::Pad, Transform::identity());
paint.shader = std::get<LinearGradient>(std::move(*result));
pb.moveTo(60.0f, 60.0f);
pb.lineTo(160.0f, 940.0f);
pb.cubicTo(380.0f, 840.0f, 660.0f, 800.0f, 940.0f, 800.0f);
pb.cubicTo(740.0f, 460.0f, 440.0f, 160.0f, 60.0f, 60.0f);
pb.close();
auto path = pb.finish();
auto pixmap = Pixmap::fromSize(1000, 1000);
Canvas canvas(*pixmap);
canvas.fillPath(*path, paint, FillRule::Winding);
Drawing surface backed by a mutable pixel buffer.
Definition Canvas.h:29
static Color fromRgba8(AlphaU8 red, AlphaU8 green, AlphaU8 blue, AlphaU8 alpha)
Creates from 8-bit components.
static std::optional< std::variant< Color, LinearGradient > > create(Point start, Point end, std::vector< GradientStop > stops, SpreadMode mode, Transform transform)
Creates a linear gradient between two points. Returns a Color if the gradient degenerates to a single...
Incrementally builds a Path from move/line/quad/cubic/close operations.
Definition PathBuilder.h:20
std::optional< Path > finish()
Builds and returns the immutable Path. Returns nullopt if empty or invalid.
PathBuilder & cubicTo(float x1, float y1, float x2, float y2, float x, float y)
Adds a cubic Bezier to (x, y) with control points (x1,y1) and (x2,y2).
PathBuilder & close()
Closes the current sub-path.
PathBuilder & lineTo(float x, float y)
Adds a line segment to (x, y).
PathBuilder & moveTo(float x, float y)
Begins a new sub-path at (x, y).
static std::optional< Pixmap > fromSize(std::uint32_t width, std::uint32_t height)
Creates a zero-filled pixmap. Returns nullopt for zero dimensions.
static GradientStop create(float position, Color color)
Creates a stop, clamping position to [0,1].
Definition Gradient.h:24
Controls how a shape is painted (shader, blend mode, anti-aliasing).
Definition Paint.h:15
bool antiAlias
Enable anti-aliased rendering. Default: true.
Definition Paint.h:23
Shader shader
Paint shader source. Default: solid black.
Definition Paint.h:17

The documentation for this class was generated from the following file: