Compare commits
12 Commits
8cef088b61
...
rework
| Author | SHA1 | Date | |
|---|---|---|---|
| 704f624f25 | |||
| ee10de863d | |||
| 3d755bd9a7 | |||
| 0abe4974df | |||
| fcfd5131ec | |||
| 2992e41050 | |||
| 9d1468fbf7 | |||
| fb4b61420a | |||
| 737458f802 | |||
| 0a8c4eed82 | |||
| b2839b4cd1 | |||
| d1dadebe4a |
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -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
|
|
||||||
@@ -24,5 +24,6 @@ enable_testing()
|
|||||||
add_subdirectory(externals)
|
add_subdirectory(externals)
|
||||||
# PROJECT
|
# PROJECT
|
||||||
add_subdirectory(source)
|
add_subdirectory(source)
|
||||||
add_subdirectory(testing)
|
#
|
||||||
|
add_subdirectory(test)
|
||||||
|
|
||||||
|
|||||||
276
includes/tart.h
276
includes/tart.h
@@ -1,42 +1,105 @@
|
|||||||
#ifndef TART_H
|
#ifndef TART_H
|
||||||
#define TART_H
|
#define TART_H
|
||||||
|
#include <string.h>
|
||||||
|
#define TART_UTF8
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../source/term.h"
|
typedef char tart_display;
|
||||||
// #========================================================================#
|
|
||||||
// | PreacherDHM:TART
|
|
||||||
// |
|
|
||||||
// | Tarts stands for Terminal Art. Tart is a terminal renderer that uses a |
|
|
||||||
// | render buffer like system that takes csprites or character sprites and |
|
|
||||||
// | displays them in the terminal. The render buffer consists of cells and |
|
|
||||||
// | each cell consists of
|
|
||||||
// | - Color
|
|
||||||
// | - Rendered Character
|
|
||||||
// | - Reset
|
|
||||||
// | In toaltol around 19 to 24 bytes. This alows for complete controle |
|
|
||||||
// | over each cell.
|
|
||||||
// #========================================================================#
|
|
||||||
|
|
||||||
#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
|
typedef unsigned int TART_FLAGS;
|
||||||
|
typedef unsigned char tart_byte;
|
||||||
|
typedef unsigned short tart_id;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
#include <wchar.h>
|
||||||
|
#undef t_char
|
||||||
|
typedef wchar_t t_char;
|
||||||
#else
|
#else
|
||||||
#define NULL_CELL (struct tart_cell){0,0,0,' '}
|
typedef char t_char;
|
||||||
#define TART_CELL_DATA_SIZE 20
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tart_byte r;
|
||||||
|
tart_byte g;
|
||||||
|
tart_byte b;
|
||||||
|
} tart_color;
|
||||||
|
|
||||||
|
#ifndef TART_PALET_SIZE
|
||||||
|
#define TART_PALET_SIZE 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tart_color forground;
|
||||||
|
tart_color background;
|
||||||
|
} tart_pallet;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} tart_vec2;
|
||||||
|
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
#define TART_CELL_SIZE 36 * 2
|
||||||
|
#else
|
||||||
|
#define TART_CELL_SIZE 26 + 19
|
||||||
|
#endif
|
||||||
|
typedef unsigned int tart_uint;
|
||||||
|
typedef unsigned int tart_style;
|
||||||
|
typedef char tart_cell[TART_CELL_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tart_cell** buffer;
|
||||||
|
tart_vec2 curser;
|
||||||
|
tart_vec2 jump;
|
||||||
|
tart_uint bufferSize;
|
||||||
|
int fd;
|
||||||
|
}tart_buffer;
|
||||||
|
|
||||||
|
/* Tart Window
|
||||||
|
*
|
||||||
|
* The tart window will have the window size and all of the buffers.
|
||||||
|
**/
|
||||||
|
typedef struct {
|
||||||
|
tart_pallet pallet[TART_PALET_SIZE];
|
||||||
|
tart_vec2 homePosition;
|
||||||
|
tart_vec2 windowSize;
|
||||||
|
tart_vec2 terminalSize;
|
||||||
|
tart_buffer buffer;
|
||||||
|
const char* name;
|
||||||
|
}tart_window ;
|
||||||
|
|
||||||
|
|
||||||
#define TART_OK 0
|
#define TART_OK 0
|
||||||
|
#define TART_NG -1
|
||||||
|
|
||||||
|
#define TART_SET_FLAG(f,x) f |= (x)
|
||||||
|
|
||||||
#define TART_STYLE_BOLD 1
|
#define TART_STYLE_NONE 0
|
||||||
#define TART_STYLE_DIM 2
|
#define TART_STYLE_BOLD 1 << 0
|
||||||
#define TART_STYLE_UNDERLINE 4
|
#define TART_STYLE_DIM 1 << 1
|
||||||
#define TART_STYLE_BLINKING 5
|
#define TART_STYLE_ITALIC 1 << 2
|
||||||
#define TART_STYLE_INVERSE 7
|
#define TART_STYLE_UNDERLINE 1 << 3
|
||||||
#define TART_STYLE_HIDDEN 8
|
#define TART_STYLE_BLINKING 1 << 4
|
||||||
#define TART_STYLE_STRIKETHROUGH 9
|
#define TART_STYLE_INVERSE 1 << 5
|
||||||
|
#define TART_STYLE_HIDDEN 1 << 6
|
||||||
|
#define TART_STYLE_STRIKETHROUGH 1 << 7
|
||||||
|
|
||||||
|
#define TART_STYLE_DRAW_BOLD 1
|
||||||
|
#define TART_STYLE_DRAW_DIM 2
|
||||||
|
#define TART_STYLE_DRAW_ITALIC 3
|
||||||
|
#define TART_STYLE_DRAW_UNDERLINE 4
|
||||||
|
#define TART_STYLE_DRAW_BLINKING 5
|
||||||
|
#define TART_STYLE_DRAW_INVERSE 7
|
||||||
|
#define TART_STYLE_DRAW_HIDDEN 8
|
||||||
|
#define TART_STYLE_DRAW_STRIKETHROUGH 9
|
||||||
|
|
||||||
#define TART_COLOR_BLACK_FOREGROUND 30
|
#define TART_COLOR_BLACK_FOREGROUND 30
|
||||||
#define TART_COLOR_RED_FOREGROUND 31
|
#define TART_COLOR_RED_FOREGROUND 31
|
||||||
@@ -76,127 +139,58 @@ extern "C" {
|
|||||||
#define TART_COLOR_BRIGHT_CYAN_BACKGROUND 106
|
#define TART_COLOR_BRIGHT_CYAN_BACKGROUND 106
|
||||||
#define TART_COLOR_BRIGHT_WHITE_BACKGROUND 107
|
#define TART_COLOR_BRIGHT_WHITE_BACKGROUND 107
|
||||||
|
|
||||||
typedef unsigned char tart_byte;
|
#define T ""
|
||||||
typedef unsigned short tart_id;
|
#define TC(x) x
|
||||||
|
|
||||||
struct tart_vec2 {
|
#define t_strlen strlen
|
||||||
unsigned short x,y;
|
#define t_strcmp strcmp
|
||||||
};
|
#define t_strcpy strcpy
|
||||||
|
#define t_strncpy strncpy
|
||||||
struct tart_rgb {
|
#define t_snprintf snprintf
|
||||||
tart_byte r,g,b;
|
#define t_sprintf sprintf
|
||||||
};
|
#define t_vsprintf vsprintf
|
||||||
|
#define t_vsnprintf vsnprintf
|
||||||
/* Tart Cell
|
#ifdef TART_UTF8
|
||||||
*
|
#undef T
|
||||||
* This holds a rgb for the foreground and the background.
|
#define T L""
|
||||||
* Includeing the display character.
|
#undef TC
|
||||||
*
|
#define TC(x) L##x
|
||||||
*/
|
#undef t_strlen
|
||||||
#ifdef TART_RGB_COLORS
|
#define t_strlen wcslen
|
||||||
struct tart_cell {
|
#undef t_strcmp
|
||||||
struct tart_rgb foreground;
|
#define t_strcmp wcscmp
|
||||||
struct tart_rgb background;
|
#undef t_snprintf
|
||||||
tart_byte style;
|
#define t_snprintf swprintf
|
||||||
char display;
|
#undef t_sprintf
|
||||||
};
|
#define t_sprintf wprintf
|
||||||
#else
|
#undef t_vsprintf
|
||||||
struct tart_cell {
|
#define t_vsprintf vswprintf
|
||||||
tart_byte foreground;
|
#undef t_vsnprintf
|
||||||
tart_byte background;
|
#define t_vsnprintf vswprintf
|
||||||
tart_byte style;
|
#undef t_strcpy
|
||||||
char display;
|
#define t_strcpy wcscpy
|
||||||
};
|
#undef t_strncpy
|
||||||
|
#define t_strncpy wcncpy
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct tart_cstring {
|
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title);
|
||||||
struct tart_cell* data;
|
int tart_init(tart_window* w);
|
||||||
long size;
|
int tart_close(tart_window* w);
|
||||||
};
|
void tart_disable_cusor();
|
||||||
|
void tart_enable_cusor();
|
||||||
|
int tart_draw(tart_window* w);
|
||||||
|
|
||||||
struct tart_csprite {
|
int tart_jump(tart_window* w, tart_vec2 pos);
|
||||||
struct tart_cell* data;
|
int tart_move_cursor(tart_window* w, tart_vec2 pos);
|
||||||
struct tart_vec2* position;
|
int tart_insert_cell(tart_window* w, tart_byte p, t_char c);
|
||||||
struct tart_vec2 bounds;
|
int tart_printf(tart_window* w,tart_byte p, const t_char* c, ...);
|
||||||
long size;
|
int tart_box(tart_window* w, tart_byte bp, tart_byte fp, const t_char* c,
|
||||||
};
|
tart_vec2 fpos,
|
||||||
|
tart_vec2 spos);
|
||||||
/* Tart Buffer
|
int tart_line(tart_window* w, tart_byte p, const t_char* c, tart_vec2 fpos,
|
||||||
*
|
tart_vec2 spos);
|
||||||
* The Buffer is a contner that holds all of the cells for that buffer.
|
|
||||||
* Allso containes the size of the buffer.
|
|
||||||
*
|
|
||||||
* ........................width...............
|
|
||||||
* ..........<-------------------------------->.
|
|
||||||
* ........^ @################################@.
|
|
||||||
* ........| #................................#.
|
|
||||||
* ........| #................................#.
|
|
||||||
* height--| #.............Buffer.............#.
|
|
||||||
* ........| #................................#.
|
|
||||||
* ........| #................................#.
|
|
||||||
* ........V @################################@.
|
|
||||||
*/
|
|
||||||
struct tart_buffer {
|
|
||||||
unsigned int cell_count;
|
|
||||||
tart_byte layer;
|
|
||||||
tart_id id;
|
|
||||||
struct tart_vec2 size;
|
|
||||||
struct tart_vec2 position;
|
|
||||||
struct tart_cell* cells;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Tart Window
|
|
||||||
*
|
|
||||||
* The tart window will have the window size and all of the buffers.
|
|
||||||
**/
|
|
||||||
struct tart_window {
|
|
||||||
struct tart_buffer buffers[0xFF+1];
|
|
||||||
tart_byte buffer_count;
|
|
||||||
struct tart_vec2 size;
|
|
||||||
char* data;
|
|
||||||
int data_count;
|
|
||||||
};
|
|
||||||
|
|
||||||
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);
|
|
||||||
#else
|
|
||||||
struct tart_cell tart_create_cell(char display, tart_byte style, tart_byte foreground, tart_byte background);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
tart_byte tart_add_buffer(struct tart_window*, struct tart_buffer);
|
|
||||||
tart_byte tart_remove_buffer(struct tart_window*, tart_id);
|
|
||||||
tart_byte tart_set_buffer(struct tart_window*, struct tart_buffer, tart_byte);
|
|
||||||
|
|
||||||
|
|
||||||
struct tart_buffer* tart_get_buffer(struct tart_window*, tart_byte);
|
|
||||||
|
|
||||||
struct tart_cell* tart_get_cell(struct tart_buffer*, int);
|
|
||||||
struct tart_cell tart_set_cell(struct tart_buffer*, struct tart_cell,int);
|
|
||||||
|
|
||||||
tart_byte tart_draw_window(struct tart_window*, char*);
|
|
||||||
|
|
||||||
tart_byte tart_add_cells_to_buffer(struct tart_buffer*, struct tart_cell*);
|
|
||||||
|
|
||||||
// rendering
|
|
||||||
// Resering positionial cells.
|
|
||||||
struct tart_cstring tart_cstring(char* string, long, struct tart_cell type);
|
|
||||||
tart_byte tart_cstring_free(struct tart_cstring*);
|
|
||||||
struct tart_cstring tart_cstring_append(struct tart_cstring*, struct tart_cstring*);
|
|
||||||
|
|
||||||
struct tart_csprite tart_csprite(struct tart_cell*, struct tart_vec2*, long);
|
|
||||||
tart_byte tart_csprite_free(struct tart_csprite*);
|
|
||||||
|
|
||||||
tart_byte tart_draw_cell_position(struct tart_buffer*, struct tart_cell, struct tart_vec2);
|
|
||||||
tart_byte tart_draw_cstring_position(struct tart_buffer*, struct tart_cstring, struct tart_vec2);
|
|
||||||
tart_byte tart_draw_csprite_position(struct tart_buffer*, struct tart_csprite, struct tart_vec2);
|
|
||||||
/*
|
|
||||||
* tart_restore_buffer sets the buffer to NULL_CELL.
|
|
||||||
* */
|
|
||||||
tart_byte tart_restore_buffer(struct tart_buffer*);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ set( CMAKE_C_STANDARD_REQUIRED ON)
|
|||||||
|
|
||||||
|
|
||||||
set(LIB_SOURCES
|
set(LIB_SOURCES
|
||||||
term.c
|
|
||||||
term.h
|
|
||||||
tart.c
|
tart.c
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
370
source/tart.c
370
source/tart.c
@@ -1,219 +1,255 @@
|
|||||||
#include "../includes/tart.h"
|
#include "../includes/tart.h"
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <memory.h>
|
#include <string.h>
|
||||||
#include "term.h"
|
#include <strings.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
struct tart_cell tart_test() {
|
|
||||||
#ifdef TART_RGB_COLORS
|
#define BUFFER_AT_POS(W) (W->windowSize.x * W->buffer.curser.y) + W->buffer.curser.x
|
||||||
return (struct tart_cell){{0,0,0}, {0,0,0}, 0, '&',0};
|
#define BUFFER_LINE_SIZE (w->windowSize.x) * TART_CELL_SIZE + sizeof(tart_cell)
|
||||||
|
#define BUFFER_SIZE (w->windowSize.x * w->windowSize.y)
|
||||||
|
#define BUFFER_BUFFER_SIZE BUFFER_LINE_SIZE * w->windowSize.y
|
||||||
|
|
||||||
|
tart_vec2 GetTerminalSize(tart_window* w) {
|
||||||
|
struct winsize win;
|
||||||
|
ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
|
||||||
|
return (tart_vec2){win.ws_col,win.ws_row};
|
||||||
|
};
|
||||||
|
|
||||||
|
int tart_create_buffer(tart_window* w) {
|
||||||
|
w->buffer.buffer = (tart_cell**)malloc(w->windowSize.y * sizeof(tart_cell*));
|
||||||
|
if(w->buffer.buffer == NULL) {
|
||||||
|
return TART_NG;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < w->windowSize.y; i++) {
|
||||||
|
|
||||||
|
int x = BUFFER_LINE_SIZE;
|
||||||
|
w->buffer.buffer[i] = (tart_cell*)malloc(x);
|
||||||
|
bzero(w->buffer.buffer[i], (BUFFER_LINE_SIZE));
|
||||||
|
}
|
||||||
|
tart_cell ce;
|
||||||
|
bzero(ce, TART_CELL_SIZE);
|
||||||
|
snprintf(ce,TART_CELL_SIZE,
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
"\e[38;2;%03hhu;%03hhu;%03hhum%lc\e[0m",
|
||||||
#else
|
#else
|
||||||
return (struct tart_cell){196,105,0,'&'};
|
"\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
|
||||||
#endif
|
#endif
|
||||||
|
w->pallet[0].forground.r,
|
||||||
|
w->pallet[0].forground.g,
|
||||||
|
w->pallet[0].forground.b,
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
L' '
|
||||||
|
#else
|
||||||
|
' '
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
for(int i = 0; i < w->windowSize.y; i++ ) {
|
||||||
|
for(int j = 0; j < w->windowSize.x + 1; j++) {
|
||||||
|
memcpy(w->buffer.buffer[i][j], ce, sizeof(tart_cell));
|
||||||
}
|
}
|
||||||
struct tart_window tart_create_window() {
|
//t_snprintf(w->buffer.buffer[i][w->windowSize.x],
|
||||||
struct tart_window window;
|
// TART_CELL_SIZE,
|
||||||
window.buffer_count = 0;
|
// TC("\e[1B\e[%dC"),
|
||||||
for(int i = 0; i < 0xFF; i++) {
|
// w->windowSize.x);
|
||||||
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++) {
|
|
||||||
window.data[g] = '\0';
|
|
||||||
}
|
|
||||||
window.data_count = (window.size.x * window.size.y * sizeof(char) * TART_CELL_DATA_SIZE)+ 100;
|
|
||||||
return window;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tart_byte tart_restore_window(struct tart_window* window) {
|
|
||||||
for (int i = 0; i < window->data_count; i++) {
|
w->buffer.curser = (tart_vec2){0,0};
|
||||||
window->data[i] = '\0';
|
|
||||||
}
|
//bzero(w->buffer.buffer[w->windowSize.y], (BUFFER_LINE_SIZE));
|
||||||
|
|
||||||
|
//t_snprintf(w->buffer.buffer[w->windowSize.y][w->windowSize.x],
|
||||||
|
// TART_CELL_SIZE,
|
||||||
|
// TC("\e[n")
|
||||||
|
// );
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tart_buffer tart_create_buffer(tart_id id, struct tart_vec2 size, struct tart_vec2 position) {
|
void tart_free_buffer(tart_window* w) {
|
||||||
unsigned int cell_count = size.x * size.y;
|
free(w->buffer.buffer);
|
||||||
|
|
||||||
struct tart_cell* cells = (struct tart_cell*)malloc((size.x * size.y) * sizeof(struct tart_cell));
|
|
||||||
|
|
||||||
for (int i = 0;i < cell_count;i++) {
|
|
||||||
cells[i] = NULL_CELL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int data_count = (size.x*size.y) * TART_CELL_DATA_SIZE;
|
int tart_create_window(tart_window* w, tart_vec2 ws, const char* title) {
|
||||||
struct tart_buffer buf = {cell_count,0,id,size,position,cells}; // -NOTE- dose not set the layer
|
w->windowSize.x = GetTerminalSize(w).x - 1;
|
||||||
buf.cell_count = cell_count;
|
w->windowSize.y = GetTerminalSize(w).y;
|
||||||
return buf;
|
w->terminalSize = GetTerminalSize(w);
|
||||||
}
|
w->homePosition = (tart_vec2){
|
||||||
#ifdef TART_RGB_COLORS
|
(w->terminalSize.x / 2) - (w->windowSize.x / 2),
|
||||||
struct tart_cell tart_create_cell(char display, tart_byte style, struct tart_rgb foreground, struct tart_rgb background) {
|
(w->terminalSize.x / 2) - (w->windowSize.x / 2)
|
||||||
struct tart_cell b = {foreground, background, style, display,0};
|
};
|
||||||
return b;
|
|
||||||
|
tart_create_buffer(w);
|
||||||
|
|
||||||
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int flush_buffer(tart_window* w) {
|
||||||
|
tart_cell ce;
|
||||||
|
bzero(ce, TART_CELL_SIZE);
|
||||||
|
snprintf(ce,TART_CELL_SIZE,
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
"\e[48;2;%03hhu;%03hhu;%03hhum\e[38;2;%03hhu;%03hhu;%03hhum%lc\e[0m",
|
||||||
#else
|
#else
|
||||||
|
"\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
|
||||||
struct tart_cell tart_create_cell(char display, tart_byte style,
|
|
||||||
tart_byte foreground, tart_byte background) {
|
|
||||||
return (struct tart_cell){foreground,background,style,display};
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
tart_byte tart_add_buffer(struct tart_window* window, struct tart_buffer buffer) {
|
w->pallet[0].background.r,
|
||||||
if(window->buffer_count <= 0xFF) {
|
w->pallet[0].background.g,
|
||||||
window->buffers[window->buffer_count] = buffer;
|
w->pallet[0].background.b,
|
||||||
window->buffer_count++;
|
w->pallet[0].forground.r,
|
||||||
return window->buffer_count;
|
w->pallet[0].forground.g,
|
||||||
|
w->pallet[0].forground.b,
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
L' '
|
||||||
|
#else
|
||||||
|
' '
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
for(int i = 0; i < w->windowSize.y; i++) {
|
||||||
|
for(int j = 0; j < w->windowSize.x ; j++) {
|
||||||
|
bzero(w->buffer.buffer[i][j], sizeof(tart_cell));
|
||||||
|
memcpy(w->buffer.buffer[i][j], ce, sizeof(tart_cell));
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
tart_byte tart_set_buffer(struct tart_window* window, struct tart_buffer buffer, tart_byte layer) {
|
|
||||||
if(layer <= 0xFF) {
|
|
||||||
window->buffers[layer] = buffer;
|
|
||||||
return layer;
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tart_buffer* tart_get_buffer(struct tart_window* window, tart_byte layer) {
|
void flush_palets(tart_window* w) {
|
||||||
return &window->buffers[layer];
|
for(int i = 0; i < TART_PALET_SIZE; i++) {
|
||||||
|
w->pallet[i].background.r = 0;
|
||||||
|
w->pallet[i].background.g = 0;
|
||||||
|
w->pallet[i].background.b = 0;
|
||||||
|
w->pallet[i].forground.r = 254;
|
||||||
|
w->pallet[i].forground.g = 254;
|
||||||
|
w->pallet[i].forground.b = 254;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tart_cell* tart_get_cell(struct tart_buffer* buffer, int idx) {
|
int tart_init(tart_window* w) {
|
||||||
return &buffer->cells[idx];
|
int y = 0;
|
||||||
}
|
int x = 0;
|
||||||
|
w->buffer.jump = (tart_vec2){0,0};
|
||||||
|
flush_buffer(w);
|
||||||
|
flush_palets(w);
|
||||||
|
|
||||||
struct tart_cell tart_set_cell(struct tart_buffer* buffer, struct tart_cell cell,int idx) {
|
//t_snprintf(ce,TART_CELL_SIZE, TC("\e[%d;%dh"),
|
||||||
struct tart_cell c = buffer->cells[idx];
|
// (w->terminalSize.x/2)-(w->windowSize.x/2),
|
||||||
buffer->cells[idx] = cell;
|
// (w->terminalSize.y/2)-(w->windowSize.y/2));
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
tart_byte tart_draw_window(struct tart_window * window, char* rend_buffer) {
|
//write(STDOUT_FILENO, ce, TART_CELL_SIZE);
|
||||||
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) - 1;
|
|
||||||
for(int preIdx = 0; preIdx < size; preIdx++) {
|
|
||||||
window->data[(y * bufferWidth) + x + offset] = pre[preIdx];
|
|
||||||
offset++;
|
|
||||||
|
|
||||||
}
|
write(STDOUT_FILENO, "\e[?1049h", 8);
|
||||||
}
|
write(STDOUT_FILENO, "\e[H", 3);
|
||||||
//window->data[((y)*window->buffers[b].size.x) + offset + window->buffers[b].size.x] = '\n';
|
write(STDOUT_FILENO, "\e[s", 3);
|
||||||
offset++;
|
|
||||||
|
|
||||||
|
|
||||||
// add cursor move command.
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fwrite(window->data, sizeof(char), window->data_count, stdout);
|
|
||||||
return TART_OK;
|
|
||||||
};
|
|
||||||
|
|
||||||
tart_byte tart_add_cells_to_buffer(struct tart_buffer* buffer, struct tart_cell* cells) {
|
|
||||||
for(int i = 0; i < buffer->cell_count; i++) {
|
|
||||||
buffer->cells[i] = cells[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tart_disable_cusor() {
|
||||||
struct tart_cstring tart_cstring(char *string, long size, struct tart_cell type){
|
write(STDOUT_FILENO, "\e[?25l", 8);
|
||||||
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;
|
void tart_enable_cusor() {
|
||||||
|
write(STDOUT_FILENO, "\e[?25h", 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
tart_byte tart_cstring_free(struct tart_cstring* string) {
|
int tart_close(tart_window* w) {
|
||||||
free(string->data);
|
write(STDOUT_FILENO, "\e[?1049l", 8);
|
||||||
string->size = 0;
|
//for(int i = 0; i < w->windowSize.y; i++) {
|
||||||
|
// free(w->buffer.buffer[i]);
|
||||||
|
//}
|
||||||
|
//free(w->buffer.buffer);
|
||||||
|
return TART_OK;
|
||||||
|
}
|
||||||
|
int tart_draw(tart_window* w) {
|
||||||
|
for(int i = 0; i < w->windowSize.y; i++) {
|
||||||
|
for(int j = 0; j < w->windowSize.x + 1; j++) {
|
||||||
|
write(STDOUT_FILENO,
|
||||||
|
w->buffer.buffer[i][j],
|
||||||
|
TART_CELL_SIZE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flush_buffer(w);
|
||||||
|
write(STDOUT_FILENO, "\e[u", strlen("\e[u"));
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tart_cstring tart_cstring_append(struct tart_cstring* lhs, struct tart_cstring* rhs) {
|
int tart_jump(tart_window* w, tart_vec2 pos) {
|
||||||
struct tart_cstring ret = {0,0};
|
w->buffer.jump = pos;
|
||||||
ret.size = lhs->size + rhs->size;
|
w->buffer.curser = pos;
|
||||||
ret.data = malloc(ret.size * sizeof(struct tart_cell));
|
|
||||||
for(int i = 0; i < lhs->size; i++) {
|
|
||||||
ret.data[i] = lhs->data[i];
|
|
||||||
}
|
|
||||||
for(int i = 0; i < rhs->size; i++) {
|
|
||||||
ret.data[lhs->size + i] = rhs->data[i];
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct tart_csprite tart_csprite(struct tart_cell* cells, struct tart_vec2* positions, long size) {
|
|
||||||
|
|
||||||
struct tart_csprite sprite = {0,0,0,size};
|
|
||||||
sprite.data = cells;
|
|
||||||
sprite.position = positions;
|
|
||||||
for(int i = 0; i < size; i++) {
|
|
||||||
|
|
||||||
if(positions[i].x > sprite.bounds.x) {
|
|
||||||
sprite.bounds.x = positions[i].x;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(positions[i].y > sprite.bounds.y) {
|
|
||||||
sprite.bounds.y = positions[i].y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sprite.size = size;
|
|
||||||
return sprite;
|
|
||||||
};
|
|
||||||
|
|
||||||
tart_byte tart_csprite_free(struct tart_csprite* sprite) {
|
|
||||||
sprite->bounds.x = 0;
|
|
||||||
sprite->bounds.y = 0;
|
|
||||||
sprite->size = 0;
|
|
||||||
free(sprite->data);
|
|
||||||
free(sprite->position);
|
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
tart_byte tart_draw_cell_position(struct tart_buffer * buffer, struct tart_cell cell, struct tart_vec2 position) {
|
int tart_move_cursor(tart_window* w, tart_vec2 pos) {
|
||||||
if(buffer->size.x > position.x && buffer->size.y > position.y) {
|
|
||||||
buffer->cells[(buffer->size.x * position.y) + position.x] = cell;
|
if(pos.x >= w->windowSize.x) {
|
||||||
|
for(int i = pos.x; i >= w->windowSize.x; i /= w->windowSize.x) {
|
||||||
|
w->buffer.curser.x = i;
|
||||||
|
w->buffer.curser.y++;
|
||||||
}
|
}
|
||||||
return TART_OK;
|
} else {
|
||||||
|
w->buffer.curser.x = pos.x;
|
||||||
|
}
|
||||||
|
if(pos.y >= w->windowSize.y - 1) {
|
||||||
|
for(int i = pos.y; i >= w->windowSize.y - 1; i /= w->windowSize.y) {
|
||||||
|
w->buffer.curser.y = i;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
w->buffer.curser.y = pos.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
tart_byte tart_draw_cstring_position(struct tart_buffer *buffer, struct tart_cstring string, struct tart_vec2 position) {
|
|
||||||
struct tart_vec2 pos = position;
|
|
||||||
for(int i = 0; i < string.size; i++) {
|
|
||||||
tart_draw_cell_position(buffer, string.data[i], pos);
|
|
||||||
pos.x++;
|
|
||||||
}
|
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
int tart_insert_cell(tart_window* w, tart_byte p, t_char c) {
|
||||||
|
if(c == TC('\n')) {
|
||||||
|
tart_move_cursor(w, (tart_vec2){w->buffer.jump.x, w->buffer.curser.y + 1});
|
||||||
|
return TART_OK;
|
||||||
|
}
|
||||||
|
bzero(w->buffer.buffer[w->buffer.curser.y][w->buffer.curser.x], TART_CELL_SIZE);
|
||||||
|
tart_cell ce;
|
||||||
|
bzero(ce, TART_CELL_SIZE);
|
||||||
|
snprintf(ce,TART_CELL_SIZE,
|
||||||
|
#ifdef TART_UTF8
|
||||||
|
"\e[48;2;%03hhu;%03hhu;%03hhum\e[38;2;%03hhu;%03hhu;%03hhum%lc\e[0m",
|
||||||
|
#else
|
||||||
|
"\e[48;2;%03hhu;%03hhu;%03hhum\e[38;2;%03hhu;%03hhu;%03hhum%c\e[0m",
|
||||||
|
#endif
|
||||||
|
w->pallet[p].background.r,
|
||||||
|
w->pallet[p].background.g,
|
||||||
|
w->pallet[p].background.b,
|
||||||
|
w->pallet[p].forground.r,
|
||||||
|
w->pallet[p].forground.g,
|
||||||
|
w->pallet[p].forground.b,
|
||||||
|
c
|
||||||
|
);
|
||||||
|
|
||||||
tart_byte tart_draw_csprite_position(struct tart_buffer * buffer, struct tart_csprite sprite, struct tart_vec2 basePosition) {
|
memcpy(w->buffer.buffer[w->buffer.curser.y][w->buffer.curser.x], ce, TART_CELL_SIZE);
|
||||||
for(int i = 0; i < sprite.size; i++) {
|
tart_move_cursor(w, (tart_vec2){w->buffer.curser.x + 1, w->buffer.curser.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);
|
|
||||||
}
|
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
int tart_printf(tart_window* w,tart_byte p, const t_char* c, ...) {
|
||||||
tart_byte tart_restore_buffer(struct tart_buffer *buffer) {
|
va_list args;
|
||||||
for (int i = 0; i < buffer->cell_count; i++) {
|
va_start(args, c);
|
||||||
buffer->cells[i] = NULL_CELL;
|
t_char tmp[1024];
|
||||||
|
t_vsnprintf(tmp,1024, c, args);
|
||||||
|
for(int i = 0; i < t_strlen(tmp); i++) {
|
||||||
|
tart_insert_cell(w, p, tmp[i]);
|
||||||
}
|
}
|
||||||
|
va_end(args);
|
||||||
|
return TART_OK;
|
||||||
|
}
|
||||||
|
int tart_box(tart_window* w, tart_byte bp, tart_byte fp, const t_char* c,
|
||||||
|
tart_vec2 fpos,
|
||||||
|
tart_vec2 spos) {
|
||||||
|
return TART_OK;
|
||||||
|
}
|
||||||
|
int tart_line(tart_window* w, tart_byte p, const t_char* c, tart_vec2 fpos,
|
||||||
|
tart_vec2 spos) {
|
||||||
return TART_OK;
|
return TART_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
182
source/term.c
182
source/term.c
@@ -1,182 +0,0 @@
|
|||||||
#include "term.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
char __term_input_buffer__[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
|
|
||||||
void set_char_push_back(char t) {
|
|
||||||
char tmp1;
|
|
||||||
char hold1;
|
|
||||||
char hold2;
|
|
||||||
hold1 = __term_input_buffer__[0];
|
|
||||||
for(int i = 0; i < 8 - 1; i++) {
|
|
||||||
hold2 = __term_input_buffer__[i+1];
|
|
||||||
__term_input_buffer__[i+1] = hold1;
|
|
||||||
hold1 = hold2;
|
|
||||||
|
|
||||||
}
|
|
||||||
__term_input_buffer__[0] = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if windows is defined.
|
|
||||||
|
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <conio.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
HANDLE __term_input_thread;
|
|
||||||
int __term_input_thread_stop;
|
|
||||||
|
|
||||||
DWORD WINAPI input_threaded_func(void* data) {
|
|
||||||
while(__term_input_thread_stop == 1) {
|
|
||||||
if(_kbhit())
|
|
||||||
set_char_push_back(_getch());
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int term_threaded_input_init() {
|
|
||||||
__term_input_thread_stop = 1;
|
|
||||||
__term_input_thread = CreateThread(NULL,0,input_threaded_func,NULL, 0, NULL);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int term_threaded_input_stop() {
|
|
||||||
__term_input_thread_stop = 0;
|
|
||||||
WaitForSingleObject(__term_input_thread, INFINITE);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <threads.h>
|
|
||||||
#include <termios.h>
|
|
||||||
struct tart_vec2 term_current_size() {
|
|
||||||
struct tart_vec2 ret;
|
|
||||||
|
|
||||||
struct winsize w;
|
|
||||||
|
|
||||||
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
||||||
|
|
||||||
unsigned int rows = w.ws_col;
|
|
||||||
unsigned int cols = w.ws_row;
|
|
||||||
|
|
||||||
unsigned short max_short = 0XFFFF;
|
|
||||||
if(rows < max_short && cols < max_short) {
|
|
||||||
|
|
||||||
ret = (struct tart_vec2){(unsigned short) rows ,(unsigned short) cols};
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct termios old, current;
|
|
||||||
|
|
||||||
void init_termios(int args) {
|
|
||||||
tcgetattr(0, &old);
|
|
||||||
|
|
||||||
current = old;
|
|
||||||
|
|
||||||
current.c_lflag &= ~ICANON;
|
|
||||||
|
|
||||||
if(args == 0x01) {
|
|
||||||
//current.c_lflag ^ ECHO;
|
|
||||||
} else {
|
|
||||||
//current.c_lflag &= ~ECHO;
|
|
||||||
current.c_lflag ^= ECHO;
|
|
||||||
//current.c_lflag |= ECHO;
|
|
||||||
}
|
|
||||||
|
|
||||||
tcsetattr(0,0, ¤t);
|
|
||||||
}
|
|
||||||
|
|
||||||
void reset_termios(void) {
|
|
||||||
|
|
||||||
tcsetattr(0, TCSANOW, &old);
|
|
||||||
}
|
|
||||||
|
|
||||||
char term_getch() {
|
|
||||||
char tmp;
|
|
||||||
init_termios(0x00);
|
|
||||||
tmp = getchar();
|
|
||||||
reset_termios();
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
char term_getche() {
|
|
||||||
char tmp;
|
|
||||||
init_termios(0x01);
|
|
||||||
tmp = getchar();
|
|
||||||
reset_termios();
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pthread_t input_thread;
|
|
||||||
|
|
||||||
|
|
||||||
void* input_threaded_func(void* vargp) {
|
|
||||||
int myid = getpid();
|
|
||||||
while(1) {
|
|
||||||
set_char_push_back(term_getch());
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int term_threaded_input_stop() {
|
|
||||||
pthread_cancel(input_thread);
|
|
||||||
reset_termios();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int term_threaded_input_init() {
|
|
||||||
|
|
||||||
pthread_create(&input_thread, NULL, input_threaded_func, NULL);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char term_tinputi(int idx){
|
|
||||||
if(idx < 8) {
|
|
||||||
return __term_input_buffer__[idx];
|
|
||||||
}
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* term_tinputb() {
|
|
||||||
return __term_input_buffer__;
|
|
||||||
}
|
|
||||||
|
|
||||||
char term_tinput() {
|
|
||||||
return __term_input_buffer__[0];
|
|
||||||
}
|
|
||||||
void term_disable_cursor() {
|
|
||||||
printf("\033[?25l", stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void term_enable_cursor() {
|
|
||||||
printf("\033[?25h", stdout);
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
// #========================================================================#
|
|
||||||
// | 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"
|
|
||||||
|
|
||||||
struct tart_vec2 term_current_size();
|
|
||||||
|
|
||||||
char term_getch();
|
|
||||||
char term_getche();
|
|
||||||
|
|
||||||
|
|
||||||
// tinput is threaded input
|
|
||||||
int term_threaded_input_init();
|
|
||||||
int term_threaded_input_stop();
|
|
||||||
char term_tinputi(int idx);
|
|
||||||
char* term_tinputb();
|
|
||||||
char term_tinput();
|
|
||||||
|
|
||||||
void term_disable_cursor();
|
|
||||||
void term_enable_cursor();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
30
test/CMakeLists.txt
Normal file
30
test/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
project(testing)
|
||||||
|
# CPP
|
||||||
|
set( CMAKE_CXX_STANDARD 11)
|
||||||
|
set( CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
# C
|
||||||
|
set( CMAKE_C_STANDARD 11)
|
||||||
|
set( CMAKE_C_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|
||||||
|
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/libs)
|
||||||
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||||
|
|
||||||
|
set( CMAKE_COLOR_MAKEFILE ON)
|
||||||
|
set( CMAKE_COLOR_DIAGNOSTICS ON)
|
||||||
|
|
||||||
|
set( CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
set( SOURCES
|
||||||
|
main.c
|
||||||
|
)
|
||||||
|
add_executable(
|
||||||
|
Testing
|
||||||
|
${SOURCES}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
Testing
|
||||||
|
TartLib
|
||||||
|
)
|
||||||
121
test/main.c
Normal file
121
test/main.c
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
#define TART_UTF8
|
||||||
|
#include "../includes/tart.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
#define jump tart_move_cursor
|
||||||
|
|
||||||
|
int e = 1;
|
||||||
|
|
||||||
|
void aOnExit() {
|
||||||
|
//printf("shutting Down");
|
||||||
|
e = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void draw_button(tart_window *w,const t_char* label, tart_vec2 position) {
|
||||||
|
|
||||||
|
jump(w, (tart_vec2){position.x,position.y + 0});
|
||||||
|
tart_printf(w, 1, T"┏━━━");
|
||||||
|
int size = t_strlen(label);
|
||||||
|
for(int i = 0; i < size; i++ ) {
|
||||||
|
tart_printf(w, 1, T"━");
|
||||||
|
}
|
||||||
|
tart_printf(w, 1, T"━━━┓");
|
||||||
|
jump(w, (tart_vec2){position.x,position.y + 1});
|
||||||
|
tart_printf(w, 1, T"┃ %ls ┃", label);
|
||||||
|
jump(w, (tart_vec2){position.x,position.y + 2});
|
||||||
|
tart_printf(w, 1, T"┗━━━");
|
||||||
|
for(int i = 0; i < size; i++ ) {
|
||||||
|
tart_printf(w, 1, T"━");
|
||||||
|
}
|
||||||
|
tart_printf(w, 1, T"━━━┛");
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
signal(SIGINT, aOnExit);
|
||||||
|
setlocale(LC_CTYPE, "en_US.UTF-8");
|
||||||
|
|
||||||
|
tart_window w;
|
||||||
|
int color0 = 0;
|
||||||
|
int color1 = 0;
|
||||||
|
int color2 = 0;
|
||||||
|
tart_create_window(&w, (tart_vec2){80,40}, "testing");
|
||||||
|
tart_init(&w);
|
||||||
|
tart_disable_cusor();
|
||||||
|
|
||||||
|
w.pallet[0].background.r = 0;
|
||||||
|
w.pallet[0].background.g = 0;
|
||||||
|
w.pallet[0].background.b = 0;
|
||||||
|
w.pallet[0].forground.r = 0;
|
||||||
|
w.pallet[0].forground.g = 0;
|
||||||
|
w.pallet[0].forground.b = 0;
|
||||||
|
|
||||||
|
w.pallet[1].forground.r = 0xff;
|
||||||
|
w.pallet[1].forground.g = 0x00;
|
||||||
|
w.pallet[1].forground.b = 0xcc;
|
||||||
|
|
||||||
|
w.pallet[2].forground.r = 0x3b;
|
||||||
|
w.pallet[2].forground.g = 0x3b;
|
||||||
|
w.pallet[2].forground.b = 0x3b;
|
||||||
|
jump(&w, (tart_vec2){1,1});
|
||||||
|
jump(&w, (tart_vec2){1,2});
|
||||||
|
int x = 0;
|
||||||
|
while(e != 0) {
|
||||||
|
|
||||||
|
tart_draw(&w);
|
||||||
|
|
||||||
|
draw_button(&w, T"This is really cool!", (tart_vec2){5,5});
|
||||||
|
tart_jump(&w, (tart_vec2){3,10});
|
||||||
|
tart_printf(&w,1, T"this is\na new line test\nyay");
|
||||||
|
tart_jump(&w, (tart_vec2){3+ 20,10});
|
||||||
|
tart_printf(&w,1, T"this is\na new line test\nyay");
|
||||||
|
tart_jump(&w, (tart_vec2){3,14});
|
||||||
|
tart_printf(&w,2, T"this is\na new line test\nyay");
|
||||||
|
if(w.pallet[1].forground.r == 254) {
|
||||||
|
color0 = 0;
|
||||||
|
}
|
||||||
|
if(w.pallet[1].forground.r == 0) {
|
||||||
|
color0 = 1;
|
||||||
|
}
|
||||||
|
if(w.pallet[1].forground.g == 254) {
|
||||||
|
color1 = 0;
|
||||||
|
}
|
||||||
|
if(w.pallet[1].forground.g == 0) {
|
||||||
|
color1 = 1;
|
||||||
|
}
|
||||||
|
if(w.pallet[1].forground.b == 254) {
|
||||||
|
color2 = 0;
|
||||||
|
}
|
||||||
|
if(w.pallet[1].forground.b == 0) {
|
||||||
|
color2 = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(color0 == 1) {
|
||||||
|
w.pallet[1].forground.r++;
|
||||||
|
}else {
|
||||||
|
w.pallet[1].forground.r--;
|
||||||
|
}
|
||||||
|
if(color1 == 1) {
|
||||||
|
w.pallet[1].forground.g++;
|
||||||
|
}else {
|
||||||
|
w.pallet[1].forground.g--;
|
||||||
|
}
|
||||||
|
if(color2 == 1) {
|
||||||
|
w.pallet[1].forground.b++;
|
||||||
|
}else {
|
||||||
|
w.pallet[1].forground.b--;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tart_close(&w);
|
||||||
|
tart_enable_cusor();
|
||||||
|
//printf("\e[?1049l");
|
||||||
|
printf("done\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
---
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Start testing: Jan 28 14:11 Pacific Standard Time (Mexico)
|
|
||||||
----------------------------------------------------------
|
|
||||||
End testing: Jan 28 14:11 Pacific Standard Time (Mexico)
|
|
||||||
1
testing/externals/CMakeLists.txt
vendored
1
testing/externals/CMakeLists.txt
vendored
@@ -1 +0,0 @@
|
|||||||
add_subdirectory(Pickler)
|
|
||||||
1
testing/externals/Pickler
vendored
1
testing/externals/Pickler
vendored
Submodule testing/externals/Pickler deleted from 22a9fb9fab
@@ -1,27 +0,0 @@
|
|||||||
#include <tart.h>
|
|
||||||
#include <iostream>
|
|
||||||
#ifdef _LINUX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char* bbuf;
|
|
||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include "test_tart.h"
|
|
||||||
#include "test_term.h"
|
|
||||||
#include <Pickler.h>
|
|
||||||
int main (int argc, char *argv[]) {
|
|
||||||
INSTALLSHELF;
|
|
||||||
tart_run(&__pickle_shelf__);
|
|
||||||
term_run(&__pickle_shelf__);
|
|
||||||
return PICKLESHELF;
|
|
||||||
}
|
|
||||||
@@ -1,166 +0,0 @@
|
|||||||
#include "test_tart.h"
|
|
||||||
#include "Pickler.h"
|
|
||||||
bool rgb_test(struct tart_rgb* lhs, struct tart_rgb* rhs) {
|
|
||||||
if(lhs->r != rhs->r) {return false;}
|
|
||||||
if(lhs->g != rhs->g) {return false;}
|
|
||||||
if(lhs->b != rhs->b) {return false;}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool vec2_test(struct tart_vec2* lhs, struct tart_vec2* rhs) {
|
|
||||||
if(lhs->x != rhs->x) {return false;}
|
|
||||||
if(lhs->y != rhs->y) {return false;}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tart_run(struct pickle_shelf* shelf) {
|
|
||||||
pickle_shelf __pickle_shelf__ = *shelf;
|
|
||||||
CREATEJAR(tart_objects_test);
|
|
||||||
PICKLE(Test_create_buffer) {
|
|
||||||
struct tart_vec2 size = {25,25};
|
|
||||||
struct tart_vec2 position = {0,0};
|
|
||||||
|
|
||||||
int data_count = (size.x*size.y) * TART_CELL_DATA_SIZE;
|
|
||||||
|
|
||||||
unsigned int cell_count = (size.x * size.y);
|
|
||||||
struct tart_buffer buffer_correct = {cell_count,0,25,size,position,0};
|
|
||||||
struct tart_buffer buffer_test = tart_create_buffer(25,size,position);
|
|
||||||
|
|
||||||
if(DIFFERENT(buffer_correct.cell_count,buffer_test.cell_count))
|
|
||||||
ASSERT("Cell count not the same.",false);
|
|
||||||
if(DIFFERENT(buffer_correct.layer,buffer_test.layer))
|
|
||||||
ASSERT("Layers not the same.",false);
|
|
||||||
if(DIFFERENT(buffer_correct.id,buffer_test.id))
|
|
||||||
ASSERT("Ids are not the same.",false);
|
|
||||||
if(DIFFERENT(buffer_correct.size.x,buffer_test.size.x))
|
|
||||||
ASSERT("size.x is not the same",false);
|
|
||||||
if(DIFFERENT(buffer_correct.size.y,buffer_test.size.y))
|
|
||||||
ASSERT("size.y is not the same",false);
|
|
||||||
if(DIFFERENT(buffer_correct.position.x,buffer_test.position.x))
|
|
||||||
ASSERT("position.x is not the same.",false);
|
|
||||||
if(DIFFERENT(buffer_correct.position.y,buffer_test.position.y))
|
|
||||||
ASSERT("position.y is not the same.",false);
|
|
||||||
if(DIFFERENT(buffer_correct.cell_count,buffer_test.cell_count))
|
|
||||||
ASSERT("data_counts are not the same.",false);
|
|
||||||
ASSERT("GOOD",true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
|
|
||||||
PICKLE(Test_create_cell) {
|
|
||||||
|
|
||||||
#ifdef TART_RGB_COLOR
|
|
||||||
struct tart_rgb b = {80,80,80};
|
|
||||||
struct tart_rgb f = {80,80,80};
|
|
||||||
struct tart_cell cell_correct = {f, b, '1', 'f'};
|
|
||||||
struct tart_cell cell_test = tart_create_cell('f', '1', f, b);
|
|
||||||
if(!rgb_test(&cell_correct.foreground, &cell_test.foreground))
|
|
||||||
ASSERT("Forground dose not match.",false);
|
|
||||||
if(!rgb_test(&cell_correct.background, &cell_test.background))
|
|
||||||
ASSERT("background dose not match.",false);
|
|
||||||
#else
|
|
||||||
tart_byte f = 20;
|
|
||||||
tart_byte b = 40;
|
|
||||||
struct tart_cell cell_correct = {f, b, '1', 'f'};
|
|
||||||
struct tart_cell cell_test = tart_create_cell('f', '1', f, b);
|
|
||||||
if(DIFFERENT(cell_correct.foreground, cell_test.foreground))
|
|
||||||
ASSERT("Forground dose not match.",false);
|
|
||||||
if(DIFFERENT(cell_correct.background, cell_test.background))
|
|
||||||
ASSERT("background dose not match.",false);
|
|
||||||
#endif
|
|
||||||
if(DIFFERENT(cell_correct.style, cell_test.style))
|
|
||||||
ASSERT("style dose not match.",false);
|
|
||||||
if(DIFFERENT(cell_correct.display, cell_test.display))
|
|
||||||
ASSERT("display dose not match.",false);
|
|
||||||
ASSERT("GOOD",true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
PICKLE(Test_create_window) {
|
|
||||||
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
|
|
||||||
struct tart_window window = tart_create_window();
|
|
||||||
for(int i = 0; i < 0xFF + 1; i++) {
|
|
||||||
if(DIFFERENT(window.buffers[i].id, 0))
|
|
||||||
ASSERT("buffer not same", false);
|
|
||||||
}
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
PICKLE(Test_add_buffer) {
|
|
||||||
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
|
|
||||||
struct tart_window window = tart_create_window();
|
|
||||||
tart_add_buffer(&window, buffer);
|
|
||||||
if(SAME(window.buffer_count, 0))
|
|
||||||
ASSERT("index has not indexed", false);
|
|
||||||
if(DIFFERENT(window.buffers[0].id, buffer.id))
|
|
||||||
ASSERT("buffer not same", false);
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
PICKLE(Test_set_buffer) {
|
|
||||||
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
|
|
||||||
struct tart_window window = tart_create_window();
|
|
||||||
tart_set_buffer(&window, buffer, 0);
|
|
||||||
if(DIFFERENT(window.buffers[0].id, buffer.id))
|
|
||||||
ASSERT("buffer not same", false);
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
PICKLE(Test_get_buffer) {
|
|
||||||
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {0,0});
|
|
||||||
struct tart_window window = tart_create_window();
|
|
||||||
tart_set_buffer(&window, buffer, 0);
|
|
||||||
if(DIFFERENT(tart_get_buffer(&window, 0)->id, buffer.id))
|
|
||||||
ASSERT("buffer not same", false);
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
PICKLE(Test_set_cell) {
|
|
||||||
#ifdef TART_RGB_COLORS
|
|
||||||
tart_rgb foreground = {90,90,90};
|
|
||||||
tart_rgb background = {80,80,80};
|
|
||||||
|
|
||||||
#else
|
|
||||||
tart_byte foreground = 9;
|
|
||||||
tart_byte background = 8;
|
|
||||||
#endif
|
|
||||||
struct tart_cell cell = tart_create_cell('0',10,foreground, background);
|
|
||||||
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20});
|
|
||||||
struct tart_window window = tart_create_window();
|
|
||||||
|
|
||||||
tart_set_cell(&buffer, cell, 0);
|
|
||||||
if(DIFFERENT(buffer.cells[0].display, cell.display))
|
|
||||||
ASSERT("buffer not same", false);
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
PICKLE(Test_get_cell) {
|
|
||||||
#ifdef TART_RGB_COLORS
|
|
||||||
tart_rgb foreground = {90,90,90};
|
|
||||||
tart_rgb background = {80,80,80};
|
|
||||||
|
|
||||||
#else
|
|
||||||
tart_byte foreground = 9;
|
|
||||||
tart_byte background = 8;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct tart_cell cell = tart_create_cell('0',10,foreground, background);
|
|
||||||
struct tart_buffer buffer = tart_create_buffer(10, {10,20}, {10,20});
|
|
||||||
struct tart_window window = tart_create_window();
|
|
||||||
|
|
||||||
tart_set_cell(&buffer, cell, 0);
|
|
||||||
if(DIFFERENT(tart_get_cell(&buffer,0)->display, cell.display))
|
|
||||||
ASSERT("buffer not same", false);
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ADDPICKLE(tart_objects_test,Test_create_buffer);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_create_cell);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_create_buffer);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_add_buffer);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_set_buffer);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_get_buffer);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_set_cell);
|
|
||||||
ADDPICKLE(tart_objects_test,Test_get_cell);
|
|
||||||
PUTJARONSHELF(tart_objects_test);
|
|
||||||
*shelf = __pickle_shelf__;
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#include <tart.h>
|
|
||||||
#include <Pickler.h>
|
|
||||||
|
|
||||||
bool rgb_test(struct tart_rgb* lhs, struct tart_rgb* rhs);
|
|
||||||
bool vec2_test(struct tart_vec2* lhs, struct tart_vec2* rhs);
|
|
||||||
void tart_run(struct pickle_shelf* shelf);
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
|
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
|
||||||
#include <Windows.h>
|
|
||||||
#else
|
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
#include <iostream>
|
|
||||||
#include "test_term.h"
|
|
||||||
void term_run(struct pickle_shelf* shelf) {
|
|
||||||
struct pickle_shelf __pickle_shelf__ = *shelf; //start
|
|
||||||
|
|
||||||
|
|
||||||
CREATEJAR(Test_Term);
|
|
||||||
|
|
||||||
PICKLE(Test_get_window_size) {
|
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
|
||||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
|
||||||
|
|
||||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
|
||||||
int columns = (unsigned int)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
|
||||||
int rows = (unsigned int)(csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
|
||||||
#else
|
|
||||||
struct winsize w;
|
|
||||||
|
|
||||||
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
||||||
|
|
||||||
unsigned int rows = w.ws_row;
|
|
||||||
unsigned int columns = w.ws_col;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::cout << "\n";
|
|
||||||
std::cout << term_current_size().x << "term_current_size()\n";
|
|
||||||
std::cout << columns << " columns\n";
|
|
||||||
|
|
||||||
if(term_current_size().x != columns)
|
|
||||||
ASSERT("current_size.x is not the same as columns", false);
|
|
||||||
if(term_current_size().y != rows)
|
|
||||||
ASSERT("current_size.y is not the same as rows", false);
|
|
||||||
ASSERT("GOOD", true);
|
|
||||||
}();
|
|
||||||
|
|
||||||
ADDPICKLE(Test_Term, Test_get_window_size);
|
|
||||||
PUTJARONSHELF(Test_Term);
|
|
||||||
*shelf = __pickle_shelf__; // end
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef TEST_TERM_H
|
|
||||||
#define TEST_TERM_H
|
|
||||||
|
|
||||||
#include <tart.h>
|
|
||||||
#include <Pickler.h>
|
|
||||||
void term_run(struct pickle_shelf*);
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user