Files
Tart/includes/tart.h
2025-02-01 14:35:06 -08:00

174 lines
5.0 KiB
C

#ifndef TART_H
#define TART_H
#ifdef __cplusplus
extern "C" {
#endif
#include "../source/term.h"
// #========================================================================#
// | 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.
// #========================================================================#
#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,0}
#define TART_CELL_DATA_SIZE 16
#endif
#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
typedef unsigned char tart_byte;
typedef unsigned short tart_id;
struct tart_vec2 {
unsigned short x,y;
};
struct tart_rgb {
tart_byte r,g,b;
};
/* Tart Cell
*
* This holds a rgb for the foreground and the background.
* Includeing the display character.
*
*/
#ifdef TART_RGB_COLORS
struct tart_cell {
struct tart_rgb foreground;
struct tart_rgb background;
tart_byte style;
char display;
};
#else
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char display;
};
#endif
/* 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 @################################@.
*/
struct tart_buffer {
unsigned int cell_count;
tart_byte layer;
tart_id id;
struct tart_vec2 size;
struct tart_vec2 position;
struct tart_cell* cells;
};
/* Tart Window
*
* The tart window will have the window size and all of the buffers.
**/
struct tart_window {
struct tart_buffer buffers[0xFF+1];
tart_byte buffer_count;
struct tart_vec2 size;
char* data;
int data_count;
};
struct tart_window tart_create_window();
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position);
#ifdef TART_RGB_COLORS
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background);
#else
struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreground, tart_byte background);
#endif
tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer);
tart_byte tart_remove_buffer(struct tart_window*, tart_id);
tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte);
struct tart_buffer* tart_get_buffer(struct tart_window*, tart_byte);
struct tart_cell* tart_get_cell(struct tart_buffer*, int);
struct tart_cell tart_set_cell(struct tart_buffer*, struct tart_cell,int);
tart_byte tart_draw_window(struct tart_window*, char*);
tart_byte tart_add_cells_to_buffer(struct tart_buffer*, struct tart_cell*);
#ifdef __cplusplus
}
#endif
#endif