added tart main tools

This commit is contained in:
2025-01-28 21:01:24 -08:00
parent f73586a28d
commit 569ea396c0
7 changed files with 108 additions and 19 deletions

View File

@@ -14,6 +14,8 @@
// | over each cell.
// #========================================================================#
#define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0}
typedef unsigned char tart_byte;
typedef unsigned short tart_id;
@@ -72,6 +74,7 @@ struct tart_window {
tart_byte buffer_count;
};
struct tart_window tart_create_window();
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position);
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background);
tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer);
@@ -80,6 +83,6 @@ 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);
struct tart_cell* tart_set_cell(struct tart_buffer*, struct tart_cell*,int);
struct tart_cell tart_set_cell(struct tart_buffer*, struct tart_cell,int);
#endif

View File

@@ -1,13 +1,23 @@
#include "../includes/tart.h"
#include <malloc.h>
#include <stdlib.h>
struct tart_cell tart_test() {
return (struct tart_cell){{0,0,0}, {0,0,0}, 0, 't'};
}
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, {0,0}, {0,0});
}
return window;
}
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position) {
unsigned int cell_count = position.x * position.y;
struct tart_cell* cells = (struct tart_cell*)malloc(sizeof(struct tart_cell[cell_count]));
struct tart_buffer buf = {cell_count,0,id,size,position,0};
struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell));
tart_cell cell = NULL_CELL;
struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer
return buf;
}
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background) {
@@ -15,12 +25,9 @@ struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb
return b;
}
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++;
return window->buffer_count;
}
return 0;
window->buffers[window->buffer_count] = buffer;
window->buffer_count++;
return window->buffer_count;
}
tart_byte tart_set_buffer(struct tart_window* window, struct tart_buffer buffer, tart_byte layer) {
if(layer <= 0xFF) {
@@ -37,10 +44,8 @@ struct tart_buffer* tart_get_buffer(struct tart_window* window, tart_byte layer)
struct tart_cell* tart_get_cell(struct tart_buffer* buffer, int idx) {
return &buffer->cells[idx];
}
struct tart_cell* tart_set_cell(struct tart_buffer* buffer, struct tart_cell* cell,int idx) {
if(buffer->cell_count >= idx) {
buffer->cells[idx] = *cell;
return cell;
}
return 0;
struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell,int idx) {
buffer->cells[idx] = cell;
return NULL_CELL;
}

0
source/term.cpp Normal file
View File

8
source/term.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef TERM_H
#define TERM_H
#include "tart.h"
int tart_draw(struct tart_window);
int tart_draw_buffer(struct tart_buffer);
#endif

View File

@@ -0,0 +1 @@
---

View File

@@ -0,0 +1,3 @@
Start testing: Jan 28 14:11 Pacific Standard Time (Mexico)
----------------------------------------------------------
End testing: Jan 28 14:11 Pacific Standard Time (Mexico)

View File

@@ -1,5 +1,6 @@
#include "test_tart.h"
#include "../includes/tart.h"
#include "Pickler.h"
bool rgb_test(struct tart_rgb* lhs, struct tart_rgb* rhs) {
if(lhs->r != rhs->r) {return false;}
if(lhs->g != rhs->g) {return false;}
@@ -55,14 +56,82 @@ void tart_run(struct pickle_shelf* shelf) {
ASSERT("GOOD",true);
}();
PICKLE(Test_Add_buffer) {
PICKLE(Test_create_window) {
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
ASSERT("GOOD",true);
struct tart_window window = tart_create_window();
for(int i = 0; i < 0xFF + 1; i++) {
if(DIFFERENT(window.buffers[i].id, 0))
ASSERT("buffer not same", false);
}
ASSERT("GOOD", true);
}();
PICKLE(Test_add_buffer) {
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
struct tart_window window = tart_create_window();
tart_add_buffer(&window, buffer);
if(SAME(window.buffer_count, 0))
ASSERT("index has not indexed", false);
if(DIFFERENT(window.buffers[0].id, buffer.id))
ASSERT("buffer not same", false);
ASSERT("GOOD", true);
}();
PICKLE(Test_set_buffer) {
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
struct tart_window window = tart_create_window();
tart_set_buffer(&window, buffer, 0);
if(DIFFERENT(window.buffers[0].id, buffer.id))
ASSERT("buffer not same", false);
ASSERT("GOOD", true);
}();
PICKLE(Test_get_buffer) {
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
struct tart_window window = tart_create_window();
tart_set_buffer(&window, buffer, 0);
if(DIFFERENT(tart_get_buffer(&window, 0)->id, buffer.id))
ASSERT("buffer not same", false);
ASSERT("GOOD", true);
}();
PICKLE(Test_set_cell) {
tart_rgb foreground = {90,90,90};
tart_rgb background = {80,80,80};
struct tart_cell cell = tart_create_cell('0',10,foreground, background);
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20});
struct tart_window window = tart_create_window();
tart_set_cell(&buffer, cell, 0);
if(DIFFERENT(buffer.cells[0].display, cell.display))
ASSERT("buffer not same", false);
ASSERT("GOOD", true);
}();
PICKLE(Test_get_cell) {
tart_rgb foreground = {90,90,90};
tart_rgb background = {80,80,80};
struct tart_cell cell = tart_create_cell('0',10,foreground, background);
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20});
struct tart_window window = tart_create_window();
tart_set_cell(&buffer, cell, 0);
if(DIFFERENT(tart_get_cell(&buffer,0)->display, cell.display))
ASSERT("buffer not same", false);
ASSERT("GOOD", true);
}();
ADDPICKLE(tart_objects_test,Test_create_buffer);
ADDPICKLE(tart_objects_test,Test_create_cell);
ADDPICKLE(tart_objects_test,Test_create_buffer);
ADDPICKLE(tart_objects_test,Test_add_buffer);
ADDPICKLE(tart_objects_test,Test_set_buffer);
ADDPICKLE(tart_objects_test,Test_get_buffer);
ADDPICKLE(tart_objects_test,Test_set_cell);
ADDPICKLE(tart_objects_test,Test_get_cell);
PUTJARONSHELF(tart_objects_test);
*shelf = __pickle_shelf__;
}