From ef694e0109a7c9a4cc3c80204e3dd9f33488c241 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Sun, 12 Aug 2007 20:40:55 +0000 Subject: [PATCH] Add User Interface library --- libui/Makefile | 19 ++++++++++++++ libui/libui.h | 26 +++++++++++++++++++ libui/progressbar.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ libui/window.c | 37 +++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 libui/Makefile create mode 100644 libui/libui.h create mode 100644 libui/progressbar.c create mode 100644 libui/window.c diff --git a/libui/Makefile b/libui/Makefile new file mode 100644 index 0000000..7c2ab13 --- /dev/null +++ b/libui/Makefile @@ -0,0 +1,19 @@ +# +# (c) 2005 Laurent Vivier +# + +TOP = $(shell pwd) + +68000FLAGS = -m68000 -Wa,-m68000 +CFLAGS += -nostdlib -nodefaultlibs -Wall -Werror -Wno-multichar -fpic -O2 -Os +CPPFLAGS = -I$(TOP) -DARCH_M68K + +LIBRARY = libui.a + +SOURCES = window.c progressbar.c + +HEADERS = + +all: $(LIBRARY) + +include $(TOP)/../Rules.mk diff --git a/libui/libui.h b/libui/libui.h new file mode 100644 index 0000000..d343557 --- /dev/null +++ b/libui/libui.h @@ -0,0 +1,26 @@ +/* + * + * (c) 2007 Laurent Vivier + * + */ + +typedef struct emile_window { + int l, c; + int h, w; +} emile_window_t; + +typedef struct emile_progressbar { + emile_window_t win; + int max; + int current; +} emile_progressbar_t; + +extern void console_set_cursor_position(int l, int c); +extern void console_video_inverse(void); +extern void console_video_normal(void); +extern void console_select_charset(char c); + +extern void emile_window(emile_window_t *win); +extern emile_progressbar_t* emile_progressbar_create(emile_window_t *win, int max); +extern void emile_progressbar_value(emile_progressbar_t* bar, int value); +extern void emile_progressbar_delete(emile_progressbar_t* bar); diff --git a/libui/progressbar.c b/libui/progressbar.c new file mode 100644 index 0000000..668f8c2 --- /dev/null +++ b/libui/progressbar.c @@ -0,0 +1,62 @@ +/* + * + * (c) 2007 Laurent Vivier + * + */ + +#include +#include +#include "libui.h" + +emile_progressbar_t* emile_progressbar_create(emile_window_t *win, int max) +{ + int i; + emile_progressbar_t *bar; + + if (max <= 0) + return NULL; + + bar = (emile_progressbar_t*)malloc(sizeof(emile_progressbar_t)); + if (bar == NULL) + return bar; + + bar->win = *win; + bar->max = max; + bar->current = 0; + + emile_window(&bar->win); + + console_set_cursor_position(bar->win.l, bar->win.c); + console_select_charset('0'); + for (i = 0; i < bar->win.w; i++) + putchar('a'); + console_select_charset('B'); + + return bar; +} + +void emile_progressbar_delete(emile_progressbar_t* bar) +{ + free(bar); +} + +void emile_progressbar_value(emile_progressbar_t* bar, int value) +{ + int i; + + if ( (value < 0) || (value > bar->max) ) + return; + + console_select_charset('0'); + console_video_inverse(); + for (i = bar->current * bar->win.w / bar->max; + i < value * bar->win.w / bar->max; i++) + { + console_set_cursor_position(bar->win.l, bar->win.c + i); + putchar(' '); + } + console_video_normal(); + console_select_charset('B'); + + bar->current = value; +} diff --git a/libui/window.c b/libui/window.c new file mode 100644 index 0000000..4904de8 --- /dev/null +++ b/libui/window.c @@ -0,0 +1,37 @@ +/* + * + * (c) 2007 Laurent Vivier + * + */ + +#include +#include "libui.h" + +void emile_window(emile_window_t *win) +{ + int i; + int c = win->c - 1; + int l = win->l - 1; + int w = win->w + 2; + int h = win->h + 2; + + console_select_charset('0'); + console_set_cursor_position(l, c); + putchar('l'); + for (i = 1; i < w - 1; i++) + putchar('q'); + putchar('k'); + for(i = 1; i < h - 1; i++) + { + console_set_cursor_position(l + i, c); + putchar('x'); + console_set_cursor_position(l + i, c + w - 1); + putchar('x'); + } + console_set_cursor_position(l + h - 1, c); + putchar('m'); + for (i = 1; i < w - 1; i++) + putchar('q'); + putchar('j'); + console_select_charset('B'); +}