HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Friends
hi::v1::graphic_path Struct Reference

#include <hikogui/graphic_path/graphic_path.hpp>

Public Member Functions

void clear () noexcept
 Clear the path.
 
ssize_t numberOfContours () const noexcept
 Return the number of closed contours.
 
ssize_t numberOfLayers () const noexcept
 Return the number of closed layers.
 
bool allLayersHaveSameColor () const noexcept
 Check if all layers have the same color.
 
aarectangle boundingBox () const noexcept
 Calculate bounding box.
 
void tryRemoveLayers () noexcept
 Try to move the layers in a path.
 
std::vector< bezier_point >::const_iterator beginContour (ssize_t contourNr) const noexcept
 Return an iterator to the start point of a contour.
 
std::vector< bezier_point >::const_iterator endContour (ssize_t contourNr) const noexcept
 
ssize_t beginLayer (ssize_t layerNr) const noexcept
 
ssize_t endLayer (ssize_t layerNr) const noexcept
 
std::vector< bezier_pointgetbezier_pointsOfContour (ssize_t contourNr) const noexcept
 
std::vector< bezier_curvegetBeziersOfContour (ssize_t contourNr) const noexcept
 
std::vector< bezier_curvegetBeziers () const noexcept
 
std::pair< graphic_path, colorgetLayer (ssize_t layerNr) const noexcept
 
color getColorOfLayer (ssize_t layerNr) const noexcept
 
void setColorOfLayer (ssize_t layerNr, color fill_color) noexcept
 
bool isContourOpen () const noexcept
 Return true if there is an open contour.
 
void closeContour () noexcept
 Close current contour.
 
bool hasLayers () const noexcept
 This path has layers.
 
bool isLayerOpen () const noexcept
 Return true if there is an open layer.
 
void closeLayer (color fill_color) noexcept
 Close current contour.
 
void optimizeLayers () noexcept
 Optimize layers.
 
point2 currentPosition () const noexcept
 Get the currentPosition of the open contour.
 
void moveTo (point2 position) noexcept
 Start a new contour at position.
 
void moveRelativeTo (vector2 direction) noexcept
 Start a new contour relative to current position.
 
void lineTo (point2 position) noexcept
 
void lineRelativeTo (vector2 direction) noexcept
 
void quadraticCurveTo (point2 controlPosition, point2 position) noexcept
 
void quadraticCurveRelativeTo (vector2 controlDirection, vector2 direction) noexcept
 Draw curve from the current position to the new direction.
 
void cubicCurveTo (point2 controlPosition1, point2 controlPosition2, point2 position) noexcept
 
void cubicCurveRelativeTo (vector2 controlDirection1, vector2 controlDirection2, vector2 direction) noexcept
 Draw curve from the current position to the new direction.
 
void arcTo (float radius, point2 position) noexcept
 Draw an circular arc.
 
void addRectangle (aarectangle rectangle, corner_radii corners=corner_radii{0.0f, 0.0f, 0.0f, 0.0f}) noexcept
 Draw a rectangle.
 
void addCircle (point2 position, float radius) noexcept
 Draw a circle.
 
void addContour (std::vector< bezier_curve > const &contour) noexcept
 Contour with the given bezier curves.
 
void addContour (std::vector< bezier_point >::const_iterator const &begin, std::vector< bezier_point >::const_iterator const &end) noexcept
 Curve with the given bezier curve.
 
void addContour (std::vector< bezier_point > const &contour) noexcept
 Curve with the given bezier curve.
 
void addPath (graphic_path const &path, color fill_color) noexcept
 Add path and close layer.
 
void addStroke (graphic_path const &path, color strokeColor, float strokeWidth, hi::line_join_style line_join_style=line_join_style::miter, float tolerance=0.05f) noexcept
 Stroke a path and close layer.
 
graphic_path toStroke (float strokeWidth=1.0f, line_join_style line_join_style=line_join_style::miter, float tolerance=0.05f) const noexcept
 Convert path to stroke-path.
 
graphic_path centerScale (extent2 extent, float padding=0.0) const noexcept
 Center and scale a path inside the extent with padding.
 
graphic_pathoperator+= (graphic_path const &rhs) noexcept
 

Data Fields

std::vector< bezier_pointpoints
 A set of all bezier points describing all bezier curves, contours and layers.
 
std::vector< ssize_tcontourEndPoints
 An index into.
 
std::vector< std::pair< ssize_t, color > > layerEndContours
 An color and index into.
 

Friends

graphic_path operator+ (graphic_path lhs, graphic_path const &rhs) noexcept
 
graphic_path operator* (transformer2 auto const &lhs, graphic_path const &rhs) noexcept
 

Detailed Description

A path is a vector graphics object.

It represents:

Member Function Documentation

◆ addCircle()

void hi::v1::graphic_path::addCircle ( point2 position,
float radius )
inlinenoexcept

Draw a circle.

Parameters
positionposition of the center of the circle.
radiusradius of the circle

◆ addContour() [1/3]

void hi::v1::graphic_path::addContour ( std::vector< bezier_curve > const & contour)
inlinenoexcept

Contour with the given bezier curves.

The first anchor will be ignored.

◆ addContour() [2/3]

void hi::v1::graphic_path::addContour ( std::vector< bezier_point > const & contour)
inlinenoexcept

Curve with the given bezier curve.

The first anchor will be ignored.

◆ addContour() [3/3]

void hi::v1::graphic_path::addContour ( std::vector< bezier_point >::const_iterator const & begin,
std::vector< bezier_point >::const_iterator const & end )
inlinenoexcept

Curve with the given bezier curve.

The first anchor will be ignored.

◆ addPath()

void hi::v1::graphic_path::addPath ( graphic_path const & path,
color fill_color )
inlinenoexcept

Add path and close layer.

◆ addRectangle()

void hi::v1::graphic_path::addRectangle ( aarectangle rectangle,
corner_radii corners = corner_radii{0.0f, 0.0f, 0.0f, 0.0f} )
inlinenoexcept

Draw a rectangle.

Parameters
rectanglethe offset and size of the rectangle.
cornersThe radius of the (bottom-left, bottom-right, top-left, top-right) positive corner are rounded, negative curves are cut.

◆ addStroke()

void hi::v1::graphic_path::addStroke ( graphic_path const & path,
color strokeColor,
float strokeWidth,
hi::line_join_style line_join_style = line_join_style::miter,
float tolerance = 0.05f )
inlinenoexcept

Stroke a path and close layer.

◆ allLayersHaveSameColor()

bool hi::v1::graphic_path::allLayersHaveSameColor ( ) const
inlinenoexcept

Check if all layers have the same color.

◆ arcTo()

void hi::v1::graphic_path::arcTo ( float radius,
point2 position )
inlinenoexcept

Draw an circular arc.

The arc is drawn from the current position to the position given in this method. A positive arc is drawn counter-clockwise.

Using method in: "Approximation of a cubic bezier curve by circular arcs and vice versa" – Aleksas Riskus (chapter 3, formulas 8 and 9, there are a few typos in the formulas)

Parameters
radiuspositive radius means positive arc, negative radius is a negative arc.
positionend position of the arc.

◆ beginContour()

std::vector< bezier_point >::const_iterator hi::v1::graphic_path::beginContour ( ssize_t contourNr) const
inlinenoexcept

Return an iterator to the start point of a contour.

◆ boundingBox()

aarectangle hi::v1::graphic_path::boundingBox ( ) const
inlinenoexcept

Calculate bounding box.

◆ centerScale()

graphic_path hi::v1::graphic_path::centerScale ( extent2 extent,
float padding = 0.0 ) const
inlinenoexcept

Center and scale a path inside the extent with padding.

◆ clear()

void hi::v1::graphic_path::clear ( )
inlinenoexcept

Clear the path.

◆ closeContour()

void hi::v1::graphic_path::closeContour ( )
inlinenoexcept

Close current contour.

No operation if there is no open contour.

◆ closeLayer()

void hi::v1::graphic_path::closeLayer ( color fill_color)
inlinenoexcept

Close current contour.

No operation if there is no open layer.

◆ cubicCurveRelativeTo()

void hi::v1::graphic_path::cubicCurveRelativeTo ( vector2 controlDirection1,
vector2 controlDirection2,
vector2 direction )
inlinenoexcept

Draw curve from the current position to the new direction.

Parameters
controlDirection1The first control point of the curve relative from the start of the curve.
controlDirection2The second control point of the curve relative from the start of the curve.
directionend point of the curve relative from the start of the curve.

◆ currentPosition()

point2 hi::v1::graphic_path::currentPosition ( ) const
inlinenoexcept

Get the currentPosition of the open contour.

Returns {0, 0} when there is no contour open.

◆ hasLayers()

bool hi::v1::graphic_path::hasLayers ( ) const
inlinenoexcept

This path has layers.

◆ isContourOpen()

bool hi::v1::graphic_path::isContourOpen ( ) const
inlinenoexcept

Return true if there is an open contour.

◆ isLayerOpen()

bool hi::v1::graphic_path::isLayerOpen ( ) const
inlinenoexcept

Return true if there is an open layer.

◆ moveRelativeTo()

void hi::v1::graphic_path::moveRelativeTo ( vector2 direction)
inlinenoexcept

Start a new contour relative to current position.

closes current subpath.

◆ moveTo()

void hi::v1::graphic_path::moveTo ( point2 position)
inlinenoexcept

Start a new contour at position.

closes current subpath.

◆ numberOfContours()

ssize_t hi::v1::graphic_path::numberOfContours ( ) const
inlinenoexcept

Return the number of closed contours.

◆ numberOfLayers()

ssize_t hi::v1::graphic_path::numberOfLayers ( ) const
inlinenoexcept

Return the number of closed layers.

◆ optimizeLayers()

void hi::v1::graphic_path::optimizeLayers ( )
inlinenoexcept

Optimize layers.

Merge contiguous layers with the same color.

◆ quadraticCurveRelativeTo()

void hi::v1::graphic_path::quadraticCurveRelativeTo ( vector2 controlDirection,
vector2 direction )
inlinenoexcept

Draw curve from the current position to the new direction.

Parameters
controlDirectioncontrol point of the curve relative from the start of the curve.
directionend point of the curve relative from the start of the curve.

◆ toStroke()

graphic_path hi::v1::graphic_path::toStroke ( float strokeWidth = 1.0f,
line_join_style line_join_style = line_join_style::miter,
float tolerance = 0.05f ) const
inlinenoexcept

Convert path to stroke-path.

This function will create contours that are offset from the original path which creates a stroke. The path will first be subdivided until the curves are mostly flat, then the curves are converted into lines and offset, then the lines are connected to each other.

Parameters
strokeWidthwidth of the stroke.
line_join_stylethe style of how outside corners of a stroke are drawn.
toleranceTolerance of how flat the curves in the path need to be.

◆ tryRemoveLayers()

void hi::v1::graphic_path::tryRemoveLayers ( )
inlinenoexcept

Try to move the layers in a path.

Layers are removed if there are layers, and all the layers have the same color.

Field Documentation

◆ contourEndPoints

std::vector<ssize_t> hi::v1::graphic_path::contourEndPoints

An index into.

See also
points where each contour ends.

◆ layerEndContours

std::vector<std::pair<ssize_t, color> > hi::v1::graphic_path::layerEndContours

An color and index into.

See also
contourEndPoints where each layer ends.

◆ points

std::vector<bezier_point> hi::v1::graphic_path::points

A set of all bezier points describing all bezier curves, contours and layers.


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