Did some formatting and added more docs to the tart.h file
This commit is contained in:
@@ -24,5 +24,5 @@ enable_testing()
|
||||
add_subdirectory(externals)
|
||||
# PROJECT
|
||||
add_subdirectory(source)
|
||||
add_subdirectory(testing)
|
||||
#add_subdirectory(testing)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
|
||||
@@ -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++;
|
||||
@@ -97,14 +104,17 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) {
|
||||
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[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];
|
||||
offset++;
|
||||
|
||||
// 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];
|
||||
// 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);
|
||||
for(int preIdx = 0; preIdx < size; 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';
|
||||
|
||||
Reference in New Issue
Block a user