From 70d96c811ba40436480fb7dd36fc55784b06473b Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 7 Mar 2006 09:17:35 +0000 Subject: [PATCH] * Polished the driver split a bit (still no events, except resize events), properly credited authors and documented a few things. --- caca/caca.c | 55 ++++++++++++++++++++++------------- caca/caca_internals.h | 22 +++++++------- caca/driver_conio.c | 33 +++++++++------------ caca/driver_gl.c | 39 +++++++++---------------- caca/driver_ncurses.c | 50 ++++++++++++-------------------- caca/driver_slang.c | 62 ++++++++++++++------------------------- caca/driver_win32.c | 64 +++++++++++++++-------------------------- caca/driver_x11.c | 47 +++++++++--------------------- caca/event.c | 10 ++----- caca/graphics.c | 32 +-------------------- cucul/bitmap.c | 8 ------ cucul/box.c | 6 ---- cucul/char.c | 11 ++----- cucul/conic.c | 6 ---- cucul/cucul.c | 7 ----- cucul/cucul_internals.h | 10 ++++++- cucul/export.c | 15 ++++------ cucul/line.c | 6 ---- cucul/math.c | 6 ---- cucul/sprite.c | 6 ---- cucul/triangle.c | 6 ---- src/cacaview.c | 6 ++-- 22 files changed, 170 insertions(+), 337 deletions(-) diff --git a/caca/caca.c b/caca/caca.c index 8f82124..b5c5e28 100644 --- a/caca/caca.c +++ b/caca/caca.c @@ -21,13 +21,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #include #include @@ -37,40 +30,54 @@ typedef unsigned char uint8_t; #include "caca_internals.h" static int caca_init_driver(caca_t *kk); -static void caca_init_terminal(caca_t *kk); +static void caca_check_terminal(caca_t *kk); +/** \brief Attach a caca graphical context to a cucul backend context. + * + * Create a graphical context using device-dependent features (ncurses for + * terminals, an X11 window, a DOS command window...) that attaches to a + * libcucul canvas. Everything that gets drawn in the libcucul canvas can + * then be displayed by the libcaca driver. + * + * \param qq The cucul backend context. + * \return The caca graphical context or NULL if an error occurred. + */ caca_t * caca_attach(cucul_t * qq) { - int ret; caca_t *kk = malloc(sizeof(caca_t)); - ret = caca_init_driver(kk); + kk->qq = qq; - if(ret) + if(caca_init_driver(kk)) { free(kk); return NULL; } - qq->refcount++; - kk->qq = qq; - - /* Only for slang and ncurses */ - caca_init_terminal(kk); + /* Only needed for slang and ncurses */ + caca_check_terminal(kk); - if(_caca_init_graphics(kk)) + if(kk->driver.init_graphics(kk)) { - qq->refcount--; free(kk); return NULL; } - /* Initialise events stuff */ + /* Attached! */ + kk->qq->refcount++; + + /* Graphics stuff */ + kk->delay = 0; + kk->rendertime = 0; + + /* Events stuff */ +#if defined(USE_SLANG) || defined(USE_NCURSES) 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; +#endif kk->timer.last_sec = 0; kk->timer.last_usec = 0; @@ -82,6 +89,14 @@ caca_t * caca_attach(cucul_t * qq) return kk; } +/** \brief Detach a caca graphical context from a cucul backend context. + * + * Detach a graphical context from its cucul backend and destroy it. The + * libcucul canvas continues to exist and other graphical contexts can be + * attached to it afterwards. + * + * \param qq The caca graphical context. + */ void caca_detach(caca_t *kk) { kk->driver.end_graphics(kk); @@ -175,7 +190,7 @@ static int caca_init_driver(caca_t *kk) return -1; } -static void caca_init_terminal(caca_t *kk) +static void caca_check_terminal(caca_t *kk) { #if defined(HAVE_GETENV) && defined(HAVE_PUTENV) && \ (defined(USE_SLANG) || defined(USE_NCURSES)) diff --git a/caca/caca_internals.h b/caca/caca_internals.h index a890111..eca4c87 100644 --- a/caca/caca_internals.h +++ b/caca/caca_internals.h @@ -20,6 +20,14 @@ #ifndef __CACA_INTERNALS_H__ #define __CACA_INTERNALS_H__ +#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) +# include +#else +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#endif + #if defined(USE_GL) # include #endif @@ -102,7 +110,7 @@ struct caca_context unsigned int (* get_window_width) (caca_t *); unsigned int (* get_window_height) (caca_t *); void (* display) (caca_t *); - void (* handle_resize) (caca_t *); + void (* handle_resize) (caca_t *, unsigned int *, unsigned int *); } driver; unsigned int width, height; @@ -124,6 +132,7 @@ struct caca_context #endif } events; + /* FIXME: maybe this should go away */ #if defined(USE_X11) && !defined(_DOXYGEN_SKIP_ME) struct x11 { @@ -163,6 +172,7 @@ struct caca_context HANDLE hin, hout; HANDLE front, back; CHAR_INFO *buffer; + CONSOLE_CURSOR_INFO cci; } win32; #endif #if defined(USE_GL) @@ -188,18 +198,8 @@ struct caca_context #endif }; -/* Initialisation functions */ -extern int _caca_init_graphics(caca_t *kk); -extern int _caca_end_graphics(caca_t *kk); - /* Timer functions */ extern void _caca_sleep(unsigned int); extern unsigned int _caca_getticks(struct caca_timer *); -/* Cached screen size */ -extern unsigned int _caca_width; -extern unsigned int _caca_height; -extern int _caca_resize; -extern int _caca_resize_event; - #endif /* __CACA_INTERNALS_H__ */ diff --git a/caca/driver_conio.c b/caca/driver_conio.c index cec6f20..818c47d 100644 --- a/caca/driver_conio.c +++ b/caca/driver_conio.c @@ -9,23 +9,16 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file graphics.c +/** \file driver_conio.c * \version \$Id$ * \author Sam Hocevar - * \brief Character drawing + * \brief DOS/conio.h driver * - * This file contains character and string drawing functions. + * This file contains the libcaca DOS/conio.h input and output driver */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #if defined(USE_CONIO) #include @@ -50,8 +43,7 @@ typedef unsigned char uint8_t; #include "cucul.h" #include "cucul_internals.h" -#if !defined(_DOXYGEN_SKIP_ME) -int conio_init_graphics(caca_t *kk) +static int conio_init_graphics(caca_t *kk) { _wscroll = 0; _setcursortype(_NOCURSOR); @@ -72,7 +64,7 @@ int conio_init_graphics(caca_t *kk) return 0; } -int conio_end_graphics(caca_t *kk) +static int conio_end_graphics(caca_t *kk) { _wscroll = 1; textcolor((enum COLORS)WHITE); @@ -85,26 +77,25 @@ int conio_end_graphics(caca_t *kk) return 0; } -#endif /* _DOXYGEN_SKIP_ME */ -int conio_set_window_title(caca_t *kk, char const *title) +static int conio_set_window_title(caca_t *kk, char const *title) { return 0; } -unsigned int conio_get_window_width(caca_t *kk) +static unsigned int conio_get_window_width(caca_t *kk) { /* Fallback to a 6x10 font */ return kk->qq->width * 6; } -unsigned int conio_get_window_height(caca_t *kk) +static unsigned int conio_get_window_height(caca_t *kk) { /* Fallback to a 6x10 font */ return kk->qq->height * 10; } -void conio_display(caca_t *kk) +static void conio_display(caca_t *kk) { int n; char *screen = kk->conio.screen; @@ -122,9 +113,11 @@ void conio_display(caca_t *kk) # endif } -void conio_handle_resize(caca_t *kk) +static void conio_handle_resize(caca_t *kk, unsigned int *new_width, + unsigned int *new_height) { - return; + *new_width = kk->qq->width; + *new_height = kk->qq->height; } /* diff --git a/caca/driver_gl.c b/caca/driver_gl.c index 18c9702..15bf24f 100644 --- a/caca/driver_gl.c +++ b/caca/driver_gl.c @@ -9,23 +9,16 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file graphics.c +/** \file driver_gl.c * \version \$Id$ - * \author Sam Hocevar - * \brief Character drawing + * \author Jean-Yves Lamoureux + * \brief OpenGL driver * - * This file contains character and string drawing functions. + * This file contains the libcaca OpenGL input and output driver */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #if defined(USE_GL) #include @@ -82,7 +75,7 @@ static void gl_handle_reshape(int, int); static void gl_handle_mouse(int, int, int, int); static void gl_handle_mouse_motion(int, int); -int gl_init_graphics(caca_t *kk) +static int gl_init_graphics(caca_t *kk) { char *empty_texture; char const *geometry; @@ -186,29 +179,29 @@ int gl_init_graphics(caca_t *kk) return 0; } -int gl_end_graphics(caca_t *kk) +static int gl_end_graphics(caca_t *kk) { glutDestroyWindow(kk->gl.window); return 0; } -int gl_set_window_title(caca_t *kk, char const *title) +static int gl_set_window_title(caca_t *kk, char const *title) { glutSetWindowTitle(title); return 0; } -unsigned int gl_get_window_width(caca_t *kk) +static unsigned int gl_get_window_width(caca_t *kk) { return kk->gl.width; } -unsigned int gl_get_window_height(caca_t *kk) +static unsigned int gl_get_window_height(caca_t *kk) { return kk->gl.height; } -void gl_display(caca_t *kk) +static void gl_display(caca_t *kk) { unsigned int x, y, line; @@ -281,18 +274,14 @@ void gl_display(caca_t *kk) glutPostRedisplay(); } -void gl_handle_resize(caca_t *kk) +static void gl_handle_resize(caca_t *kk, unsigned int *new_width, + unsigned int *new_height) { - unsigned int new_width, new_height; - - new_width = kk->qq->width; - new_height = kk->qq->height; - kk->gl.width = kk->gl.new_width; kk->gl.height = kk->gl.new_height; - new_width = kk->gl.width / kk->gl.font_width; - new_height = (kk->gl.height / kk->gl.font_height) + 1; + *new_width = kk->gl.width / kk->gl.font_width; + *new_height = (kk->gl.height / kk->gl.font_height) + 1; glMatrixMode(GL_PROJECTION); glPushMatrix(); diff --git a/caca/driver_ncurses.c b/caca/driver_ncurses.c index ecc63e3..500220e 100644 --- a/caca/driver_ncurses.c +++ b/caca/driver_ncurses.c @@ -9,23 +9,16 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file graphics.c +/** \file driver_ncurses.c * \version \$Id$ * \author Sam Hocevar - * \brief Character drawing + * \brief Ncurses driver * - * This file contains character and string drawing functions. + * This file contains the libcaca Ncurses input and output driver */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #if defined(USE_NCURSES) #if defined(HAVE_NCURSES_H) @@ -54,23 +47,16 @@ typedef unsigned char uint8_t; #include "cucul.h" #include "cucul_internals.h" -int ncurses_init_graphics(caca_t *); -int ncurses_end_graphics(caca_t *); -int ncurses_set_window_title(caca_t *, char const *); -unsigned int ncurses_get_window_width(caca_t *); -unsigned int ncurses_get_window_height(caca_t *); -void ncurses_display(caca_t *); -void ncurses_handle_resize(caca_t *); - /* * Local functions */ + #if defined(HAVE_SIGNAL) static RETSIGTYPE sigwinch_handler(int); static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */ #endif -int ncurses_init_graphics(caca_t *kk) +static int ncurses_init_graphics(caca_t *kk) { static int curses_colors[] = { @@ -157,7 +143,7 @@ int ncurses_init_graphics(caca_t *kk) return 0; } -int ncurses_end_graphics(caca_t *kk) +static int ncurses_end_graphics(caca_t *kk) { mousemask(kk->ncurses.oldmask, NULL); curs_set(1); @@ -167,24 +153,24 @@ int ncurses_end_graphics(caca_t *kk) return 0; } -int ncurses_set_window_title(caca_t *kk, char const *title) +static int ncurses_set_window_title(caca_t *kk, char const *title) { return 0; } -unsigned int ncurses_get_window_width(caca_t *kk) +static unsigned int ncurses_get_window_width(caca_t *kk) { /* Fallback to a 6x10 font */ return kk->qq->width * 6; } -unsigned int ncurses_get_window_height(caca_t *kk) +static unsigned int ncurses_get_window_height(caca_t *kk) { /* Fallback to a 6x10 font */ return kk->qq->height * 10; } -void ncurses_display(caca_t *kk) +static void ncurses_display(caca_t *kk) { int x, y; uint8_t *attr = kk->qq->attr; @@ -201,22 +187,22 @@ void ncurses_display(caca_t *kk) refresh(); } -void ncurses_handle_resize(caca_t *kk) +static void ncurses_handle_resize(caca_t *kk, unsigned int *new_width, + unsigned int *new_height) { - unsigned int new_width, new_height; struct winsize size; - new_width = kk->qq->width; - new_height = kk->qq->height; + *new_width = kk->qq->width; + *new_height = kk->qq->height; if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { - new_width = size.ws_col; - new_height = size.ws_row; + *new_width = size.ws_col; + *new_height = size.ws_row; #if defined(HAVE_RESIZE_TERM) - resize_term(new_height, new_width); + resize_term(*new_height, *new_width); #else - resizeterm(new_height, new_width); + resizeterm(*new_height, *new_width); #endif wrefresh(curscr); } diff --git a/caca/driver_slang.c b/caca/driver_slang.c index 3d0a7ea..10b70de 100644 --- a/caca/driver_slang.c +++ b/caca/driver_slang.c @@ -9,23 +9,16 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file graphics.c +/** \file driver_slang.c * \version \$Id$ * \author Sam Hocevar - * \brief Character drawing + * \brief SLang driver * - * This file contains character and string drawing functions. + * This file contains the libcaca SLang input and output driver */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #if defined(USE_SLANG) #if defined(HAVE_SLANG_SLANG_H) @@ -112,14 +105,6 @@ static int const slang_assoc[16*16] = 123, 149, 158, 167, 176, 185, 194, 19, 125, 21, 30, 39, 48, 57, 66, 255, }; -int slang_init_graphics(caca_t *); -int slang_end_graphics(caca_t *); -int slang_set_window_title(caca_t *, char const *); -unsigned int slang_get_window_width(caca_t *); -unsigned int slang_get_window_height(caca_t *); -void slang_display(caca_t *); -void slang_handle_resize(caca_t *); - /* * Local functions */ @@ -130,8 +115,7 @@ static RETSIGTYPE sigwinch_handler(int); static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */ #endif -#if !defined(_DOXYGEN_SKIP_ME) -int slang_init_graphics(caca_t *kk) +static int slang_init_graphics(caca_t *kk) { #if defined(HAVE_SIGNAL) sigwinch_kk = kk; @@ -145,7 +129,7 @@ int slang_init_graphics(caca_t *kk) if(SLkp_init() == -1) { SLsig_unblock_signals(); - return NULL; + return -1; } SLang_init_tty(-1, 0, 1); @@ -153,7 +137,7 @@ int slang_init_graphics(caca_t *kk) if(SLsmg_init_smg() == -1) { SLsig_unblock_signals(); - return NULL; + return -1; } SLsig_unblock_signals(); @@ -179,7 +163,7 @@ int slang_init_graphics(caca_t *kk) return 0; } -int slang_end_graphics(caca_t *kk) +static int slang_end_graphics(caca_t *kk) { SLtt_set_mouse_mode(0, 0); SLtt_set_cursor_visibility(1); @@ -188,26 +172,26 @@ int slang_end_graphics(caca_t *kk) return 0; } -#endif /* _DOXYGEN_SKIP_ME */ -int slang_set_window_title(caca_t *kk, char const *title) +static int slang_set_window_title(caca_t *kk, char const *title) { + /* FIXME */ return 0; } -unsigned int slang_get_window_width(caca_t *kk) +static unsigned int slang_get_window_width(caca_t *kk) { /* Fallback to a 6x10 font */ return kk->qq->width * 6; } -unsigned int slang_get_window_height(caca_t *kk) +static unsigned int slang_get_window_height(caca_t *kk) { /* Fallback to a 6x10 font */ return kk->qq->height * 10; } -void slang_display(caca_t *kk) +static void slang_display(caca_t *kk) { int x, y; uint8_t *attr = kk->qq->attr; @@ -250,25 +234,21 @@ void slang_display(caca_t *kk) SLsmg_refresh(); } -/* - * XXX: following functions are local - */ - -void slang_handle_resize(caca_t *kk) +static void slang_handle_resize(caca_t *kk, unsigned int *new_width, + unsigned int *new_height) { - unsigned int new_width, new_height; - - new_width = kk->qq->width; - new_height = kk->qq->height; - SLtt_get_screen_size(); - new_width = SLtt_Screen_Cols; - new_height = SLtt_Screen_Rows; + *new_width = SLtt_Screen_Cols; + *new_height = SLtt_Screen_Rows; - if(new_width != kk->qq->width || new_height != kk->qq->height) + if(*new_width != kk->qq->width || *new_height != kk->qq->height) SLsmg_reinit_smg(); } +/* + * XXX: following functions are local + */ + static void slang_init_palette(void) { /* See SLang ref., 5.4.4. */ diff --git a/caca/driver_win32.c b/caca/driver_win32.c index 989209b..2e6ceb3 100644 --- a/caca/driver_win32.c +++ b/caca/driver_win32.c @@ -9,23 +9,16 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file graphics.c +/** \file driver_win32.c * \version \$Id$ * \author Sam Hocevar - * \brief Character drawing + * \brief Win32 driver * - * This file contains character and string drawing functions. + * This file contains the libcaca Win32 input and output driver */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #if defined(USE_WIN32) #include @@ -87,17 +80,8 @@ static int const win32_bg_palette[] = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE }; -int win32_init_graphics(caca_t *); -int win32_end_graphics(caca_t *); -int win32_set_window_title(caca_t *, char const *); -unsigned int win32_get_window_width(caca_t *); -unsigned int win32_get_window_height(caca_t *); -void win32_display(caca_t *); -void win32_handle_resize(caca_t *); - -int win32_init_graphics(caca_t *kk) +static int win32_init_graphics(caca_t *kk) { - CONSOLE_CURSOR_INFO cci; CONSOLE_SCREEN_BUFFER_INFO csbi; COORD size; @@ -111,9 +95,9 @@ int win32_init_graphics(caca_t *kk) if(kk->win32.hout == INVALID_HANDLE_VALUE) return -1; - GetConsoleCursorInfo(kk->win32.hout, &cci); - cci.bVisible = FALSE; - SetConsoleCursorInfo(kk->win32.hout, &cci); + GetConsoleCursorInfo(kk->win32.hout, &kk->win32.cci); + kk->win32.cci.bVisible = FALSE; + SetConsoleCursorInfo(kk->win32.hout, &kk->win32.cci); SetConsoleMode(kk->win32.hout, ENABLE_MOUSE_INPUT); @@ -144,11 +128,11 @@ int win32_init_graphics(caca_t *kk) SetConsoleMode(kk->win32.front, 0); SetConsoleMode(kk->win32.back, 0); - GetConsoleCursorInfo(kk->win32.front, &cci); - cci.dwSize = 0; - cci.bVisible = FALSE; - SetConsoleCursorInfo(kk->win32.front, &cci); - SetConsoleCursorInfo(kk->win32.back, &cci); + GetConsoleCursorInfo(kk->win32.front, &kk->win32.cci); + kk->win32.cci.dwSize = 0; + kk->win32.cci.bVisible = FALSE; + SetConsoleCursorInfo(kk->win32.front, &kk->win32.cci); + SetConsoleCursorInfo(kk->win32.back, &kk->win32.cci); SetConsoleActiveScreenBuffer(kk->win32.front); @@ -160,7 +144,7 @@ int win32_init_graphics(caca_t *kk) return 0; } -int win32_end_graphics(caca_t *kk) +static int win32_end_graphics(caca_t *kk) { SetConsoleActiveScreenBuffer(kk->win32.hout); CloseHandle(kk->win32.back); @@ -170,20 +154,20 @@ int win32_end_graphics(caca_t *kk) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); - cci.bVisible = TRUE; - SetConsoleCursorInfo(kk->win32.hout, &cci); + kk->win32.cci.bVisible = TRUE; + SetConsoleCursorInfo(kk->win32.hout, &kk->win32.cci); CloseHandle(kk->win32.hout); return 0; } -int win32_set_window_title(caca_t *kk, char const *title) +static int win32_set_window_title(caca_t *kk, char const *title) { SetConsoleTitle(title); return 0; } -unsigned int win32_get_window_width(caca_t *kk) +static unsigned int win32_get_window_width(caca_t *kk) { /* FIXME */ @@ -191,7 +175,7 @@ unsigned int win32_get_window_width(caca_t *kk) return kk->qq->width * 6; } -unsigned int win32_get_window_height(caca_t *kk) +static unsigned int win32_get_window_height(caca_t *kk) { /* FIXME */ @@ -199,7 +183,7 @@ unsigned int win32_get_window_height(caca_t *kk) return kk->qq->height * 10; } -void win32_display(caca_t *kk) +static void win32_display(caca_t *kk) { COORD size, pos; SMALL_RECT rect; @@ -224,14 +208,12 @@ void win32_display(caca_t *kk) WriteConsoleOutput(kk->win32.front, kk->win32.buffer, size, pos, &rect); } -void win32_handle_resize(caca_t *kk) +static void win32_handle_resize(caca_t *kk, unsigned int *new_width, + unsigned int *new_height) { - unsigned int new_width, new_height; - - new_width = kk->qq->width; - new_height = kk->qq->height; - /* Nothing to do here. */ + *new_width = kk->qq->width; + *new_height = kk->qq->height; } /* diff --git a/caca/driver_x11.c b/caca/driver_x11.c index 1330492..2be2b62 100644 --- a/caca/driver_x11.c +++ b/caca/driver_x11.c @@ -9,23 +9,16 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file graphics.c +/** \file driver_x11.c * \version \$Id$ * \author Sam Hocevar - * \brief Character drawing + * \brief X11 driver * - * This file contains character and string drawing functions. + * This file contains the libcaca X11 input and output driver */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #if defined(USE_X11) #include @@ -46,21 +39,12 @@ typedef unsigned char uint8_t; #include "cucul.h" #include "cucul_internals.h" -int x11_init_graphics(caca_t *); -int x11_end_graphics(caca_t *); -int x11_set_window_title(caca_t *, char const *); -unsigned int x11_get_window_width(caca_t *); -unsigned int x11_get_window_height(caca_t *); -void x11_display(caca_t *); -void x11_handle_resize(caca_t *); - /* * Local functions */ static int x11_error_handler(Display *, XErrorEvent *); -#if !defined(_DOXYGEN_SKIP_ME) -int x11_init_graphics(caca_t *kk) +static int x11_init_graphics(caca_t *kk) { static int const x11_palette[] = { @@ -210,7 +194,7 @@ int x11_init_graphics(caca_t *kk) return 0; } -int x11_end_graphics(caca_t *kk) +static int x11_end_graphics(caca_t *kk) { XSync(kk->x11.dpy, False); #if defined(HAVE_X11_XKBLIB_H) @@ -226,25 +210,24 @@ int x11_end_graphics(caca_t *kk) return 0; } -#endif /* _DOXYGEN_SKIP_ME */ -int x11_set_window_title(caca_t *kk, char const *title) +static int x11_set_window_title(caca_t *kk, char const *title) { XStoreName(kk->x11.dpy, kk->x11.window, title); return 0; } -unsigned int x11_get_window_width(caca_t *kk) +static unsigned int x11_get_window_width(caca_t *kk) { return kk->qq->width * kk->x11.font_width; } -unsigned int x11_get_window_height(caca_t *kk) +static unsigned int x11_get_window_height(caca_t *kk) { return kk->qq->height * kk->x11.font_height; } -void x11_display(caca_t *kk) +static void x11_display(caca_t *kk) { unsigned int x, y, len; @@ -308,17 +291,13 @@ void x11_display(caca_t *kk) XFlush(kk->x11.dpy); } -void x11_handle_resize(caca_t *kk) +static void x11_handle_resize(caca_t *kk, unsigned int *new_width, + unsigned int *new_height) { - unsigned int new_width, new_height; - Pixmap new_pixmap; - new_width = kk->qq->width; - new_height = kk->qq->height; - - new_width = kk->x11.new_width; - new_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, diff --git a/caca/event.c b/caca/event.c index ade2470..879a5ea 100644 --- a/caca/event.c +++ b/caca/event.c @@ -19,12 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #if defined(USE_SLANG) # if defined(HAVE_SLANG_SLANG_H) # include @@ -658,11 +652,11 @@ static unsigned int _lowlevel_event(caca_t *kk) for( ; ; ) { - GetNumberOfConsoleInputEvents(win32_hin, &num); + GetNumberOfConsoleInputEvents(kk->win32.hin, &num); if(num == 0) break; - ReadConsoleInput(win32_hin, &rec, 1, &num); + ReadConsoleInput(kk->win32.hin, &rec, 1, &num); if(rec.EventType == KEY_EVENT) { if(rec.Event.KeyEvent.bKeyDown) diff --git a/caca/graphics.c b/caca/graphics.c index 19abec4..2f56db8 100644 --- a/caca/graphics.c +++ b/caca/graphics.c @@ -19,13 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #include /* BUFSIZ */ #include #include @@ -44,26 +37,6 @@ typedef unsigned char uint8_t; */ static void caca_handle_resize(caca_t *kk); -#if !defined(_DOXYGEN_SKIP_ME) -int _caca_init_graphics(caca_t *kk) -{ - int ret = kk->driver.init_graphics(kk); - - if(!ret) - return ret; - - kk->delay = 0; - kk->rendertime = 0; - - return 0; -} - -int _caca_end_graphics(caca_t *kk) -{ - return kk->driver.end_graphics(kk); -} -#endif /* _DOXYGEN_SKIP_ME */ - /** \brief Set the window title. * * If libcaca runs in a window, try to change its title. This works with @@ -191,10 +164,7 @@ static void caca_handle_resize(caca_t *kk) { unsigned int new_width, new_height; - new_width = kk->qq->width; - new_height = kk->qq->height; - - kk->driver.handle_resize(kk); + kk->driver.handle_resize(kk, &new_width, &new_height); /* Tell libcucul we changed size */ if(new_width != kk->qq->width || new_height != kk->qq->height) diff --git a/cucul/bitmap.c b/cucul/bitmap.c index 9707654..86a51e4 100644 --- a/cucul/bitmap.c +++ b/cucul/bitmap.c @@ -19,14 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -#endif - #if defined(HAVE_ENDIAN_H) # include #endif diff --git a/cucul/box.c b/cucul/box.c index 8538d81..88d94ae 100644 --- a/cucul/box.c +++ b/cucul/box.c @@ -19,12 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #include #include "cucul.h" diff --git a/cucul/char.c b/cucul/char.c index e64bc31..8ecd6fe 100644 --- a/cucul/char.c +++ b/cucul/char.c @@ -19,13 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #include /* BUFSIZ */ #include #include @@ -102,7 +95,7 @@ void cucul_putchar(cucul_t *qq, int x, int y, char c) y < 0 || y >= (int)qq->height) return; - qq->chars[x + y * qq->width] = c & 0x7f; /* FIXME: ASCII-only */ + qq->chars[x + y * qq->width] = c & 0x0000007f; /* FIXME: ASCII-only */ qq->attr[x + y * qq->width] = (qq->bgcolor << 4) | qq->fgcolor; } @@ -151,7 +144,7 @@ void cucul_putstr(cucul_t *qq, int x, int y, char const *s) t = s; while(*t) { - *chars++ = *t++ & 0x7f; /* FIXME: ASCII-only */ + *chars++ = *t++ & 0x0000007f; /* FIXME: ASCII-only */ *attr++ = (qq->bgcolor << 4) | qq->fgcolor; } } diff --git a/cucul/conic.c b/cucul/conic.c index 016cfb7..5b4db62 100644 --- a/cucul/conic.c +++ b/cucul/conic.c @@ -20,12 +20,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #include #include "cucul.h" diff --git a/cucul/cucul.c b/cucul/cucul.c index a9ecbf1..94a7ae5 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -20,13 +20,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #include #include diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h index 005204e..afa843f 100644 --- a/cucul/cucul_internals.h +++ b/cucul/cucul_internals.h @@ -20,6 +20,14 @@ #ifndef __CUCUL_INTERNALS_H__ #define __CUCUL_INTERNALS_H__ +#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) +# include +#else +typedef unsigned char uint8_t; +typedef unsigned char uint16_t; +typedef unsigned int uint32_t; +#endif + struct cucul_context { /* Context size */ @@ -27,7 +35,7 @@ struct cucul_context uint32_t *chars; uint8_t *attr; - uint8_t *empty_line, *scratch_line; + char *empty_line, *scratch_line; enum cucul_color fgcolor; enum cucul_color bgcolor; diff --git a/cucul/export.c b/cucul/export.c index 9ab81a8..9f6dffa 100644 --- a/cucul/export.c +++ b/cucul/export.c @@ -9,23 +9,18 @@ * http://sam.zoy.org/wtfpl/COPYING for more details. */ -/** \file char.c +/** \file export.c * \version \$Id$ * \author Sam Hocevar - * \brief Character drawing + * \author Jean-Yves Lamoureux + * \brief Export function * - * This file contains character and string drawing functions. + * This file contains export functions for various file formats such + * as HTML or IRC. */ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned int uint32_t; -typedef unsigned char uint8_t; -#endif - #include #include #include diff --git a/cucul/line.c b/cucul/line.c index ab5fb7e..85c2b47 100644 --- a/cucul/line.c +++ b/cucul/line.c @@ -20,12 +20,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #include #include "cucul.h" diff --git a/cucul/math.c b/cucul/math.c index d5d923e..21f6e79 100644 --- a/cucul/math.c +++ b/cucul/math.c @@ -19,12 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #include #include "cucul.h" diff --git a/cucul/sprite.c b/cucul/sprite.c index 97fd66e..56677ed 100644 --- a/cucul/sprite.c +++ b/cucul/sprite.c @@ -19,12 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #include #include #include diff --git a/cucul/triangle.c b/cucul/triangle.c index 5e025cd..7dcac88 100644 --- a/cucul/triangle.c +++ b/cucul/triangle.c @@ -19,12 +19,6 @@ #include "config.h" -#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME) -# include -#else -typedef unsigned char uint8_t; -#endif - #include #include "cucul.h" diff --git a/src/cacaview.c b/src/cacaview.c index fb647e9..1f0b8ab 100644 --- a/src/cacaview.c +++ b/src/cacaview.c @@ -680,8 +680,8 @@ static void load_image(char const *name) fclose(fp); /* Create the libcaca bitmap */ - bitmap = caca_create_bitmap(bpp, w, h, depth * w, - rmask, gmask, bmask, amask); + bitmap = cucul_create_bitmap(qq, bpp, w, h, depth * w, + rmask, gmask, bmask, amask); if(!bitmap) { free(pixels); @@ -690,7 +690,7 @@ static void load_image(char const *name) } if(bpp == 8) - caca_set_bitmap_palette(bitmap, red, green, blue, alpha); + cucul_set_bitmap_palette(qq, bitmap, red, green, blue, alpha); #endif }