cstring and csprite are working

This commit is contained in:
2025-02-18 15:28:17 -08:00
parent 993330a3a4
commit a77df22ffe
5 changed files with 46 additions and 41 deletions

31
;
View File

@@ -1,31 +0,0 @@
#include <tart.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
struct tart_window window = tart_create_window();
struct tart_buffer mainbuff = tart_create_buffer(109, {20,20},{20,20});
struct tart_cell* cells = (struct tart_cell*)malloc(mainbuff.cell_count * sizeof(struct tart_cell));
//for(int i = 1; i < mainbuff.cell_count; i += 2) {
// cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND);
//}
//for(int i = 0; i < + mainbuff.cell_count; i += 2) {
// cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_BLACK_BACKGROUND);
//}
tart_add_cells_to_buffer(&mainbuff, cells);
struct tart_vec2 positions[4] = {{0,0},{0,1},{1,0},{1,1}};
struct tart_cell cell = tart_create_cell('0', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_GREEN_BACKGROUND);
struct tart_cell cellss[4] = {cell,cell,cell,cell};
struct tart_csprite sprite = tart_csprite(cellss,positions,4);
tart_draw_cell_position(&mainbuff, cell, {3,3});
//tart_draw_csprite_position(&mainbuff, sprite, {2,2});
char t[1] = {'0'};
tart_add_buffer(&window, mainbuff);
tart_draw_window(&window, t);
return 0;
}

View File

@@ -159,6 +159,7 @@ struct tart_window {
struct tart_window tart_create_window();
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position);
tart_byte tart_restore_window(struct tart_window*);
#ifdef TART_RGB_COLORS
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background);

View File

@@ -26,6 +26,13 @@ struct tart_window tart_create_window() {
return window;
}
tart_byte tart_restore_window(struct tart_window* window) {
for (int i = 0; i < window->data_count; i++) {
window->data[i] = '\0';
}
return TART_OK;
}
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;
@@ -37,6 +44,7 @@ struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct
unsigned int data_count = (size.x*size.y) * TART_CELL_DATA_SIZE;
struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer
buf.cell_count = cell_count;
return buf;
}
#ifdef TART_RGB_COLORS
@@ -174,7 +182,7 @@ 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) {
if(buffer->size.x > position.x && buffer->size.y > position.y) {
buffer->cells[(buffer->size.x * position.y) + position.x] = cell;
}
return TART_OK;
@@ -198,5 +206,8 @@ 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;
}
return TART_OK;
}

View File

@@ -170,9 +170,9 @@ char term_tinput() {
return __term_input_buffer__[0];
}
void term_disable_cursor() {
fputs("\033[?25l", stdout);
printf("\033[?25l", stdout);
}
void term_enable_cursor() {
fputs("\033[?25h", stdout);
printf("\033[?25h", stdout);
}

View File

@@ -5,7 +5,7 @@
int main (int argc, char *argv[]) {
struct tart_window window = tart_create_window();
struct tart_buffer mainbuff = tart_create_buffer(109, {20,20},{20,20});
struct tart_buffer mainbuff = tart_create_buffer(109, {40,20},{20,20});
struct tart_cell* cells = (struct tart_cell*)malloc(mainbuff.cell_count * sizeof(struct tart_cell));
for(int i = 1; i < mainbuff.cell_count; i += 2) {
cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND);
@@ -15,7 +15,7 @@ int main (int argc, char *argv[]) {
}
tart_add_cells_to_buffer(&mainbuff, cells);
struct tart_vec2 positions[4] = {{0,0},{0,1},{1,0},{3,2}};
struct tart_vec2 positions[4] = {{0,0},{0,1},{1,0},{1,1}};
struct tart_cell cell = tart_create_cell('0', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_GREEN_BACKGROUND);
struct tart_cell cellss[4] = {cell,cell,cell,cell};
@@ -23,11 +23,35 @@ int main (int argc, char *argv[]) {
tart_draw_csprite_position(&mainbuff, sprite, {2,2});
tart_draw_csprite_position(&mainbuff, sprite, {5,2});
tart_draw_csprite_position(&mainbuff, sprite, {5,5});
tart_draw_csprite_position(&mainbuff, sprite, {21,18});
char t[1] = {'0'};
tart_add_buffer(&window, mainbuff);
tart_draw_window(&window, t);
tart_draw_csprite_position(&mainbuff, sprite, {39,18});
float x = 0;
tart_byte layer = tart_add_buffer(&window, mainbuff);
char t[1] = {'0'};
struct tart_vec2 p = {0,0};
term_disable_cursor();
term_threaded_input_init();
for(;;) {
// printf("\033[H");
// struct tart_buffer* buf = tart_get_buffer(&window, 0);
// tart_draw_csprite_position(buf, sprite, {3,18});
// tart_draw_csprite_position(buf, sprite, p);
// //tart_draw_window(&window, t);
// tart_restore_window(&window);
// tart_restore_buffer(buf);
// if(term_tinput() == 's') {
// x += 0.01;
// }
if(term_tinput() == 'q') {
term_threaded_input_stop();
break;
}
// p.x = (int)x;
}
term_disable_cursor();
term_enable_cursor();
//term_getche();
term_threaded_input_stop();
return 0;
}