Skip to content
Snippets Groups Projects
Commit cde16183 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

More stuff, really just a checkpoint before I start rendering.

parent e2bbb4d5
No related branches found
No related tags found
No related merge requests found
Pipeline #5454 passed
CFLAGS += -I../xpdev -I../cutest -pthread
CFLAGS += -I../conio -I../xpdev -I../cutest -pthread
CFLAGS += -DHAS_STDINT_H
CFLAGS += -DHAS_INTTYPES_H
CFLAGS += -g -std=c11 -Wall -Wextra -Wpedantic
LIBS += -lpthread
LDFLAGS += -L../conio/clang.freebsd.amd64.lib.portable -L../xpdev/clang.freebsd.amd64.lib.portable
LIBS += -lpthread -lciolib_mt -lxpdev_mt -lcursesw -lm
VPATH = ../cutest:../xpdev
......@@ -10,7 +11,7 @@ ifdef TESTS
CFLAGS += -DBUILD_TESTS
all: runtest
test: alltests.o CuTest.o threadwrap.o libnewifc.a
test: alltests.o CuTest.o libnewifc.a
cc ${LDFLAGS} -L. ${CFLAGS} $^ -o $@ ${LIBS} -lnewifc
runtest: test
......
......@@ -67,7 +67,6 @@ attributes[] = {
{"child_width", NI_attr_type_uint16_t, attr_impl_global, 1},
{"child_xpos", NI_attr_type_uint16_t, attr_impl_global, 1},
{"child_ypos", NI_attr_type_uint16_t, attr_impl_global, 1},
{"dirty", NI_attr_type_bool, attr_impl_root, 1},
{"fill_character", NI_attr_type_uint32_t, attr_impl_global, 0},
{"fill_character_colour", NI_attr_type_uint32_t, attr_impl_global, 0},
{"fill_colour", NI_attr_type_uint32_t, attr_impl_global, 0},
......@@ -84,9 +83,6 @@ attributes[] = {
{"min_width", NI_attr_type_uint16_t, attr_impl_global, 1},
{"parent", NI_attr_type_NewIfcObj, attr_impl_global, 1},
{"root", NI_attr_type_NewIfcObj, attr_impl_global, 1},
{"show_help", NI_attr_type_bool, attr_impl_object, 0},
{"show_title", NI_attr_type_bool, attr_impl_object, 0},
{"title", NI_attr_type_charptr, attr_impl_object, 0},
{"topchild", NI_attr_type_NewIfcObj, attr_impl_global, 1},
{"type", NI_attr_type_NewIfc_object, attr_impl_global, 1},
{"width", NI_attr_type_uint16_t, attr_impl_global, 0},
......@@ -132,6 +128,7 @@ const struct handler_info
extra_handlers[] = {
{"on_render", "NI_err (*on_render)(NewIfcObj obj, void *cbdata)"},
{"on_destroy", "NI_err (*on_destroy)(NewIfcObj obj, void *cbdata)"},
{"on_key", "NI_err (*on_key)(NewIfcObj obj, uint16_t scancode)"},
};
size_t
......@@ -319,7 +316,23 @@ main(int argc, char **argv)
}
fputs("};\n\n", header);
fputs("#define NI_TRANSPARENT UINT32_MAX\n\n", header);
fputs("#define NI_TRANSPARENT UINT32_MAX\n"
"#define NI_BLACK UINT32_C(0)\n"
"#define NI_BLUE UINT32_C(0x0000A8)\n"
"#define NI_GREEN UINT32_C(0x00A800)\n"
"#define NI_CYAN UINT32_C(0x00A8A8)\n"
"#define NI_RED UINT32_C(0xA80000)\n"
"#define NI_MAGENTA UINT32_C(0xA800A8)\n"
"#define NI_BROWN UINT32_C(0xA85400)\n"
"#define NI_LIGHTGRAY UINT32_C(0xA8A8A8)\n"
"#define NI_DARKGRAY UINT32_C(0x545454)\n"
"#define NI_LIGHTBLUE UINT32_C(0x5454FF)\n"
"#define NI_LIGHTGREEN UINT32_C(0x54FF54)\n"
"#define NI_LIGHTCYAN UINT32_C(0x54FFFF)\n"
"#define NI_LIGHTRED UINT32_C(0xFF5454)\n"
"#define NI_LIGHTMAGENTA UINT32_C(0xFF54FF)\n"
"#define NI_YELLOW UINT32_C(0xFFFF54)\n"
"#define NI_WHITE UINT32_C(0xFFFFFF)\n\n", header);
fputs("NI_err NI_copy(NewIfcObj obj, NewIfcObj *newobj);\n", header);
fputs("NI_err NI_create(enum NewIfc_object obj, NewIfcObj parent, NewIfcObj *newobj);\n", header);
......@@ -485,6 +498,7 @@ main(int argc, char **argv)
" (*newobj)->topchild = NULL;\n"
" (*newobj)->bottomchild = NULL;\n"
" (*newobj)->handlers = NULL;\n"
" (*newobj)->handlers_sz = 0;\n"
" if (parent) {\n"
" (*newobj)->root = parent->root;\n"
" (*newobj)->lowerpeer = parent->topchild;\n"
......
......@@ -2,6 +2,8 @@
#include <stdarg.h>
#include <stdlib.h> // malloc()/free()
#define CIOLIB_NO_MACROS
#include "ciolib.h"
#include "genwrap.h"
#include "strwrap.h"
#include "threadwrap.h"
......@@ -19,12 +21,9 @@ static const char default_title[] = "No Title Set";
struct root_window {
struct newifc_api api;
char *title;
size_t title_sz;
struct vmem_cell *display;
pthread_mutex_t mtx;
unsigned locks;
unsigned show_title:1;
unsigned help:1;
unsigned dirty:1;
};
......@@ -146,36 +145,68 @@ rw_copy(NewIfcObj old, NewIfcObj *newobj)
return NewIfc_error_none;
}
static NI_err
rw_render(NewIfcObj obj, uint16_t xpos, uint16_t ypos, uint16_t width, uint16_t height)
{
struct root_window *rw = (struct root_window *)obj;
size_t sz = rw->api.width;
sz *= rw->api.height;
if (rw->api.fill_colour != NI_TRANSPARENT || rw->api.fill_character_colour != NI_TRANSPARENT) {
for (size_t c = 0; c < sz; c++) {
// TODO: No way to generate legacy attribute from colour.
if (rw->api.fill_colour != NI_TRANSPARENT)
rw->display[c].bg = rw->api.fill_colour;
if (rw->api.fill_character_colour != NI_TRANSPARENT) {
rw->display[c].fg = rw->api.fill_character_colour;
rw->display[c].ch = rw->api.fill_character;
if (ciolib_checkfont(rw->api.fill_font))
rw->display[c].font = rw->api.fill_font;
}
}
}
}
static NI_err
NewIFC_root_window(NewIfcObj *newobj)
{
struct root_window **newrw = (struct root_window **)newobj;
*newrw = malloc(sizeof(struct root_window));
*newrw = calloc(1, sizeof(struct root_window));
if (*newrw == NULL) {
if (*newrw == NULL)
return NewIfc_error_allocation_failure;
}
(*newrw)->api.get = rw_get;
(*newrw)->api.set = rw_set;
(*newrw)->api.copy = rw_copy;
(*newrw)->api.last_error = NewIfc_error_none;
(*newrw)->api.width = 80;
(*newrw)->api.height = 25;
(*newrw)->api.child_width = 80;
(*newrw)->api.child_height = 25;
(*newrw)->api.xpos = 0;
(*newrw)->api.ypos = 0;
(*newrw)->api.child_xpos = 0;
(*newrw)->api.child_ypos = 1;
(*newrw)->api.min_height = 2;
(*newrw)->api.min_width = 40;
// TODO: This is only needed by the unit tests...
(*newrw)->api.root = *newobj;
(*newrw)->api.focus = true;
(*newrw)->locks = 0;
(*newrw)->mtx = pthread_mutex_initializer_np(true);
struct text_info ti;
ciolib_gettextinfo(&ti);
(*newrw)->api.width = ti.screenwidth;
(*newrw)->api.height = ti.screenheight;
(*newrw)->api.child_width = ti.screenwidth;
(*newrw)->api.child_height = ti.screenheight;
(*newrw)->api.fill_character = ' ';
(*newrw)->api.fill_colour = ciolib_bg;
(*newrw)->api.fill_character_colour = ciolib_fg;
int cf = ciolib_getfont(0);
if (cf < 0)
cf = 0;
(*newrw)->api.fill_font = cf;
size_t cells = ti.screenwidth;
cells *= ti.screenheight;
(*newrw)->display = malloc(sizeof(struct vmem_cell) * cells);
if ((*newrw)->display == NULL) {
free(*newrw);
*newrw = NULL;
return NewIfc_error_allocation_failure;
}
ciolib_vmem_gettext(1, 1, (*newrw)->api.width, (*newrw)->api.height, (*newrw)->display);
return NewIfc_error_none;
}
......@@ -196,8 +227,8 @@ void test_root_window(CuTest *ct)
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->width == 80);
CuAssertTrue(ct, obj->height == 25);
CuAssertTrue(ct, obj->min_width == 40);
CuAssertTrue(ct, obj->min_height == 2);
CuAssertTrue(ct, obj->min_width == 0);
CuAssertTrue(ct, obj->min_height == 0);
CuAssertTrue(ct, obj->last_error == NewIfc_error_none);
CuAssertTrue(ct, obj->focus == true);
CuAssertTrue(ct, obj->get(obj, NewIfc_locked, &b) == NewIfc_error_none && !b);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment