cmdfx 0.3.0
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
path.h File Reference

Draw on Canvas using SVG-like path commands. More...

Go to the source code of this file.

Macros

#define CMDFX_PATH_COMMAND_MOVETO_ABSOLUTE   'M'
#define CMDFX_PATH_COMMAND_MOVETO_RELATIVE   'm'
#define CMDFX_PATH_COMMAND_LINETO_ABSOLUTE   'L'
#define CMDFX_PATH_COMMAND_LINETO_RELATIVE   'l'
#define CMDFX_PATH_COMMAND_HLINETO_ABSOLUTE   'H'
#define CMDFX_PATH_COMMAND_HLINETO_RELATIVE   'h'
#define CMDFX_PATH_COMMAND_VLINETO_ABSOLUTE   'V'
#define CMDFX_PATH_COMMAND_VLINETO_RELATIVE   'v'
#define CMDFX_PATH_COMMAND_RECT_ABSOLUTE   'R'
#define CMDFX_PATH_COMMAND_RECT_RELATIVE   'r'
#define CMDFX_PATH_COMMAND_ELLIPSE_ABSOLUTE   'E'
#define CMDFX_PATH_COMMAND_ELLIPSE_RELATIVE   'e'
#define CMDFX_PATH_COMMAND_QUAD_ABSOLUTE   'Q'
#define CMDFX_PATH_COMMAND_QUAD_RELATIVE   'q'
#define CMDFX_PATH_COMMAND_CUBIC_ABSOLUTE   'C'
#define CMDFX_PATH_COMMAND_CUBIC_RELATIVE   'c'
#define CMDFX_PATH_COMMAND_ARC_ABSOLUTE   'A'
#define CMDFX_PATH_COMMAND_ARC_RELATIVE   'a'

Functions

int Canvas_path (const char *path, char ch)
 Draws a path on the canvas using the specified path string.

Detailed Description

Draw on Canvas using SVG-like path commands.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.2.0
Date
2025-04-25

Macro Definition Documentation

◆ CMDFX_PATH_COMMAND_ARC_ABSOLUTE

#define CMDFX_PATH_COMMAND_ARC_ABSOLUTE   'A'

Draws an elliptical arc from the current point to the specified coordinates.

Parameters
rxThe x radius of the ellipse
ryThe y radius of the ellipse
x_axis_rotationThe rotation of the ellipse in degrees
large_arc_flagA flag indicating whether to use the large arc
sweep_flagA flag indicating whether to use the positive angle
x2The x coordinate of the end point
y2The y coordinate of the end point

◆ CMDFX_PATH_COMMAND_ARC_RELATIVE

#define CMDFX_PATH_COMMAND_ARC_RELATIVE   'a'

Draws an elliptical arc from the current point to the specified coordinates relative to the current point.

Parameters
rxThe x radius of the ellipse
ryThe y radius of the ellipse
x_axis_rotationThe rotation of the ellipse in degrees
large_arc_flagA flag indicating whether to use the large arc
sweep_flagA flag indicating whether to use the positive angle
dx2The x coordinate of the end point relative to the current point
dy2The y coordinate of the end point relative to the current point

◆ CMDFX_PATH_COMMAND_CUBIC_ABSOLUTE

#define CMDFX_PATH_COMMAND_CUBIC_ABSOLUTE   'C'

Draws a cubic Bezier curve from the current point to the specified coordinates.

Parameters
x1The x coordinate of the first control point
y1The y coordinate of the first control point
x2The x coordinate of the second control point
y2The y coordinate of the second control point
x3The x coordinate of the end point
y3The y coordinate of the end point

◆ CMDFX_PATH_COMMAND_CUBIC_RELATIVE

#define CMDFX_PATH_COMMAND_CUBIC_RELATIVE   'c'

Draws a cubic Bezier curve from the current point to the specified coordinates relative to the current point.

Parameters
dx1The x coordinate of the first control point relative to the current point
dy1The y coordinate of the first control point relative to the current point
dx2The x coordinate of the second control point relative to the current point
dy2The y coordinate of the second control point relative to the current point
dx3The x coordinate of the end point relative to the current point
dy3The y coordinate of the end point relative to the current point

◆ CMDFX_PATH_COMMAND_ELLIPSE_ABSOLUTE

#define CMDFX_PATH_COMMAND_ELLIPSE_ABSOLUTE   'E'

Draws an ellipse with the specified coordinates.

Parameters
cxThe x coordinate of the center of the ellipse
cyThe y coordinate of the center of the ellipse
rxThe x radius of the ellipse
ryThe y radius of the ellipse
x_axis_rotationThe rotation of the ellipse in degrees

◆ CMDFX_PATH_COMMAND_ELLIPSE_RELATIVE

#define CMDFX_PATH_COMMAND_ELLIPSE_RELATIVE   'e'

Draws an ellipse with the specified coordinates relative to the current point.

Parameters
dxThe x coordinate of the center of the ellipse relative to the current point
dyThe y coordinate of the center of the ellipse relative to the current point
rxThe x radius of the ellipse
ryThe y radius of the ellipse
x_axis_rotationThe rotation of the ellipse in degrees

◆ CMDFX_PATH_COMMAND_HLINETO_ABSOLUTE

#define CMDFX_PATH_COMMAND_HLINETO_ABSOLUTE   'H'

Draws a horizontal line from the current point to the specified x coordinate.

Parameters
xThe x coordinate of the point

◆ CMDFX_PATH_COMMAND_HLINETO_RELATIVE

#define CMDFX_PATH_COMMAND_HLINETO_RELATIVE   'h'

Draws a horizontal line from the current point to the specified x coordinate relative to the current point.

Parameters
dxThe x coordinate of the point relative to the current point

◆ CMDFX_PATH_COMMAND_LINETO_ABSOLUTE

#define CMDFX_PATH_COMMAND_LINETO_ABSOLUTE   'L'

Draws a line from the current point to the specified coordinates.

Parameters
xThe x coordinate of the point
yThe y coordinate of the point

◆ CMDFX_PATH_COMMAND_LINETO_RELATIVE

#define CMDFX_PATH_COMMAND_LINETO_RELATIVE   'l'

Draws a line from the current point to the specified coordinates relative to the current point.

Parameters
dxThe x coordinate of the point relative to the current point
dyThe y coordinate of the point relative to the current point

◆ CMDFX_PATH_COMMAND_MOVETO_ABSOLUTE

#define CMDFX_PATH_COMMAND_MOVETO_ABSOLUTE   'M'

Moves the current point to the specified coordinates.

Parameters
xThe x coordinate of the point
yThe y coordinate of the point

◆ CMDFX_PATH_COMMAND_MOVETO_RELATIVE

#define CMDFX_PATH_COMMAND_MOVETO_RELATIVE   'm'

Moves the current point to the specified coordinates relative to the current point.

Parameters
dxThe x coordinate of the point relative to the current point
dyThe y coordinate of the point relative to the current point

◆ CMDFX_PATH_COMMAND_QUAD_ABSOLUTE

#define CMDFX_PATH_COMMAND_QUAD_ABSOLUTE   'Q'

Draws a quadratic Bezier curve from the current point to the specified coordinates.

Parameters
x1The x coordinate of the control point
y1The y coordinate of the control point
x2The x coordinate of the end point
y2The y coordinate of the end point

◆ CMDFX_PATH_COMMAND_QUAD_RELATIVE

#define CMDFX_PATH_COMMAND_QUAD_RELATIVE   'q'

Draws a quadratic Bezier curve from the current point to the specified coordinates relative to the current point.

Parameters
dx1The x coordinate of the control point relative to the current point
dy1The y coordinate of the control point relative to the current point
dx2The x coordinate of the end point relative to the current point
dy2The y coordinate of the end point relative to the current point

◆ CMDFX_PATH_COMMAND_RECT_ABSOLUTE

#define CMDFX_PATH_COMMAND_RECT_ABSOLUTE   'R'

Draws a rectangle with the specified coordinates.

Parameters
x1The x coordinate of the top-left corner of the rectangle
y1The y coordinate of the top-left corner of the rectangle
x2The x coordinate of the bottom-right corner of the rectangle
y2The y coordinate of the bottom-right corner of the rectangle

◆ CMDFX_PATH_COMMAND_RECT_RELATIVE

#define CMDFX_PATH_COMMAND_RECT_RELATIVE   'r'

Draws a rectangle with the specified coordinates relative to the current point.

Parameters
dx1The x coordinate of the top-left corner of the rectangle relative to the current point
dy1The y coordinate of the top-left corner of the rectangle relative to the current point
dx2The x coordinate of the bottom-right corner of the rectangle relative to the current point
dy2The y coordinate of the bottom-right corner of the rectangle relative to the current point

◆ CMDFX_PATH_COMMAND_VLINETO_ABSOLUTE

#define CMDFX_PATH_COMMAND_VLINETO_ABSOLUTE   'V'

Draws a vertical line from the current point to the specified y coordinate.

Parameters
yThe y coordinate of the point

◆ CMDFX_PATH_COMMAND_VLINETO_RELATIVE

#define CMDFX_PATH_COMMAND_VLINETO_RELATIVE   'v'

Draws a vertical line from the current point to the specified y coordinate relative to the current point.

Parameters
dyThe y coordinate of the point relative to the current point

Function Documentation

◆ Canvas_path()

int Canvas_path ( const char * path,
char ch )

Draws a path on the canvas using the specified path string.

This function interprets the path string as a series of SVG-like commands and draws the corresponding shapes on the canvas. The path string can contain commands for moving to a point, drawing lines, rectangles, ellipses, and curves, as well as closing the path.

The function will make no attempt to validate the path string, so it is the responsibility of the caller to ensure that the path string is well-formed and contains valid commands. The function will return -1 if the path string is NULL or if an error occurs while drawing the path.

Parameters
pathThe path string to draw
chThe character to draw
Returns
0 on success, -1 on error