diff --git a/includes/tart.h b/includes/tart.h index f4056fa..65c8577 100644 --- a/includes/tart.h +++ b/includes/tart.h @@ -25,7 +25,7 @@ extern "C" { #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 +#define TART_CELL_DATA_SIZE 20 #endif #define TART_OK 0 diff --git a/source/tart.c b/source/tart.c index ee7b54b..e54c4a7 100644 --- a/source/tart.c +++ b/source/tart.c @@ -18,6 +18,11 @@ struct tart_window tart_create_window() { window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},(struct tart_vec2){0,0}); } window.size = term_current_size(); + window.data = malloc((window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100 ); + for(int g = 0; g < (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100; g++) { + window.data[g] = '\0'; + } + window.data_count = (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100; return window; } @@ -79,7 +84,6 @@ struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { int offset = 0; int i = 0; - window->data = malloc((window->size.x * window->size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100 ); for (int b = 0;b < 0xFF; b++) { if(window->buffers[b].cell_count == 0) continue; @@ -87,7 +91,7 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { for (int x = 0; x < window->buffers[b].size.x; x++) { // add data to window c buffer. struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x]; - char pre[16]; + char pre[TART_CELL_DATA_SIZE]; int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m", (int)cell.style, cell.foreground, cell.background, cell.display); for(int preIdx = 0; preIdx < size; preIdx++) { window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx]; @@ -103,8 +107,7 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { i++; } } - fwrite(window->data, sizeof(char), (window->size.x * window->size.y * sizeof(char))+ 100 , stdout); - free(window->data); + fwrite(window->data, sizeof(char), window->data_count, stdout); return TART_OK; }; diff --git a/testing/render_test/main.cpp b/testing/render_test/main.cpp index 0875d57..420e6dc 100644 --- a/testing/render_test/main.cpp +++ b/testing/render_test/main.cpp @@ -1,18 +1,21 @@ #include +#include +#include +#include int main (int argc, char *argv[]) { struct tart_window window = tart_create_window(); - struct tart_buffer mainbuff = tart_create_buffer(109, {20,20},{20,20}); - struct tart_cell cells[20*20]; - for(int i = 1; i < 20*20; i += 2) { - cells[i] = tart_create_cell('^', TART_STYLE_BOLD, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND); + struct tart_buffer mainbuff = tart_create_buffer(109, {100,50},{20,20}); + struct tart_cell* cells = (struct tart_cell*)malloc(mainbuff.cell_count * sizeof(struct tart_cell)); + for(int i = 1; i < mainbuff.cell_count; i += 2) { + cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND); } - for(int i = 0; i < + 20*20; i += 2) { - cells[i] = tart_create_cell('^', TART_STYLE_BOLD, TART_COLOR_WHITE_BACKGROUND, TART_COLOR_BLACK_BACKGROUND); + for(int i = 0; i < + mainbuff.cell_count; i += 2) { + cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_BLACK_BACKGROUND); } tart_add_cells_to_buffer(&mainbuff, cells); - char* t; + char t[1] = {'0'}; tart_add_buffer(&window, mainbuff); tart_draw_window(&window, t);