Added rgb build option/definition

This commit is contained in:
2025-02-01 12:49:17 -08:00
parent 3040b8ac5a
commit 4d81feab16
3 changed files with 48 additions and 35 deletions

View File

@@ -20,7 +20,13 @@ extern "C" {
// | over each cell. // | 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,0} #define NULL_CELL (struct tart_cell){0,0,0,0,0}
#define TART_CELL_DATA_SIZE 16
#endif
#define TART_OK 0 #define TART_OK 0
@@ -127,6 +133,8 @@ struct tart_buffer {
struct tart_vec2 size; struct tart_vec2 size;
struct tart_vec2 position; struct tart_vec2 position;
struct tart_cell* cells; struct tart_cell* cells;
char* data;
int data_count;
}; };
/* Tart Window /* Tart Window
@@ -149,6 +157,7 @@ struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreg
#endif #endif
tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer); 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); 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_buffer* tart_get_buffer(struct tart_window*, tart_byte);

View File

@@ -5,7 +5,11 @@
#include "term.h" #include "term.h"
struct tart_cell tart_test() { struct tart_cell tart_test() {
return (struct tart_cell){{0,0,0}, {0,0,0}, 0, 't'}; #ifdef TART_RGB_COLORS
return (struct tart_cell){{0,0,0}, {0,0,0}, 0, 't',0};
#else
return (struct tart_cell){0,0,0,0,0};
#endif
} }
struct tart_window tart_create_window() { struct tart_window tart_create_window() {
struct tart_window window; struct tart_window window;
@@ -18,20 +22,23 @@ struct tart_window tart_create_window() {
} }
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position) { struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position) {
unsigned int cell_count = position.x * position.y; unsigned int cell_count = size.x * size.y;
struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell)); struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell));
memset(&cells,0, size.x * size.y);
struct tart_cell cell = NULL_CELL; struct tart_cell cell = NULL_CELL;
struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer char* data = (char*)malloc((size.x*size.y) * (sizeof(char) * TART_CELL_DATA_SIZE));
unsigned int data_count = (size.x*size.y) * TART_CELL_DATA_SIZE;
struct tart_buffer buf = {cell_count,0,id,size,position,cells, data, data_count}; // -NOTE- dose not set the layer
return buf; return buf;
} }
#ifdef TART_RGB_COLORS #ifdef TART_RGB_COLORS
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background) { struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background) {
struct tart_cell b = {foreground, background, style, display}; struct tart_cell b = {foreground, background, style, display,0};
return b; return b;
} }
#else #else
struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreground, tart_byte background) {
struct tart_cell tart_create_cell(char display, tart_byte style,
tart_byte foreground, tart_byte background) {
return (struct tart_cell){foreground,background,style,display,0}; return (struct tart_cell){foreground,background,style,display,0};
} }
#endif #endif
@@ -65,24 +72,3 @@ struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell
return c; return c;
} }
int render_cell(struct tart_cell* cell, char* cell_buffer, unsigned char buffer_size) {
unsigned char cell_size = 10;
#ifdef TART_RGB_PALET
sprintf(cell_buffer, "\x1b[%i;%i;%im%c\x1b[0m",cell->style, cell->foreground.r, cell->background.r, cell->display);
#endif
return TART_OK;
}
int tart_render(struct tart_buffer* buffer) {
for(int i = 0; i < buffer->cell_count; i++) {
for(int y = 0; y < buffer->size.x; y++) {
for(int x = 0; x < buffer->size.x; x++) {
}
}
}
return 0;
}

View File

@@ -17,9 +17,14 @@ void tart_run(struct pickle_shelf* shelf) {
pickle_shelf __pickle_shelf__ = *shelf; pickle_shelf __pickle_shelf__ = *shelf;
CREATEJAR(tart_objects_test); CREATEJAR(tart_objects_test);
PICKLE(Test_create_buffer) { PICKLE(Test_create_buffer) {
tart_vec2 size = {25,25};
tart_vec2 position = {0,0};
struct tart_buffer buffer_correct = {0,0,25,{20,20},{0,0}, 0}; int data_count = (size.x*size.y) * TART_CELL_DATA_SIZE;
struct tart_buffer buffer_test = tart_create_buffer(25,{20,20},{0,0});
unsigned int cell_count = (size.x * size.y);
struct tart_buffer buffer_correct = {cell_count,0,25,size,position,0,0,data_count};
struct tart_buffer buffer_test = tart_create_buffer(25,size,position);
if(DIFFERENT(buffer_correct.cell_count,buffer_test.cell_count)) if(DIFFERENT(buffer_correct.cell_count,buffer_test.cell_count))
ASSERT("Cell count not the same.",false); ASSERT("Cell count not the same.",false);
@@ -35,16 +40,14 @@ void tart_run(struct pickle_shelf* shelf) {
ASSERT("position.x is not the same.",false); ASSERT("position.x is not the same.",false);
if(DIFFERENT(buffer_correct.position.y,buffer_test.position.y)) if(DIFFERENT(buffer_correct.position.y,buffer_test.position.y))
ASSERT("position.y is not the same.",false); ASSERT("position.y is not the same.",false);
if(DIFFERENT(buffer_correct.data_count,buffer_test.data_count))
ASSERT("data_counts are not the same.",false);
ASSERT("GOOD",true); ASSERT("GOOD",true);
}(); }();
PICKLE(Test_create_cell) { PICKLE(Test_create_cell) {
tart_byte f = 20;
tart_byte b = 40;
struct tart_cell cell_correct = {f, b, '1', 'f'};
struct tart_cell cell_test = tart_create_cell('f', '1', f, b);
#ifdef TART_RGB_COLOR #ifdef TART_RGB_COLOR
struct tart_rgb b = {80,80,80}; struct tart_rgb b = {80,80,80};
struct tart_rgb f = {80,80,80}; struct tart_rgb f = {80,80,80};
@@ -55,9 +58,13 @@ void tart_run(struct pickle_shelf* shelf) {
if(!rgb_test(&cell_correct.background, &cell_test.background)) if(!rgb_test(&cell_correct.background, &cell_test.background))
ASSERT("background dose not match.",false); ASSERT("background dose not match.",false);
#else #else
if(DIFFERENT(&cell_correct.foreground, &cell_test.foreground)) tart_byte f = 20;
tart_byte b = 40;
struct tart_cell cell_correct = {f, b, '1', 'f',0};
struct tart_cell cell_test = tart_create_cell('f', '1', f, b);
if(DIFFERENT(cell_correct.foreground, cell_test.foreground))
ASSERT("Forground dose not match.",false); ASSERT("Forground dose not match.",false);
if(DIFFERENT(&cell_correct.background, &cell_test.background)) if(DIFFERENT(cell_correct.background, cell_test.background))
ASSERT("background dose not match.",false); ASSERT("background dose not match.",false);
#endif #endif
if(DIFFERENT(cell_correct.style, cell_test.style)) if(DIFFERENT(cell_correct.style, cell_test.style))
@@ -106,9 +113,14 @@ void tart_run(struct pickle_shelf* shelf) {
}(); }();
PICKLE(Test_set_cell) { PICKLE(Test_set_cell) {
#ifdef TART_RGB_COLORS
tart_rgb foreground = {90,90,90}; tart_rgb foreground = {90,90,90};
tart_rgb background = {80,80,80}; tart_rgb background = {80,80,80};
#else
tart_byte foreground = 9;
tart_byte background = 8;
#endif
struct tart_cell cell = tart_create_cell('0',10,foreground, background); struct tart_cell cell = tart_create_cell('0',10,foreground, background);
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20}); struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20});
struct tart_window window = tart_create_window(); struct tart_window window = tart_create_window();
@@ -120,9 +132,15 @@ void tart_run(struct pickle_shelf* shelf) {
}(); }();
PICKLE(Test_get_cell) { PICKLE(Test_get_cell) {
#ifdef TART_RGB_COLORS
tart_rgb foreground = {90,90,90}; tart_rgb foreground = {90,90,90};
tart_rgb background = {80,80,80}; tart_rgb background = {80,80,80};
#else
tart_byte foreground = 9;
tart_byte background = 8;
#endif
struct tart_cell cell = tart_create_cell('0',10,foreground, background); struct tart_cell cell = tart_create_cell('0',10,foreground, background);
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20}); struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20});
struct tart_window window = tart_create_window(); struct tart_window window = tart_create_window();