Add User Interface library

This commit is contained in:
Laurent Vivier 2007-08-12 20:40:55 +00:00
parent 03adde4f89
commit ef694e0109
4 changed files with 144 additions and 0 deletions

19
libui/Makefile Normal file
View File

@ -0,0 +1,19 @@
#
# (c) 2005 Laurent Vivier <Laurent@lvivier.info>
#
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

26
libui/libui.h Normal file
View File

@ -0,0 +1,26 @@
/*
*
* (c) 2007 Laurent Vivier <Laurent@lvivier.info>
*
*/
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);

62
libui/progressbar.c Normal file
View File

@ -0,0 +1,62 @@
/*
*
* (c) 2007 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#include <stdlib.h>
#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;
}

37
libui/window.c Normal file
View File

@ -0,0 +1,37 @@
/*
*
* (c) 2007 Laurent Vivier <Laurent@lvivier.info>
*
*/
#include <stdio.h>
#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');
}