diff --git a/caca-config.in b/caca-config.in index 9d2e485..2e69240 100644 --- a/caca-config.in +++ b/caca-config.in @@ -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 - diff --git a/configure.ac b/configure.ac index 41f0b50..d276972 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/examples/aafire.c b/examples/aafire.c index b8daf12..6a62ce1 100644 --- a/examples/aafire.c +++ b/examples/aafire.c @@ -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 diff --git a/examples/cacaball.c b/examples/cacaball.c index 1736f78..b2f4fa3 100644 --- a/examples/cacaball.c +++ b/examples/cacaball.c @@ -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 */ diff --git a/examples/cacamoir.c b/examples/cacamoir.c index 4c52119..6bfa264 100644 --- a/examples/cacamoir.c +++ b/examples/cacamoir.c @@ -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: diff --git a/examples/cacaplas.c b/examples/cacaplas.c index 2328916..02a552b 100644 --- a/examples/cacaplas.c +++ b/examples/cacaplas.c @@ -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: diff --git a/examples/cacaview.c b/examples/cacaview.c index 83d0c24..fb647e9 100644 --- a/examples/cacaview.c +++ b/examples/cacaview.c @@ -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; } diff --git a/src/Makefile.am b/src/Makefile.am index 8b1ef68..f6850ac 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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@ diff --git a/src/bitmap.c b/src/bitmap.c index a7c098e..416e007 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * 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, diff --git a/src/box.c b/src/box.c index f737e9b..8538d81 100644 --- a/src/box.c +++ b/src/box.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/src/caca.c b/src/caca.c index 405a32c..c4817ac 100644 --- a/src/caca.c +++ b/src/caca.c @@ -1,6 +1,6 @@ /* * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * Copyright (c) 2002-2006 Sam Hocevar * 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 diff --git a/src/caca.h b/src/caca.h index 399785a..778082c 100644 --- a/src/caca.h +++ b/src/caca.h @@ -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); diff --git a/src/caca_internals.h b/src/caca_internals.h index c2382c5..415bd31 100644 --- a/src/caca_internals.h +++ b/src/caca_internals.h @@ -1,6 +1,6 @@ /* * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * Copyright (c) 2002-2006 Sam Hocevar * 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 */ diff --git a/src/char.c b/src/char.c index 10c3285..a428449 100644 --- a/src/char.c +++ b/src/char.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * 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. diff --git a/src/conic.c b/src/conic.c index 384e61e..016cfb7 100644 --- a/src/conic.c +++ b/src/conic.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/src/cucul.c b/src/cucul.c index f8c26ea..01c48ce 100644 --- a/src/cucul.c +++ b/src/cucul.c @@ -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) diff --git a/src/cucul_internals.h b/src/cucul_internals.h index eeb9b61..01cd9ab 100644 --- a/src/cucul_internals.h +++ b/src/cucul_internals.h @@ -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; diff --git a/src/event.c b/src/event.c index d347278..6e2cc38 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ /* * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or @@ -54,17 +54,8 @@ typedef unsigned char uint8_t; #include #include #include -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; } } diff --git a/src/export.c b/src/export.c index e101541..e69b69d 100644 --- a/src/export.c +++ b/src/export.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/src/graphics.c b/src/graphics.c index 49395c0..554c2b9 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1,6 +1,6 @@ /* * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or @@ -142,16 +142,7 @@ static int const slang_assoc[16*16] = }; #endif -#if defined(USE_CONIO) -static struct text_info conio_ti; -static char *conio_screen; -#endif - #if defined(USE_WIN32) -HANDLE win32_hin, win32_hout; -static HANDLE win32_front, win32_back; -static CHAR_INFO *win32_buffer; - static int const win32_fg_palette[] = { 0, @@ -192,52 +183,30 @@ static int const win32_bg_palette[] = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE }; #endif -#if defined(USE_GL) -static unsigned int const gl_bgpal[] = +#if defined(USE_GL) +static float const gl_bgpal[][3] = { - 0, - 0x0000007F, - 0x00007F00, - 0x00007F7F, - 0x007F0000, - 0x007F007F, - 0x007F7F00, - 0x007F7F7F, + { 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.5f }, + { 0.0f, 0.5f, 0.0f }, + { 0.0f, 0.5f, 0.5f }, + { 0.5f, 0.0f, 0.0f }, + { 0.5f, 0.0f, 0.5f }, + { 0.5f, 0.5f, 0.0f }, + { 0.5f, 0.5f, 0.5f }, // + intensity - 0x00000000, - 0x000000FF, - 0x0000FF00, - 0x0000FFFF, - 0x00FF0000, - 0x00FF00FF, - 0x00FFFF00, - 0x00FFFFFF, - + { 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 1.0f }, + { 1.0f, 1.0f, 0.0f }, + { 1.0f, 1.0f, 1.0f }, }; -int gl_window; -unsigned int gl_width, gl_height; -float gl_font_width, gl_font_height; -float gl_incx, gl_incy; -int id[94]; -unsigned char gl_resized = 0, gl_bit = 0; -unsigned char gl_mouse_changed = 0, gl_mouse_clicked = 0; -unsigned int gl_mouse_x, gl_mouse_y; -unsigned int gl_mouse_button = 0, gl_mouse_state = 0; - -unsigned char gl_key = 0; -int gl_special_key = 0; -int gl_new_width; -int gl_new_height; - -float gl_sw = 9.0f/16.0f; -float gl_sh = 15.0f/16.0f; - -#endif - -#if defined(USE_NCURSES) -static int ncurses_attr[16*16]; +static caca_t *gl_kk; /* FIXME: we ought to get rid of this */ #endif /* @@ -250,8 +219,8 @@ static void slang_init_palette(void); #endif #if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG)) -static caca_t *sigwinch_kk; static RETSIGTYPE sigwinch_handler(int); +static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */ #endif #if defined(USE_X11) @@ -283,8 +252,7 @@ int _caca_init_graphics(caca_t *kk) * 256 colour pairs */ SLtt_Has_Alt_Charset = 0; - if(!kk->qq->size_set) - cucul_set_size(kk->qq, SLtt_Screen_Cols, SLtt_Screen_Rows); + cucul_set_size(kk->qq, SLtt_Screen_Cols, SLtt_Screen_Rows); } else #endif @@ -334,48 +302,47 @@ int _caca_init_graphics(caca_t *kk) * colour pair to be redefined. */ int col = ((max + 7 - fg) % max) + max * bg; init_pair(col, curses_colors[fg], curses_colors[bg]); - ncurses_attr[fg + 16 * bg] = COLOR_PAIR(col); + kk->ncurses.attr[fg + 16 * bg] = COLOR_PAIR(col); if(max == 8) { /* Bright fg on simple bg */ - ncurses_attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); + kk->ncurses.attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col); /* Simple fg on bright bg */ - ncurses_attr[fg + 16 * (bg + 8)] = A_BLINK + kk->ncurses.attr[fg + 16 * (bg + 8)] = A_BLINK | COLOR_PAIR(col); /* Bright fg on bright bg */ - ncurses_attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD + kk->ncurses.attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD | COLOR_PAIR(col); } } - if(!kk->qq->size_set) - cucul_set_size(kk->qq, COLS, LINES); + cucul_set_size(kk->qq, COLS, LINES); } else #endif #if defined(USE_CONIO) if(kk->driver == CACA_DRIVER_CONIO) { - gettextinfo(&conio_ti); - conio_screen = malloc(2 * conio_ti.screenwidth - * conio_ti.screenheight * sizeof(char)); - if(conio_screen == NULL) + gettextinfo(&kk->conio.ti); + kk->conio.screen = malloc(2 * kk->conio.ti.screenwidth + * kk->conio.ti.screenheight * sizeof(char)); + if(kk->conio.screen == NULL) return -1; # if defined(SCREENUPDATE_IN_PC_H) - ScreenRetrieve(conio_screen); + ScreenRetrieve(kk->conio.screen); # else /* FIXME */ # endif - if(!kk->qq->size_set) - cucul_set_size(kk->qq, conio_ti.screenwidth, conio_ti.screenheight); + cucul_set_size(kk->qq, kk->conio.ti.screenwidth, + kk->conio.ti.screenheight); } else #endif #if defined(USE_X11) if(kk->driver == CACA_DRIVER_X11) { - static int x11_palette[] = + static int const x11_palette[] = { /* Standard curses colours */ 0x0, 0x0, 0x0, @@ -400,43 +367,53 @@ int _caca_init_graphics(caca_t *kk) Colormap colormap; XSetWindowAttributes x11_winattr; int (*old_error_handler)(Display *, XErrorEvent *); - char const *font_name = "8x13bold"; + char const *fonts[] = { NULL, "8x13bold", "fixed" }, **parser; + char const *geometry; + unsigned int width = 0, height = 0; int i; - if(!kk->qq->size_set) - { - unsigned int width = 0, height = 0; - - if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY"))) - sscanf(getenv("CACA_GEOMETRY"), "%ux%u", &width, &height); + geometry = getenv("CACA_GEOMETRY"); + if(geometry && *(geometry)) + sscanf(geometry, "%ux%u", &width, &height); - if(width && height) - cucul_set_size(kk->qq, width, height); - } + if(width && height) + cucul_set_size(kk->qq, width, height); kk->x11.dpy = XOpenDisplay(NULL); if(kk->x11.dpy == NULL) return -1; - if(getenv("CACA_FONT") && *(getenv("CACA_FONT"))) - font_name = getenv("CACA_FONT"); + fonts[0] = getenv("CACA_FONT"); + if(fonts[0] && *fonts[0]) + parser = fonts; + else + parser = fonts + 1; /* Ignore font errors */ old_error_handler = XSetErrorHandler(x11_error_handler); - kk->x11.font = XLoadFont(kk->x11.dpy, font_name); - if(!kk->x11.font) + /* Parse our font list */ + for( ; ; parser++) { - XCloseDisplay(kk->x11.dpy); - return -1; - } + if(!*parser) + { + XSetErrorHandler(old_error_handler); + XCloseDisplay(kk->x11.dpy); + return -1; + } - kk->x11.font_struct = XQueryFont(kk->x11.dpy, kk->x11.font); - if(!kk->x11.font_struct) - { - XUnloadFont(kk->x11.dpy, kk->x11.font); - XCloseDisplay(kk->x11.dpy); - return -1; + kk->x11.font = XLoadFont(kk->x11.dpy, *parser); + if(!kk->x11.font) + continue; + + kk->x11.font_struct = XQueryFont(kk->x11.dpy, kk->x11.font); + if(!kk->x11.font_struct) + { + XUnloadFont(kk->x11.dpy, kk->x11.font); + continue; + } + + break; } /* Reset the default X11 error handler */ @@ -462,12 +439,13 @@ int _caca_init_graphics(caca_t *kk) x11_winattr.background_pixel = kk->x11.colors[0]; x11_winattr.event_mask = ExposureMask | StructureNotifyMask; - kk->x11.window = XCreateWindow(kk->x11.dpy, DefaultRootWindow(kk->x11.dpy), 0, 0, - kk->qq->width * kk->x11.font_width, - kk->qq->height * kk->x11.font_height, - 0, 0, InputOutput, 0, - CWBackingStore | CWBackPixel | CWEventMask, - &x11_winattr); + kk->x11.window = + XCreateWindow(kk->x11.dpy, DefaultRootWindow(kk->x11.dpy), 0, 0, + kk->qq->width * kk->x11.font_width, + kk->qq->height * kk->x11.font_height, + 0, 0, InputOutput, 0, + CWBackingStore | CWBackPixel | CWEventMask, + &x11_winattr); XStoreName(kk->x11.dpy, kk->x11.window, "caca for X"); @@ -486,10 +464,10 @@ int _caca_init_graphics(caca_t *kk) break; } - /* Disable autorepeat */ #if defined(HAVE_X11_XKBLIB_H) - XkbSetDetectableAutoRepeat(kk->x11.dpy, True, &kk->x11.detect_autorepeat); - if(!kk->x11.detect_autorepeat) + /* Disable autorepeat */ + XkbSetDetectableAutoRepeat(kk->x11.dpy, True, &kk->x11.autorepeat); + if(!kk->x11.autorepeat) XAutoRepeatOff(kk->x11.dpy); #endif @@ -498,9 +476,9 @@ int _caca_init_graphics(caca_t *kk) XSync(kk->x11.dpy, False); kk->x11.pixmap = XCreatePixmap(kk->x11.dpy, kk->x11.window, - kk->qq->width * kk->x11.font_width, - kk->qq->height * kk->x11.font_height, - DefaultDepth(kk->x11.dpy, + kk->qq->width * kk->x11.font_width, + kk->qq->height * kk->x11.font_height, + DefaultDepth(kk->x11.dpy, DefaultScreen(kk->x11.dpy))); kk->x11.new_width = kk->x11.new_height = 0; @@ -514,47 +492,44 @@ int _caca_init_graphics(caca_t *kk) CONSOLE_SCREEN_BUFFER_INFO csbi; COORD size; - win32_front = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, - 0, NULL, - CONSOLE_TEXTMODE_BUFFER, NULL); - if(!win32_front || win32_front == INVALID_HANDLE_VALUE) + kk->win32.front = + CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, + 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); + if(!kk->win32.front || kk->win32.front == INVALID_HANDLE_VALUE) return -1; - win32_back = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, - 0, NULL, - CONSOLE_TEXTMODE_BUFFER, NULL); - if(!win32_back || win32_back == INVALID_HANDLE_VALUE) + kk->win32.back = + CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, + 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); + if(!kk->win32.back || kk->win32.back == INVALID_HANDLE_VALUE) return -1; - if(!GetConsoleScreenBufferInfo(win32_hout, &csbi)) + if(!GetConsoleScreenBufferInfo(kk->win32.hout, &csbi)) return -1; /* Sample code to get the biggest possible window */ - //size = GetLargestConsoleWindowSize(win32_hout); - if(!kk->qq->size_set) - { - cucul_set_size(kk->qq, - csbi.srWindow.Right - csbi.srWindow.Left + 1, - csbi.srWindow.Bottom - csbi.srWindow.Top + 1); - } + //size = GetLargestConsoleWindowSize(kk->win32.hout); + cucul_set_size(kk->qq, csbi.srWindow.Right - csbi.srWindow.Left + 1, + csbi.srWindow.Bottom - csbi.srWindow.Top + 1); size.X = kk->qq->width; size.Y = kk->qq->height; - SetConsoleScreenBufferSize(win32_front, size); - SetConsoleScreenBufferSize(win32_back, size); + SetConsoleScreenBufferSize(kk->win32.front, size); + SetConsoleScreenBufferSize(kk->win32.back, size); - SetConsoleMode(win32_front, 0); - SetConsoleMode(win32_back, 0); + SetConsoleMode(kk->win32.front, 0); + SetConsoleMode(kk->win32.back, 0); - GetConsoleCursorInfo(win32_front, &cci); + GetConsoleCursorInfo(kk->win32.front, &cci); cci.dwSize = 0; cci.bVisible = FALSE; - SetConsoleCursorInfo(win32_front, &cci); - SetConsoleCursorInfo(win32_back, &cci); + SetConsoleCursorInfo(kk->win32.front, &cci); + SetConsoleCursorInfo(kk->win32.back, &cci); - SetConsoleActiveScreenBuffer(win32_front); + SetConsoleActiveScreenBuffer(kk->win32.front); - win32_buffer = malloc(kk->qq->width * kk->qq->height * sizeof(CHAR_INFO)); - if(win32_buffer == NULL) + kk->win32.buffer = malloc(kk->qq->width * kk->qq->height + * sizeof(CHAR_INFO)); + if(kk->win32.buffer == NULL) return -1; } else @@ -562,38 +537,47 @@ int _caca_init_graphics(caca_t *kk) #if defined(USE_GL) if(kk->driver == CACA_DRIVER_GL) { - int argc; - char *argv[2]; + char *empty_texture; + char const *geometry; + char *argv[2] = { "", NULL }; + unsigned int width = 0, height = 0; + int argc = 1; int i; - char *empty; - - if(!kk->qq->size_set) - { - unsigned int width = 0, height = 0; - if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY"))) - sscanf(getenv("CACA_GEOMETRY"), "%ux%u", &width, &height); + gl_kk = kk; - if(width && height) - cucul_set_size(kk->qq, width, height); - } + geometry = getenv("CACA_GEOMETRY"); + if(geometry && *(geometry)) + sscanf(geometry, "%ux%u", &width, &height); + + if(width && height) + cucul_set_size(kk->qq, width, height); + + kk->gl.font_width = 9; + kk->gl.font_height = 15; - gl_font_width = 9; - gl_font_height = 15; + kk->gl.width = kk->qq->width * kk->gl.font_width; + kk->gl.height = kk->qq->height * kk->gl.font_height; - gl_width = kk->qq->width * gl_font_width; - gl_height = kk->qq->height * gl_font_height; + kk->gl.resized = 0; + kk->gl.bit = 0; + + kk->gl.mouse_changed = kk->gl.mouse_clicked = 0; + kk->gl.mouse_button = kk->gl.mouse_state = 0; + + kk->gl.key = 0; + kk->gl.special_key = 0; + + kk->gl.sw = 9.0f / 16.0f; + kk->gl.sh = 15.0f / 16.0f; - argc = 1; - argv[0] = ""; - argv[1] = NULL; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); - glutInitWindowSize(gl_width, gl_height); - gl_window = glutCreateWindow("caca for GL"); + glutInitWindowSize(kk->gl.width, kk->gl.height); + kk->gl.window = glutCreateWindow("caca for GL"); - gluOrtho2D(0, gl_width, gl_height, 0); + gluOrtho2D(0, kk->gl.width, kk->gl.height, 0); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); @@ -611,27 +595,27 @@ int _caca_init_graphics(caca_t *kk) glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - gluOrtho2D(0, gl_width, gl_height, 0); + gluOrtho2D(0, kk->gl.width, kk->gl.height, 0); glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT); - empty = malloc(16 * 16 * 4); - if(empty == NULL) + empty_texture = malloc(16 * 16 * 4); + if(empty_texture == NULL) return -1; - memset(empty, 0xff, 16 * 16 * 4); + memset(empty_texture, 0xff, 16 * 16 * 4); glEnable(GL_TEXTURE_2D); for(i = 0; i < 94; i++) { - glGenTextures(1, (GLuint*)&id[i]); - glBindTexture(GL_TEXTURE_2D, id[i]); + glGenTextures(1, (GLuint*)&kk->gl.id[i]); + glBindTexture(GL_TEXTURE_2D, kk->gl.id[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, - 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, empty); + 16, 16, 0, GL_RGB, GL_UNSIGNED_BYTE, empty_texture); } for(i = 0; i < 94; i++) @@ -644,9 +628,9 @@ int _caca_init_graphics(caca_t *kk) glutBitmapCharacter(GLUT_BITMAP_9_BY_15, i + 32); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, id[i]); + glBindTexture(GL_TEXTURE_2D, kk->gl.id[i]); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, - 0, gl_height - 16, 16, 16, 0); + 0, kk->gl.height - 16, 16, 16, 0); glutMainLoopEvent(); glutPostRedisplay(); @@ -675,7 +659,7 @@ int _caca_end_graphics(caca_t *kk) #if defined(USE_CONIO) if(kk->driver == CACA_DRIVER_CONIO) { - free(conio_screen); + free(kk->conio.screen); } else #endif @@ -684,7 +668,7 @@ int _caca_end_graphics(caca_t *kk) { XSync(kk->x11.dpy, False); #if defined(HAVE_X11_XKBLIB_H) - if(!kk->x11.detect_autorepeat) + if(!kk->x11.autorepeat) XAutoRepeatOn(kk->x11.dpy); #endif XFreePixmap(kk->x11.dpy, kk->x11.pixmap); @@ -699,16 +683,16 @@ int _caca_end_graphics(caca_t *kk) #if defined(USE_WIN32) if(kk->driver == CACA_DRIVER_WIN32) { - SetConsoleActiveScreenBuffer(win32_hout); - CloseHandle(win32_back); - CloseHandle(win32_front); + SetConsoleActiveScreenBuffer(kk->win32.hout); + CloseHandle(kk->win32.back); + CloseHandle(kk->win32.front); } else #endif #if defined(USE_GL) if(kk->driver == CACA_DRIVER_GL) { - glutDestroyWindow(gl_window); + glutDestroyWindow(kk->gl.window); } else #endif @@ -787,7 +771,7 @@ unsigned int caca_get_window_width(caca_t *kk) #if defined(USE_GL) if(kk->driver == CACA_DRIVER_GL) { - return gl_width; + return kk->gl.width; } else #endif @@ -827,7 +811,7 @@ unsigned int caca_get_window_height(caca_t *kk) #if defined(USE_GL) if(kk->driver == CACA_DRIVER_GL) { - return gl_height; + return kk->gl.height; } else #endif @@ -850,8 +834,8 @@ unsigned int caca_get_window_height(caca_t *kk) */ void caca_set_size(caca_t *kk, unsigned int width, unsigned int height) { - kk->qq->width = width; - kk->qq->height = height; + kk->qq->width = width; + kk->qq->height = height; } @@ -863,7 +847,7 @@ void caca_set_size(caca_t *kk, unsigned int width, unsigned int height) */ void caca_set_width(caca_t *kk, unsigned int width) { - kk->qq->width = width; + kk->qq->width = width; } /** \brief Set the height of the window, in characters, if device permits it. * @@ -872,7 +856,7 @@ void caca_set_width(caca_t *kk, unsigned int width) */ void caca_set_height(caca_t *kk, unsigned int height) { - kk->qq->height = height; + kk->qq->height = height; } @@ -880,8 +864,8 @@ void caca_set_height(caca_t *kk, unsigned int height) /** \brief Set the refresh delay. * * This function sets the refresh delay in microseconds. The refresh delay - * is used by caca_refresh() to achieve constant framerate. See the - * caca_refresh() documentation for more details. + * is used by caca_display() to achieve constant framerate. See the + * caca_display() documentation for more details. * * If the argument is zero, constant framerate is disabled. This is the * default behaviour. @@ -896,7 +880,7 @@ void caca_set_delay(caca_t *kk, unsigned int usec) /** \brief Get the average rendering time. * * This function returns the average rendering time, which is the average - * measured time between two caca_refresh() calls, in microseconds. If + * measured time between two caca_display() calls, in microseconds. If * constant framerate was activated by calling caca_set_delay(), the average * rendering time will not be considerably shorter than the requested delay * even if the real rendering time was shorter. @@ -911,27 +895,63 @@ unsigned int caca_get_rendertime(caca_t *kk) /** \brief Flush pending changes and redraw the screen. * * This function flushes all graphical operations and prints them to the - * screen. Nothing will show on the screen until caca_refresh() is + * screen. Nothing will show on the screen until caca_display() is * called. * - * If caca_set_delay() was called with a non-zero value, caca_refresh() + * If caca_set_delay() was called with a non-zero value, caca_display() * will use that value to achieve constant framerate: if two consecutive - * calls to caca_refresh() are within a time range shorter than the value + * calls to caca_display() are within a time range shorter than the value * set with caca_set_delay(), the second call will wait a bit before * performing the screen refresh. */ -void caca_refresh(caca_t *kk) +void caca_display(caca_t *kk) { #if !defined(_DOXYGEN_SKIP_ME) #define IDLE_USEC 10000 #endif - static struct caca_timer timer = CACA_TIMER_INITIALIZER; - static int lastticks = 0; - int ticks = lastticks + _caca_getticks(&timer); + int ticks = kk->lastticks + _caca_getticks(&kk->timer); #if defined(USE_SLANG) if(kk->driver == CACA_DRIVER_SLANG) { + int x, y; + uint8_t *attr = kk->qq->attr; + uint8_t *chars = kk->qq->chars; + for(y = 0; y < kk->qq->height; y++) + { + SLsmg_gotorc(y, 0); + for(x = kk->qq->width; x--; ) + { +#if defined(OPTIMISE_SLANG_PALETTE) + /* If foreground == background, just don't use this colour + * pair, and print a space instead of the real character. */ + uint8_t fgcolor = *attr & 0xf; + uint8_t bgcolor = *attr >> 4; + if(fgcolor != bgcolor) + { + SLsmg_set_color(slang_assoc[*attr++]); + SLsmg_write_char(*chars++); + } + else + { + 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; + SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]); + SLsmg_write_char(' '); + chars++; + attr++; + } +#else + SLsmg_set_color(*attr++); + SLsmg_write_char(*chars++); +#endif + } + } SLsmg_refresh(); } else @@ -939,6 +959,18 @@ void caca_refresh(caca_t *kk) #if defined(USE_NCURSES) if(kk->driver == CACA_DRIVER_NCURSES) { + int x, y; + uint8_t *attr = kk->qq->attr; + uint8_t *chars = kk->qq->chars; + for(y = 0; y < kk->qq->height; y++) + { + move(y, 0); + for(x = kk->qq->width; x--; ) + { + attrset(kk->ncurses.attr[*attr++]); + addch(*chars++); + } + } refresh(); } else @@ -946,8 +978,17 @@ void caca_refresh(caca_t *kk) #if defined(USE_CONIO) if(kk->driver == CACA_DRIVER_CONIO) { + int n; + char *screen = kk->conio.screen; + uint8_t *attr = kk->qq->attr; + uint8_t *chars = kk->qq->chars; + for(n = kk->qq->height * kk->qq->width; n--; ) + { + *screen++ = *chars++; + *screen++ = *attr++; + } # if defined(SCREENUPDATE_IN_PC_H) - ScreenUpdate(conio_screen); + ScreenUpdate(kk->conio.screen); # else /* FIXME */ # endif @@ -972,7 +1013,8 @@ void caca_refresh(caca_t *kk) && (attr[len] >> 4) == (attr[0] >> 4)) len++; - XSetForeground(kk->x11.dpy, kk->x11.gc, kk->x11.colors[attr[0] >> 4]); + XSetForeground(kk->x11.dpy, kk->x11.gc, + kk->x11.colors[attr[0] >> 4]); XFillRectangle(kk->x11.dpy, kk->x11.pixmap, kk->x11.gc, x * kk->x11.font_width, y * kk->x11.font_height, len * kk->x11.font_width, kk->x11.font_height); @@ -1020,9 +1062,10 @@ void caca_refresh(caca_t *kk) /* Render everything to our back buffer */ for(i = 0; i < kk->qq->width * kk->qq->height; i++) { - win32_buffer[i].Char.AsciiChar = kk->qq->chars[i]; - win32_buffer[i].Attributes = win32_fg_palette[kk->qq->attr[i] & 0xf] - | win32_bg_palette[kk->qq->attr[i] >> 4]; + kk->win32.buffer[i].Char.AsciiChar = kk->qq->chars[i]; + kk->win32.buffer[i].Attributes = + win32_fg_palette[kk->qq->attr[i] & 0xf] + | win32_bg_palette[kk->qq->attr[i] >> 4]; } /* Blit the back buffer to the front buffer */ @@ -1032,7 +1075,7 @@ void caca_refresh(caca_t *kk) rect.Left = rect.Top = 0; rect.Right = kk->qq->width - 1; rect.Bottom = kk->qq->height - 1; - WriteConsoleOutput(win32_front, win32_buffer, size, pos, &rect); + WriteConsoleOutput(kk->win32.front, kk->win32.buffer, size, pos, &rect); } else #endif @@ -1044,27 +1087,27 @@ void caca_refresh(caca_t *kk) glClear(GL_COLOR_BUFFER_BIT); offsety = 0; - for(y = 0; y < gl_height; y += gl_font_height) + for(y = 0; y < kk->gl.height; y += kk->gl.font_height) { offsetx = 0; - for(x = 0; x < gl_width; x += gl_font_width) + for(x = 0; x < kk->gl.width; x += kk->gl.font_width) { uint8_t *attr = kk->qq->attr + offsetx + offsety * kk->qq->width; int offset; float br, bg, bb; offset = attr[0] >> 4; - br = ((gl_bgpal[offset] & 0x00FF0000) >> 16) / 255.0f; - bg = ((gl_bgpal[offset] & 0x0000FF00) >> 8) / 255.0f; - bb = ((gl_bgpal[offset] & 0x000000FF)) / 255.0f; + br = gl_bgpal[offset][0]; + bg = gl_bgpal[offset][1]; + bb = gl_bgpal[offset][2]; glDisable(GL_TEXTURE_2D); glColor3f(br, bg, bb); glBegin(GL_QUADS); glVertex2f(x, y); - glVertex2f(x + gl_font_width, y); - glVertex2f(x + gl_font_width, y + gl_font_height); - glVertex2f(x, y + gl_font_height); + glVertex2f(x + kk->gl.font_width, y); + glVertex2f(x + kk->gl.font_width, y + kk->gl.font_height); + glVertex2f(x, y + kk->gl.font_height); glEnd(); offsetx++; @@ -1079,33 +1122,33 @@ void caca_refresh(caca_t *kk) glBlendFunc(GL_ONE, GL_ONE); offsety = 0; - for(y = 0; y < gl_height; y += gl_font_height) + for(y = 0; y < kk->gl.height; y += kk->gl.font_height) { offsetx = 0; - for(x = 0; x < gl_width; x += gl_font_width) + for(x = 0; x < kk->gl.width; x += kk->gl.font_width) { uint8_t *attr = kk->qq->attr + offsetx + offsety * kk->qq->width; unsigned char *chr = kk->qq->chars + offsetx + offsety * kk->qq->width; float fr, fg, fb; - fr = ((gl_bgpal[attr[0] & 0xf] & 0x00FF0000) >> 16) / 255.0f; - fg = ((gl_bgpal[attr[0] & 0xf] & 0x0000FF00) >> 8) / 255.0f; - fb = ((gl_bgpal[attr[0] & 0xf] & 0x000000FF)) / 255.0f; + fr = gl_bgpal[attr[0] & 0xf][0]; + fg = gl_bgpal[attr[0] & 0xf][1]; + fb = gl_bgpal[attr[0] & 0xf][2]; if(chr[0] != ' ') { - glBindTexture(GL_TEXTURE_2D, id[chr[0]-32]); + glBindTexture(GL_TEXTURE_2D, kk->gl.id[chr[0]-32]); glColor3f(fr, fg, fb); glBegin(GL_QUADS); - glTexCoord2f(0, gl_sh); + glTexCoord2f(0, kk->gl.sh); glVertex2f(x, y); - glTexCoord2f(gl_sw, gl_sh); - glVertex2f(x + gl_font_width, y); - glTexCoord2f(gl_sw, 0); - glVertex2f(x + gl_font_width, y + gl_font_height); + glTexCoord2f(kk->gl.sw, kk->gl.sh); + glVertex2f(x + kk->gl.font_width, y); + glTexCoord2f(kk->gl.sw, 0); + glVertex2f(x + kk->gl.font_width, y + kk->gl.font_height); glTexCoord2f(0, 0); - glVertex2f(x, y + gl_font_height); + glVertex2f(x, y + kk->gl.font_height); glEnd(); } offsetx++; @@ -1125,6 +1168,7 @@ void caca_refresh(caca_t *kk) /* Dummy */ } + /* FIXME handle this somewhere else */ if(kk->resize) { kk->resize = 0; @@ -1132,10 +1176,10 @@ void caca_refresh(caca_t *kk) } /* Wait until kk->delay + time of last call */ - ticks += _caca_getticks(&timer); - for(ticks += _caca_getticks(&timer); + ticks += _caca_getticks(&kk->timer); + for(ticks += _caca_getticks(&kk->timer); ticks + IDLE_USEC < (int)kk->delay; - ticks += _caca_getticks(&timer)) + ticks += _caca_getticks(&kk->timer)) { _caca_sleep(IDLE_USEC); } @@ -1143,11 +1187,11 @@ void caca_refresh(caca_t *kk) /* Update the sliding mean of the render time */ kk->rendertime = (7 * kk->rendertime + ticks) / 8; - lastticks = ticks - kk->delay; + kk->lastticks = ticks - kk->delay; /* If we drifted too much, it's bad, bad, bad. */ - if(lastticks > (int)kk->delay) - lastticks = 0; + if(kk->lastticks > (int)kk->delay) + kk->lastticks = 0; } /* @@ -1156,17 +1200,19 @@ void caca_refresh(caca_t *kk) static void caca_handle_resize(caca_t *kk) { - unsigned int old_width = kk->qq->width; - unsigned int old_height = kk->qq->height; + unsigned int new_width, new_height; + + new_width = kk->qq->width; + new_height = kk->qq->height; #if defined(USE_SLANG) if(kk->driver == CACA_DRIVER_SLANG) { SLtt_get_screen_size(); - kk->qq->width = SLtt_Screen_Cols; - kk->qq->height = SLtt_Screen_Rows; + new_width = SLtt_Screen_Cols; + new_height = SLtt_Screen_Rows; - if(kk->qq->width != old_width || kk->qq->height != old_height) + if(new_width != kk->qq->width || new_height != kk->qq->height) SLsmg_reinit_smg(); } else @@ -1178,12 +1224,12 @@ static void caca_handle_resize(caca_t *kk) if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { - kk->qq->width = size.ws_col; - kk->qq->height = size.ws_row; + new_width = size.ws_col; + new_height = size.ws_row; #if defined(HAVE_RESIZE_TERM) - resize_term(kk->qq->height, kk->qq->width); + resize_term(new_height, new_width); #else - resizeterm(kk->qq->height, kk->qq->width); + resizeterm(new_height, new_width); #endif wrefresh(curscr); } @@ -1202,8 +1248,8 @@ static void caca_handle_resize(caca_t *kk) { Pixmap new_pixmap; - kk->qq->width = kk->x11.new_width; - kk->qq->height = kk->x11.new_height; + new_width = kk->x11.new_width; + new_height = kk->x11.new_height; new_pixmap = XCreatePixmap(kk->x11.dpy, kk->x11.window, kk->qq->width * kk->x11.font_width, @@ -1211,8 +1257,8 @@ static void caca_handle_resize(caca_t *kk) DefaultDepth(kk->x11.dpy, DefaultScreen(kk->x11.dpy))); XCopyArea(kk->x11.dpy, kk->x11.pixmap, new_pixmap, kk->x11.gc, 0, 0, - old_width * kk->x11.font_width, old_height * kk->x11.font_height, - 0, 0); + kk->qq->width * kk->x11.font_width, + kk->qq->height * kk->x11.font_height, 0, 0); XFreePixmap(kk->x11.dpy, kk->x11.pixmap); kk->x11.pixmap = new_pixmap; } @@ -1228,20 +1274,19 @@ static void caca_handle_resize(caca_t *kk) #if defined(USE_GL) if(kk->driver == CACA_DRIVER_GL) { - gl_width = gl_new_width; - gl_height = gl_new_height; - - kk->qq->width = gl_width/gl_font_width; - kk->qq->height = (gl_height/gl_font_height)+1; + kk->gl.width = kk->gl.new_width; + kk->gl.height = kk->gl.new_height; - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); + new_width = kk->gl.width / kk->gl.font_width; + new_height = (kk->gl.height / kk->gl.font_height) + 1; - glViewport(0,0,gl_width, gl_height); - gluOrtho2D(0, gl_width, gl_height, 0); - glMatrixMode(GL_MODELVIEW); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glViewport(0, 0, kk->gl.width, kk->gl.height); + gluOrtho2D(0, kk->gl.width, kk->gl.height, 0); + glMatrixMode(GL_MODELVIEW); } else #endif @@ -1249,27 +1294,9 @@ static void caca_handle_resize(caca_t *kk) /* Dummy */ } - if(kk->qq->width != old_width || kk->qq->height != old_height) - { - free(kk->qq->chars); - free(kk->qq->attr); - - kk->qq->chars = malloc(kk->qq->width * kk->qq->height * sizeof(uint8_t)); - memset(kk->qq->chars, 0, kk->qq->width * kk->qq->height * sizeof(uint8_t)); - kk->qq->attr = malloc(kk->qq->width * kk->qq->height * sizeof(uint8_t)); - memset(kk->qq->attr, 0, kk->qq->width * kk->qq->height * sizeof(uint8_t)); - } - - if(kk->qq->width != old_width) - { - free(kk->qq->empty_line); - kk->qq->empty_line = malloc(kk->qq->width + 1); - memset(kk->qq->empty_line, ' ', kk->qq->width); - kk->qq->empty_line[kk->qq->width] = '\0'; - - free(kk->qq->scratch_line); - kk->qq->scratch_line = malloc(kk->qq->width + 1); - } + /* Tell libcucul we changed size */ + if(new_width != kk->qq->width || new_height != kk->qq->height) + cucul_set_size(kk->qq, new_width, new_height); } #if defined(USE_SLANG) @@ -1337,42 +1364,52 @@ static RETSIGTYPE sigwinch_handler(int sig) #if defined(USE_GL) static void gl_handle_keyboard(unsigned char key, int x, int y) { - gl_key = key; + caca_t *kk = gl_kk; + + kk->gl.key = key; } static void gl_handle_special_key(int key, int x, int y) { - gl_special_key = key; + caca_t *kk = gl_kk; + + kk->gl.special_key = key; } static void gl_handle_reshape(int w, int h) { - if(gl_bit) /* Do not handle reshaping at the first time*/ + caca_t *kk = gl_kk; + + if(kk->gl.bit) /* Do not handle reshaping at the first time */ { - gl_new_width = w; - gl_new_height = h; + kk->gl.new_width = w; + kk->gl.new_height = h; - gl_resized = 1; + kk->gl.resized = 1; } else - gl_bit = 1; + kk->gl.bit = 1; } static void gl_handle_mouse(int button, int state, int x, int y) { - gl_mouse_clicked = 1; - gl_mouse_button = button; - gl_mouse_state = state; - gl_mouse_x = x / gl_font_width; - gl_mouse_y = y / gl_font_height; - gl_mouse_changed = 1; + caca_t *kk = gl_kk; + + kk->gl.mouse_clicked = 1; + kk->gl.mouse_button = button; + kk->gl.mouse_state = state; + kk->gl.mouse_x = x / kk->gl.font_width; + kk->gl.mouse_y = y / kk->gl.font_height; + kk->gl.mouse_changed = 1; } static void gl_handle_mouse_motion(int x, int y) { - gl_mouse_x = x / gl_font_width; - gl_mouse_y = y / gl_font_height; - gl_mouse_changed = 1; + caca_t *kk = gl_kk; + + kk->gl.mouse_x = x / kk->gl.font_width; + kk->gl.mouse_y = y / kk->gl.font_height; + kk->gl.mouse_changed = 1; } #endif diff --git a/src/line.c b/src/line.c index 62c06a3..ab5fb7e 100644 --- a/src/line.c +++ b/src/line.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/src/math.c b/src/math.c index 5e1b85b..d5d923e 100644 --- a/src/math.c +++ b/src/math.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/src/sprite.c b/src/sprite.c index 4cf5fa0..97fd66e 100644 --- a/src/sprite.c +++ b/src/sprite.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/src/time.c b/src/time.c index 34e700b..a43355b 100644 --- a/src/time.c +++ b/src/time.c @@ -1,6 +1,6 @@ /* * libcaca ASCII-Art library - * Copyright (c) 2002, 2003, 2004 Sam Hocevar + * Copyright (c) 2002-2006 Sam Hocevar * 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; diff --git a/src/triangle.c b/src/triangle.c index e5910ce..5e025cd 100644 --- a/src/triangle.c +++ b/src/triangle.c @@ -1,6 +1,6 @@ /* - * libcaca ASCII-Art library - * Copyright (c) 2002, 2003 Sam Hocevar + * libcucul Unicode canvas library + * Copyright (c) 2002-2006 Sam Hocevar * All Rights Reserved * * This library is free software; you can redistribute it and/or diff --git a/test/colors.c b/test/colors.c index 09d919b..a1fb2c9 100644 --- a/test/colors.c +++ b/test/colors.c @@ -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); diff --git a/test/demo.c b/test/demo.c index b374d97..2d52e33 100644 --- a/test/demo.c +++ b/test/demo.c @@ -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); } } diff --git a/test/dithering.c b/test/dithering.c index 3f9bef1..729e67a 100644 --- a/test/dithering.c +++ b/test/dithering.c @@ -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)); diff --git a/test/event.c b/test/event.c index feee34b..a56484e 100644 --- a/test/event.c +++ b/test/event.c @@ -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 */ diff --git a/test/hsv.c b/test/hsv.c index 22ece59..4a2dac2 100644 --- a/test/hsv.c +++ b/test/hsv.c @@ -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)); diff --git a/test/spritedit.c b/test/spritedit.c index 1c780ef..df5b4cd 100644 --- a/test/spritedit.c +++ b/test/spritedit.c @@ -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 */