Compare commits
7 Commits
9f46853d5d
...
preproduct
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a8c4eed82 | |||
| b2839b4cd1 | |||
| 8cef088b61 | |||
| b6a50cf942 | |||
| a942782e47 | |||
| a77df22ffe | |||
| 993330a3a4 |
@@ -24,5 +24,5 @@ enable_testing()
|
||||
add_subdirectory(externals)
|
||||
# PROJECT
|
||||
add_subdirectory(source)
|
||||
add_subdirectory(testing)
|
||||
#add_subdirectory(testing)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ extern "C" {
|
||||
#define NULL_CELL (struct tart_cell){{0,0,0},{0,0,0},0,0,0}
|
||||
#define TART_CELL_DATA_SIZE 16 // todo add number
|
||||
#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
|
||||
#endif
|
||||
#define TART_OK 0
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
#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_remove_buffer
|
||||
*
|
||||
* This will remove the buffer using the *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);
|
||||
|
||||
|
||||
|
||||
@@ -15,21 +15,34 @@ 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, (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.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_count = (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100;
|
||||
window.data_count = dataSize;
|
||||
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;
|
||||
|
||||
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++) {
|
||||
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;
|
||||
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
|
||||
@@ -51,7 +65,8 @@ struct tart_cell tart_create_cell(char display, tart_byte style,
|
||||
return (struct tart_cell){foreground,background,style,display};
|
||||
}
|
||||
#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) {
|
||||
window->buffers[window->buffer_count] = buffer;
|
||||
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) {
|
||||
int offset = 0;
|
||||
int i = 0;
|
||||
int bufferWidth = 0;
|
||||
for (int b = 0;b < 0xFF; b++) {
|
||||
if(window->buffers[b].cell_count == 0)
|
||||
continue;
|
||||
bufferWidth = window->buffers[b].size.x;
|
||||
for (int y = 0; y < window->buffers[b].size.y; y++) {
|
||||
for (int x = 0; x < window->buffers[b].size.x; x++) {
|
||||
// add data to window c buffer.
|
||||
struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x];
|
||||
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
|
||||
int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m",
|
||||
(int)cell.style, cell.foreground,
|
||||
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++;
|
||||
|
||||
|
||||
@@ -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 str = {0,size};
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -160,6 +183,7 @@ struct tart_csprite tart_csprite(struct tart_cell* cells, struct tart_vec2* posi
|
||||
sprite.bounds.y = positions[i].y;
|
||||
}
|
||||
}
|
||||
sprite.size = size;
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
return TART_OK;
|
||||
@@ -197,5 +221,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;
|
||||
}
|
||||
|
||||
@@ -101,16 +101,19 @@ void init_termios(int args) {
|
||||
current.c_lflag &= ~ICANON;
|
||||
|
||||
if(args == 0x01) {
|
||||
current.c_lflag |= ECHO;
|
||||
//current.c_lflag ^ ECHO;
|
||||
} else {
|
||||
current.c_lflag &= ~ECHO;
|
||||
//current.c_lflag &= ~ECHO;
|
||||
current.c_lflag ^= ECHO;
|
||||
//current.c_lflag |= ECHO;
|
||||
}
|
||||
|
||||
tcsetattr(0,TCSAFLUSH, ¤t);
|
||||
tcsetattr(0,0, ¤t);
|
||||
}
|
||||
|
||||
void reset_termios(void) {
|
||||
tcsetattr(0, TCSAFLUSH, &old);
|
||||
|
||||
tcsetattr(0, TCSANOW, &old);
|
||||
}
|
||||
|
||||
char term_getch() {
|
||||
@@ -143,6 +146,7 @@ void* input_threaded_func(void* vargp) {
|
||||
|
||||
int term_threaded_input_stop() {
|
||||
pthread_cancel(input_thread);
|
||||
reset_termios();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -170,9 +174,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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
project(TartTest)
|
||||
add_subdirectory(externals)
|
||||
#add_subdirectory(externals)
|
||||
set( CMAKE_CXX_STANDARD 11)
|
||||
set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set( SOURCES
|
||||
@@ -8,21 +8,21 @@ set( SOURCES
|
||||
test_term.cpp
|
||||
)
|
||||
|
||||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/tests)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES} )
|
||||
target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing")
|
||||
endif()
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing.exe")
|
||||
endif()
|
||||
|
||||
project(InputTartTest)
|
||||
set( CMAKE_CXX_STANDARD 11)
|
||||
set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
add_executable(${PROJECT_NAME} input.cpp )
|
||||
target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
||||
#set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/tests)
|
||||
#
|
||||
#add_executable(${PROJECT_NAME} ${SOURCES} )
|
||||
#target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
||||
#
|
||||
#if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
# add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing")
|
||||
#endif()
|
||||
#if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
# add_test(${PROJECT_NAME} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testing.exe")
|
||||
#endif()
|
||||
#
|
||||
#project(InputTartTest)
|
||||
#set( CMAKE_CXX_STANDARD 11)
|
||||
#set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
#add_executable(${PROJECT_NAME} input.cpp )
|
||||
#target_link_libraries(${PROJECT_NAME} TartLib PickleLib)
|
||||
add_subdirectory(render_test)
|
||||
|
||||
@@ -2,22 +2,80 @@
|
||||
#include <memory.h>
|
||||
#include <stdio.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[]) {
|
||||
struct tart_window window = tart_create_window();
|
||||
struct tart_buffer mainbuff = tart_create_buffer(109, {100,50},{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);
|
||||
|
||||
char t[1] = {'0'};
|
||||
tart_add_buffer(&window, mainbuff);
|
||||
tart_draw_window(&window, t);
|
||||
int n;
|
||||
int counter = 0;
|
||||
term_disable_cursor();
|
||||
term_threaded_input_init();
|
||||
bbuf = term_tinputb();
|
||||
while(bbuf[0] != 'q') {
|
||||
|
||||
std::cout << counter++ << '[';
|
||||
for (int i = 0; i < 8; i++) {
|
||||
std::cout << bbuf[i] << ',';
|
||||
}
|
||||
std::cout << "] \r";
|
||||
}
|
||||
std::cout << '\n';
|
||||
term_threaded_input_stop();
|
||||
term_enable_cursor();
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user