From: John Tsiombikas Date: Thu, 29 Dec 2022 05:31:03 +0000 (+0200) Subject: input events and empty UNIX functions X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=oftp;a=commitdiff_plain;h=5363ed21fccc528965a8482b3b71fe0133595499 input events and empty UNIX functions --- diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..734fb67 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,24 @@ +src = $(wildcard src/*.c) $(wildcard src/unix/*.c) +obj = $(src:.c=.o) +dep = $(src:.c=.d) +bin = oftp + +warn = -pedantic -Wall +dbg = -g +incdir = -Isrc + +CFLAGS = $(warn) $(dbg) $(incdir) -MMD +LDFLAGS = -lcurses + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +-include $(dep) + +.PHONY: clean +clean: + $(RM) $(obj) $(bin) + +.PHONY: cleandep +cleandep: + $(RM) $(dep) diff --git a/Makefile b/Makefile index dd0f1bf..05eac20 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -obj = main.obj tgfx.obj tui.obj darray.obj util.obj +obj = main.obj tgfx.obj tui.obj darray.obj util.obj input.obj bin = oftp.exe !ifdef __UNIX__ diff --git a/src/dos/input.c b/src/dos/input.c new file mode 100644 index 0000000..99a40de --- /dev/null +++ b/src/dos/input.c @@ -0,0 +1,18 @@ +#include +#include "input.h" + +int init_input(void) +{ + return 0; +} + +void cleanup_input(void) +{ +} + +int wait_input(union event *ev) +{ + ev->type = EV_KEY; + ev->key.key = getch(); + return 1; +} diff --git a/src/input.h b/src/input.h new file mode 100644 index 0000000..412b2a0 --- /dev/null +++ b/src/input.h @@ -0,0 +1,38 @@ +#ifndef INPUT_H_ +#define INPUT_H_ + +enum { + EV_KEY, + EV_MMOVE, + EV_MBUTTON +}; + +struct event_key { + int type; + int key; +}; + +struct event_mmove { + int type; + int x, y; +}; + +struct event_mbutton { + int type; + int x, y, bn, press; +}; + +union event { + int type; + struct event_key key; + struct event_mmove mmove; + struct event_mbutton mbutton; +}; + + +int init_input(void); +void cleanup_input(void); + +int wait_input(union event *ev); + +#endif /* INPUT_H_ */ diff --git a/src/main.c b/src/main.c index 5fb66a6..2323ea3 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,12 @@ -#include #include "tgfx.h" +#include "input.h" int main(void) { + union event ev; + + init_input(); + tg_bgchar(' '); tg_clear(); @@ -14,11 +18,23 @@ int main(void) tg_text(0, 24, "fooolalala bar"); /* tg_setcursor(2, 24);*/ - while(getch() != 27); + while(wait_input(&ev)) { + switch(ev.type) { + case EV_KEY: + if(ev.key.key == 27) goto done; + break; + default: + break; + } + } + +done: tg_bgchar(' '); tg_bgcolor(0); tg_fgcolor(7); tg_clear(); + + cleanup_input(); return 0; } diff --git a/src/unix/input.c b/src/unix/input.c new file mode 100644 index 0000000..e1d689d --- /dev/null +++ b/src/unix/input.c @@ -0,0 +1,15 @@ +#include "input.h" + +int init_input(void) +{ + return 0; +} + +void cleanup_input(void) +{ +} + +int wait_input(union event *ev) +{ + return 0; +} diff --git a/src/unix/tgfx.c b/src/unix/tgfx.c new file mode 100644 index 0000000..4c8955d --- /dev/null +++ b/src/unix/tgfx.c @@ -0,0 +1,38 @@ +#include +#include "tgfx.h" + +void tg_clear(void) +{ +} + + +void tg_fgcolor(int col) +{ +} + +void tg_bgcolor(int col) +{ +} + +void tg_color(int col) +{ +} + +void tg_bgchar(int c) +{ +} + + +void tg_setcursor(int x, int y) +{ +} + + +void tg_text(int x, int y, const char *fmt, ...) +{ +} + + +void tg_rect(const char *label, int x, int y, int xsz, int ysz, unsigned int flags) +{ +}