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
#include "../source/term.h"
#include <stdio.h>
// #========================================================================#
// | PreacherDHM:TART
// |
@@ -22,16 +23,19 @@ extern "C" {
#ifdef TART_RGB_COLORS
#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
#define NULL_CELL (struct tart_cell){0,0,0,' '}
#define TART_CELL_DATA_SIZE 20
typedef char tart_display;
#endif
#define TART_OK 0
#define TART_STYLE_BOLD 1
#define TART_STYLE_DIM 2
#define TART_STYLE_ITALIC 3
#define TART_STYLE_UNDERLINE 4
#define TART_STYLE_BLINKING 5
#define TART_STYLE_INVERSE 7
@@ -101,11 +105,20 @@ struct tart_cell {
char display;
};
#else
#ifdef TART_UTF8
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char[2] display;
};
#endif
struct tart_cell {
tart_byte foreground;
tart_byte background;
tart_byte style;
char display;
struct tart_vec2 screen_pos;
};
#endif
@@ -143,6 +156,7 @@ struct tart_buffer {
struct tart_vec2 size;
struct tart_vec2 position;
struct tart_cell* cells;
unsigned int current_idx;
};
/* Tart Window
@@ -158,6 +172,7 @@ struct tart_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);
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_count = dataSize;
printf("\033[?1049h");
return window;
}
void tart_destroy_window(struct tart_window* winodw) {
printf("\033[?1049l");
}
tart_byte tart_restore_window(struct tart_window* window) {
for (int i = 0; i < window->data_count; i++) {
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++) {
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];
// 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++;
}
//char bufferSetPre[16];
//int bufferSetSize = sprintf(bufferSetPre, "\033[%d;%dH", window->buffers[b].position.y, window->buffers[b].position.x);
//for(int preIdx = 0; preIdx < bufferSetSize; preIdx++) {
// //window->data[(y*window->buffers[b].size.x) + offset] = movePre[preIdx];
// window->data[offset] = bufferSetPre[preIdx];
// offset++;
//}
// offset++;
//bufferWidth = window->buffers[b].size.x;
for (int y = 0; y < window->buffers[b].current_idx; y++) {
// add data to window c buffer.
struct tart_cell cell = window->buffers[b].cells[y];
// 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++;
@@ -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) {
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;
}
@@ -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) {
for (int i = 0; i < buffer->cell_count; i++) {
buffer->cells[i] = NULL_CELL;
buffer->current_idx = 0;
}
return TART_OK;
}

View File

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

View File

@@ -9,6 +9,9 @@
// #========================================================================#
#ifndef TERM_H
#define TERM_H
#define NOREAD 0
#include "tart.h"
struct tart_vec2 term_current_size();
@@ -23,6 +26,10 @@ int term_threaded_input_stop();
char term_tinputi(int idx);
char* term_tinputb();
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_enable_cursor();