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

Incrementally builds a Path from move/line/quad/cubic/close operations. More...

#include <tiny_skia/PathBuilder.h>

Public Member Functions

 PathBuilder (std::size_t verbsCapacity, std::size_t pointsCapacity)
 Pre-allocates capacity for verbs and points.
 
void reserve (std::size_t additionalVerbs, std::size_t additionalPoints)
 Reserves additional capacity.
 
PathBuildermoveTo (float x, float y)
 Begins a new sub-path at (x, y).
 
PathBuilderlineTo (float x, float y)
 Adds a line segment to (x, y).
 
PathBuilderquadTo (float x1, float y1, float x, float y)
 Adds a quadratic Bezier to (x, y) with control point (x1, y1).
 
PathBuilderquadToPt (Point p1, Point p)
 Adds a quadratic Bezier using Point arguments.
 
PathBuildercubicTo (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).
 
PathBuildercubicToPt (Point p1, Point p2, Point p)
 Adds a cubic Bezier using Point arguments.
 
PathBuilderconicTo (float x1, float y1, float x, float y, float weight)
 Adds a conic (rational quadratic) segment, approximated as quadratics.
 
PathBuilderconicPointsTo (Point pt1, Point pt2, float weight)
 Adds a conic segment using Point arguments.
 
void setConicTolerance (float tolerance)
 Sets the tolerance for conic-to-quadratic conversion (default 0.25).
 
PathBuilderclose ()
 Closes the current sub-path.
 
PathBuilderpushRect (const Rect &rect)
 Appends a closed rectangle sub-path.
 
PathBuilderpushOval (const Rect &oval)
 Appends a closed oval sub-path inscribed in the given rect.
 
PathBuilderpushCircle (float x, float y, float r)
 Appends a closed circle sub-path.
 
PathBuilderpushPath (const Path &other)
 Appends all segments from another path.
 
PathBuilderpushPathBuilder (const PathBuilder &other)
 Appends all segments from another builder.
 
void clear ()
 Resets the builder, discarding all segments.
 
std::optional< Pathfinish ()
 Builds and returns the immutable Path. Returns nullopt if empty or invalid.
 

Static Public Member Functions

static std::optional< PathfromCircle (float cx, float cy, float radius)
 Creates a Path from a circle. Returns nullopt for non-positive radius.
 

Detailed Description

Example
Paint paint1;
paint1.setColorRgba8(50, 127, 150, 200);
paint1.antiAlias = true;
Paint paint2;
paint2.setColorRgba8(220, 140, 75, 180);
paint2.antiAlias = false;
pb1.moveTo(60.0f, 60.0f);
pb1.lineTo(160.0f, 940.0f);
pb1.cubicTo(380.0f, 840.0f, 660.0f, 800.0f, 940.0f, 800.0f);
pb1.cubicTo(740.0f, 460.0f, 440.0f, 160.0f, 60.0f, 60.0f);
pb1.close();
auto path1 = pb1.finish();
pb2.moveTo(940.0f, 60.0f);
pb2.lineTo(840.0f, 940.0f);
pb2.cubicTo(620.0f, 840.0f, 340.0f, 800.0f, 60.0f, 800.0f);
pb2.cubicTo(260.0f, 460.0f, 560.0f, 160.0f, 940.0f, 60.0f);
pb2.close();
auto path2 = pb2.finish();
auto pixmap = Pixmap::fromSize(1000, 1000);
Canvas canvas(*pixmap);
canvas.fillPath(*path1, paint1, FillRule::Winding);
canvas.fillPath(*path2, paint2, FillRule::Winding);
Drawing surface backed by a mutable pixel buffer.
Definition Canvas.h:29
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.
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
void setColorRgba8(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
Sets the shader to a solid color from 8-bit RGBA components.
Definition Paint.h:41

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