Compare commits

...

2 Commits

Author SHA1 Message Date
0a8c4eed82 fixed merge conflix 2025-06-06 11:13:21 -07:00
b2839b4cd1 Did some formatting and added more docs to the tart.h file 2025-06-06 11:08:10 -07:00
3 changed files with 34 additions and 11 deletions

View File

@@ -24,5 +24,5 @@ enable_testing()
add_subdirectory(externals)
# PROJECT
add_subdirectory(source)
add_subdirectory(testing)
#add_subdirectory(testing)

View File

@@ -167,8 +167,22 @@ struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb
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);

View File

@@ -15,14 +15,19 @@ struct tart_window tart_create_window() {
struct tart_window window;
window.buffer_count = 0;
for(int i = 0; i < 0xFF; i++) {
window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},(struct tart_vec2){0,0});
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++) {
int dataSize = (window.size.x * window.size.y * sizeof(char) *
TART_CELL_DATA_SIZE) + 100;
window.data = malloc(dataSize);
for(int g = 0; g < dataSize; g++) {
window.data[g] = '\0';
}
window.data_count = (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100;
window.data_count = dataSize;
return window;
}
@@ -33,10 +38,11 @@ tart_byte tart_restore_window(struct tart_window* window) {
return TART_OK;
}
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 = 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(cell_count * sizeof(struct tart_cell));
for (int i = 0;i < cell_count;i++) {
cells[i] = NULL_CELL;
@@ -59,7 +65,8 @@ struct tart_cell tart_create_cell(char display, tart_byte style,
return (struct tart_cell){foreground,background,style,display};
}
#endif
tart_byte tart_add_buffer(struct tart_window* window, struct tart_buffer buffer) {
tart_byte tart_add_buffer(struct tart_window* window,
struct tart_buffer buffer) {
if(window->buffer_count <= 0xFF) {
window->buffers[window->buffer_count] = buffer;
window->buffer_count++;
@@ -102,11 +109,13 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) {
// add data to window c buffer.
struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x];
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) - 1;
// puts cell drawing data in pre
int size = sprintf(pre, "\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[(y * bufferWidth) + x + offset] = pre[preIdx];
window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx];
offset++;
}
}
//window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n';