Files
Tart/includes/tart.h

219 lines
6.4 KiB
C
Raw Permalink Normal View History

#ifndef TART_H
#define TART_H
2025-01-31 21:25:55 -08:00
2025-01-29 19:09:58 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2025-01-31 21:25:55 -08:00
2025-01-29 14:46:08 -08:00
#include "../source/term.h"
2025-01-25 12:57:45 -08:00
// #========================================================================#
// | PreacherDHM:TART
// |
// | Tarts stands for Terminal Art. Tart is a terminal renderer that uses a |
// | render buffer like system that takes csprites or character sprites and |
// | displays them in the terminal. The render buffer consists of cells and |
// | each cell consists of
// | - Color
// | - Rendered Character
// | - Reset
// | In toaltol around 19 to 24 bytes. This alows for complete controle |
// | over each cell.
// #========================================================================#
2025-02-01 12:49:17 -08:00
#ifdef TART_RGB_COLORS
#define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0,0}
#define TART_CELL_DATA_SIZE 16 // todo add number
#else
#define NULL_CELL (struct tart_cell){0,0,0,' '}
#define TART_CELL_DATA_SIZE 20
2025-02-01 12:49:17 -08:00
#endif
2025-01-31 21:25:55 -08:00
#define TART_OK 0
#define TART_STYLE_BOLD 1
#define TART_STYLE_DIM 2
#define TART_STYLE_UNDERLINE 4
#define TART_STYLE_BLINKING 5
#define TART_STYLE_INVERSE 7
#define TART_STYLE_HIDDEN 8
#define TART_STYLE_STRIKETHROUGH 9
#define TART_COLOR_BLACK_FOREGROUND 30
#define TART_COLOR_RED_FOREGROUND 31
#define TART_COLOR_GREEN_FOREGROUND 32
#define TART_COLOR_YELLOW_FOREGROUND 33
#define TART_COLOR_BLUE_FOREGROUND 34
#define TART_COLOR_MAGENTA_FOREGROUND 35
#define TART_COLOR_CYAN_FOREGROUND 36
#define TART_COLOR_WHITE_FOREGROUND 37
#define TART_COLOR_DEFAULT_FOREGROUND 39
#define TART_COLOR_BLACK_BACKGROUND 40
#define TART_COLOR_RED_BACKGROUND 41
#define TART_COLOR_GREEN_BACKGROUND 42
#define TART_COLOR_YELLOW_BACKGROUND 43
#define TART_COLOR_BLUE_BACKGROUND 44
#define TART_COLOR_MAGENTA_BACKGROUND 55
#define TART_COLOR_CYAN_BACKGROUND 46
#define TART_COLOR_WHITE_BACKGROUND 47
#define TART_COLOR_DEFAULT_BACKGROUND 49
#define TART_COLOR_BRIGHT_BLACK_FOREGROUND 90
#define TART_COLOR_BRIGHT_RED_FOREGROUND 91
#define TART_COLOR_BRIGHT_GREEN_FOREGROUND 92
#define TART_COLOR_BRIGHT_YELLOW_FOREGROUND 93
#define TART_COLOR_BRIGHT_BLUE_FOREGROUND 94
#define TART_COLOR_BRIGHT_MAGENTA_FOREGROUND 95
#define TART_COLOR_BRIGHT_CYAN_FOREGROUND 96
#define TART_COLOR_BRIGHT_WHITE_FOREGROUND 97
#define TART_COLOR_BRIGHT_BLACK_BACKGROUND 100
#define TART_COLOR_BRIGHT_RED_BACKGROUND 101
#define TART_COLOR_BRIGHT_GREEN_BACKGROUND 102
#define TART_COLOR_BRIGHT_YELLOW_BACKGROUND 103
#define TART_COLOR_BRIGHT_BLUE_BACKGROUND 104
#define TART_COLOR_BRIGHT_MAGENTA_BACKGROUND 105
#define TART_COLOR_BRIGHT_CYAN_BACKGROUND 106
#define TART_COLOR_BRIGHT_WHITE_BACKGROUND 107
2025-01-28 21:01:24 -08:00
2025-01-25 12:57:45 -08:00
typedef unsigned char tart_byte;
typedef unsigned short tart_id;
struct tart_vec2 {
2025-01-29 10:51:20 -08:00
unsigned short x,y;
2025-01-25 12:57:45 -08:00
};
struct tart_rgb {
tart_byte r,g,b;
};
2025-01-25 12:57:45 -08:00
/* Tart Cell
*
* This holds a rgb for the foreground and the background.
* Includeing the display character.
*
*/
2025-01-31 21:25:55 -08:00
#ifdef TART_RGB_COLORS
2025-01-25 12:57:45 -08:00
struct tart_cell {
struct tart_rgb foreground;
struct tart_rgb background;
2025-01-25 12:57:45 -08:00
tart_byte style;
char display;
};
2025-01-31 21:25:55 -08:00
#else
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char display;
};
#endif
2025-01-25 12:57:45 -08:00
2025-02-14 15:03:04 -08:00
struct tart_cstring {
struct tart_cell* data;
long size;
};
struct tart_csprite {
struct tart_cell* data;
struct tart_vec2* position;
struct tart_vec2 bounds;
long size;
};
2025-01-25 12:57:45 -08:00
/* Tart Buffer
*
* The Buffer is a contner that holds all of the cells for that buffer.
* Allso containes the size of the buffer.
*
* ........................width...............
* ..........<-------------------------------->.
* ........^ @################################@.
* ........| #................................#.
* ........| #................................#.
* height--| #.............Buffer.............#.
* ........| #................................#.
* ........| #................................#.
* ........V @################################@.
2025-01-25 12:57:45 -08:00
*/
struct tart_buffer {
unsigned int cell_count;
2025-01-25 12:57:45 -08:00
tart_byte layer;
tart_id id;
struct tart_vec2 size;
struct tart_vec2 position;
struct tart_cell* cells;
2025-01-25 12:57:45 -08:00
};
/* Tart Window
*
* The tart window will have the window size and all of the buffers.
**/
struct tart_window {
struct tart_buffer buffers[0xFF+1];
2025-01-25 12:57:45 -08:00
tart_byte buffer_count;
2025-01-29 10:51:20 -08:00
struct tart_vec2 size;
2025-02-01 14:35:06 -08:00
char* data;
int data_count;
2025-01-25 12:57:45 -08:00
};
2025-01-28 21:01:24 -08:00
struct tart_window tart_create_window();
2025-01-28 13:36:01 -08:00
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position);
2025-02-18 15:28:17 -08:00
tart_byte tart_restore_window(struct tart_window*);
2025-01-31 21:25:55 -08:00
#ifdef TART_RGB_COLORS
2025-01-28 13:36:01 -08:00
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background);
2025-01-31 21:25:55 -08:00
#else
struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreground, tart_byte background);
#endif
/* tart_add_buffer
*
* This adds a buffer to the window.
*
* tart_byte tart_add_buffer(struct tart_window*, struct struct tart_buffer*)
*/
tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer);
/* tart_remove_buffer
*
* This will remove the buffer using the *tart_id*.
*/
2025-02-01 12:49:17 -08:00
tart_byte tart_remove_buffer(struct tart_window*, tart_id);
/* tart_set_buffer
*
* This will replace the the buffer at the index *(tart_byte)*.
*/
tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte);
2025-01-25 12:57:45 -08:00
2025-02-14 15:03:04 -08:00
struct tart_buffer* tart_get_buffer(struct tart_window*, tart_byte);
2025-01-25 12:57:45 -08:00
struct tart_cell* tart_get_cell(struct tart_buffer*, int);
2025-01-28 21:01:24 -08:00
struct tart_cell tart_set_cell(struct tart_buffer*, struct tart_cell,int);
2025-01-25 12:57:45 -08:00
2025-02-01 14:35:06 -08:00
tart_byte tart_draw_window(struct tart_window*, char*);
tart_byte tart_add_cells_to_buffer(struct tart_buffer*, struct tart_cell*);
2025-02-14 15:03:04 -08:00
// rendering
// Resering positionial cells.
struct tart_cstring tart_cstring(char* string, long, struct tart_cell type);
tart_byte tart_cstring_free(struct tart_cstring*);
struct tart_cstring tart_cstring_append(struct tart_cstring*, struct tart_cstring*);
struct tart_csprite tart_csprite(struct tart_cell*, struct tart_vec2*, long);
tart_byte tart_csprite_free(struct tart_csprite*);
tart_byte tart_draw_cell_position(struct tart_buffer*, struct tart_cell, struct tart_vec2);
tart_byte tart_draw_cstring_position(struct tart_buffer*, struct tart_cstring, struct tart_vec2);
tart_byte tart_draw_csprite_position(struct tart_buffer*, struct tart_csprite, struct tart_vec2);
/*
* tart_restore_buffer sets the buffer to NULL_CELL.
* */
tart_byte tart_restore_buffer(struct tart_buffer*);
2025-01-29 19:09:58 +00:00
#ifdef __cplusplus
}
#endif
#endif