Compare commits

...

7 Commits

6 changed files with 162 additions and 58 deletions

View File

@@ -24,5 +24,5 @@ enable_testing()
add_subdirectory(externals) add_subdirectory(externals)
# PROJECT # PROJECT
add_subdirectory(source) add_subdirectory(source)
add_subdirectory(testing) #add_subdirectory(testing)

View File

@@ -24,7 +24,7 @@ extern "C" {
#define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0,0} #define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0,0}
#define TART_CELL_DATA_SIZE 16 // todo add number #define TART_CELL_DATA_SIZE 16 // todo add number
#else #else
#define NULL_CELL (struct tart_cell){0,0,0,0} #define NULL_CELL (struct tart_cell){0,0,0,' '}
#define TART_CELL_DATA_SIZE 20 #define TART_CELL_DATA_SIZE 20
#endif #endif
#define TART_OK 0 #define TART_OK 0
@@ -159,6 +159,7 @@ struct tart_window {
struct tart_window tart_create_window(); 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_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 #ifdef TART_RGB_COLORS
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background); struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background);
@@ -166,8 +167,22 @@ struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb
struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreground, tart_byte background); struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreground, tart_byte background);
#endif #endif
/* tart_add_buffer
*
* This adds a buffer to the window.
*
* tart_byte tart_add_buffer(struct tart_window*, struct struct tart_buffer*)
*/
tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer); tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer);
/* tart_remove_buffer
*
* This will remove the buffer using the *tart_id*.
*/
tart_byte tart_remove_buffer(struct tart_window*, tart_id); tart_byte tart_remove_buffer(struct tart_window*, tart_id);
/* tart_set_buffer
*
* This will replace the the buffer at the index *(tart_byte)*.
*/
tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte); tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte);

View File

@@ -15,21 +15,34 @@ struct tart_window tart_create_window() {
struct tart_window window; struct tart_window window;
window.buffer_count = 0; window.buffer_count = 0;
for(int i = 0; i < 0xFF; i++) { for(int i = 0; i < 0xFF; i++) {
window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},(struct tart_vec2){0,0}); window.buffers[i] = tart_create_buffer(0, (struct tart_vec2){0,0},
(struct tart_vec2){0,0});
} }
window.size = term_current_size(); window.size = term_current_size();
window.data = malloc((window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100 );
for(int g = 0; g < (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100; g++) { int dataSize = (window.size.x * window.size.y * sizeof(char) *
TART_CELL_DATA_SIZE) + 100;
window.data = malloc(dataSize);
for(int g = 0; g < dataSize; g++) {
window.data[g] = '\0'; window.data[g] = '\0';
} }
window.data_count = (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100; window.data_count = dataSize;
return window; return 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* 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; unsigned int cell_count = size.x * size.y;
struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell)); struct tart_cell* cells = (struct tart_cell*)malloc(cell_count * sizeof(struct tart_cell));
for (int i = 0;i < cell_count;i++) { for (int i = 0;i < cell_count;i++) {
cells[i] = NULL_CELL; cells[i] = NULL_CELL;
@@ -37,6 +50,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; 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 struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer
buf.cell_count = cell_count;
return buf; return buf;
} }
#ifdef TART_RGB_COLORS #ifdef TART_RGB_COLORS
@@ -51,7 +65,8 @@ struct tart_cell tart_create_cell(char display, tart_byte style,
return (struct tart_cell){foreground,background,style,display}; return (struct tart_cell){foreground,background,style,display};
} }
#endif #endif
tart_byte tart_add_buffer(struct tart_window* window, struct tart_buffer buffer) { tart_byte tart_add_buffer(struct tart_window* window,
struct tart_buffer buffer) {
if(window->buffer_count <= 0xFF) { if(window->buffer_count <= 0xFF) {
window->buffers[window->buffer_count] = buffer; window->buffers[window->buffer_count] = buffer;
window->buffer_count++; window->buffer_count++;
@@ -84,22 +99,26 @@ struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell
tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) { tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) {
int offset = 0; int offset = 0;
int i = 0; int i = 0;
int bufferWidth = 0;
for (int b = 0;b < 0xFF; b++) { for (int b = 0;b < 0xFF; b++) {
if(window->buffers[b].cell_count == 0) if(window->buffers[b].cell_count == 0)
continue; continue;
bufferWidth = window->buffers[b].size.x;
for (int y = 0; y < window->buffers[b].size.y; y++) { for (int y = 0; y < window->buffers[b].size.y; y++) {
for (int x = 0; x < window->buffers[b].size.x; x++) { for (int x = 0; x < window->buffers[b].size.x; x++) {
// add data to window c buffer. // add data to window c buffer.
struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x]; struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x];
char pre[TART_CELL_DATA_SIZE]; char pre[TART_CELL_DATA_SIZE];
int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m", (int)cell.style, cell.foreground, cell.background, cell.display); // puts cell drawing data in pre
for(int preIdx = 0; preIdx < size; preIdx++) { int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m",
window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx]; (int)cell.style, cell.foreground,
offset++; cell.background, cell.display) -1;
for(int preIdx = 0; preIdx < size; preIdx++) {
window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx];
offset++;
} }
} }
window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n'; //window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n';
offset++; offset++;
@@ -123,6 +142,10 @@ tart_byte tart_add_cells_to_buffer(struct tart_buffer* buffer, struct tart_cell*
struct tart_cstring tart_cstring(char *string, long size, struct tart_cell type){ struct tart_cstring tart_cstring(char *string, long size, struct tart_cell type){
struct tart_cstring str = {0,size}; struct tart_cstring str = {0,size};
str.data = malloc(size * sizeof(struct tart_cell)); str.data = malloc(size * sizeof(struct tart_cell));
for(int i = 0; i < size; i++) {
str.data[i] = type;
str.data[i].display = string[i];
}
return str; return str;
} }
@@ -160,6 +183,7 @@ struct tart_csprite tart_csprite(struct tart_cell* cells, struct tart_vec2* posi
sprite.bounds.y = positions[i].y; sprite.bounds.y = positions[i].y;
} }
} }
sprite.size = size;
return sprite; return sprite;
}; };
@@ -173,7 +197,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) { 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) { if(buffer->size.x > position.x && buffer->size.y > position.y) {
buffer->cells[(buffer->size.x * position.y) + position.x] = cell; buffer->cells[(buffer->size.x * position.y) + position.x] = cell;
} }
return TART_OK; return TART_OK;
@@ -190,12 +214,15 @@ tart_byte tart_draw_cstring_position(struct tart_buffer *buffer, struct tart_cst
tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_csprite sprite, struct tart_vec2 basePosition) { 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++) { for(int i = 0; i < sprite.size; i++) {
struct tart_vec2 position = {sprite.position[i].x + basePosition.x, sprite.position[i].y + basePosition.y}; 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); tart_draw_cell_position(buffer, sprite.data[i], position);
} }
return TART_OK; return TART_OK;
} }
tart_byte tart_restore_buffer(struct tart_buffer *buffer) { 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; return TART_OK;
} }

View File

@@ -101,16 +101,19 @@ void init_termios(int args) {
current.c_lflag &= ~ICANON; current.c_lflag &= ~ICANON;
if(args == 0x01) { if(args == 0x01) {
current.c_lflag |= ECHO; //current.c_lflag ^ ECHO;
} else { } else {
current.c_lflag &= ~ECHO; //current.c_lflag &= ~ECHO;
current.c_lflag ^= ECHO;
//current.c_lflag |= ECHO;
} }
tcsetattr(0,TCSAFLUSH, &current); tcsetattr(0,0, &current);
} }
void reset_termios(void) { void reset_termios(void) {
tcsetattr(0, TCSAFLUSH, &old);
tcsetattr(0, TCSANOW, &old);
} }
char term_getch() { char term_getch() {
@@ -143,6 +146,7 @@ void* input_threaded_func(void* vargp) {
int term_threaded_input_stop() { int term_threaded_input_stop() {
pthread_cancel(input_thread); pthread_cancel(input_thread);
reset_termios();
return 1; return 1;
} }
@@ -170,9 +174,9 @@ char term_tinput() {
return __term_input_buffer__[0]; return __term_input_buffer__[0];
} }
void term_disable_cursor() { void term_disable_cursor() {
fputs("\033[?25l", stdout); printf("\033[?25l", stdout);
} }
void term_enable_cursor() { void term_enable_cursor() {
fputs("\033[?25h", stdout); printf("\033[?25h", stdout);
} }

View File

@@ -1,5 +1,5 @@
project(TartTest) project(TartTest)
add_subdirectory(externals) #add_subdirectory(externals)
set( CMAKE_CXX_STANDARD 11) set( CMAKE_CXX_STANDARD 11)
set( CMAKE_CXX_STANDARD_REQUIRED ON) set( CMAKE_CXX_STANDARD_REQUIRED ON)
set( SOURCES set( SOURCES
@@ -8,21 +8,21 @@ set( SOURCES
test_term.cpp test_term.cpp
) )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/tests) #set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/tests)
#
add_executable(${PROJECT_NAME} ${SOURCES} ) #add_executable(${PROJECT_NAME} ${SOURCES} )
target_link_libraries(${PROJECT_NAME} TartLib PickleLib) #target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
#
if(CMAKE_SYSTEM_NAME STREQUAL "Linux") #if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing") # add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing")
endif() #endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows") #if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing.exe") # add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing.exe")
endif() #endif()
#
project(InputTartTest) #project(InputTartTest)
set( CMAKE_CXX_STANDARD 11) #set( CMAKE_CXX_STANDARD 11)
set( CMAKE_CXX_STANDARD_REQUIRED ON) #set( CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(${PROJECT_NAME} input.cpp ) #add_executable(${PROJECT_NAME} input.cpp )
target_link_libraries(${PROJECT_NAME} TartLib PickleLib) #target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
add_subdirectory(render_test) add_subdirectory(render_test)

View File

@@ -2,22 +2,80 @@
#include <memory.h> #include <memory.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <iostream>
//int main (int argc, char *argv[]) {
// struct tart_window window = tart_create_window();
// 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);
// }
// 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_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, {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();
// char* bbuf = term_tinputb();
// 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') {
// break;
// }
// // p.x = (int)x;
// }
// term_threaded_input_stop();
// term_enable_cursor();
// exit(0);
// //term_getche();
// //term_threaded_input_stop();
// return 0;
//}
char* bbuf;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
struct tart_window window = tart_create_window(); int n;
struct tart_buffer mainbuff = tart_create_buffer(109, {100,50},{20,20}); int counter = 0;
struct tart_cell* cells = (struct tart_cell*)malloc(mainbuff.cell_count * sizeof(struct tart_cell)); term_disable_cursor();
for(int i = 1; i < mainbuff.cell_count; i += 2) { term_threaded_input_init();
cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_BLACK_FOREGROUND, TART_COLOR_WHITE_BACKGROUND); bbuf = term_tinputb();
while(bbuf[0] != 'q') {
std::cout << counter++ << '[';
for (int i = 0; i < 8; i++) {
std::cout << bbuf[i] << ',';
}
std::cout << "] \r";
} }
for(int i = 0; i < + mainbuff.cell_count; i += 2) { std::cout << '\n';
cells[i] = tart_create_cell('^', TART_STYLE_BLINKING, TART_COLOR_RED_FOREGROUND, TART_COLOR_BLACK_BACKGROUND); term_threaded_input_stop();
} term_enable_cursor();
tart_add_cells_to_buffer(&mainbuff, cells); exit(0);
char t[1] = {'0'};
tart_add_buffer(&window, mainbuff);
tart_draw_window(&window, t);
return 0; return 0;
} }