cmdfx 0.1.0
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
builder.h File Reference

Builder API for building 2D Character Arrays. More...

Go to the source code of this file.

Functions

int getArrayWidth (char **array)
 Gets the width of a 2D Character Array.
 
int getArrayHeight (char **array)
 Gets the height of a 2D Character Array.
 
char ** CharBuilder_create (int width, int height)
 Creates a 2D Character Array with a specific width and height.
 
int CharBuilder_setChar (char **array, int x, int y, char c)
 Sets a character in a 2D Character Array.
 
int CharBuilder_hLine (char **array, int x, int y, int width, char c)
 Draws a horizontal line in a 2D Character Array.
 
int CharBuilder_vLine (char **array, int x, int y, int height, char c)
 Draws a vertical line in a 2D Character Array.
 
int CharBuilder_rect (char **array, int x, int y, int width, int height, char c)
 Draws a rectangle in a 2D Character Array.
 
int CharBuilder_fillRect (char **array, int x, int y, int width, int height, char c)
 Fills a rectangle in a 2D Character Array.
 
int CharBuilder_circle (char **array, int x, int y, int radius, char c)
 Draws a circle in a 2D Character Array.
 
int CharBuilder_fillCircle (char **array, int x, int y, int radius, char c)
 Fills a circle in a 2D Character Array.
 
int CharBuilder_ellipse (char **array, int x, int y, int xradius, int yradius, char c)
 Draws an ellipse in a 2D Character Array.
 
int CharBuilder_fillEllipse (char **array, int x, int y, int xradius, int yradius, char c)
 Fills an ellipse in a 2D Character Array.
 
int CharBuilder_line (char **array, int x1, int y1, int x2, int y2, char c)
 Draws a line in a 2D Character Array.
 
int CharBuilder_text (char **array, int x, int y, char *text)
 Writes text in a 2D Character Array.
 
int CharBuilder_resize (char **array, int width, int height)
 Resizes an 2D Character Array to a specific width and height.
 
int CharBuilder_resizeWithPadding (char **array, int width, int height, char padding)
 Resizes an 2D Character Array to a specific width and height with padding.
 
int CharBuilder_center (char **array)
 Centers an 2D Character Array.
 
int CharBuilder_resizeAndCenter (char **array, int width, int height)
 Resizes and centers an 2D Character Array.
 
int getAnsiArrayWidth (char ***array)
 Gets the width of a 2D String Array.
 
int getAnsiArrayHeight (char ***array)
 Gets the height of a 2D String Array.
 
char *** AnsiBuilder_create (int width, int height)
 Creates a 2D String Array with a specific width and height.
 
int AnsiBuilder_setAnsi (char ***array, int x, int y, char *c)
 Sets an ANSI code in a 2D String Array.
 
int AnsiBuilder_hLine (char ***array, int x, int y, int width, char *c)
 Draws a horizontal line in a 2D String Array.
 
int AnsiBuilder_vLine (char ***array, int x, int y, int height, char *c)
 Draws a vertical line in a 2D String Array.
 
int AnsiBuilder_rect (char ***array, int x, int y, int width, int height, char *c)
 Draws a rectangle in a 2D String Array.
 
int AnsiBuilder_fillRect (char ***array, int x, int y, int width, int height, char *c)
 Fills a rectangle in a 2D String Array.
 
int AnsiBuilder_circle (char ***array, int x, int y, int radius, char *c)
 Draws a circle in a 2D String Array.
 
int AnsiBuilder_fillCircle (char ***array, int x, int y, int radius, char *c)
 Fills a circle in a 2D String Array.
 
int AnsiBuilder_ellipse (char ***array, int x, int y, int xradius, int yradius, char *c)
 Draws an ellipse in a 2D String Array.
 
int AnsiBuilder_fillEllipse (char ***array, int x, int y, int xradius, int yradius, char *c)
 Fills an ellipse in a 2D String Array.
 
int AnsiBuilder_line (char ***array, int x1, int y1, int x2, int y2, char *c)
 Draws a line in a 2D String Array.
 

Detailed Description

Builder API for building 2D Character Arrays.

Author
Gregory Mitchell (me@gm.nosp@m.itch.nosp@m.215.x.nosp@m.yz)
Version
0.1.0
Date
2025-01-23

Function Documentation

◆ AnsiBuilder_circle()

int AnsiBuilder_circle ( char *** array,
int x,
int y,
int radius,
char * c )

Draws a circle in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
radiusThe radius of the circle.
cThe ANSI code to draw the circle with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_create()

char *** AnsiBuilder_create ( int width,
int height )

Creates a 2D String Array with a specific width and height.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

This method creates an array with a specific width and height. The array will be initialized with the space character.

Parameters
widthThe width of the array.
heightThe height of the array.
Returns
The 2D String Array.

◆ AnsiBuilder_ellipse()

int AnsiBuilder_ellipse ( char *** array,
int x,
int y,
int xradius,
int yradius,
char * c )

Draws an ellipse in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
xradiusThe x radius of the ellipse.
yradiusThe y radius of the ellipse.
cThe ANSI code to draw the ellipse with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_fillCircle()

int AnsiBuilder_fillCircle ( char *** array,
int x,
int y,
int radius,
char * c )

Fills a circle in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
radiusThe radius of the circle.
cThe ANSI code to fill the circle with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_fillEllipse()

int AnsiBuilder_fillEllipse ( char *** array,
int x,
int y,
int xradius,
int yradius,
char * c )

Fills an ellipse in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
xradiusThe x radius of the ellipse.
yradiusThe y radius of the ellipse.
cThe ANSI code to fill the ellipse with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_fillRect()

int AnsiBuilder_fillRect ( char *** array,
int x,
int y,
int width,
int height,
char * c )

Fills a rectangle in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
widthThe width of the rectangle.
heightThe height of the rectangle.
cThe ANSI code to fill the rectangle with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_hLine()

int AnsiBuilder_hLine ( char *** array,
int x,
int y,
int width,
char * c )

Draws a horizontal line in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
widthThe width of the line.
cThe ANSI code to draw the line with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_line()

int AnsiBuilder_line ( char *** array,
int x1,
int y1,
int x2,
int y2,
char * c )

Draws a line in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
x1The x coordinate of the first point.
y1The y coordinate of the first point.
x2The x coordinate of the second point.
y2The y coordinate of the second point.
cThe ANSI code to draw the line with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_rect()

int AnsiBuilder_rect ( char *** array,
int x,
int y,
int width,
int height,
char * c )

Draws a rectangle in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
widthThe width of the rectangle.
heightThe height of the rectangle.
cThe ANSI code to draw the rectangle with.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_setAnsi()

int AnsiBuilder_setAnsi ( char *** array,
int x,
int y,
char * c )

Sets an ANSI code in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

This method sets an ANSI code at the specified x and y coordinates. If the x or y coordinate is out of bounds, the method will return -1.

The values at array[height] and array[height][width] will be set to 0 for null termination. It is advised that you create a char*** with this method and pass it to other functions presented in this header file, rather than create a char*** and pass it to other functions, in order to avoid undefined behavior.

Parameters
arrayThe 2D String Array.
xThe x coordinate.
yThe y coordinate
cThe ANSI code to set.
Returns
0 if successful, -1 if an error occurred.

◆ AnsiBuilder_vLine()

int AnsiBuilder_vLine ( char *** array,
int x,
int y,
int height,
char * c )

Draws a vertical line in a 2D String Array.

Like all methods in AnsiBuilder, this does not append anything to the string. You will need to input the full ANSI code, like "\033[31m" for red text.

Parameters
arrayThe string array.
xThe x coordinate.
yThe y coordinate.
heightThe height of the line.
cThe ANSI to draw the line with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_center()

int CharBuilder_center ( char ** array)

Centers an 2D Character Array.

This method centers an 2D Character Array both horizontally and vertically. It will reposition the characters depending on whether there is whitespace surrounding other characters.

Parameters
arrayThe 2D Character Array.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_circle()

int CharBuilder_circle ( char ** array,
int x,
int y,
int radius,
char c )

Draws a circle in a 2D Character Array.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
radiusThe radius of the circle.
cThe character to draw the circle with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_create()

char ** CharBuilder_create ( int width,
int height )

Creates a 2D Character Array with a specific width and height.

This method creates an array with a specific width and height. The array will be initialized with the space character.

The values at array[height] and array[height][width] will be set to 0 for null termination. It is advised that you create a char** with this method and pass it to other functions presented in this header file, rather than create a char** and pass it to other functions, in order to avoid undefined behavior.

Parameters
widthThe width of the array.
heightThe height of the array.
Returns
The 2D Character Array.

◆ CharBuilder_ellipse()

int CharBuilder_ellipse ( char ** array,
int x,
int y,
int xradius,
int yradius,
char c )

Draws an ellipse in a 2D Character Array.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
xradiusThe x radius of the ellipse.
yradiusThe y radius of the ellipse.
cThe character to draw the ellipse with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_fillCircle()

int CharBuilder_fillCircle ( char ** array,
int x,
int y,
int radius,
char c )

Fills a circle in a 2D Character Array.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
radiusThe radius of the circle.
cThe character to fill the circle with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_fillEllipse()

int CharBuilder_fillEllipse ( char ** array,
int x,
int y,
int xradius,
int yradius,
char c )

Fills an ellipse in a 2D Character Array.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
xradiusThe x radius of the ellipse.
yradiusThe y radius of the ellipse.
cThe character to fill the ellipse with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_fillRect()

int CharBuilder_fillRect ( char ** array,
int x,
int y,
int width,
int height,
char c )

Fills a rectangle in a 2D Character Array.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
widthThe width of the rectangle.
heightThe height of the rectangle.
cThe character to fill the rectangle with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_hLine()

int CharBuilder_hLine ( char ** array,
int x,
int y,
int width,
char c )

Draws a horizontal line in a 2D Character Array.

This method draws a horizontal line in a 2D Character Array. If the x or y coordinate is out of bounds, the method will return -1. If the line goes out of bounds, the line will be cropped.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
widthThe width of the line.
cThe character to draw the line with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_line()

int CharBuilder_line ( char ** array,
int x1,
int y1,
int x2,
int y2,
char c )

Draws a line in a 2D Character Array.

Parameters
arrayThe character array.
x1The x coordinate of the first point.
y1The y coordinate of the first point.
x2The x coordinate of the second point.
y2The y coordinate of the second point.
cThe character to draw the line with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_rect()

int CharBuilder_rect ( char ** array,
int x,
int y,
int width,
int height,
char c )

Draws a rectangle in a 2D Character Array.

This method draws a rectangle in a 2D Character Array. If the x or y coordinate is out of bounds, the method will return -1. If the rectangle goes out of bounds, the rectangle will be cropped.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
widthThe width of the rectangle.
heightThe height of the rectangle.
cThe character to draw the rectangle with.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_resize()

int CharBuilder_resize ( char ** array,
int width,
int height )

Resizes an 2D Character Array to a specific width and height.

This method resizes an 2D Character Array to a specific width and height. If the new width or height is smaller than the original width or height, the 2D Character Array will be cropped. If the new width or height is larger than the original width or height, the 2D Character Array will be padded with empty space.

Parameters
arrayThe 2D Character Array.
widthThe new width.
heightThe new height.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_resizeAndCenter()

int CharBuilder_resizeAndCenter ( char ** array,
int width,
int height )

Resizes and centers an 2D Character Array.

This method resizes and centers an 2D Character Array to a specific width and height. If the new width or height is smaller than the original width or height, the ASCII art character will be cropped. If the new width or height is larger than the original width or height, the 2D Character Array will be padded with the specified character.

Parameters
arrayThe 2D Character Array.
widthThe new width.
heightThe new height.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_resizeWithPadding()

int CharBuilder_resizeWithPadding ( char ** array,
int width,
int height,
char padding )

Resizes an 2D Character Array to a specific width and height with padding.

This method resizes an 2D Character Array to a specific width and height with padding. If the new width or height is smaller than the original width or height, the ASCII art character will be cropped. If the new width or height is larger than the original width or height, the 2D Character Array will be padded with the specified character.

Parameters
arrayThe 2D Character Array.
widthThe new width.
heightThe new height.
paddingThe padding character.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_setChar()

int CharBuilder_setChar ( char ** array,
int x,
int y,
char c )

Sets a character in a 2D Character Array.

This method sets a character at the specified x and y coordinates. If the x or y coordinate is out of bounds, the method will return -1.

Parameters
arrayThe 2D Character Array.
xThe x coordinate.
yThe y coordinate
cThe character to set.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_text()

int CharBuilder_text ( char ** array,
int x,
int y,
char * text )

Writes text in a 2D Character Array.

If the text is too long to fit in the array, it will be wrapped to the next line. If the text is too long to fit in the array at all, the string will be truncated.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
textThe text to draw.
Returns
0 if successful, -1 if an error occurred.

◆ CharBuilder_vLine()

int CharBuilder_vLine ( char ** array,
int x,
int y,
int height,
char c )

Draws a vertical line in a 2D Character Array.

This method draws a vertical line in a 2D Character Array. If the x or y coordinate is out of bounds, the method will return -1. If the line goes out of bounds, the line will be cropped.

Parameters
arrayThe character array.
xThe x coordinate.
yThe y coordinate.
heightThe height of the line.
cThe character to draw the line with.
Returns
0 if successful, -1 if an error occurred.

◆ getAnsiArrayHeight()

int getAnsiArrayHeight ( char *** array)

Gets the height of a 2D String Array.

Parameters
arrayThe a 2D String Array.
Returns
The height of the array.

◆ getAnsiArrayWidth()

int getAnsiArrayWidth ( char *** array)

Gets the width of a 2D String Array.

Parameters
arrayThe 2D String Array.
Returns
The width of the array.

◆ getArrayHeight()

int getArrayHeight ( char ** array)

Gets the height of a 2D Character Array.

Parameters
arrayThe a 2D Character Array.
Returns
The height of the array.

◆ getArrayWidth()

int getArrayWidth ( char ** array)

Gets the width of a 2D Character Array.

Parameters
arrayThe 2D Character Array.
Returns
The width of the array.