diff --git a/source/tart.c b/source/tart.c index eaa7c0b..4096580 100644 --- a/source/tart.c +++ b/source/tart.c @@ -77,26 +77,41 @@ 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 p = 0; + 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++) { - for (int y = 0; y < window->size.y; y++) { - for (int x = 0; x < window->size.x; x++) { - for (int p = 0; p < TART_CELL_DATA_SIZE;p++) { + if(window->buffers[b].cell_count == 0) + continue; + for (int y = 0; y < window->buffers[b].size.y; y++) { + 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]; + 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]; + offset++; - i++; } } + window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n'; + offset++; + + // add cursor move command. i++; } } - printf(window->data); + fwrite(window->data, sizeof(char), (window->size.x * window->size.y * sizeof(char))+ 100 , stdout); + free(window->data); return TART_OK; }; tart_byte tart_add_cells_to_buffer(struct tart_buffer* buffer, struct tart_cell* cells) { + for(int i = 0; i < buffer->cell_count; i++) { + buffer->cells[i] = cells[i]; + } return TART_OK; } diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index a310f3d..d38bd13 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -25,3 +25,4 @@ set( CMAKE_CXX_STANDARD 11) set( CMAKE_CXX_STANDARD_REQUIRED ON) add_executable(${PROJECT_NAME} input.cpp ) target_link_libraries(${PROJECT_NAME} TartLib PickleLib) +add_subdirectory(render_test) diff --git a/testing/render_test/CMakeLists.txt b/testing/render_test/CMakeLists.txt new file mode 100644 index 0000000..284f22d --- /dev/null +++ b/testing/render_test/CMakeLists.txt @@ -0,0 +1,7 @@ +set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/tests) +project(render_test) + +set( CMAKE_CXX_STANDARD 11) +set( CMAKE_CXX_STANDARD_REQUIRED ON) +add_executable(${PROJECT_NAME} main.cpp ) +target_link_libraries(${PROJECT_NAME} TartLib) diff --git a/testing/render_test/main.cpp b/testing/render_test/main.cpp new file mode 100644 index 0000000..0875d57 --- /dev/null +++ b/testing/render_test/main.cpp @@ -0,0 +1,20 @@ +#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); + } + 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); + } + tart_add_cells_to_buffer(&mainbuff, cells); + + char* t; + tart_add_buffer(&window, mainbuff); + tart_draw_window(&window, t); + + return 0; +}