![]() |
cmdfx 0.2.0
Lightweight game engine for your terminal
|
Scenes API for CmdFX. More...
Go to the source code of this file.
Classes | |
struct | CmdFX_Scene |
Represents a CmdFX Scene. More... | |
Macros | |
#define | MAX_REGISTERED_SCENES 1024 |
Represents the maximum number of registered scenes that can be stored. | |
Typedefs | |
typedef struct CmdFX_Scene | CmdFX_Scene |
Represents a CmdFX Scene. | |
Functions | |
CmdFX_Scene ** | Scene_getDrawnScenes () |
Gets a list of all scenes that are drawn on the screen. | |
int | Scene_getDrawnScenesCount () |
Gets the number of scenes that are drawn on the screen. | |
CmdFX_Scene * | Scene_create (int width, int height) |
Creates an empty scene with a specified width and height. | |
CmdFX_Scene * | Scene_createFilled (int width, int height, char c, char *ansi, int z) |
Creates a filled scene with a specified width, height, and character. | |
CmdFX_Scene * | Scene_createFromData (char **data, char ***ansiData) |
Creates a scene from a 2D array of characters and ANSI strings. | |
int | Scene_clear (CmdFX_Scene *scene) |
Clears a scene of its data. | |
int | Scene_draw (CmdFX_Scene *scene, int x, int y) |
Draws a scene at the specified position on the screen. | |
int | Scene_drawPortion (CmdFX_Scene *scene, int x, int y, int sx, int sy, int width, int height) |
Draws a portion of a scene at the specified position on the screen. | |
CmdFX_Scene * | Scene_getSceneAt (int x, int y) |
Gets the scene at the specified position on the screen. | |
int | Scene_isOnTop (CmdFX_Scene *scene) |
Checks if the specified scene is on top of the screen. | |
int | Scene_isOnTopAt (CmdFX_Scene *scene, int x, int y) |
Checks if the specified scene is on top at the specified position on the screen. | |
int | Scene_isOnBottom (CmdFX_Scene *scene) |
Checks if the specified scene is on the bottom of the screen. | |
int | Scene_isOnBottomAt (CmdFX_Scene *scene, int x, int y) |
Checks if the specified scene is on the bottom at the specified position on the screen. | |
int | Scene_remove (CmdFX_Scene *scene) |
Removes a scene from the screen. | |
int | Scene_isEmpty (CmdFX_Scene *scene) |
Checks if the specified scene is empty. | |
int | Scene_switchTo (CmdFX_Scene *scene, int x, int y) |
Removes all of the currently drawn scenes, only leaving this scene. | |
int | Scene_free (CmdFX_Scene *scene) |
Destroys the scene, freeing the memory allocated. | |
CmdFX_Scene ** | Scene_getRegisteredScenes () |
Gets a list of all registered scenes. | |
int | Scene_getRegisteredScenesCount () |
Gets the number of registered scenes. | |
int | Scene_register (CmdFX_Scene *scene) |
Registers a scene with the Scene Engine. | |
int | Scene_unregister (CmdFX_Scene *scene) |
Unregisters a scene with the Scene Engine. | |
int | Scene_drawRegistered (int uid, int x, int y) |
Draws a registered scene at the specified position on the screen. | |
int | Scene_switchToRegistered (int uid, int x, int y) |
Removes all of the currently drawn scenes, only leaving the registered scene with the specified unique identifier. | |
int | Scene_scroll (int uid, int dx, int dy) |
Scrolls the scene by the specified amount. | |
void | tickCmdFXSceneEngine () |
Ticks the CmdFX Scene Engine. | |
int | beginCmdFXSceneEngine () |
Begins the CmdFX Scene Engine. | |
int | endCmdFXSceneEngine () |
Ends the CmdFX Scene Engine. | |
int | Scene_setData (CmdFX_Scene *scene, char **data) |
Sets the data of the scene. | |
int | Scene_setChar (CmdFX_Scene *scene, int x, int y, char c) |
Sets the character at the specified position in the scene. | |
int | Scene_setAnsiData (CmdFX_Scene *scene, char ***ansiData) |
Sets the ANSI data of the scene. | |
int | Scene_appendAnsiData (CmdFX_Scene *scene, char ***ansiData) |
Appends the ANSi data to the current ansi data, setting it if it is not currently set. | |
int | Scene_setForeground (CmdFX_Scene *scene, int x, int y, int width, int height, int rgb) |
Fills the foreground of the scene with the specified RGB color. | |
int | Scene_setForegroundAll (CmdFX_Scene *scene, int rgb) |
Fills the entirety of the foreground of the scene with the specified RGB color. | |
int | Scene_setBackground (CmdFX_Scene *scene, int x, int y, int width, int height, int rgb) |
Fills the background of the scene with the specified RGB color. | |
int | Scene_setBackgroundAll (CmdFX_Scene *scene, int rgb) |
Fills the entirety of the background of the scene with the specified RGB color. | |
Scenes API for CmdFX.
#define MAX_REGISTERED_SCENES 1024 |
Represents the maximum number of registered scenes that can be stored.
The maximum number of registered scenes that can be stored is 256. This is the maximum number of scenes that can be registered with the Scene Engine at any given time.
typedef struct CmdFX_Scene CmdFX_Scene |
Represents a CmdFX Scene.
A CmdFX Scene is a storage buffer for different characters on the screen. It is drawn using the cnvas API and should be used when displaying large amounts of characters at a time.
int beginCmdFXSceneEngine | ( | ) |
Begins the CmdFX Scene Engine.
This function initializes the CmdFX Scene Engine. The Scene Engine is responsible for managing all scenes that are drawn on the screen. It will automatically redraw scenes each frame if necessary for registered scenes.
0
if the Scene Engine was started successfully, or -1
if an error occurred. int endCmdFXSceneEngine | ( | ) |
Ends the CmdFX Scene Engine.
This function stops the CmdFX Scene Engine. The Scene Engine will no longer manage scenes that are drawn on the screen. Scenes will no longer be automatically redrawn each frame.
0
if the Scene Engine was stopped successfully, or -1
if an error occurred. int Scene_appendAnsiData | ( | CmdFX_Scene * | scene, |
char *** | ansiData ) |
Appends the ANSi data to the current ansi data, setting it if it is not currently set.
This function appends the ANSI data to the current ANSI data of the scene. The width and height of the scene must match the width and height of the 2D array. The ANSI data field will be resized to match the new size. If an error occurs, the function will return -1
.
The scene will be redrawn if it is currently drawn.
scene | The scene to modify. |
ansiData | The 2D array of ANSI strings to append. |
0
if the scene data was set, or -1
if an error occurred. int Scene_clear | ( | CmdFX_Scene * | scene | ) |
Clears a scene of its data.
This function clears the specified scene of its data. This means that all characters in the data field will be set to 0, making Scene_isEmpty
return 1
.
scene | The scene to clear. |
0
if the scene was cleared successfully, or -1
if an error occurred. CmdFX_Scene * Scene_create | ( | int | width, |
int | height ) |
Creates an empty scene with a specified width and height.
This function creates a new scene with the specified width and height. The scene will be empty, meaning that all characters in the data field will be set to ‘’ '`.
The width and height parameters must be greater than 0. If either parameter is less than or equal to 0, the function will return NULL
.
width | The width of the scene. |
height | The height of the scene. |
NULL
if the scene could not be created. CmdFX_Scene * Scene_createFilled | ( | int | width, |
int | height, | ||
char | c, | ||
char * | ansi, | ||
int | z ) |
Creates a filled scene with a specified width, height, and character.
This function creates a new scene with the specified width and height. The scene will be filled with the specified character. The ANSI data will be set to the specified ANSI string.
The width and height parameters must be greater than 0. If either parameter is less than or equal to 0, the function will return NULL
.
width | The width of the scene. |
height | The height of the scene. |
c | The character to fill the scene with. |
ansi | The ANSI string to fill the scene with. |
z | The Z index of the scene. |
NULL
if the scene could not be created. CmdFX_Scene * Scene_createFromData | ( | char ** | data, |
char *** | ansiData ) |
Creates a scene from a 2D array of characters and ANSI strings.
This function creates a new scene from the specified 2D array of characters and ANSI strings. The width and height of the scene will be set to the width and height of the 2D array. Therefore, the arrays must be properly null-teminated with a NULL
character at the end of each array.
The bounds will be based on the data
array. If the bounds do not match, the function will return NULL
.
The data parameter must not be NULL
. If data is NULL
, the function will return NULL
. ansiData
can optionally be NULL
to represent no color.
data | The 2D array of characters that represent the scene. |
ansiData | The 2D array of ANSI strings that represent the scene. |
NULL
if the scene could not be created. int Scene_draw | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y ) |
Draws a scene at the specified position on the screen.
This function draws the specified scene at the specified position on the screen. The scene will be drawn using the Canvas API, which means that it will disappear if a Sprite is drawn over it. The Scene Engine will automatically redraw the scene each frame if necessary.
scene | The scene to draw. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
0
if the scene was drawn successfully, or -1
if an error occurred. int Scene_drawPortion | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y, | ||
int | sx, | ||
int | sy, | ||
int | width, | ||
int | height ) |
Draws a portion of a scene at the specified position on the screen.
This function draws a portion of the specified scene at the specified position on the screen. The portion is defined by the specified x, y, width, and height parameters. The scene will be drawn using the Canvas API, which means that it will disappear if a Sprite is drawn over it. The Scene Engine will automatically redraw the scene each frame if necessary.
The x and y parameters must be greater than or equal to 0. If either parameter is less than 0, the function will return -1
.
scene | The scene to draw. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
sx | The x-coordinate of the top-left corner of the portion to draw. |
sy | The y-coordinate of the top-left corner of the portion to draw. |
width | The width of the portion to draw. |
height | The height of the portion to draw. |
0
if the scene was drawn successfully, or -1
if an error occurred. int Scene_drawRegistered | ( | int | uid, |
int | x, | ||
int | y ) |
Draws a registered scene at the specified position on the screen.
This function draws the registered scene with the specified unique identifier at the specified position on the screen. The scene will be drawn using the Canvas API, which means that it will disappear if a Sprite is drawn over it. The Scene Engine will automatically redraw the scene each frame if necessary.
uid | The unique identifier of the scene to draw. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
0
if the scene was drawn successfully, or -1
if an error occurred. int Scene_free | ( | CmdFX_Scene * | scene | ) |
Destroys the scene, freeing the memory allocated.
This function frees the memory allocated for the specified scene. After calling this function, the scene should no longer be used.
scene | The scene to free. |
0
if the scene was freed successfully, or -1
if an error occurred. CmdFX_Scene ** Scene_getDrawnScenes | ( | ) |
Gets a list of all scenes that are drawn on the screen.
int Scene_getDrawnScenesCount | ( | ) |
Gets the number of scenes that are drawn on the screen.
CmdFX_Scene ** Scene_getRegisteredScenes | ( | ) |
Gets a list of all registered scenes.
int Scene_getRegisteredScenesCount | ( | ) |
Gets the number of registered scenes.
CmdFX_Scene * Scene_getSceneAt | ( | int | x, |
int | y ) |
Gets the scene at the specified position on the screen.
This function gets the top-most scene at the specified position on the screen. The scene will be drawn using the Canvas API, which means that it will disappear if a Sprite is drawn over it. The Scene Engine will automatically redraw the scene each frame if necessary.
The x and y parameters must be greater than or equal to 0. If either parameter is less than 0, the function will return NULL
.
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
NULL
if no scene was found. int Scene_isEmpty | ( | CmdFX_Scene * | scene | ) |
Checks if the specified scene is empty.
This function checks if the specified scene is empty. A scene is considered empty if all characters in the data field are set to 0.
scene | The scene to check. |
1
if the scene is empty, or 0
if the scene is not empty. int Scene_isOnBottom | ( | CmdFX_Scene * | scene | ) |
Checks if the specified scene is on the bottom of the screen.
This function checks if the specified scene is on the bottom of the screen. A scene is considered to be on the bottom if it is the bottom-most scene at its position on the screen according to scene->z
.
scene | The scene to check. |
1
if the scene is on the bottom, or 0
if the scene is not on bottom. int Scene_isOnBottomAt | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y ) |
Checks if the specified scene is on the bottom at the specified position on the screen.
This function checks if the specified scene is on the bottom at the specified position on the screen. A scene is considered to be on the bottom if it is the bottom-most scene at its position on the screen according to scene->z
.
scene | The scene to check. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
1
if the scene is on bottom, or 0
if the scene is not on bottom. int Scene_isOnTop | ( | CmdFX_Scene * | scene | ) |
Checks if the specified scene is on top of the screen.
This function checks if the specified scene is on top of the screen. A scene is considered to be on top if it is the top-most scene at its position on the screen according to scene->z
.
scene | The scene to check. |
1
if the scene is on top, or 0
if the scene is not on top. int Scene_isOnTopAt | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y ) |
Checks if the specified scene is on top at the specified position on the screen.
This function checks if the specified scene is on top at the specified position on the screen. A scene is considered to be on top if it is the top-most scene at its position on the screen according to scene->z
.
scene | The scene to check. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
1
if the scene is on top, or 0
if the scene is not on top. int Scene_register | ( | CmdFX_Scene * | scene | ) |
Registers a scene with the Scene Engine.
This function registers the specified scene with the Scene Engine. This allows the Scene Engine to keep track of the scene and automatically redraw it each frame if necessary.
scene | The scene to register. |
scene->uid
, or -1
if an error occurred. int Scene_remove | ( | CmdFX_Scene * | scene | ) |
Removes a scene from the screen.
This function removes the specified scene from the screen. The scene will no longer be drawn on the screen, and the Scene Engine will stop automatically redrawing it each frame.
scene | The scene to remove. |
0
if the scene was removed successfully, or -1
if an error occurred. int Scene_scroll | ( | int | uid, |
int | dx, | ||
int | dy ) |
Scrolls the scene by the specified amount.
This function scrolls the scene by the specified amount. The amount is specified by the dx
and dy
parameters, which represent the amount to scroll in the x and y directions, respectively.
Scrolling refers to moving (redrawing) the specified draw bounds over by the values of dx
and dy
. This is useful for creating scrolling effects in the scene.
uid | The unique identifier of the scene to scroll. |
dx | The amount to scroll in the x direction. |
dy | The amount to scroll in the y direction. |
0
if the scene was scrolled successfully, -1
if an error occurred. int Scene_setAnsiData | ( | CmdFX_Scene * | scene, |
char *** | ansiData ) |
Sets the ANSI data of the scene.
This function sets the ANSI data to the current ANSI data of the scene. The width and height of the scene must match the width and height of the 2D array. The ANSI data field will be resized to match the new size. If an error occurs, the function will return -1
.
The scene will be redrawn if it is currently drawn.
scene | The scene to modify. |
ansiData | The 2D array of ANSI strings to set. |
0
if the scene data was set, or -1
if an error occurred. int Scene_setBackground | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y, | ||
int | width, | ||
int | height, | ||
int | rgb ) |
Fills the background of the scene with the specified RGB color.
This function fills the background of the scene with the specified RGB color. The position is specified by the X and Y coordinates, where (0, 0) is the top-left corner of the scene. If the position is out of bounds, the function will return -1
.
scene | The scene to modify. |
x | The top-left X position in the scene. |
y | The top-left Y position in the scene. |
width | The width of the fill. |
height | The height of the fill. |
rgb | The RGB color to set. |
0
if the fill was successful, or -1
if an error occurred. int Scene_setBackgroundAll | ( | CmdFX_Scene * | scene, |
int | rgb ) |
Fills the entirety of the background of the scene with the specified RGB color.
This function fills the entirety of the background of the scene with the specified RGB color. If an error occurs, the function will return -1
.
scene | The scene to modify. |
rgb | The RGB color to set. |
0
if the fill was successful, or -1
if an error occurred. int Scene_setChar | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y, | ||
char | c ) |
Sets the character at the specified position in the scene.
This function sets the character at the specified position in the scene. The position is specified by the X and Y coordinates, where (0, 0) is the top-left corner of the scene. If the position is out of bounds, the function will return -1
.
If the scene has no data, this function will return -1
.
This function will also redraw the character if the scene is currently drawn.
scene | The scene to modify. |
x | The X position in the scene. |
y | The Y position in the scene. |
c | The character to set. |
0
if the character was set, or -1
if the position is out of bounds. int Scene_setData | ( | CmdFX_Scene * | scene, |
char ** | data ) |
Sets the data of the scene.
This function sets the data of the scene to the specified 2D array of characters. The width and height of the scene will be set to the width and height of the 2D array. The data field will be resized to match the new size. If an error occurs, the function will return -1
.
The scene will be redrawn if it is currently drawn.
scene | The scene to modify. |
data | The 2D array of characters to set. |
0
if the scene data was set, or -1
if an error occurred. int Scene_setForeground | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y, | ||
int | width, | ||
int | height, | ||
int | rgb ) |
Fills the foreground of the scene with the specified RGB color.
This function fills the foreground of the scene with the specified RGB color. The position is specified by the X and Y coordinates, where (0, 0) is the top-left corner of the scene. If the position is out of bounds, the function will return -1
.
scene | The scene to modify. |
x | The top-left X position in the scene. |
y | The top-left Y position in the scene. |
width | The width of the fill. |
height | The height of the fill. |
rgb | The RGB color to set. |
0
if the fill was successful, or -1
if an error occurred. int Scene_setForegroundAll | ( | CmdFX_Scene * | scene, |
int | rgb ) |
Fills the entirety of the foreground of the scene with the specified RGB color.
This function fills the entirety of the foreground of the scene with the specified RGB color. If an error occurs, the function will return -1
.
scene | The scene to modify. |
rgb | The RGB color to set. |
0
if the fill was successful, or -1
if an error occurred. int Scene_switchTo | ( | CmdFX_Scene * | scene, |
int | x, | ||
int | y ) |
Removes all of the currently drawn scenes, only leaving this scene.
This function removes all of the currently drawn scenes from the screen, leaving only the specified scene.
scene | The scene to leave on the screen. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
0
if the scene was switched to successfully, or -1
if an error occurred. int Scene_switchToRegistered | ( | int | uid, |
int | x, | ||
int | y ) |
Removes all of the currently drawn scenes, only leaving the registered scene with the specified unique identifier.
This function removes all of the currently drawn scenes from the screen, leaving only the registered scene with the specified unique identifier.
uid | The unique identifier of the scene to leave on the screen. |
x | The x-coordinate of the top-left corner of the scene. |
y | The y-coordinate of the top-left corner of the scene. |
0
if the scene was switched to successfully, or -1
if an error occurred. int Scene_unregister | ( | CmdFX_Scene * | scene | ) |
Unregisters a scene with the Scene Engine.
This function unregisters the specified scene with the Scene Engine. This allows the Scene Engine to stop keeping track of the scene and stop automatically redrawing it each frame.
scene | The scene to unregister. |
scene->uid
, or -1
if an error occurred. void tickCmdFXSceneEngine | ( | ) |
Ticks the CmdFX Scene Engine.
This function calls all of the necessary things apart of the Scene Engine to keep scenes redrawn every frame.