Files
Tart/source/tart.c

75 lines
2.4 KiB
C
Raw Normal View History

2025-01-28 13:36:01 -08:00
#include "../includes/tart.h"
2025-01-31 21:25:55 -08:00
#include <stdio.h>
2025-01-28 21:01:24 -08:00
#include <stdlib.h>
2025-01-31 21:25:55 -08:00
#include <memory.h>
2025-01-29 10:51:20 -08:00
#include "term.h"
2025-01-28 12:11:56 -08:00
struct tart_cell tart_test() {
2025-02-01 12:49:17 -08:00
#ifdef TART_RGB_COLORS
return (struct tart_cell){{0,0,0}, {0,0,0}, 0, 't',0};
#else
return (struct tart_cell){0,0,0,0,0};
#endif
2025-01-28 12:11:56 -08:00
}
2025-01-28 21:01:24 -08:00
struct tart_window tart_create_window() {
struct tart_window window;
window.buffer_count = 0;
for(int i = 0; i < 0xFF; i++) {
2025-01-29 10:51:20 -08:00
window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},(struct tart_vec2){0,0});
2025-01-28 21:01:24 -08:00
}
2025-01-29 10:51:20 -08:00
window.size = term_current_size();
2025-01-28 21:01:24 -08:00
return window;
}
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position) {
2025-02-01 12:49:17 -08:00
unsigned int cell_count = size.x * size.y;
2025-01-28 21:01:24 -08:00
struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell));
2025-01-31 21:25:55 -08:00
struct tart_cell cell = NULL_CELL;
2025-02-01 12:49:17 -08:00
char* data = (char*)malloc((size.x*size.y) * (sizeof(char) * TART_CELL_DATA_SIZE));
unsigned int data_count = (size.x*size.y) * TART_CELL_DATA_SIZE;
struct tart_buffer buf = {cell_count,0,id,size,position,cells, data, data_count}; // -NOTE- dose not set the layer
return buf;
}
2025-01-31 21:25:55 -08:00
#ifdef TART_RGB_COLORS
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background) {
2025-02-01 12:49:17 -08:00
struct tart_cell b = {foreground, background, style, display,0};
2025-01-28 12:11:56 -08:00
return b;
}
2025-01-31 21:25:55 -08:00
#else
2025-02-01 12:49:17 -08:00
struct tart_cell tart_create_cell(char display, tart_byte style,
tart_byte foreground, tart_byte background) {
2025-01-31 21:25:55 -08:00
return (struct tart_cell){foreground,background,style,display,0};
}
#endif
tart_byte tart_add_buffer(struct tart_window* window, struct tart_buffer buffer) {
2025-01-31 21:25:55 -08:00
if(window->buffer_count <= 0xFF) {
window->buffers[window->buffer_count] = buffer;
window->buffer_count++;
return window->buffer_count;
}
return 0;
}
tart_byte tart_set_buffer(struct tart_window* window, struct tart_buffer buffer, tart_byte layer) {
if(layer <= 0xFF) {
window->buffers[layer] = buffer;
return layer;
}
return 0;
}
struct tart_buffer* tart_get_buffer(struct tart_window* window, tart_byte layer) {
return &window->buffers[layer];
}
struct tart_cell* tart_get_cell(struct tart_buffer* buffer, int idx) {
return &buffer->cells[idx];
}
2025-01-28 21:01:24 -08:00
struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell,int idx) {
2025-01-29 10:51:20 -08:00
struct tart_cell c = buffer->cells[idx];
2025-01-28 21:01:24 -08:00
buffer->cells[idx] = cell;
2025-01-29 10:51:20 -08:00
return c;
}
2025-01-31 21:25:55 -08:00