cmdfx 0.1.0
Lightweight game engine for your terminal
|
Canvas API for drawing shapes and text on the terminal. More...
Go to the source code of this file.
Functions | |
int | Canvas_getWidth () |
Gets the width of the canvas, which is the width of the terminal. | |
int | Canvas_getHeight () |
Gets the height of the canvas, which is the height of the terminal. | |
void | Canvas_clearScreen () |
Clears the screen. | |
void | Canvas_setCursor (int x, int y) |
Sets the cursor position. | |
int | Canvas_getCursorX () |
Gets the cursor position. | |
int | Canvas_getCursorY () |
Gets the cursor position. | |
void | Canvas_setChar (int x, int y, char c) |
Sets a character at a specific position. | |
void | Canvas_setAnsiCurrent (const char *ansi) |
Appends the ANSI code at the current cursor position. | |
void | Canvas_setAnsi (int x, int y, const char *ansi) |
Appends the ANSI code at a specific position. | |
int | Canvas_isCursorVisible () |
Gets the cursor visibility. | |
void | Canvas_hideCursor () |
Hides the cursor. | |
void | Canvas_showCursor () |
Shows the cursor. | |
void | Canvas_resetFormat () |
Resets all formatting at the current cursor position. | |
void | Canvas_setForeground (int rgb) |
Sets the foreground color at the current cursor position. | |
void | Canvas_setBackground (int rgb) |
Sets the background color at the current cursor position. | |
void | Canvas_setColor8 (int color) |
Sets the color at the current cursor position using the built-in 8-bit color palette. | |
void | Canvas_setForeground256 (int color) |
Sets the foreground color at the current cursor position using the built-in 256-color palette. | |
void | Canvas_setBackground256 (int color) |
Sets the background color at the current cursor position using the built-in 256-color palette. | |
void | Canvas_enableBold () |
Enables the bold text attribute. | |
void | Canvas_disableBold () |
Disables the bold text attribute. | |
void | Canvas_enableDim () |
Enables the dim text attribute. | |
void | Canvas_disableDim () |
Disables the dim text attribute. | |
void | Canvas_enableItalic () |
Enables the italic text attribute. | |
void | Canvas_disableItalic () |
Disables the italic text attribute. | |
void | Canvas_enableUnderline () |
Enables the underline text attribute. | |
void | Canvas_disableUnderline () |
Disables the underline text attribute. | |
void | Canvas_enableBlink () |
Enables the blink text attribute. | |
void | Canvas_disableBlink () |
Disables the blink text attribute. | |
void | Canvas_enableInvert () |
Enables the invert text attribute. | |
void | Canvas_disableInvert () |
Disables the invert text attribute. | |
void | Canvas_enableHidden () |
Enables the hidden text attribute. | |
void | Canvas_disableHidden () |
Disables the hidden text attribute. | |
void | Canvas_enableStrikethrough () |
Enables the strikethrough text attribute. | |
void | Canvas_disableStrikethrough () |
Disables the strikethrough text attribute. | |
void | Canvas_hLine (int x, int y, int width, char c) |
Draws a horizontal line. | |
void | Canvas_vLine (int x, int y, int height, char c) |
Draws a vertical line. | |
void | Canvas_rect (int x, int y, int width, int height, char c) |
Draws a hollow rectangle. | |
void | Canvas_fillRect (int x, int y, int width, int height, char c) |
Fills a rectangle with a character. | |
void | Canvas_circle (int x, int y, int radius, char c) |
Draws a hollow circle. | |
void | Canvas_fillCircle (int x, int y, int radius, char c) |
Fills a circle with a character. | |
void | Canvas_ellipse (int x, int y, int xradius, int yradius, char c) |
Draws a hollow ellipse. | |
void | Canvas_fillEllipse (int x, int y, int xradius, int yradius, char c) |
Fills an ellipse with a character. | |
void | Canvas_line (int x1, int y1, int x2, int y2, char c) |
Draws a line between two points. | |
void | Canvas_drawText (int x, int y, const char *text) |
Draws text at the current cursor position. | |
void | Canvas_drawAscii (int x, int y, char ascii[8][5]) |
Draws an ASCII character at a specific position. | |
void | Canvas_drawAsciiText (int x, int y, char character, const char *text) |
Draws text at a specific position. | |
Variables | |
char | ASCII_EMPTY [8][5] |
Represents empty space in ASCII art. | |
char | ASCII_UPPER_A [8][5] |
An 'A' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_A [8][5] |
An 'a' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_B [8][5] |
A 'B' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_B [8][5] |
A 'b' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_C [8][5] |
A 'C' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_C [8][5] |
A 'c' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_D [8][5] |
A 'D' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_D [8][5] |
A 'd' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_E [8][5] |
An 'E' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_E [8][5] |
An 'e' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_F [8][5] |
A 'F' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_F [8][5] |
A 'f' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_G [8][5] |
A 'G' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_G [8][5] |
A 'g' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_H [8][5] |
A 'H' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_H [8][5] |
A 'h' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_I [8][5] |
An 'I' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_I [8][5] |
An 'i' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_J [8][5] |
A 'J' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_J [8][5] |
A 'j' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_K [8][5] |
A 'K' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_K [8][5] |
A 'k' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_L [8][5] |
A 'L' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_L [8][5] |
A 'l' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_M [8][5] |
A 'M' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_M [8][5] |
A 'm' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_N [8][5] |
A 'N' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_N [8][5] |
A 'n' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_O [8][5] |
An 'O' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_O [8][5] |
An 'o' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_P [8][5] |
A 'P' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_P [8][5] |
A 'p' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_Q [8][5] |
A 'Q' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_Q [8][5] |
A 'q' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_R [8][5] |
A 'R' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_R [8][5] |
A 'r' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_S [8][5] |
A 'S' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_S [8][5] |
A 's' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_T [8][5] |
A 'T' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_T [8][5] |
A 't' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_U [8][5] |
An 'U' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_U [8][5] |
A 'u' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_V [8][5] |
A 'V' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_V [8][5] |
A 'v' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_W [8][5] |
A 'W' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_W [8][5] |
A 'w' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_X [8][5] |
An 'X' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_X [8][5] |
A 'x' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_Y [8][5] |
A 'Y' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_Y [8][5] |
A 'y' character in ASCII art using the '#' character. | |
char | ASCII_UPPER_Z [8][5] |
A 'Z' character in ASCII art using the '#' character. | |
char | ASCII_LOWER_Z [8][5] |
A 'z' character in ASCII art using the '#' character. | |
char | ASCII_ZERO [8][5] |
A '0' character in ASCII art using the '#' character. | |
char | ASCII_ONE [8][5] |
A '1' character in ASCII art using the '#' character. | |
char | ASCII_TWO [8][5] |
A '2' character in ASCII art using the '#' character. | |
char | ASCII_THREE [8][5] |
A '3' character in ASCII art using the '#' character. | |
char | ASCII_FOUR [8][5] |
A '4' character in ASCII art using the '#' character. | |
char | ASCII_FIVE [8][5] |
A '5' character in ASCII art using the '#' character. | |
char | ASCII_SIX [8][5] |
A '6' character in ASCII art using the '#' character. | |
char | ASCII_SEVEN [8][5] |
A '7' character in ASCII art using the '#' character. | |
char | ASCII_EIGHT [8][5] |
A '8' character in ASCII art using the '#' character. | |
char | ASCII_NINE [8][5] |
A '9' character in ASCII art using the '#' character. | |
char | ASCII_MAP [128][8][5] |
Represents a mapping of ASCII characters to their respective ASCII art. | |
Canvas API for drawing shapes and text on the terminal.
void Canvas_circle | ( | int | x, |
int | y, | ||
int | radius, | ||
char | c ) |
Draws a hollow circle.
x | X coordinate. |
y | Y coordinate. |
radius | Radius of the circle. |
c | The character to draw the circle with. |
void Canvas_clearScreen | ( | ) |
Clears the screen.
This method uses a system
call to clear the screen.
void Canvas_disableBlink | ( | ) |
Disables the blink text attribute.
This is a simple print of the ANSI code "\033[25m".
void Canvas_disableBold | ( | ) |
Disables the bold text attribute.
This is a simple print of the ANSI code "\033[22m".
Both this and Canvas_disableDim
share the same code, meaning it will disable both bold and dim text if both are enabled.
void Canvas_disableDim | ( | ) |
Disables the dim text attribute.
This is a simple print of the ANSI code "\033[22m".
Faint is not widely supported, and is often rendered as normal text.
Both this and Canvas_disableBold
share the same code, meaning it will disable both bold and dim text if both are enabled.
void Canvas_disableHidden | ( | ) |
Disables the hidden text attribute.
This is a simple print of the ANSI code "\033[28m".
void Canvas_disableInvert | ( | ) |
Disables the invert text attribute.
This is a simple print of the ANSI code "\033[27m".
void Canvas_disableItalic | ( | ) |
Disables the italic text attribute.
This is a simple print of the ANSI code "\033[23m".
Italic is not widely supported, and is often rendered as normal text.
void Canvas_disableStrikethrough | ( | ) |
Disables the strikethrough text attribute.
This is a simple print of the ANSI code "\033[29m".
void Canvas_disableUnderline | ( | ) |
Disables the underline text attribute.
This is a simple print of the ANSI code "\033[24m".
void Canvas_drawAscii | ( | int | x, |
int | y, | ||
char | ascii[8][5] ) |
Draws an ASCII character at a specific position.
x | X coordinate. |
y | Y coordinate. |
ascii | The ASCII character as a 2D array of characters. |
void Canvas_drawAsciiText | ( | int | x, |
int | y, | ||
char | character, | ||
const char * | text ) |
Draws text at a specific position.
This method uses the Canvas_drawAscii method to draw ASCII characters. The ASCII characters are stored in pre-defined 2D arrays that are declared in this header. Characters that are not present in the header will be skipped.
x | X coordinate. |
y | Y coordinate. |
character | The character to use when drawing. |
text | The text to draw. |
void Canvas_drawText | ( | int | x, |
int | y, | ||
const char * | text ) |
Draws text at the current cursor position.
x | X coordinate. |
y | Y coordinate. |
text | The text to draw. |
void Canvas_ellipse | ( | int | x, |
int | y, | ||
int | xradius, | ||
int | yradius, | ||
char | c ) |
Draws a hollow ellipse.
x | X coordinate. |
y | Y coordinate. |
xradius | X radius of the ellipse. |
yradius | Y radius of the ellipse. |
c | The character to draw the ellipse with. |
void Canvas_enableBlink | ( | ) |
Enables the blink text attribute.
This is a simple print of the ANSI code "\033[5m".
"Blinking" refers to the text blinking on and off.
void Canvas_enableBold | ( | ) |
Enables the bold text attribute.
This is a simple print of the ANSI code "\033[1m".
void Canvas_enableDim | ( | ) |
Enables the dim text attribute.
This is a simple print of the ANSI code "\033[2m".
Faint is not widely supported, and is often rendered as normal text.
void Canvas_enableHidden | ( | ) |
Enables the hidden text attribute.
Hidden is not widely supported, and is often rendered as normal text.
This is a simple print of the ANSI code "\033[8m".
"Hidden" refers to the text being hidden.
void Canvas_enableInvert | ( | ) |
Enables the invert text attribute.
This is a simple print of the ANSI code "\033[7m".
"Invert" refers to the text and background colors being swapped.
void Canvas_enableItalic | ( | ) |
Enables the italic text attribute.
This is a simple print of the ANSI code "\033[3m".
Italic is not widely supported, and is often rendered as normal text.
void Canvas_enableStrikethrough | ( | ) |
Enables the strikethrough text attribute.
Strikethrough is not widely supported, and is often rendered as normal text.
This is a simple print of the ANSI code "\033[9m".
"Strikethrough" refers to the text having a line through the middle.
void Canvas_enableUnderline | ( | ) |
Enables the underline text attribute.
This is a simple print of the ANSI code "\033[4m".
void Canvas_fillCircle | ( | int | x, |
int | y, | ||
int | radius, | ||
char | c ) |
Fills a circle with a character.
x | X coordinate. |
y | Y coordinate. |
radius | Radius of the circle. |
c | The character to fill the circle with. |
void Canvas_fillEllipse | ( | int | x, |
int | y, | ||
int | xradius, | ||
int | yradius, | ||
char | c ) |
Fills an ellipse with a character.
x | X coordinate. |
y | Y coordinate. |
xradius | X radius of the ellipse. |
yradius | Y radius of the ellipse. |
c | The character to fill the ellipse with. |
void Canvas_fillRect | ( | int | x, |
int | y, | ||
int | width, | ||
int | height, | ||
char | c ) |
Fills a rectangle with a character.
x | X coordinate. |
y | Y coordinate. |
width | Width of the rectangle. |
height | Height of the rectangle. |
c | The character to fill the rectangle with. |
int Canvas_getCursorX | ( | ) |
Gets the cursor position.
On POSIX, this method uses the ESC[6n
ANSI code to get the cursor position. This can make the method more expensive than on Windows, where the cursor position is stored internally. On Windows, this method uses the GetConsoleScreenBufferInfo
function to get the cursor position.
int Canvas_getCursorY | ( | ) |
Gets the cursor position.
On POSIX, this method uses the ESC[6n
ANSI code to get the cursor position. This can make the method more expensive than on Windows, where the cursor position is stored internally. On Windows, this method uses the GetConsoleScreenBufferInfo
function to get the cursor position.
int Canvas_getHeight | ( | ) |
Gets the height of the canvas, which is the height of the terminal.
int Canvas_getWidth | ( | ) |
Gets the width of the canvas, which is the width of the terminal.
void Canvas_hideCursor | ( | ) |
Hides the cursor.
On POSIX, this is a simple print of the ANSI code "\033[?25l", which hides the cursor. On Windows, this is a call to the SetConsoleCursorInfo
function.
void Canvas_hLine | ( | int | x, |
int | y, | ||
int | width, | ||
char | c ) |
Draws a horizontal line.
x | X coordinate. |
y | Y coordinate. |
width | Width of the line. |
c | The character to draw the line with. |
int Canvas_isCursorVisible | ( | ) |
Gets the cursor visibility.
On POSIX, this is handled by an internal variable. On Windows, this is determined by the cursor visibility state. Therefore, this method is often less reliable on POSIX systems, since it cannot detect changes made by other programs.
void Canvas_line | ( | int | x1, |
int | y1, | ||
int | x2, | ||
int | y2, | ||
char | c ) |
Draws a line between two points.
x1 | The x coordinate of the first point. |
y1 | The y coordinate of the first point. |
x2 | The x coordinate of the second point. |
y2 | The y coordinate of the second point. |
c | The character to draw the line with. |
void Canvas_rect | ( | int | x, |
int | y, | ||
int | width, | ||
int | height, | ||
char | c ) |
Draws a hollow rectangle.
x | X coordinate. |
y | Y coordinate. |
width | Width of the rectangle. |
height | Height of the rectangle. |
c | The character to draw the rectangle with. |
void Canvas_resetFormat | ( | ) |
Resets all formatting at the current cursor position.
This is a simple print of the ANSI code "\033[0m", which resets all formatting at the current cursor position.
void Canvas_setAnsi | ( | int | x, |
int | y, | ||
const char * | ansi ) |
Appends the ANSI code at a specific position.
This method sets the ANSI code at a specific position. The ANSI code is a series of semicolon-separated numbers and letters that control the terminal behavior. For example, the ANSI code "\033[31m" sets the text color to red.
x | X coordinate. |
y | Y coordinate. |
ansi | The ANSI code. |
void Canvas_setAnsiCurrent | ( | const char * | ansi | ) |
Appends the ANSI code at the current cursor position.
This method sets the ANSI code at a specific position. The ANSI code is a series of semicolon-separated numbers and letters that control the terminal behavior. For example, the ANSI code "\033[31m" sets the text color to red.
ansi | The ANSI code. |
void Canvas_setBackground | ( | int | rgb | ) |
Sets the background color at the current cursor position.
This uses the ANSI code "\033[48;2;r;g;bm", where r, g, and b are the red, green, and blue values of the color, respectively.
rgb | The RGB color. |
void Canvas_setBackground256 | ( | int | color | ) |
Sets the background color at the current cursor position using the built-in 256-color palette.
This uses the ANSI code "\033[48;5;{ID}m", where {ID} is the color number.
color | The color number. |
void Canvas_setChar | ( | int | x, |
int | y, | ||
char | c ) |
Sets a character at a specific position.
x | X coordinate. |
y | Y coordinate. |
c | The character to set. |
void Canvas_setColor8 | ( | int | color | ) |
Sets the color at the current cursor position using the built-in 8-bit color palette.
This uses the ANSI code "\033[{ID}m", where m is the color number.
color | The color number. |
void Canvas_setCursor | ( | int | x, |
int | y ) |
Sets the cursor position.
x | X coordinate. |
y | Y coordinate. |
void Canvas_setForeground | ( | int | rgb | ) |
Sets the foreground color at the current cursor position.
This uses the ANSI code "\033[38;2;r;g;bm", where r, g, and b are the red, green, and blue values of the color, respectively.
rgb | The RGB color. |
void Canvas_setForeground256 | ( | int | color | ) |
Sets the foreground color at the current cursor position using the built-in 256-color palette.
This uses the ANSI code "\033[38;5;{ID}m", where {ID} is the color number.
color | The color number. |
void Canvas_showCursor | ( | ) |
Shows the cursor.
On POSIX, this is a simple print of the ANSI code "\033[?25h", which shows the cursor. On Windows, this is a call to the SetConsoleCursorInfo
function.
void Canvas_vLine | ( | int | x, |
int | y, | ||
int | height, | ||
char | c ) |
Draws a vertical line.
x | X coordinate. |
y | Y coordinate. |
height | Height of the line. |
c | The character to draw the line with. |
|
extern |
Represents a mapping of ASCII characters to their respective ASCII art.
This 3D array is automatically initialized when Canvas_drawAsciiText
is called.
This 3D array is used to map ASCII characters to their respective ASCII art. The first dimension is the ASCII character, the second dimension is the row, and the third dimension is the column. The ASCII art is represented as a 2D array of characters, and drawn using the Canvas_drawAscii method.