reworded tart and now it works with utf8 and is enabled by defalt

This commit is contained in:
2026-01-29 10:47:16 -08:00
parent ee10de863d
commit 704f624f25
8 changed files with 493 additions and 622 deletions

View File

@@ -1,46 +1,105 @@
#ifndef TART_H
#define TART_H
#include <string.h>
#define TART_UTF8
#ifdef __cplusplus
extern "C" {
#endif
#include "../source/term.h"
#include <stdio.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 32 // todo add number
typedef char tart_display[2];
#else
#define NULL_CELL (struct tart_cell){0,0,0,' '}
#define TART_CELL_DATA_SIZE 20
typedef char tart_display;
typedef unsigned int TART_FLAGS;
typedef unsigned char tart_byte;
typedef unsigned short tart_id;
#ifdef TART_UTF8
#include <wchar.h>
#undef t_char
typedef wchar_t t_char;
#else
typedef char t_char;
#endif
typedef struct {
tart_byte r;
tart_byte g;
tart_byte b;
} tart_color;
#ifndef TART_PALET_SIZE
#define TART_PALET_SIZE 32
#endif
typedef struct {
tart_color forground;
tart_color background;
} tart_pallet;
typedef struct {
int x;
int y;
} tart_vec2;
#ifdef TART_UTF8
#define TART_CELL_SIZE 36 * 2
#else
#define TART_CELL_SIZE 26 + 19
#endif
typedef unsigned int tart_uint;
typedef unsigned int tart_style;
typedef char tart_cell[TART_CELL_SIZE];
typedef struct {
tart_cell** buffer;
tart_vec2 curser;
tart_vec2 jump;
tart_uint bufferSize;
int fd;
}tart_buffer;
/* Tart Window
*
* The tart window will have the window size and all of the buffers.
**/
typedef struct {
tart_pallet pallet[TART_PALET_SIZE];
tart_vec2 homePosition;
tart_vec2 windowSize;
tart_vec2 terminalSize;
tart_buffer buffer;
const char* name;
}tart_window ;
#define TART_OK 0
#define TART_NG -1
#define TART_SET_FLAG(f,x) f |= (x)
#define TART_STYLE_BOLD 1
#define TART_STYLE_DIM 2
#define TART_STYLE_ITALIC 3
#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_STYLE_NONE 0
#define TART_STYLE_BOLD 1 << 0
#define TART_STYLE_DIM 1 << 1
#define TART_STYLE_ITALIC 1 << 2
#define TART_STYLE_UNDERLINE 1 << 3
#define TART_STYLE_BLINKING 1 << 4
#define TART_STYLE_INVERSE 1 << 5
#define TART_STYLE_HIDDEN 1 << 6
#define TART_STYLE_STRIKETHROUGH 1 << 7
#define TART_STYLE_DRAW_BOLD 1
#define TART_STYLE_DRAW_DIM 2
#define TART_STYLE_DRAW_ITALIC 3
#define TART_STYLE_DRAW_UNDERLINE 4
#define TART_STYLE_DRAW_BLINKING 5
#define TART_STYLE_DRAW_INVERSE 7
#define TART_STYLE_DRAW_HIDDEN 8
#define TART_STYLE_DRAW_STRIKETHROUGH 9
#define TART_COLOR_BLACK_FOREGROUND 30
#define TART_COLOR_RED_FOREGROUND 31
@@ -80,152 +139,58 @@ typedef char tart_display;
#define TART_COLOR_BRIGHT_CYAN_BACKGROUND 106
#define TART_COLOR_BRIGHT_WHITE_BACKGROUND 107
typedef unsigned char tart_byte;
typedef unsigned short tart_id;
#define T ""
#define TC(x) x
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
#define t_strlen strlen
#define t_strcmp strcmp
#define t_strcpy strcpy
#define t_strncpy strncpy
#define t_snprintf snprintf
#define t_sprintf sprintf
#define t_vsprintf vsprintf
#define t_vsnprintf vsnprintf
#ifdef TART_UTF8
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char[2] display;
};
#endif
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char display;
struct tart_vec2 screen_pos;
};
#undef T
#define T L""
#undef TC
#define TC(x) L##x
#undef t_strlen
#define t_strlen wcslen
#undef t_strcmp
#define t_strcmp wcscmp
#undef t_snprintf
#define t_snprintf swprintf
#undef t_sprintf
#define t_sprintf wprintf
#undef t_vsprintf
#define t_vsprintf vswprintf
#undef t_vsnprintf
#define t_vsnprintf vswprintf
#undef t_strcpy
#define t_strcpy wcscpy
#undef t_strncpy
#define t_strncpy wcncpy
#endif
struct tart_cstring {
struct tart_cell* data;
long size;
};
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title);
int tart_init(tart_window* w);
int tart_close(tart_window* w);
void tart_disable_cusor();
void tart_enable_cusor();
int tart_draw(tart_window* w);
struct tart_csprite {
struct tart_cell* data;
struct tart_vec2* position;
struct tart_vec2 bounds;
long size;
};
/* 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;
unsigned int current_idx;
};
/* 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();
void tart_destroy_window(struct tart_window* window);
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position);
tart_byte tart_restore_window(struct tart_window*);
#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_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*.
*/
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);
int tart_jump(tart_window* w, tart_vec2 pos);
int tart_move_cursor(tart_window* w, tart_vec2 pos);
int tart_insert_cell(tart_window* w, tart_byte p, t_char c);
int tart_printf(tart_window* w,tart_byte p, const t_char* c, ...);
int tart_box(tart_window* w, tart_byte bp, tart_byte fp, const t_char* c,
tart_vec2 fpos,
tart_vec2 spos);
int tart_line(tart_window* w, tart_byte p, const t_char* c, tart_vec2 fpos,
tart_vec2 spos);
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*);
// 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*);
#ifdef __cplusplus
}