Compare commits

...

7 Commits

5 changed files with 92 additions and 23 deletions

6
.gitmodules vendored
View File

@@ -1,6 +0,0 @@
[submodule "externals/Pickler"]
path = externals/Pickler
url = http://www.gitea.preacherdhm.com/PreacherDHM/Pickler.git
[submodule "testing/externals/Pickler"]
path = testing/externals/Pickler
url = http://www.gitea.preacherdhm.com/PreacherDHM/Pickler.git

View File

@@ -6,6 +6,7 @@ extern "C" {
#endif #endif
#include "../source/term.h" #include "../source/term.h"
#include <stdio.h>
// #========================================================================# // #========================================================================#
// | PreacherDHM:TART // | PreacherDHM:TART
// | // |
@@ -22,16 +23,19 @@ extern "C" {
#ifdef TART_RGB_COLORS #ifdef TART_RGB_COLORS
#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 32 // todo add number
typedef char tart_display[2];
#else #else
#define NULL_CELL (struct tart_cell){0,0,0,' '} #define NULL_CELL (struct tart_cell){0,0,0,' '}
#define TART_CELL_DATA_SIZE 20 #define TART_CELL_DATA_SIZE 20
typedef char tart_display;
#endif #endif
#define TART_OK 0 #define TART_OK 0
#define TART_STYLE_BOLD 1 #define TART_STYLE_BOLD 1
#define TART_STYLE_DIM 2 #define TART_STYLE_DIM 2
#define TART_STYLE_ITALIC 3
#define TART_STYLE_UNDERLINE 4 #define TART_STYLE_UNDERLINE 4
#define TART_STYLE_BLINKING 5 #define TART_STYLE_BLINKING 5
#define TART_STYLE_INVERSE 7 #define TART_STYLE_INVERSE 7
@@ -101,11 +105,20 @@ struct tart_cell {
char display; char display;
}; };
#else #else
#ifdef TART_UTF8
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char[2] display;
};
#endif
struct tart_cell { struct tart_cell {
tart_byte foreground; tart_byte foreground;
tart_byte background; tart_byte background;
tart_byte style; tart_byte style;
char display; char display;
struct tart_vec2 screen_pos;
}; };
#endif #endif
@@ -143,6 +156,7 @@ struct tart_buffer {
struct tart_vec2 size; struct tart_vec2 size;
struct tart_vec2 position; struct tart_vec2 position;
struct tart_cell* cells; struct tart_cell* cells;
unsigned int current_idx;
}; };
/* Tart Window /* Tart Window
@@ -158,6 +172,7 @@ struct tart_window {
}; };
struct tart_window tart_create_window(); struct tart_window tart_create_window();
void tart_destroy_window(struct tart_window* 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*); tart_byte tart_restore_window(struct tart_window*);

View File

@@ -28,9 +28,14 @@ struct tart_window tart_create_window() {
window.data[g] = '\0'; window.data[g] = '\0';
} }
window.data_count = dataSize; window.data_count = dataSize;
printf("\033[?1049h");
return window; return window;
} }
void tart_destroy_window(struct tart_window* winodw) {
printf("\033[?1049l");
}
tart_byte tart_restore_window(struct tart_window* window) { tart_byte tart_restore_window(struct tart_window* window) {
for (int i = 0; i < window->data_count; i++) { for (int i = 0; i < window->data_count; i++) {
window->data[i] = '\0'; window->data[i] = '\0';
@@ -103,22 +108,41 @@ tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) {
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; //char bufferSetPre[16];
for (int y = 0; y < window->buffers[b].size.y; y++) { //int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x);
for (int x = 0; x < window->buffers[b].size.x; x++) { //for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) {
// add data to window c buffer. // //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
struct tart_cell cell = window->buffers[b].cells[(y*window->buffers[b].size.x) + x]; // window->data[offset] = bufferSetPre[preIdx];
char pre[TART_CELL_DATA_SIZE]; // offset++;
// puts cell drawing data in pre //}
int size = sprintf(pre, "\033[%d;%d;%dm%c\033[0;0m", // offset++;
(int)cell.style, cell.foreground, //bufferWidth = window->buffers[b].size.x;
cell.background, cell.display) -1; for (int y = 0; y < window->buffers[b].current_idx; y++) {
for(int preIdx = 0; preIdx < size; preIdx++) { // add data to window c buffer.
window->data[(y*window->buffers[b].size.x) + x + offset] = pre[preIdx]; struct tart_cell cell = window->buffers[b].cells[y];
offset++; // puts cell drawing data in pre
}
char pre[TART_CELL_DATA_SIZE+20];
int size = sprintf(pre, "\033[%d;%dH\033[0m\033[%d;%d;%dm%c\033[0;0m",
cell.screen_pos.y+1,cell.screen_pos.x+1,
(int)cell.style, cell.foreground,
cell.background, cell.display) -1;
for(int preIdx = 0; preIdx < size; preIdx++) {
window->data[offset] = pre[preIdx];
offset++;
} }
//window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n'; #ifdef TART_RGB_COLORS
char pre[TART_CELL_DATA_SIZE+4];
int size = sprintf(pre, "\033[0m\033[38;2;%d;%d;%dm\033[0m\033[48;2;%d;%d;%dm%\033[%dmc\033[0;0m",
// TODO add rgb
(int)cell.style, cell.foreground,
cell.background, cell.display) -1;
#endif
offset++; offset++;
@@ -198,7 +222,9 @@ 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.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; cell.screen_pos = position;
buffer->cells[buffer->current_idx] = cell;
buffer->current_idx++;
} }
return TART_OK; return TART_OK;
} }
@@ -223,6 +249,7 @@ tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_cs
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++) { for (int i = 0; i < buffer->cell_count; i++) {
buffer->cells[i] = NULL_CELL; buffer->cells[i] = NULL_CELL;
buffer->current_idx = 0;
} }
return TART_OK; return TART_OK;
} }

View File

@@ -1,11 +1,14 @@
#include "term.h" #include "term.h"
#include <stdio.h> #include <stdio.h>
unsigned char haveread = 0;
unsigned char __state__ = 0;
char __term_input_buffer__[8] = {' ',' ',' ',' ',' ',' ',' ',' '}; char __term_input_buffer__[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
void set_char_push_back(char t) { void set_char_push_back(char t) {
char tmp1; char tmp1;
char hold1; char hold1;
char hold2; char hold2;
__state__ = __state__ + 1;
hold1 = __term_input_buffer__[0]; hold1 = __term_input_buffer__[0];
for(int i = 0; i < 8 - 1; i++) { for(int i = 0; i < 8 - 1; i++) {
hold2 = __term_input_buffer__[i+1]; hold2 = __term_input_buffer__[i+1];
@@ -140,6 +143,7 @@ void* input_threaded_func(void* vargp) {
int myid = getpid(); int myid = getpid();
while(1) { while(1) {
set_char_push_back(term_getch()); set_char_push_back(term_getch());
usleep(1000);
} }
return NULL; return NULL;
} }
@@ -156,6 +160,28 @@ int term_threaded_input_init() {
return 1; return 1;
} }
unsigned char term_key_pressed() {
if( __state__ > 0 ) {
return 1;
}
return 0;
}
void term_handled_key() {
if( __state__ > 0 ) {
__state__ = 0;
}
}
void term_end_of_key() {
if(__state__ > 0 && haveread > 200) {
//__state__ = 0;
}
}
void term_start_read() {
haveread += 1;
}
#endif #endif

View File

@@ -9,6 +9,9 @@
// #========================================================================# // #========================================================================#
#ifndef TERM_H #ifndef TERM_H
#define TERM_H #define TERM_H
#define NOREAD 0
#include "tart.h" #include "tart.h"
struct tart_vec2 term_current_size(); struct tart_vec2 term_current_size();
@@ -23,6 +26,10 @@ int term_threaded_input_stop();
char term_tinputi(int idx); char term_tinputi(int idx);
char* term_tinputb(); char* term_tinputb();
char term_tinput(); char term_tinput();
unsigned char term_key_pressed();
void term_handled_key();
void term_end_of_key();
void term_start_read();
void term_disable_cursor(); void term_disable_cursor();
void term_enable_cursor(); void term_enable_cursor();