diff --git a/includes/tart.h b/includes/tart.h index 839d3d2..efc151f 100644 --- a/includes/tart.h +++ b/includes/tart.h @@ -118,6 +118,7 @@ struct tart_cell { tart_byte background; tart_byte style; char display; + struct tart_vec2 screen_pos; }; #endif @@ -155,6 +156,7 @@ struct tart_buffer { struct tart_vec2 size; struct tart_vec2 position; struct tart_cell* cells; + unsigned int current_idx; }; /* Tart Window diff --git a/source/tart.c b/source/tart.c index c6fb887..25f1aa8 100644 --- a/source/tart.c +++ b/source/tart.c @@ -108,43 +108,40 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { for (int b = 0;b < 0xFF; b++) { if(window->buffers[b].cell_count == 0) continue; - char bufferSetPre[16]; - int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x); - for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) { - //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx]; - window->data[offset] = bufferSetPre[preIdx]; - offset++; - } - offset++; - bufferWidth = window->buffers[b].size.x; - for (int y = 0; y < window->buffers[b].size.y; y++) { - char movePre[16]; - int moveSize = sprintf(movePre, "\033[%dB\033[%dG", 1, window->buffers[b].position.x); - for(int preIdx = 0; preIdx < moveSize; preIdx++) { - //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx]; - window->data[offset] = movePre[preIdx]; + //char bufferSetPre[16]; + //int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x); + //for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) { + // //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx]; + // window->data[offset] = bufferSetPre[preIdx]; + // offset++; + //} + // offset++; + //bufferWidth = window->buffers[b].size.x; + for (int y = 0; y < window->buffers[b].current_idx; y++) { + // add data to window c buffer. + struct tart_cell cell = window->buffers[b].cells[y]; + // puts cell drawing data in pre + + + char pre[TART_CELL_DATA_SIZE+20]; + int size = sprintf(pre, "\033[%d;%dH\033[0m\033[%d;%d;%dm%c\033[0;0m", + cell.screen_pos.y+1,cell.screen_pos.x+1, + (int)cell.style, cell.foreground, + cell.background, cell.display) -1; + for(int preIdx = 0; preIdx < size; preIdx++) { + window->data[offset] = pre[preIdx]; offset++; } - 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]; - // puts cell drawing data in pre -#ifdef TART_RGB_COLORS - char pre[TART_CELL_DATA_SIZE+4]; - int size = sprintf(pre, "\033[0m\033[38;2;%d;%d;%dm\033[0m\033[48;2;%d;%d;%dm%\033[%dmc\033[0;0m", - // TODO add rgb - (int)cell.style, cell.foreground, - cell.background, cell.display) -1; -#endif - char pre[TART_CELL_DATA_SIZE+4]; - int size = sprintf(pre, "\033[0m\033[%d;%d;%dm%c\033[0;0m", - (int)cell.style, cell.foreground, - cell.background, cell.display) -1; - for(int preIdx = 0; preIdx < size; preIdx++) { - window->data[offset] = pre[preIdx]; - offset++; - } - } + #ifdef TART_RGB_COLORS + char pre[TART_CELL_DATA_SIZE+4]; + int size = sprintf(pre, "\033[0m\033[38;2;%d;%d;%dm\033[0m\033[48;2;%d;%d;%dm%\033[%dmc\033[0;0m", + // TODO add rgb + (int)cell.style, cell.foreground, + cell.background, cell.display) -1; + #endif + + + offset++; @@ -225,7 +222,9 @@ tart_byte tart_csprite_free(struct tart_csprite* sprite) { tart_byte tart_draw_cell_position(struct tart_buffer * buffer, struct tart_cell cell, struct tart_vec2 position) { if(buffer->size.x > position.x && buffer->size.y > position.y) { - buffer->cells[(buffer->size.x * position.y) + position.x] = cell; + cell.screen_pos = position; + buffer->cells[buffer->current_idx] = cell; + buffer->current_idx++; } return TART_OK; } @@ -250,6 +249,7 @@ tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_cs tart_byte tart_restore_buffer(struct tart_buffer *buffer) { for (int i = 0; i < buffer->cell_count; i++) { buffer->cells[i] = NULL_CELL; + buffer->current_idx = 0; } return TART_OK; }