From 58d3ec9e71b6f9c56c3acc48ba8fbb1d1ee412e5 Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Wed, 29 Jan 2025 10:51:20 -0800 Subject: [PATCH] testing on linux --- includes/tart.h | 5 +++-- source/CMakeLists.txt | 10 +++++++--- source/{tart.cpp => tart.c} | 9 ++++++--- source/term.c | 21 +++++++++++++++++++++ source/term.cpp | 0 source/term.h | 12 ++++++++++-- testing/CMakeLists.txt | 3 ++- testing/test_tart.h | 2 +- 8 files changed, 50 insertions(+), 12 deletions(-) rename source/{tart.cpp => tart.c} (83%) create mode 100644 source/term.c delete mode 100644 source/term.cpp diff --git a/includes/tart.h b/includes/tart.h index 5cb0535..618e798 100644 --- a/includes/tart.h +++ b/includes/tart.h @@ -14,13 +14,13 @@ // | over each cell. // #========================================================================# -#define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0} +#define NULL_CELL 0 typedef unsigned char tart_byte; typedef unsigned short tart_id; struct tart_vec2 { - short x,y; + unsigned short x,y; }; struct tart_rgb { @@ -72,6 +72,7 @@ struct tart_buffer { struct tart_window { struct tart_buffer buffers[0xFF+1]; tart_byte buffer_count; + struct tart_vec2 size; }; struct tart_window tart_create_window(); diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 9ceee39..2260e72 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -1,9 +1,13 @@ project(TartLib VERSION 0.1) set( CMAKE_STATIC_LIBRARY_PREFIX "") +set( CMAKE_CXX_STANDARD 11) +set( CMAKE_CXX_STANDARD_REQUIRED ON) -set(Lib_SOURCES - tart.cpp +set(LIB_SOURCES + term.c + term.h + tart.c ) -add_library(${PROJECT_NAME} STATIC tart.cpp) +add_library(${PROJECT_NAME} STATIC ${LIB_SOURCES}) target_include_directories(${PROJECT_NAME} BEFORE PUBLIC "../includes/") diff --git a/source/tart.cpp b/source/tart.c similarity index 83% rename from source/tart.cpp rename to source/tart.c index bf52eea..cd55140 100644 --- a/source/tart.cpp +++ b/source/tart.c @@ -1,5 +1,6 @@ #include "../includes/tart.h" #include +#include "term.h" struct tart_cell tart_test() { return (struct tart_cell){{0,0,0}, {0,0,0}, 0, 't'}; @@ -8,15 +9,16 @@ 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}); + window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},(struct tart_vec2){0,0}); } + window.size = term_current_size(); 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((size.x * size.y) * sizeof(struct tart_cell)); - tart_cell cell = NULL_CELL; + struct tart_cell cell = {.foreground = {0,0,0}, .background = {10,0,0}, .style = 0x0, .display = 0x0}; struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer return buf; } @@ -46,6 +48,7 @@ struct tart_cell* tart_get_cell(struct tart_buffer* buffer, int idx) { } struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell,int idx) { + struct tart_cell c = buffer->cells[idx]; buffer->cells[idx] = cell; - return NULL_CELL; + return c; } diff --git a/source/term.c b/source/term.c new file mode 100644 index 0000000..6c1e5ee --- /dev/null +++ b/source/term.c @@ -0,0 +1,21 @@ +#include "term.h" +#include "../includes/tart.h" + + +// windows only +#include +struct tart_vec2 term_current_size() { + struct tart_vec2 ret; + CONSOLE_SCREEN_BUFFER_INFO csbi; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); + unsigned int rows = (csbi.srWindow.Right - csbi.srWindow.Left + 1); + unsigned int cols = (csbi.srWindow.Bottom - csbi.srWindow.Top + 1); + + unsigned short max_short = 0XFFFF; + if(rows < max_short && cols < max_short) { + + ret = (struct tart_vec2){(unsigned short) rows ,(unsigned short) cols}; + } + + return ret; +} diff --git a/source/term.cpp b/source/term.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/term.h b/source/term.h index 54b5ded..82f00e2 100644 --- a/source/term.h +++ b/source/term.h @@ -1,8 +1,16 @@ +// #========================================================================# +// | PREACHERDHM:TERM | +// | | +// | term renders all of the data from TART. Term takes a tart_window and | +// | renders all of the buffers and cells inside the that window object. | +// | There is a draw function and a draw buffer function. | +// | | +// | Term is just a way to output the data from tart. | +// #========================================================================# #ifndef TERM_H #define TERM_H #include "tart.h" -int tart_draw(struct tart_window); -int tart_draw_buffer(struct tart_buffer); +struct tart_vec2 term_current_size(); #endif diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index f221a28..8a886ae 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -5,7 +5,8 @@ set( SOURCES main.cpp test_tart.cpp ) + add_executable(${PROJECT_NAME} ${SOURCES} ) -target_link_libraries(${PROJECT_NAME} PickleLib TartLib) +target_link_libraries(${PROJECT_NAME} TartLib PickleLib) add_test(${PROJECT_NAME} "${CMAKE_SOURCE_DIR}/bin/testing.exe") diff --git a/testing/test_tart.h b/testing/test_tart.h index dfd1eaa..ccbf5f8 100644 --- a/testing/test_tart.h +++ b/testing/test_tart.h @@ -1,4 +1,4 @@ -#include +#include "../includes/tart.h" #include bool rgb_test(struct tart_rgb* lhs, struct tart_rgb* rhs);