Compare commits

...

2 Commits

2 changed files with 111 additions and 0 deletions

View File

@@ -109,6 +109,18 @@ struct tart_cell {
};
#endif
struct tart_cstring {
struct tart_cell* data;
long size;
};
struct tart_csprite {
struct tart_cell* data;
struct tart_vec2* position;
struct tart_vec2 bounds;
long size;
};
/* Tart Buffer
*
* The Buffer is a contner that holds all of the cells for that buffer.
@@ -158,6 +170,7 @@ tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer);
tart_byte tart_remove_buffer(struct tart_window*, tart_id);
tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte);
struct tart_buffer* tart_get_buffer(struct tart_window*, tart_byte);
struct tart_cell* tart_get_cell(struct tart_buffer*, int);
@@ -167,6 +180,23 @@ tart_byte tart_draw_window(struct tart_window*, char*);
tart_byte tart_add_cells_to_buffer(struct tart_buffer*, struct tart_cell*);
// rendering
// Resering positionial cells.
struct tart_cstring tart_cstring(char* string, long, struct tart_cell type);
tart_byte tart_cstring_free(struct tart_cstring*);
struct tart_cstring tart_cstring_append(struct tart_cstring*, struct tart_cstring*);
struct tart_csprite tart_csprite(struct tart_cell*, struct tart_vec2*, long);
tart_byte tart_csprite_free(struct tart_csprite*);
tart_byte tart_draw_cell_position(struct tart_buffer*, struct tart_cell, struct tart_vec2);
tart_byte tart_draw_cstring_position(struct tart_buffer*, struct tart_cstring, struct tart_vec2);
tart_byte tart_draw_csprite_position(struct tart_buffer*, struct tart_csprite, struct tart_vec2);
/*
* tart_restore_buffer sets the buffer to NULL_CELL.
* */
tart_byte tart_restore_buffer(struct tart_buffer*);
#ifdef __cplusplus
}
#endif

View File

@@ -118,3 +118,84 @@ tart_byte tart_add_cells_to_buffer(struct tart_buffer* buffer, struct tart_cell*
return TART_OK;
}
struct tart_cstring tart_cstring(char *string, long size, struct tart_cell type){
struct tart_cstring str = {0,size};
str.data = malloc(size * sizeof(struct tart_cell));
return str;
}
tart_byte tart_cstring_free(struct tart_cstring* string) {
free(string->data);
string->size = 0;
return TART_OK;
}
struct tart_cstring tart_cstring_append(struct tart_cstring* lhs, struct tart_cstring* rhs) {
struct tart_cstring ret = {0,0};
ret.size = lhs->size + rhs->size;
ret.data = malloc(ret.size * sizeof(struct tart_cell));
for(int i = 0; i < lhs->size; i++) {
ret.data[i] = lhs->data[i];
}
for(int i = 0; i < rhs->size; i++) {
ret.data[lhs->size + i] = rhs->data[i];
}
return ret;
}
struct tart_csprite tart_csprite(struct tart_cell* cells, struct tart_vec2* positions, long size) {
struct tart_csprite sprite = {0,0,0,size};
sprite.data = cells;
sprite.position = positions;
for(int i = 0; i < size; i++) {
if(positions[i].x > sprite.bounds.x) {
sprite.bounds.x = positions[i].x;
}
if(positions[i].y > sprite.bounds.y) {
sprite.bounds.y = positions[i].y;
}
}
return sprite;
};
tart_byte tart_csprite_free(struct tart_csprite* sprite) {
sprite->bounds.x = 0;
sprite->bounds.y = 0;
sprite->size = 0;
free(sprite->data);
free(sprite->position);
return TART_OK;
}
tart_byte tart_draw_cell_position(struct tart_buffer * buffer, struct tart_cell cell, struct tart_vec2 position) {
if(buffer->size.y >= position.y && buffer->size.x >= position.x) {
buffer->cells[(buffer->size.x * position.y) + position.x] = cell;
}
return TART_OK;
}
tart_byte tart_draw_cstring_position(struct tart_buffer *buffer, struct tart_cstring string, struct tart_vec2 position) {
struct tart_vec2 pos = position;
for(int i = 0; i < string.size; i++) {
tart_draw_cell_position(buffer, string.data[i], pos);
pos.x++;
}
return TART_OK;
}
tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_csprite sprite, struct tart_vec2 basePosition) {
for(int i = 0; i < sprite.size; i++) {
struct tart_vec2 position = {sprite.position[i].x + basePosition.x, sprite.position[i].y + basePosition.y};
tart_draw_cell_position(buffer, sprite.data[i], position);
}
return TART_OK;
}
tart_byte tart_restore_buffer(struct tart_buffer *buffer) {
return TART_OK;
}