* Renamed caca_refresh() into caca_display() which makes more sense. * Optimised gl_bgpal by directly storing floats instead of doing the conversion at runtime. * Handle resizing in cucul_set_size() and try to keep as much information as possible from the previous canvas. * Moved most global variables into cucul_t or caca_t contexts. * Moved time.c into libcaca.tags/v0.99.beta14
@@ -63,13 +63,9 @@ do | |||
--ldflags) | |||
echo_ldflags=yes | |||
;; | |||
@NEED_PIC_TRUE@ --libs) | |||
@NEED_PIC_FALSE@ --libs | --plugin-libs) | |||
--libs | --plugin-libs) | |||
echo_libs=yes | |||
;; | |||
@NEED_PIC_TRUE@ --plugin-libs) | |||
@NEED_PIC_TRUE@ echo_plugin_libs=yes | |||
@NEED_PIC_TRUE@ ;; | |||
*) | |||
usage 1 1>&2 | |||
;; | |||
@@ -109,11 +105,6 @@ fi | |||
if test "$echo_libs" = "yes" | |||
then | |||
echo -L@libdir@ -lcaca @CACA_LIBS@ | |||
echo -L@libdir@ -lcucul -lcaca @CUCUL_LIBS@ @CACA_LIBS@ | |||
fi | |||
@NEED_PIC_TRUE@if test "$echo_plugin_libs" = "yes" | |||
@NEED_PIC_TRUE@then | |||
@NEED_PIC_TRUE@ echo -L@libdir@ -lcaca_pic @CACA_LIBS@ | |||
@NEED_PIC_TRUE@fi | |||
@@ -6,7 +6,7 @@ AC_PREREQ(2.50) | |||
AC_CONFIG_AUX_DIR(autotools) | |||
AC_CANONICAL_SYSTEM | |||
AM_INIT_AUTOMAKE(libcaca, 0.9) | |||
AM_INIT_AUTOMAKE(libcaca, 0.10) | |||
AM_CONFIG_HEADER(config.h) | |||
AM_PROG_CC_C_O | |||
@@ -236,7 +236,7 @@ paused: | |||
cucul_draw_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_bitmap, bitmap); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
/*XSIZ = caca_get_width() * 2; | |||
YSIZ = caca_get_height() * 2 - 4;*/ | |||
#else | |||
@@ -144,7 +144,7 @@ paused: | |||
cucul_draw_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
cucul_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ)); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
} | |||
/* End, bye folks */ | |||
@@ -103,7 +103,7 @@ paused: | |||
cucul_draw_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
bitmap, screen); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
} | |||
end: | |||
@@ -113,7 +113,7 @@ paused: | |||
cucul_draw_bitmap(qq, 0, 0, | |||
cucul_get_width(qq) - 1, cucul_get_height(qq) - 1, | |||
bitmap, screen); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
} | |||
end: | |||
@@ -270,7 +270,7 @@ int main(int argc, char **argv) | |||
} | |||
else if(event == CACA_EVENT_RESIZE) | |||
{ | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
ww = cucul_get_width(qq); | |||
wh = cucul_get_height(qq); | |||
update = 1; | |||
@@ -300,7 +300,7 @@ int main(int argc, char **argv) | |||
buffer[ww] = '\0'; | |||
cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE); | |||
cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
ww = cucul_get_width(qq); | |||
wh = cucul_get_height(qq); | |||
@@ -394,7 +394,7 @@ int main(int argc, char **argv) | |||
print_help(ww - 25, 2); | |||
} | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
update = 0; | |||
} | |||
@@ -17,7 +17,6 @@ libcucul_la_SOURCES = \ | |||
sprite.c \ | |||
bitmap.c \ | |||
export.c \ | |||
time.c \ | |||
$(NULL) | |||
libcucul_la_LDFLAGS = -no-undefined | |||
libcucul_la_LIBADD = @CUCUL_LIBS@ | |||
@@ -28,6 +27,7 @@ libcaca_la_SOURCES = \ | |||
caca_internals.h \ | |||
graphics.c \ | |||
event.c \ | |||
time.c \ | |||
$(NULL) | |||
libcaca_la_LDFLAGS = -no-undefined | |||
libcaca_la_LIBADD = libcucul.la @CACA_LIBS@ | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -832,12 +832,12 @@ static void increment_no_dither(void) | |||
/* | |||
* Ordered 2 dithering | |||
*/ | |||
static unsigned int *ordered2_table; | |||
static unsigned int const *ordered2_table; | |||
static unsigned int ordered2_index; | |||
static void init_ordered2_dither(int line) | |||
{ | |||
static unsigned int dither2x2[] = | |||
static unsigned int const dither2x2[] = | |||
{ | |||
0x00, 0x80, | |||
0xc0, 0x40, | |||
@@ -864,12 +864,12 @@ static void increment_ordered2_dither(void) | |||
-1, -6, -5, 2, | |||
-2, -7, -8, 3, | |||
4, -3, -4, -7};*/ | |||
static unsigned int *ordered4_table; | |||
static unsigned int const *ordered4_table; | |||
static unsigned int ordered4_index; | |||
static void init_ordered4_dither(int line) | |||
{ | |||
static unsigned int dither4x4[] = | |||
static unsigned int const dither4x4[] = | |||
{ | |||
0x00, 0x80, 0x20, 0xa0, | |||
0xc0, 0x40, 0xe0, 0x60, | |||
@@ -894,12 +894,12 @@ static void increment_ordered4_dither(void) | |||
/* | |||
* Ordered 8 dithering | |||
*/ | |||
static unsigned int *ordered8_table; | |||
static unsigned int const *ordered8_table; | |||
static unsigned int ordered8_index; | |||
static void init_ordered8_dither(int line) | |||
{ | |||
static unsigned int dither8x8[] = | |||
static unsigned int const dither8x8[] = | |||
{ | |||
0x00, 0x80, 0x20, 0xa0, 0x08, 0x88, 0x28, 0xa8, | |||
0xc0, 0x40, 0xe0, 0x60, 0xc8, 0x48, 0xe8, 0x68, | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -166,22 +166,22 @@ caca_t * caca_attach(cucul_t * qq) | |||
#if defined(USE_WIN32) | |||
if(kk->driver == CACA_DRIVER_WIN32) | |||
{ | |||
/* This call is allowed to fail in cas we already have a console */ | |||
/* This call is allowed to fail in case we already have a console */ | |||
AllocConsole(); | |||
win32_hin = GetStdHandle(STD_INPUT_HANDLE); | |||
win32_hout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, | |||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | |||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |||
kk->win32.hin = GetStdHandle(STD_INPUT_HANDLE); | |||
kk->win32.hout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, | |||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | |||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |||
if(win32_hout == INVALID_HANDLE_VALUE) | |||
if(kk->win32.hout == INVALID_HANDLE_VALUE) | |||
return NULL; | |||
GetConsoleCursorInfo(win32_hout, &cci); | |||
GetConsoleCursorInfo(kk->win32.hout, &cci); | |||
cci.bVisible = FALSE; | |||
SetConsoleCursorInfo(win32_hout, &cci); | |||
SetConsoleCursorInfo(kk->win32.hout, &cci); | |||
SetConsoleMode(win32_hout, ENABLE_MOUSE_INPUT); | |||
SetConsoleMode(kk->win32.hout, ENABLE_MOUSE_INPUT); | |||
} | |||
else | |||
#endif | |||
@@ -196,9 +196,20 @@ caca_t * caca_attach(cucul_t * qq) | |||
/* Dummy */ | |||
} | |||
/* Initialise events stuff */ | |||
kk->events.key_timer.last_sec = 0; | |||
kk->events.key_timer.last_usec = 0; | |||
kk->events.last_key_ticks = 0; | |||
kk->events.autorepeat_ticks = 0; | |||
kk->events.last_key = 0; | |||
qq->refcount++; | |||
kk->qq = qq; | |||
kk->timer.last_sec = 0; | |||
kk->timer.last_usec = 0; | |||
kk->lastticks = 0; | |||
kk->resize = 0; | |||
kk->resize_event = 0; | |||
@@ -254,13 +265,13 @@ void caca_detach(caca_t *kk) | |||
#if defined(USE_WIN32) | |||
if(kk->driver == CACA_DRIVER_WIN32) | |||
{ | |||
SetConsoleTextAttribute(win32_hout, FOREGROUND_INTENSITY | |||
| FOREGROUND_RED | |||
| FOREGROUND_GREEN | |||
| FOREGROUND_BLUE); | |||
SetConsoleTextAttribute(kk->win32.hout, FOREGROUND_INTENSITY | |||
| FOREGROUND_RED | |||
| FOREGROUND_GREEN | |||
| FOREGROUND_BLUE); | |||
cci.bVisible = TRUE; | |||
SetConsoleCursorInfo(win32_hout, &cci); | |||
CloseHandle(win32_hout); | |||
SetConsoleCursorInfo(kk->win32.hout, &cci); | |||
CloseHandle(kk->win32.hout); | |||
} | |||
else | |||
#endif | |||
@@ -177,7 +177,7 @@ typedef struct caca_context caca_t; | |||
caca_t * caca_attach(cucul_t *qq); | |||
void caca_detach(caca_t *kk); | |||
void caca_set_delay(caca_t *kk, unsigned int); | |||
void caca_refresh(caca_t *kk); | |||
void caca_display(caca_t *kk); | |||
unsigned int caca_get_rendertime(caca_t *kk); | |||
unsigned int caca_get_window_width(caca_t *kk); | |||
unsigned int caca_get_window_height(caca_t *kk); | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -49,7 +49,6 @@ enum caca_driver | |||
}; | |||
/* Timer structure */ | |||
#define CACA_TIMER_INITIALIZER { 0, 0 } | |||
struct caca_timer | |||
{ | |||
int last_sec, last_usec; | |||
@@ -67,6 +66,18 @@ struct caca_context | |||
int resize_event; | |||
unsigned int delay, rendertime; | |||
struct caca_timer timer; | |||
int lastticks; | |||
struct events | |||
{ | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) | |||
struct caca_timer key_timer; | |||
unsigned int last_key_ticks; | |||
unsigned int autorepeat_ticks; | |||
unsigned int last_key; | |||
#endif | |||
} events; | |||
#if defined(USE_X11) && !defined(_DOXYGEN_SKIP_ME) | |||
struct x11 | |||
@@ -83,10 +94,52 @@ struct caca_context | |||
XFontStruct *font_struct; | |||
int font_offset; | |||
#if defined(HAVE_X11_XKBLIB_H) | |||
Bool detect_autorepeat; | |||
Bool autorepeat; | |||
#endif | |||
} x11; | |||
#endif | |||
#if defined(USE_NCURSES) | |||
struct ncurses | |||
{ | |||
int attr[16*16]; | |||
} ncurses; | |||
#endif | |||
#if defined(USE_CONIO) | |||
struct conio | |||
{ | |||
struct text_info ti; | |||
char *screen; | |||
} conio; | |||
#endif | |||
#if defined(USE_WIN32) | |||
struct win32 | |||
{ | |||
HANDLE hin, hout; | |||
HANDLE front, back; | |||
CHAR_INFO *buffer; | |||
} win32; | |||
#endif | |||
#if defined(USE_GL) | |||
struct gl | |||
{ | |||
int window; | |||
unsigned int width, height; | |||
float font_width, font_height; | |||
float incx, incy; | |||
int id[94]; | |||
unsigned char resized, bit; | |||
unsigned char mouse_changed, mouse_clicked; | |||
unsigned int mouse_x, mouse_y; | |||
unsigned int mouse_button, mouse_state; | |||
unsigned char key; | |||
int special_key; | |||
int new_width; | |||
int new_height; | |||
float sw, sh; | |||
} gl; | |||
#endif | |||
}; | |||
/* Initialisation functions */ | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -59,68 +59,6 @@ void cucul_set_color(cucul_t *qq, enum cucul_color fgcolor, enum cucul_color bgc | |||
qq->fgcolor = fgcolor; | |||
qq->bgcolor = bgcolor; | |||
#if 0 | |||
switch(kk->driver) | |||
{ | |||
#if defined(USE_SLANG) | |||
case CACA_DRIVER_SLANG: | |||
#if defined(OPTIMISE_SLANG_PALETTE) | |||
/* If foreground == background, discard this colour pair. Functions | |||
* such as cucul_putchar will print spaces instead of characters */ | |||
if(fgcolor != bgcolor) | |||
qq->fgisbg = 0; | |||
else | |||
{ | |||
qq->fgisbg = 1; | |||
if(fgcolor == CUCUL_COLOR_BLACK) | |||
fgcolor = CUCUL_COLOR_WHITE; | |||
else if(fgcolor == CUCUL_COLOR_WHITE | |||
|| fgcolor <= CUCUL_COLOR_LIGHTGRAY) | |||
fgcolor = CUCUL_COLOR_BLACK; | |||
else | |||
fgcolor = CUCUL_COLOR_WHITE; | |||
} | |||
#endif | |||
#if defined(OPTIMISE_SLANG_PALETTE) | |||
SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]); | |||
#else | |||
SLsmg_set_color(fgcolor + 16 * bgcolor); | |||
#endif | |||
break; | |||
#endif | |||
#if defined(USE_NCURSES) | |||
case CACA_DRIVER_NCURSES: | |||
attrset(ncurses_attr[fgcolor + 16 * bgcolor]); | |||
break; | |||
#endif | |||
#if defined(USE_CONIO) | |||
case CACA_DRIVER_CONIO: | |||
textbackground(bgcolor); | |||
textcolor(fgcolor); | |||
break; | |||
#endif | |||
#if defined(USE_X11) | |||
case CACA_DRIVER_X11: | |||
/* Nothing to do */ | |||
break; | |||
#endif | |||
#if defined(USE_WIN32) | |||
case CACA_DRIVER_WIN32: | |||
/* Nothing to do */ | |||
break; | |||
#endif | |||
#if defined(USE_GL) | |||
case CACA_DRIVER_GL: | |||
/* Nothing to do */ | |||
break; | |||
#endif | |||
default: | |||
break; | |||
} | |||
#endif | |||
} | |||
/** \brief Get the current foreground colour. | |||
@@ -159,59 +97,12 @@ enum cucul_color cucul_get_bg_color(cucul_t *qq) | |||
*/ | |||
void cucul_putchar(cucul_t *qq, int x, int y, char c) | |||
{ | |||
#if defined(USE_CONIO) | |||
char *data; | |||
#endif | |||
if(x < 0 || x >= (int)qq->width || | |||
y < 0 || y >= (int)qq->height) | |||
return; | |||
qq->chars[x + y * qq->width] = c; | |||
qq->attr[x + y * qq->width] = (qq->bgcolor << 4) | qq->fgcolor; | |||
#if 0 | |||
switch(kk->driver) | |||
{ | |||
#if defined(USE_SLANG) | |||
case CACA_DRIVER_SLANG: | |||
SLsmg_gotorc(y, x); | |||
#if defined(OPTIMISE_SLANG_PALETTE) | |||
if(qq->fgisbg) | |||
SLsmg_write_char(' '); | |||
else | |||
#endif | |||
SLsmg_write_char(c); | |||
break; | |||
#endif | |||
#if defined(USE_NCURSES) | |||
case CACA_DRIVER_NCURSES: | |||
move(y, x); | |||
addch(c); | |||
break; | |||
#endif | |||
#if defined(USE_CONIO) | |||
case CACA_DRIVER_CONIO: | |||
data = conio_screen + 2 * (x + y * qq->width); | |||
data[0] = c; | |||
data[1] = (qq->bgcolor << 4) | qq->fgcolor; | |||
break; | |||
#endif | |||
#if defined(USE_X11) | |||
case CACA_DRIVER_X11: | |||
break; | |||
#endif | |||
#if defined(USE_WIN32) | |||
case CACA_DRIVER_WIN32: | |||
break; | |||
#endif | |||
#if defined(USE_GL) | |||
case CACA_DRIVER_GL: | |||
break; | |||
#endif | |||
default: | |||
break; | |||
} | |||
#endif | |||
} | |||
/** \brief Print a string. | |||
@@ -262,57 +153,6 @@ void cucul_putstr(cucul_t *qq, int x, int y, char const *s) | |||
*charbuf++ = *t++; | |||
*attrbuf++ = (qq->bgcolor << 4) | qq->fgcolor; | |||
} | |||
#if 0 | |||
switch(kk->driver) | |||
{ | |||
#if defined(USE_SLANG) | |||
case CACA_DRIVER_SLANG: | |||
SLsmg_gotorc(y, x); | |||
#if defined(OPTIMISE_SLANG_PALETTE) | |||
if(qq->fgisbg) | |||
SLsmg_write_string(qq->empty_line + qq->width - len); | |||
else | |||
#endif | |||
{ | |||
union { char *ch; const char *constch; } u; | |||
u.constch = s; | |||
SLsmg_write_string(u.ch); | |||
} | |||
break; | |||
#endif | |||
#if defined(USE_NCURSES) | |||
case CACA_DRIVER_NCURSES: | |||
move(y, x); | |||
addstr(s); | |||
break; | |||
#endif | |||
#if defined(USE_CONIO) | |||
case CACA_DRIVER_CONIO: | |||
charbuf = conio_screen + 2 * (x + y * qq->width); | |||
while(*s) | |||
{ | |||
*charbuf++ = *s++; | |||
*charbuf++ = (qq->bgcolor << 4) | qq->fgcolor; | |||
} | |||
break; | |||
#endif | |||
#if defined(USE_X11) | |||
case CACA_DRIVER_X11: | |||
break; | |||
#endif | |||
#if defined(USE_WIN32) | |||
case CACA_DRIVER_WIN32: | |||
break; | |||
#endif | |||
#if defined(USE_GL) | |||
case CACA_DRIVER_GL: | |||
break; | |||
#endif | |||
default: | |||
break; | |||
} | |||
#endif | |||
} | |||
/** \brief Format a string. | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -32,7 +32,7 @@ typedef unsigned char uint8_t; | |||
#include "cucul.h" | |||
#include "cucul_internals.h" | |||
static void cucul_init_features(cucul_t *qq); | |||
static void cucul_read_environment(cucul_t *qq); | |||
/** \brief Initialise \e libcucul. | |||
* | |||
@@ -47,24 +47,20 @@ cucul_t * cucul_init(void) | |||
{ | |||
cucul_t *qq = malloc(sizeof(cucul_t)); | |||
cucul_init_features(qq); | |||
cucul_read_environment(qq); | |||
qq->fgcolor = CUCUL_COLOR_LIGHTGRAY; | |||
qq->bgcolor = CUCUL_COLOR_BLACK; | |||
#if defined(OPTIMISE_SLANG_PALETTE) | |||
qq->fgisbg = 0; | |||
#endif | |||
/* Initialise to a default size. If a graphic driver attaches to | |||
* us before cucul_set_size is called, we'll adapt. */ | |||
/* Initialise to a default size. When a graphic driver attaches to | |||
* us, we'll adapt to its size. */ | |||
qq->width = 80; | |||
qq->height = 32; | |||
qq->size_set = 0; | |||
qq->chars = malloc(qq->width * qq->height * sizeof(uint8_t)); | |||
qq->attr = malloc(qq->width * qq->height * sizeof(uint8_t)); | |||
memset(qq->chars, 0, qq->width * qq->height * sizeof(uint8_t)); | |||
memset(qq->chars, ' ', qq->width * qq->height * sizeof(uint8_t)); | |||
memset(qq->attr, 0, qq->width * qq->height * sizeof(uint8_t)); | |||
qq->empty_line = malloc(qq->width + 1); | |||
@@ -91,9 +87,89 @@ cucul_t * cucul_init(void) | |||
*/ | |||
void cucul_set_size(cucul_t *qq, unsigned int width, unsigned int height) | |||
{ | |||
unsigned int x, y, old_width, old_height, new_size, old_size; | |||
old_width = qq->width; | |||
old_height = qq->height; | |||
old_size = old_width * old_height; | |||
qq->width = width; | |||
qq->height = height; | |||
qq->size_set = 1; | |||
new_size = width * height; | |||
/* Step 1: if new area is bigger, resize the memory area now. */ | |||
if(new_size > old_size) | |||
{ | |||
qq->chars = realloc(qq->chars, new_size * sizeof(uint8_t)); | |||
qq->attr = realloc(qq->attr, new_size * sizeof(uint8_t)); | |||
} | |||
/* Step 2: move line data if necessary. */ | |||
if(width == old_width) | |||
{ | |||
/* Width did not change, which means we do not need to move data. */ | |||
; | |||
} | |||
else if(width > old_width) | |||
{ | |||
/* New width is bigger than old width, which means we need to | |||
* copy lines starting from the bottom of the screen otherwise | |||
* we will overwrite information. */ | |||
for(y = height < old_height ? height : old_height; y--; ) | |||
{ | |||
for(x = old_width; x--; ) | |||
{ | |||
qq->chars[y * width + x] = qq->chars[y * old_width + x]; | |||
qq->attr[y * width + x] = qq->attr[y * old_width + x]; | |||
} | |||
/* Zero the end of the line */ | |||
memset(qq->chars + y * width + old_width, ' ', | |||
width - old_width); | |||
memset(qq->attr + y * width + old_width, 0, | |||
width - old_width); | |||
} | |||
} | |||
else | |||
{ | |||
/* New width is smaller. Copy as many lines as possible. Ignore | |||
* the first line, it is already in place. */ | |||
unsigned int lines = height < old_height ? height : old_height; | |||
for(y = 1; y < lines; y++) | |||
{ | |||
for(x = 0; x < width; x++) | |||
{ | |||
qq->chars[y * width + x] = qq->chars[y * old_width + x]; | |||
qq->attr[y * width + x] = qq->attr[y * old_width + x]; | |||
} | |||
} | |||
} | |||
/* Step 3: fill the bottom of the new screen if necessary. */ | |||
if(height > old_height) | |||
{ | |||
/* Zero the bottom of the screen */ | |||
memset(qq->chars + old_height * width, ' ', | |||
(height - old_height) * width); | |||
} | |||
/* Step 4: if new area is smaller, resize memory area now. */ | |||
if(new_size <= old_size) | |||
{ | |||
qq->chars = realloc(qq->chars, new_size * sizeof(uint8_t)); | |||
qq->attr = realloc(qq->attr, new_size * sizeof(uint8_t)); | |||
} | |||
/* Recompute the scratch line and the empty line */ | |||
if(width != old_width) | |||
{ | |||
qq->empty_line = realloc(qq->empty_line, width + 1); | |||
memset(qq->empty_line, ' ', width); | |||
qq->empty_line[width] = '\0'; | |||
qq->scratch_line = realloc(qq->scratch_line, width + 1); | |||
} | |||
} | |||
/** \brief Get the screen width. | |||
@@ -120,7 +196,7 @@ unsigned int cucul_get_height(cucul_t *qq) | |||
/** \brief Translate a colour index into the colour's name. | |||
* | |||
* This function translates a caca_color enum into a human-readable | |||
* This function translates a cucul_color enum into a human-readable | |||
* description string of the associated colour. | |||
* | |||
* \param color The colour value. | |||
@@ -156,7 +232,7 @@ char const *cucul_get_color_name(enum cucul_color color) | |||
/** \brief Get the current value of a feature. | |||
* | |||
* This function retrieves the value of an internal \e libcaca feature. A | |||
* This function retrieves the value of an internal \e libcucul feature. A | |||
* generic feature value is expected, such as CUCUL_ANTIALIASING. | |||
* | |||
* \param feature The requested feature. | |||
@@ -181,7 +257,7 @@ enum cucul_feature cucul_get_feature(cucul_t *qq, enum cucul_feature feature) | |||
/** \brief Set a feature. | |||
* | |||
* This function sets an internal \e libcaca feature such as the antialiasing | |||
* This function sets an internal \e libcucul feature such as the antialiasing | |||
* or dithering modes. If a specific feature such as CUCUL_DITHERING_RANDOM, | |||
* cucul_set_feature() will set it immediately. If a generic feature is given | |||
* instead, such as CUCUL_DITHERING, the default value will be used instead. | |||
@@ -274,7 +350,7 @@ void cucul_end(cucul_t *qq) | |||
* XXX: The following functions are local. | |||
*/ | |||
static void cucul_init_features(cucul_t * qq) | |||
static void cucul_read_environment(cucul_t * qq) | |||
{ | |||
/* FIXME: if strcasecmp isn't available, use strcmp */ | |||
#if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP) | |||
@@ -24,16 +24,12 @@ struct cucul_context | |||
{ | |||
/* Context size */ | |||
unsigned int width, height; | |||
int size_set; | |||
uint8_t *chars, *attr; | |||
uint8_t *empty_line, *scratch_line; | |||
enum cucul_color fgcolor; | |||
enum cucul_color bgcolor; | |||
#if defined(OPTIMISE_SLANG_PALETTE) | |||
int fgisbg; | |||
#endif | |||
/* Internal libcucul features */ | |||
enum cucul_feature background, antialiasing, dithering; | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -54,17 +54,8 @@ typedef unsigned char uint8_t; | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include <GL/freeglut_ext.h> | |||
extern int gl_special_key; | |||
extern unsigned char gl_key; | |||
extern unsigned char gl_resized; | |||
extern float gl_font_width; | |||
extern float gl_font_height; | |||
extern int gl_new_width; | |||
extern int gl_new_height; | |||
extern unsigned char gl_mouse_changed, gl_mouse_clicked; | |||
extern unsigned int gl_mouse_x, gl_mouse_y; | |||
extern unsigned int gl_mouse_button, gl_mouse_state; | |||
#endif | |||
#include "cucul.h" | |||
#include "cucul_internals.h" | |||
#include "caca.h" | |||
@@ -189,10 +180,6 @@ unsigned int caca_get_mouse_y(caca_t *kk) | |||
static unsigned int _get_next_event(caca_t *kk) | |||
{ | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) | |||
static struct caca_timer key_timer = CACA_TIMER_INITIALIZER; | |||
static unsigned int last_key_ticks = 0; | |||
static unsigned int autorepeat_ticks = 0; | |||
static unsigned int last_key = 0; | |||
unsigned int ticks; | |||
#endif | |||
unsigned int event; | |||
@@ -209,45 +196,47 @@ static unsigned int _get_next_event(caca_t *kk) | |||
#if defined(USE_SLANG) || defined(USE_NCURSES) | |||
/* Simulate long keypresses using autorepeat features */ | |||
ticks = _caca_getticks(&key_timer); | |||
last_key_ticks += ticks; | |||
autorepeat_ticks += ticks; | |||
ticks = _caca_getticks(&kk->events.key_timer); | |||
kk->events.last_key_ticks += ticks; | |||
kk->events.autorepeat_ticks += ticks; | |||
/* Handle autorepeat */ | |||
if(last_key && autorepeat_ticks > AUTOREPEAT_TRIGGER | |||
&& autorepeat_ticks > AUTOREPEAT_THRESHOLD | |||
&& autorepeat_ticks > AUTOREPEAT_RATE) | |||
if(kk->events.last_key | |||
&& kk->events.autorepeat_ticks > AUTOREPEAT_TRIGGER | |||
&& kk->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD | |||
&& kk->events.autorepeat_ticks > AUTOREPEAT_RATE) | |||
{ | |||
_push_event(event); | |||
autorepeat_ticks -= AUTOREPEAT_RATE; | |||
return CACA_EVENT_KEY_PRESS | last_key; | |||
kk->events.autorepeat_ticks -= AUTOREPEAT_RATE; | |||
return CACA_EVENT_KEY_PRESS | kk->events.last_key; | |||
} | |||
/* We are in autorepeat mode and the same key was just pressed, ignore | |||
* this event and return the next one by calling ourselves. */ | |||
if(event == (CACA_EVENT_KEY_PRESS | last_key)) | |||
if(event == (CACA_EVENT_KEY_PRESS | kk->events.last_key)) | |||
{ | |||
last_key_ticks = 0; | |||
kk->events.last_key_ticks = 0; | |||
return _get_next_event(kk); | |||
} | |||
/* We are in autorepeat mode, but key has expired or a new key was | |||
* pressed - store our event and return a key release event first */ | |||
if(last_key && (last_key_ticks > AUTOREPEAT_THRESHOLD | |||
|| (event & CACA_EVENT_KEY_PRESS))) | |||
if(kk->events.last_key | |||
&& (kk->events.last_key_ticks > AUTOREPEAT_THRESHOLD | |||
|| (event & CACA_EVENT_KEY_PRESS))) | |||
{ | |||
_push_event(event); | |||
event = CACA_EVENT_KEY_RELEASE | last_key; | |||
last_key = 0; | |||
event = CACA_EVENT_KEY_RELEASE | kk->events.last_key; | |||
kk->events.last_key = 0; | |||
return event; | |||
} | |||
/* A new key was pressed, enter autorepeat mode */ | |||
if(event & CACA_EVENT_KEY_PRESS) | |||
{ | |||
last_key_ticks = 0; | |||
autorepeat_ticks = 0; | |||
last_key = event & 0x00ffffff; | |||
kk->events.last_key_ticks = 0; | |||
kk->events.autorepeat_ticks = 0; | |||
kk->events.last_key = event & 0x00ffffff; | |||
} | |||
return event; | |||
@@ -280,7 +269,8 @@ static unsigned int _lowlevel_event(caca_t *kk) | |||
/* Expose event */ | |||
if(xevent.type == Expose) | |||
{ | |||
XCopyArea(kk->x11.dpy, kk->x11.pixmap, kk->x11.window, kk->x11.gc, 0, 0, | |||
XCopyArea(kk->x11.dpy, kk->x11.pixmap, | |||
kk->x11.window, kk->x11.gc, 0, 0, | |||
kk->qq->width * kk->x11.font_width, | |||
kk->qq->height * kk->x11.font_height, 0, 0); | |||
continue; | |||
@@ -302,6 +292,7 @@ static unsigned int _lowlevel_event(caca_t *kk) | |||
kk->x11.new_width = w; | |||
kk->x11.new_height = h; | |||
/* If we are already resizing, ignore the new signal */ | |||
if(kk->resize) | |||
continue; | |||
@@ -738,56 +729,56 @@ static unsigned int _lowlevel_event(caca_t *kk) | |||
{ | |||
glutMainLoopEvent(); | |||
if(gl_resized && !kk->resize) | |||
if(kk->gl.resized && !kk->resize) | |||
{ | |||
kk->resize = 1; | |||
gl_resized = 0; | |||
kk->gl.resized = 0; | |||
return CACA_EVENT_RESIZE; | |||
} | |||
if(gl_mouse_changed) | |||
if(kk->gl.mouse_changed) | |||
{ | |||
if(gl_mouse_clicked) | |||
if(kk->gl.mouse_clicked) | |||
{ | |||
event|= CACA_EVENT_MOUSE_PRESS | gl_mouse_button; | |||
gl_mouse_clicked=0; | |||
event|= CACA_EVENT_MOUSE_PRESS | kk->gl.mouse_button; | |||
kk->gl.mouse_clicked=0; | |||
} | |||
mouse_x = gl_mouse_x; | |||
mouse_y = gl_mouse_y; | |||
mouse_x = kk->gl.mouse_x; | |||
mouse_y = kk->gl.mouse_y; | |||
event |= CACA_EVENT_MOUSE_MOTION | (mouse_x << 12) | mouse_y; | |||
gl_mouse_changed = 0; | |||
kk->gl.mouse_changed = 0; | |||
} | |||
if(gl_key != 0) | |||
if(kk->gl.key != 0) | |||
{ | |||
event |= CACA_EVENT_KEY_PRESS; | |||
event |= gl_key; | |||
gl_key = 0; | |||
event |= kk->gl.key; | |||
kk->gl.key = 0; | |||
return event; | |||
} | |||
if(gl_special_key != 0) | |||
if(kk->gl.special_key != 0) | |||
{ | |||
event |= CACA_EVENT_KEY_PRESS; | |||
switch(gl_special_key) | |||
switch(kk->gl.special_key) | |||
{ | |||
case GLUT_KEY_F1 : gl_special_key = 0; return event | CACA_KEY_F1; | |||
case GLUT_KEY_F2 : gl_special_key = 0; return event | CACA_KEY_F2; | |||
case GLUT_KEY_F3 : gl_special_key = 0; return event | CACA_KEY_F3; | |||
case GLUT_KEY_F4 : gl_special_key = 0; return event | CACA_KEY_F4; | |||
case GLUT_KEY_F5 : gl_special_key = 0; return event | CACA_KEY_F5; | |||
case GLUT_KEY_F6 : gl_special_key = 0; return event | CACA_KEY_F6; | |||
case GLUT_KEY_F7 : gl_special_key = 0; return event | CACA_KEY_F7; | |||
case GLUT_KEY_F8 : gl_special_key = 0; return event | CACA_KEY_F8; | |||
case GLUT_KEY_F9 : gl_special_key = 0; return event | CACA_KEY_F9; | |||
case GLUT_KEY_F10: gl_special_key = 0; return event | CACA_KEY_F10; | |||
case GLUT_KEY_F11: gl_special_key = 0; return event | CACA_KEY_F11; | |||
case GLUT_KEY_F12: gl_special_key = 0; return event | CACA_KEY_F12; | |||
case GLUT_KEY_LEFT : gl_special_key = 0; return event | CACA_KEY_LEFT; | |||
case GLUT_KEY_RIGHT: gl_special_key = 0; return event | CACA_KEY_RIGHT; | |||
case GLUT_KEY_UP : gl_special_key = 0; return event | CACA_KEY_UP; | |||
case GLUT_KEY_DOWN : gl_special_key = 0; return event | CACA_KEY_DOWN; | |||
case GLUT_KEY_F1 : kk->gl.special_key = 0; return event | CACA_KEY_F1; | |||
case GLUT_KEY_F2 : kk->gl.special_key = 0; return event | CACA_KEY_F2; | |||
case GLUT_KEY_F3 : kk->gl.special_key = 0; return event | CACA_KEY_F3; | |||
case GLUT_KEY_F4 : kk->gl.special_key = 0; return event | CACA_KEY_F4; | |||
case GLUT_KEY_F5 : kk->gl.special_key = 0; return event | CACA_KEY_F5; | |||
case GLUT_KEY_F6 : kk->gl.special_key = 0; return event | CACA_KEY_F6; | |||
case GLUT_KEY_F7 : kk->gl.special_key = 0; return event | CACA_KEY_F7; | |||
case GLUT_KEY_F8 : kk->gl.special_key = 0; return event | CACA_KEY_F8; | |||
case GLUT_KEY_F9 : kk->gl.special_key = 0; return event | CACA_KEY_F9; | |||
case GLUT_KEY_F10: kk->gl.special_key = 0; return event | CACA_KEY_F10; | |||
case GLUT_KEY_F11: kk->gl.special_key = 0; return event | CACA_KEY_F11; | |||
case GLUT_KEY_F12: kk->gl.special_key = 0; return event | CACA_KEY_F12; | |||
case GLUT_KEY_LEFT : kk->gl.special_key = 0; return event | CACA_KEY_LEFT; | |||
case GLUT_KEY_RIGHT: kk->gl.special_key = 0; return event | CACA_KEY_RIGHT; | |||
case GLUT_KEY_UP : kk->gl.special_key = 0; return event | CACA_KEY_UP; | |||
case GLUT_KEY_DOWN : kk->gl.special_key = 0; return event | CACA_KEY_DOWN; | |||
default: return CACA_EVENT_NONE; | |||
} | |||
} | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003, 2004 Sam Hocevar <sam@zoy.org> | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -52,7 +52,7 @@ unsigned int _caca_getticks(struct caca_timer *timer) | |||
#if defined(HAVE_GETTIMEOFDAY) | |||
struct timeval tv; | |||
#elif defined(USE_WIN32) | |||
static __int64 freq = -1; | |||
static __int64 freq = -1; /* FIXME: can this move to caca_context? */ | |||
unsigned __int64 usec; | |||
#endif | |||
unsigned int ticks = 0; | |||
@@ -1,6 +1,6 @@ | |||
/* | |||
* libcaca ASCII-Art library | |||
* Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org> | |||
* libcucul Unicode canvas library | |||
* Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org> | |||
* All Rights Reserved | |||
* | |||
* This library is free software; you can redistribute it and/or | |||
@@ -46,7 +46,7 @@ int main(int argc, char **argv) | |||
} | |||
} | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
caca_wait_event(kk, CACA_EVENT_KEY_PRESS); | |||
caca_detach(kk); | |||
@@ -63,7 +63,7 @@ int main(int argc, char **argv) | |||
/* Main menu */ | |||
display_menu(); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
/* Go ! */ | |||
while(!quit) | |||
@@ -155,7 +155,7 @@ int main(int argc, char **argv) | |||
cucul_set_color(qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK); | |||
cucul_putstr(qq, xmouse, ymouse, "|\\"); | |||
} | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
mouse = menu = 0; | |||
} | |||
@@ -168,7 +168,7 @@ int main(int argc, char **argv) | |||
cucul_printf(qq, 4, 1, "[%i.%i fps]----", | |||
1000000 / caca_get_rendertime(kk), | |||
(10000000 / caca_get_rendertime(kk)) % 10); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
} | |||
} | |||
@@ -121,7 +121,7 @@ int main(void) | |||
(100 - y) * cucul_get_height(qq) / 100, ch); | |||
} | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | |||
@@ -45,7 +45,7 @@ int main(int argc, char **argv) | |||
cucul_draw_line(qq, 0, h, cucul_get_width(qq) - 1, h, ' '); | |||
cucul_putstr(qq, 0, h, "type \"quit\" to exit"); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
events = malloc(h * sizeof(int)); | |||
memset(events, 0, h * sizeof(int)); | |||
@@ -95,7 +95,7 @@ int main(int argc, char **argv) | |||
for(i = 1; i < h && events[i]; i++) | |||
print_event(0, i, events[i]); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
} | |||
/* Clean up */ | |||
@@ -50,7 +50,7 @@ int main(void) | |||
bitmap, buffer); | |||
cucul_free_bitmap(qq, bitmap); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
while(!caca_get_event(kk, CACA_EVENT_KEY_PRESS)); | |||
@@ -108,7 +108,7 @@ int main(int argc, char **argv) | |||
/* Free sprite */ | |||
cucul_draw_sprite(qq, 20, 10, sprite, frame); | |||
caca_refresh(kk); | |||
caca_display(kk); | |||
} | |||
/* Clean up */ | |||