Browse Source

* Renamed caca_t into caca_display_t.

* Renamed canvas handle variables from "c" to "cv". Eh ouais mon gros.
tags/v0.99.beta14
Sam Hocevar sam 19 years ago
parent
commit
687a2c43f6
49 changed files with 1785 additions and 1782 deletions
  1. +46
    -46
      caca/caca.c
  2. +13
    -13
      caca/caca.h
  3. +23
    -23
      caca/caca_internals.h
  4. +41
    -41
      caca/driver_conio.c
  5. +127
    -127
      caca/driver_gl.c
  6. +118
    -118
      caca/driver_ncurses.c
  7. +27
    -27
      caca/driver_raw.c
  8. +52
    -52
      caca/driver_slang.c
  9. +26
    -26
      caca/driver_vga.c
  10. +83
    -83
      caca/driver_win32.c
  11. +200
    -200
      caca/driver_x11.c
  12. +60
    -60
      caca/event.c
  13. +39
    -39
      caca/graphics.c
  14. +18
    -18
      cpp/caca++.cpp
  15. +1
    -1
      cpp/caca++.h
  16. +45
    -45
      cpp/cucul++.cpp
  17. +2
    -2
      cpp/cucul++.h
  18. +23
    -23
      cucul/box.c
  19. +35
    -35
      cucul/canvas.c
  20. +13
    -13
      cucul/charset.c
  21. +8
    -8
      cucul/colour.c
  22. +31
    -31
      cucul/conic.c
  23. +57
    -56
      cucul/cucul.c
  24. +7
    -7
      cucul/dither.c
  25. +62
    -62
      cucul/export.c
  26. +10
    -10
      cucul/font.c
  27. +35
    -34
      cucul/line.c
  28. +8
    -7
      cucul/sprite.c
  29. +26
    -26
      cucul/transform.c
  30. +18
    -18
      cucul/triangle.c
  31. +19
    -19
      src/aafire.c
  32. +17
    -17
      src/cacaball.c
  33. +14
    -14
      src/cacamoir.c
  34. +18
    -18
      src/cacaplas.c
  35. +9
    -9
      src/cacaplay.c
  36. +65
    -65
      src/cacaview.c
  37. +9
    -9
      src/img2irc.c
  38. +15
    -15
      test/colors.c
  39. +136
    -136
      test/demo.c
  40. +11
    -11
      test/dithering.c
  41. +32
    -32
      test/event.c
  42. +16
    -16
      test/export.c
  43. +20
    -20
      test/font.c
  44. +20
    -20
      test/gamma.c
  45. +10
    -10
      test/hsv.c
  46. +27
    -27
      test/spritedit.c
  47. +17
    -17
      test/transform.c
  48. +12
    -12
      test/truecolor.c
  49. +64
    -64
      test/unicode.c

+ 46
- 46
caca/caca.c View File

@@ -29,7 +29,7 @@
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


static int caca_init_driver(caca_t *kk);
static int caca_init_driver(caca_display_t *dp);


/** \brief Attach a caca graphical context to a cucul canvas. /** \brief Attach a caca graphical context to a cucul canvas.
* *
@@ -38,58 +38,58 @@ static int caca_init_driver(caca_t *kk);
* libcucul canvas. Everything that gets drawn in the libcucul canvas can * libcucul canvas. Everything that gets drawn in the libcucul canvas can
* then be displayed by the libcaca driver. * then be displayed by the libcaca driver.
* *
* \param c The cucul cavas.
* \param cv The cucul cavas.
* \return The caca graphical context or NULL if an error occurred. * \return The caca graphical context or NULL if an error occurred.
*/ */
caca_t * caca_attach(cucul_canvas_t * c)
caca_display_t * caca_attach(cucul_canvas_t * cv)
{ {
caca_t *kk = malloc(sizeof(caca_t));
caca_display_t *dp = malloc(sizeof(caca_display_t));


kk->c = c;
dp->cv = cv;


if(caca_init_driver(kk))
if(caca_init_driver(dp))
{ {
free(kk);
free(dp);
return NULL; return NULL;
} }


if(kk->drv.init_graphics(kk))
if(dp->drv.init_graphics(dp))
{ {
free(kk);
free(dp);
return NULL; return NULL;
} }


/* Attached! */ /* Attached! */
kk->c->refcount++;
dp->cv->refcount++;


/* Graphics stuff */ /* Graphics stuff */
kk->delay = 0;
kk->rendertime = 0;
dp->delay = 0;
dp->rendertime = 0;


/* Events stuff */ /* Events stuff */
#if defined(USE_SLANG) || defined(USE_NCURSES) #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_event.type = CACA_EVENT_NONE;
dp->events.key_timer.last_sec = 0;
dp->events.key_timer.last_usec = 0;
dp->events.last_key_ticks = 0;
dp->events.autorepeat_ticks = 0;
dp->events.last_key_event.type = CACA_EVENT_NONE;
#endif #endif
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
kk->events.queue = 0;
dp->events.queue = 0;
#endif #endif


kk->timer.last_sec = 0;
kk->timer.last_usec = 0;
kk->lastticks = 0;
dp->timer.last_sec = 0;
dp->timer.last_usec = 0;
dp->lastticks = 0;


/* Mouse position */ /* Mouse position */
kk->mouse.x = kk->c->width / 2;
kk->mouse.y = kk->c->height / 2;
dp->mouse.x = dp->cv->width / 2;
dp->mouse.y = dp->cv->height / 2;


/* Resize events */ /* Resize events */
kk->resize.resized = 0;
dp->resize.resized = 0;


return kk;
return dp;
} }


/** \brief Detach a caca graphical context from a cucul backend context. /** \brief Detach a caca graphical context from a cucul backend context.
@@ -98,20 +98,20 @@ caca_t * caca_attach(cucul_canvas_t * c)
* libcucul canvas continues to exist and other graphical contexts can be * libcucul canvas continues to exist and other graphical contexts can be
* attached to it afterwards. * attached to it afterwards.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
*/ */
void caca_detach(caca_t *kk)
void caca_detach(caca_display_t *dp)
{ {
kk->drv.end_graphics(kk);
kk->c->refcount--;
free(kk);
dp->drv.end_graphics(dp);
dp->cv->refcount--;
free(dp);
} }


/* /*
* XXX: The following functions are local. * XXX: The following functions are local.
*/ */


static int caca_init_driver(caca_t *kk)
static int caca_init_driver(caca_display_t *dp)
{ {
#if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP) #if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP)
char *var = getenv("CACA_DRIVER"); char *var = getenv("CACA_DRIVER");
@@ -120,51 +120,51 @@ static int caca_init_driver(caca_t *kk)
if(var && *var) if(var && *var)
{ {
#if defined(USE_WIN32) #if defined(USE_WIN32)
if(!strcasecmp(var, "win32")) return win32_install(kk);
if(!strcasecmp(var, "win32")) return win32_install(dp);
#endif #endif
#if defined(USE_CONIO) #if defined(USE_CONIO)
if(!strcasecmp(var, "conio")) return conio_install(kk);
if(!strcasecmp(var, "conio")) return conio_install(dp);
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
if(!strcasecmp(var, "x11")) return x11_install(kk);
if(!strcasecmp(var, "x11")) return x11_install(dp);
#endif #endif
#if defined(USE_GL) #if defined(USE_GL)
if(!strcasecmp(var, "gl")) return gl_install(kk);
if(!strcasecmp(var, "gl")) return gl_install(dp);
#endif #endif
if(!strcasecmp(var, "raw")) return raw_install(kk);
if(!strcasecmp(var, "raw")) return raw_install(dp);
#if defined(USE_SLANG) #if defined(USE_SLANG)
if(!strcasecmp(var, "slang")) return slang_install(kk);
if(!strcasecmp(var, "slang")) return slang_install(dp);
#endif #endif
#if defined(USE_NCURSES) #if defined(USE_NCURSES)
if(!strcasecmp(var, "ncurses")) return ncurses_install(kk);
if(!strcasecmp(var, "ncurses")) return ncurses_install(dp);
#endif #endif
#if defined(USE_VGA) #if defined(USE_VGA)
if(!strcasecmp(var, "vga")) return vga_install(kk);
if(!strcasecmp(var, "vga")) return vga_install(dp);
#endif #endif
return -1; return -1;
} }
#endif #endif


#if defined(USE_WIN32) #if defined(USE_WIN32)
if(win32_install(kk) == 0) return 0;
if(win32_install(dp) == 0) return 0;
#endif #endif
#if defined(USE_CONIO) #if defined(USE_CONIO)
if(conio_install(kk) == 0) return 0;
if(conio_install(dp) == 0) return 0;
#endif #endif
#if defined(USE_VGA) #if defined(USE_VGA)
if(vga_install(kk) == 0) return 0;
if(vga_install(dp) == 0) return 0;
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
if(x11_install(kk) == 0) return 0;
if(x11_install(dp) == 0) return 0;
#endif #endif
#if defined(USE_GL) #if defined(USE_GL)
if(gl_install(kk) == 0) return 0;
if(gl_install(dp) == 0) return 0;
#endif #endif
#if defined(USE_SLANG) #if defined(USE_SLANG)
if(slang_install(kk) == 0) return 0;
if(slang_install(dp) == 0) return 0;
#endif #endif
#if defined(USE_NCURSES) #if defined(USE_NCURSES)
if(ncurses_install(kk) == 0) return 0;
if(ncurses_install(dp) == 0) return 0;
#endif #endif


return -1; return -1;


+ 13
- 13
caca/caca.h View File

@@ -88,7 +88,7 @@ extern "C"
#endif #endif


/** \e libcaca context */ /** \e libcaca context */
typedef struct caca caca_t;
typedef struct caca_display caca_display_t;
/** event structure */ /** event structure */
typedef struct caca_event caca_event_t; typedef struct caca_event caca_event_t;


@@ -203,14 +203,14 @@ enum caca_key
* initialisation, system information retrieval and configuration. * initialisation, system information retrieval and configuration.
* *
* @{ */ * @{ */
caca_t * caca_attach(cucul_canvas_t *);
void caca_detach(caca_t *);
void caca_set_delay(caca_t *, unsigned int);
void caca_display(caca_t *);
unsigned int caca_get_rendertime(caca_t *);
unsigned int caca_get_window_width(caca_t *);
unsigned int caca_get_window_height(caca_t *);
int caca_set_window_title(caca_t *, char const *);
caca_display_t * caca_attach(cucul_canvas_t *);
void caca_detach(caca_display_t *);
void caca_set_delay(caca_display_t *, unsigned int);
void caca_display(caca_display_t *);
unsigned int caca_get_rendertime(caca_display_t *);
unsigned int caca_get_window_width(caca_display_t *);
unsigned int caca_get_window_height(caca_display_t *);
int caca_set_window_title(caca_display_t *, char const *);
/* @} */ /* @} */


/** \defgroup event Event handling /** \defgroup event Event handling
@@ -219,10 +219,10 @@ int caca_set_window_title(caca_t *, char const *);
* clicks. * clicks.
* *
* @{ */ * @{ */
int caca_get_event(caca_t *, unsigned int, caca_event_t *, int);
unsigned int caca_get_mouse_x(caca_t *);
unsigned int caca_get_mouse_y(caca_t *);
void caca_set_mouse(caca_t *, int);
int caca_get_event(caca_display_t *, unsigned int, caca_event_t *, int);
unsigned int caca_get_mouse_x(caca_display_t *);
unsigned int caca_get_mouse_y(caca_display_t *);
void caca_set_mouse(caca_display_t *, int);
/* @} */ /* @} */


#ifdef __cplusplus #ifdef __cplusplus


+ 23
- 23
caca/caca_internals.h View File

@@ -61,26 +61,26 @@ enum caca_driver


/* Available external drivers */ /* Available external drivers */
#if defined(USE_CONIO) #if defined(USE_CONIO)
int conio_install(caca_t *);
int conio_install(caca_display_t *);
#endif #endif
#if defined(USE_GL) #if defined(USE_GL)
int gl_install(caca_t *);
int gl_install(caca_display_t *);
#endif #endif
#if defined(USE_NCURSES) #if defined(USE_NCURSES)
int ncurses_install(caca_t *);
int ncurses_install(caca_display_t *);
#endif #endif
int raw_install(caca_t *);
int raw_install(caca_display_t *);
#if defined(USE_SLANG) #if defined(USE_SLANG)
int slang_install(caca_t *);
int slang_install(caca_display_t *);
#endif #endif
#if defined(USE_VGA) #if defined(USE_VGA)
int vga_install(caca_t *);
int vga_install(caca_display_t *);
#endif #endif
#if defined(USE_WIN32) #if defined(USE_WIN32)
int win32_install(caca_t *);
int win32_install(caca_display_t *);
#endif #endif
#if defined(USE_X11) #if defined(USE_X11)
int x11_install(caca_t *);
int x11_install(caca_display_t *);
#endif #endif


/* Timer structure */ /* Timer structure */
@@ -89,11 +89,11 @@ struct caca_timer
int last_sec, last_usec; int last_sec, last_usec;
}; };


/* Internal caca context */
struct caca
/* Internal caca display context */
struct caca_display
{ {
/* A link to our cucul canvas */ /* A link to our cucul canvas */
cucul_canvas_t *c;
cucul_canvas_t *cv;


/* Device-specific functions */ /* Device-specific functions */
struct drv struct drv
@@ -101,15 +101,15 @@ struct caca
enum caca_driver driver; enum caca_driver driver;
struct driver_private *p; struct driver_private *p;


int (* init_graphics) (caca_t *);
int (* end_graphics) (caca_t *);
int (* set_window_title) (caca_t *, char const *);
unsigned int (* get_window_width) (caca_t *);
unsigned int (* get_window_height) (caca_t *);
void (* display) (caca_t *);
void (* handle_resize) (caca_t *);
int (* get_event) (caca_t *, caca_event_t *);
void (* set_mouse) (caca_t *, int);
int (* init_graphics) (caca_display_t *);
int (* end_graphics) (caca_display_t *);
int (* set_window_title) (caca_display_t *, char const *);
unsigned int (* get_window_width) (caca_display_t *);
unsigned int (* get_window_height) (caca_display_t *);
void (* display) (caca_display_t *);
void (* handle_resize) (caca_display_t *);
int (* get_event) (caca_display_t *, caca_event_t *);
void (* set_mouse) (caca_display_t *, int);
} drv; } drv;


/* Mouse position */ /* Mouse position */
@@ -153,10 +153,10 @@ extern void _caca_sleep(unsigned int);
extern unsigned int _caca_getticks(caca_timer_t *); extern unsigned int _caca_getticks(caca_timer_t *);


/* Internal event functions */ /* Internal event functions */
extern void _caca_handle_resize(caca_t *);
extern void _caca_handle_resize(caca_display_t *);
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
extern void _push_event(caca_t *, caca_event_t *);
extern int _pop_event(caca_t *, caca_event_t *);
extern void _push_event(caca_display_t *, caca_event_t *);
extern int _pop_event(caca_display_t *, caca_event_t *);
#endif #endif


#endif /* __CACA_INTERNALS_H__ */ #endif /* __CACA_INTERNALS_H__ */

+ 41
- 41
caca/driver_conio.c View File

@@ -38,88 +38,88 @@ struct driver_private
char *screen; char *screen;
}; };


static int conio_init_graphics(caca_t *kk)
static int conio_init_graphics(caca_display_t *dp)
{ {
kk->drv.p = malloc(sizeof(struct driver_private));
dp->drv.p = malloc(sizeof(struct driver_private));


_wscroll = 0; _wscroll = 0;
_setcursortype(_NOCURSOR); _setcursortype(_NOCURSOR);
clrscr(); clrscr();


gettextinfo(&kk->drv.p->ti);
kk->drv.p->screen = malloc(2 * kk->drv.p->ti.screenwidth
* kk->drv.p->ti.screenheight * sizeof(char));
if(kk->drv.p->screen == NULL)
gettextinfo(&dp->drv.p->ti);
dp->drv.p->screen = malloc(2 * dp->drv.p->ti.screenwidth
* dp->drv.p->ti.screenheight * sizeof(char));
if(dp->drv.p->screen == NULL)
return -1; return -1;
# if defined(SCREENUPDATE_IN_PC_H) # if defined(SCREENUPDATE_IN_PC_H)
ScreenRetrieve(kk->drv.p->screen);
ScreenRetrieve(dp->drv.p->screen);
# else # else
/* FIXME */ /* FIXME */
# endif # endif
_cucul_set_size(kk->c, kk->drv.p->ti.screenwidth,
kk->drv.p->ti.screenheight);
_cucul_set_size(dp->cv, dp->drv.p->ti.screenwidth,
dp->drv.p->ti.screenheight);
return 0; return 0;
} }


static int conio_end_graphics(caca_t *kk)
static int conio_end_graphics(caca_display_t *dp)
{ {
_wscroll = 1; _wscroll = 1;
textcolor((enum COLORS)WHITE); textcolor((enum COLORS)WHITE);
textbackground((enum COLORS)BLACK); textbackground((enum COLORS)BLACK);
gotoxy(kk->c->width, kk->c->height);
gotoxy(dp->cv->width, dp->cv->height);
cputs("\r\n"); cputs("\r\n");
_setcursortype(_NORMALCURSOR); _setcursortype(_NORMALCURSOR);


free(kk->drv.p->screen);
free(kk->drv.p);
free(dp->drv.p->screen);
free(dp->drv.p);


return 0; return 0;
} }


static int conio_set_window_title(caca_t *kk, char const *title)
static int conio_set_window_title(caca_display_t *dp, char const *title)
{ {
return 0; return 0;
} }


static unsigned int conio_get_window_width(caca_t *kk)
static unsigned int conio_get_window_width(caca_display_t *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->width * 6;
return dp->cv->width * 6;
} }


static unsigned int conio_get_window_height(caca_t *kk)
static unsigned int conio_get_window_height(caca_display_t *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->height * 10;
return dp->cv->height * 10;
} }


static void conio_display(caca_t *kk)
static void conio_display(caca_display_t *dp)
{ {
char *screen = kk->drv.p->screen;
uint32_t *attr = kk->c->attr;
uint32_t *chars = kk->c->chars;
char *screen = dp->drv.p->screen;
uint32_t *attr = dp->cv->attr;
uint32_t *chars = dp->cv->chars;
int n; int n;


for(n = kk->c->height * kk->c->width; n--; )
for(n = dp->cv->height * dp->cv->width; n--; )
{ {
*screen++ = _cucul_utf32_to_cp437(*chars++); *screen++ = _cucul_utf32_to_cp437(*chars++);
*screen++ = _cucul_argb32_to_ansi8(*attr++); *screen++ = _cucul_argb32_to_ansi8(*attr++);
} }
# if defined(SCREENUPDATE_IN_PC_H) # if defined(SCREENUPDATE_IN_PC_H)
ScreenUpdate(kk->drv.p->screen);
ScreenUpdate(dp->drv.p->screen);
# else # else
/* FIXME */ /* FIXME */
# endif # endif
} }


static void conio_handle_resize(caca_t *kk)
static void conio_handle_resize(caca_display_t *dp)
{ {
/* We know nothing about our window */ /* We know nothing about our window */
kk->resize.w = kk->c->width;
kk->resize.h = kk->c->height;
dp->resize.w = dp->cv->width;
dp->resize.h = dp->cv->height;
} }


static int conio_get_event(caca_t *kk, caca_event_t *ev)
static int conio_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
unsigned char ch; unsigned char ch;
caca_event_t release; caca_event_t release;
@@ -140,7 +140,7 @@ static int conio_get_event(caca_t *kk, caca_event_t *ev)


release = *ev; release = *ev;
release.type = CACA_EVENT_KEY_RELEASE; release.type = CACA_EVENT_KEY_RELEASE;
_push_event(kk, &release);
_push_event(dp, &release);


return 1; return 1;
} }
@@ -149,19 +149,19 @@ static int conio_get_event(caca_t *kk, caca_event_t *ev)
* Driver initialisation * Driver initialisation
*/ */


int conio_install(caca_t *kk)
int conio_install(caca_display_t *dp)
{ {
kk->drv.driver = CACA_DRIVER_CONIO;
kk->drv.init_graphics = conio_init_graphics;
kk->drv.end_graphics = conio_end_graphics;
kk->drv.set_window_title = conio_set_window_title;
kk->drv.get_window_width = conio_get_window_width;
kk->drv.get_window_height = conio_get_window_height;
kk->drv.display = conio_display;
kk->drv.handle_resize = conio_handle_resize;
kk->drv.get_event = conio_get_event;
kk->drv.set_mouse = NULL;
dp->drv.driver = CACA_DRIVER_CONIO;
dp->drv.init_graphics = conio_init_graphics;
dp->drv.end_graphics = conio_end_graphics;
dp->drv.set_window_title = conio_set_window_title;
dp->drv.get_window_width = conio_get_window_width;
dp->drv.get_window_height = conio_get_window_height;
dp->drv.display = conio_display;
dp->drv.handle_resize = conio_handle_resize;
dp->drv.get_event = conio_get_event;
dp->drv.set_mouse = NULL;


return 0; return 0;
} }


+ 127
- 127
caca/driver_gl.c View File

@@ -41,7 +41,7 @@
* Global variables * Global variables
*/ */


static caca_t *gl_kk; /* FIXME: we ought to get rid of this */
static caca_display_t *gl_d; /* FIXME: we ought to get rid of this */


/* /*
* Local functions * Local functions
@@ -76,7 +76,7 @@ struct driver_private
float sw, sh; float sw, sh;
}; };


static int gl_init_graphics(caca_t *kk)
static int gl_init_graphics(caca_display_t *dp)
{ {
char *empty_texture; char *empty_texture;
char const *geometry; char const *geometry;
@@ -85,9 +85,9 @@ static int gl_init_graphics(caca_t *kk)
int argc = 1; int argc = 1;
int i; int i;


kk->drv.p = malloc(sizeof(struct driver_private));
dp->drv.p = malloc(sizeof(struct driver_private));


gl_kk = kk;
gl_d = dp;


#if defined(HAVE_GETENV) #if defined(HAVE_GETENV)
geometry = getenv("CACA_GEOMETRY"); geometry = getenv("CACA_GEOMETRY");
@@ -96,35 +96,35 @@ static int gl_init_graphics(caca_t *kk)
#endif #endif


if(width && height) if(width && height)
_cucul_set_size(kk->c, width, height);
_cucul_set_size(dp->cv, width, height);


kk->drv.p->font_width = 9;
kk->drv.p->font_height = 15;
dp->drv.p->font_width = 9;
dp->drv.p->font_height = 15;


kk->drv.p->width = kk->c->width * kk->drv.p->font_width;
kk->drv.p->height = kk->c->height * kk->drv.p->font_height;
dp->drv.p->width = dp->cv->width * dp->drv.p->font_width;
dp->drv.p->height = dp->cv->height * dp->drv.p->font_height;


#ifdef HAVE_GLUTCLOSEFUNC #ifdef HAVE_GLUTCLOSEFUNC
kk->drv.p->close = 0;
dp->drv.p->close = 0;
#endif #endif
kk->drv.p->bit = 0;
dp->drv.p->bit = 0;


kk->drv.p->mouse_changed = kk->drv.p->mouse_clicked = 0;
kk->drv.p->mouse_button = kk->drv.p->mouse_state = 0;
dp->drv.p->mouse_changed = dp->drv.p->mouse_clicked = 0;
dp->drv.p->mouse_button = dp->drv.p->mouse_state = 0;


kk->drv.p->key = 0;
kk->drv.p->special_key = 0;
dp->drv.p->key = 0;
dp->drv.p->special_key = 0;


kk->drv.p->sw = 9.0f / 16.0f;
kk->drv.p->sh = 15.0f / 16.0f;
dp->drv.p->sw = 9.0f / 16.0f;
dp->drv.p->sh = 15.0f / 16.0f;


glutInit(&argc, argv); glutInit(&argc, argv);


glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(kk->drv.p->width, kk->drv.p->height);
kk->drv.p->window = glutCreateWindow("caca for GL");
glutInitWindowSize(dp->drv.p->width, dp->drv.p->height);
dp->drv.p->window = glutCreateWindow("caca for GL");


gluOrtho2D(0, kk->drv.p->width, kk->drv.p->height, 0);
gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);


glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
@@ -147,7 +147,7 @@ static int gl_init_graphics(caca_t *kk)
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
gluOrtho2D(0, kk->drv.p->width, kk->drv.p->height, 0);
gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);


glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);


@@ -162,8 +162,8 @@ static int gl_init_graphics(caca_t *kk)


for(i = 32; i < 128; i++) for(i = 32; i < 128; i++)
{ {
glGenTextures(1, (GLuint*)&kk->drv.p->id[i - 32]);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[i - 32]);
glGenTextures(1, (GLuint*)&dp->drv.p->id[i - 32]);
glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[i - 32]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,
@@ -180,9 +180,9 @@ static int gl_init_graphics(caca_t *kk)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, i); glutBitmapCharacter(GLUT_BITMAP_9_BY_15, i);


glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[i - 32]);
glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[i - 32]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
0, kk->drv.p->height - 16, 16, 16, 0);
0, dp->drv.p->height - 16, 16, 16, 0);


#ifdef HAVE_GLUTCHECKLOOP #ifdef HAVE_GLUTCHECKLOOP
glutCheckLoop(); glutCheckLoop();
@@ -195,41 +195,41 @@ static int gl_init_graphics(caca_t *kk)
return 0; return 0;
} }


static int gl_end_graphics(caca_t *kk)
static int gl_end_graphics(caca_display_t *dp)
{ {
glutDestroyWindow(kk->drv.p->window);
free(kk->drv.p);
glutDestroyWindow(dp->drv.p->window);
free(dp->drv.p);
return 0; return 0;
} }


static int gl_set_window_title(caca_t *kk, char const *title)
static int gl_set_window_title(caca_display_t *dp, char const *title)
{ {
glutSetWindowTitle(title); glutSetWindowTitle(title);
return 0; return 0;
} }


static unsigned int gl_get_window_width(caca_t *kk)
static unsigned int gl_get_window_width(caca_display_t *dp)
{ {
return kk->drv.p->width;
return dp->drv.p->width;
} }


static unsigned int gl_get_window_height(caca_t *kk)
static unsigned int gl_get_window_height(caca_display_t *dp)
{ {
return kk->drv.p->height;
return dp->drv.p->height;
} }


static void gl_display(caca_t *kk)
static void gl_display(caca_display_t *dp)
{ {
unsigned int x, y, line; unsigned int x, y, line;


glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);


line = 0; line = 0;
for(y = 0; y < kk->drv.p->height; y += kk->drv.p->font_height)
for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height)
{ {
uint32_t *attr = kk->c->attr + line * kk->c->width;
uint32_t *attr = dp->cv->attr + line * dp->cv->width;


for(x = 0; x < kk->drv.p->width; x += kk->drv.p->font_width)
for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width)
{ {
uint16_t bg = _cucul_argb32_to_rgb12bg(*attr++); uint16_t bg = _cucul_argb32_to_rgb12bg(*attr++);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
@@ -238,10 +238,10 @@ static void gl_display(caca_t *kk)
(bg & 0x00f) * 8); (bg & 0x00f) * 8);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(x, y); glVertex2f(x, y);
glVertex2f(x + kk->drv.p->font_width, y);
glVertex2f(x + kk->drv.p->font_width,
y + kk->drv.p->font_height);
glVertex2f(x, y + kk->drv.p->font_height);
glVertex2f(x + dp->drv.p->font_width, y);
glVertex2f(x + dp->drv.p->font_width,
y + dp->drv.p->font_height);
glVertex2f(x, y + dp->drv.p->font_height);
glEnd(); glEnd();
} }


@@ -254,32 +254,32 @@ static void gl_display(caca_t *kk)
glBlendFunc(GL_ONE, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);


line = 0; line = 0;
for(y = 0; y < kk->drv.p->height; y += kk->drv.p->font_height)
for(y = 0; y < dp->drv.p->height; y += dp->drv.p->font_height)
{ {
uint32_t *attr = kk->c->attr + line * kk->c->width;
uint32_t *chars = kk->c->chars + line * kk->c->width;
uint32_t *attr = dp->cv->attr + line * dp->cv->width;
uint32_t *chars = dp->cv->chars + line * dp->cv->width;


for(x = 0; x < kk->drv.p->width; x += kk->drv.p->font_width)
for(x = 0; x < dp->drv.p->width; x += dp->drv.p->font_width)
{ {
uint32_t c = *chars++;
uint32_t cv = *chars++;


if(c > 0x00000020 && c < 0x00000080)
if(cv > 0x00000020 && cv < 0x00000080)
{ {
uint16_t fg = _cucul_argb32_to_rgb12fg(*attr); uint16_t fg = _cucul_argb32_to_rgb12fg(*attr);
glBindTexture(GL_TEXTURE_2D, kk->drv.p->id[c - 32]);
glBindTexture(GL_TEXTURE_2D, dp->drv.p->id[cv - 32]);
glColor3b(((fg & 0xf00) >> 8) * 8, glColor3b(((fg & 0xf00) >> 8) * 8,
((fg & 0x0f0) >> 4) * 8, ((fg & 0x0f0) >> 4) * 8,
(fg & 0x00f) * 8); (fg & 0x00f) * 8);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, kk->drv.p->sh);
glTexCoord2f(0, dp->drv.p->sh);
glVertex2f(x, y); glVertex2f(x, y);
glTexCoord2f(kk->drv.p->sw, kk->drv.p->sh);
glVertex2f(x + kk->drv.p->font_width, y);
glTexCoord2f(kk->drv.p->sw, 0);
glVertex2f(x + kk->drv.p->font_width,
y + kk->drv.p->font_height);
glTexCoord2f(dp->drv.p->sw, dp->drv.p->sh);
glVertex2f(x + dp->drv.p->font_width, y);
glTexCoord2f(dp->drv.p->sw, 0);
glVertex2f(x + dp->drv.p->font_width,
y + dp->drv.p->font_height);
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
glVertex2f(x, y + kk->drv.p->font_height);
glVertex2f(x, y + dp->drv.p->font_height);
glEnd(); glEnd();
} }


@@ -299,21 +299,21 @@ static void gl_display(caca_t *kk)
glutPostRedisplay(); glutPostRedisplay();
} }


static void gl_handle_resize(caca_t *kk)
static void gl_handle_resize(caca_display_t *dp)
{ {
kk->drv.p->width = kk->drv.p->new_width;
kk->drv.p->height = kk->drv.p->new_height;
dp->drv.p->width = dp->drv.p->new_width;
dp->drv.p->height = dp->drv.p->new_height;


glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();


glViewport(0, 0, kk->drv.p->width, kk->drv.p->height);
gluOrtho2D(0, kk->drv.p->width, kk->drv.p->height, 0);
glViewport(0, 0, dp->drv.p->width, dp->drv.p->height);
gluOrtho2D(0, dp->drv.p->width, dp->drv.p->height, 0);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
} }


static int gl_get_event(caca_t *kk, caca_event_t *ev)
static int gl_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
#ifdef HAVE_GLUTCHECKLOOP #ifdef HAVE_GLUTCHECKLOOP
glutCheckLoop(); glutCheckLoop();
@@ -322,54 +322,54 @@ static int gl_get_event(caca_t *kk, caca_event_t *ev)
#endif #endif


#ifdef HAVE_GLUTCLOSEFUNC #ifdef HAVE_GLUTCLOSEFUNC
if(kk->drv.p->close)
if(dp->drv.p->close)
{ {
kk->drv.p->close = 0;
dp->drv.p->close = 0;
ev->type = CACA_EVENT_QUIT; ev->type = CACA_EVENT_QUIT;
return 1; return 1;
} }
#endif #endif


if(kk->resize.resized)
if(dp->resize.resized)
{ {
ev->type = CACA_EVENT_RESIZE; ev->type = CACA_EVENT_RESIZE;
ev->data.resize.w = kk->c->width;
ev->data.resize.h = kk->c->height;
ev->data.resize.w = dp->cv->width;
ev->data.resize.h = dp->cv->height;
return 1; return 1;
} }


if(kk->drv.p->mouse_changed)
if(dp->drv.p->mouse_changed)
{ {
ev->type = CACA_EVENT_MOUSE_MOTION; ev->type = CACA_EVENT_MOUSE_MOTION;
ev->data.mouse.x = kk->mouse.x;
ev->data.mouse.y = kk->mouse.y;
kk->drv.p->mouse_changed = 0;
ev->data.mouse.x = dp->mouse.x;
ev->data.mouse.y = dp->mouse.y;
dp->drv.p->mouse_changed = 0;


if(kk->drv.p->mouse_clicked)
if(dp->drv.p->mouse_clicked)
{ {
_push_event(kk, ev);
_push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; ev->type = CACA_EVENT_MOUSE_PRESS;
ev->data.mouse.button = kk->drv.p->mouse_button;
kk->drv.p->mouse_clicked = 0;
ev->data.mouse.button = dp->drv.p->mouse_button;
dp->drv.p->mouse_clicked = 0;
} }


return 1; return 1;
} }


if(kk->drv.p->key != 0)
if(dp->drv.p->key != 0)
{ {
ev->type = CACA_EVENT_KEY_PRESS; ev->type = CACA_EVENT_KEY_PRESS;
ev->data.key.ch = kk->drv.p->key;
ev->data.key.ucs4 = (uint32_t)kk->drv.p->key;
ev->data.key.utf8[0] = kk->drv.p->key;
ev->data.key.ch = dp->drv.p->key;
ev->data.key.ucs4 = (uint32_t)dp->drv.p->key;
ev->data.key.utf8[0] = dp->drv.p->key;
ev->data.key.utf8[1] = '\0'; ev->data.key.utf8[1] = '\0';
kk->drv.p->key = 0;
dp->drv.p->key = 0;
return 1; return 1;
} }


if(kk->drv.p->special_key != 0)
if(dp->drv.p->special_key != 0)
{ {
switch(kk->drv.p->special_key)
switch(dp->drv.p->special_key)
{ {
case GLUT_KEY_F1 : ev->data.key.ch = CACA_KEY_F1; break; case GLUT_KEY_F1 : ev->data.key.ch = CACA_KEY_F1; break;
case GLUT_KEY_F2 : ev->data.key.ch = CACA_KEY_F2; break; case GLUT_KEY_F2 : ev->data.key.ch = CACA_KEY_F2; break;
@@ -394,7 +394,7 @@ static int gl_get_event(caca_t *kk, caca_event_t *ev)
ev->data.key.ucs4 = 0; ev->data.key.ucs4 = 0;
ev->data.key.utf8[0] = '\0'; ev->data.key.utf8[0] = '\0';


kk->drv.p->special_key = 0;
dp->drv.p->special_key = 0;
return 1; return 1;
} }


@@ -403,7 +403,7 @@ static int gl_get_event(caca_t *kk, caca_event_t *ev)
} }




static void gl_set_mouse(caca_t *kk, int flag)
static void gl_set_mouse(caca_display_t *dp, int flag)
{ {
if(flag) if(flag)
glutSetCursor(GLUT_CURSOR_RIGHT_ARROW); glutSetCursor(GLUT_CURSOR_RIGHT_ARROW);
@@ -417,72 +417,72 @@ static void gl_set_mouse(caca_t *kk, int flag)


static void gl_handle_keyboard(unsigned char key, int x, int y) static void gl_handle_keyboard(unsigned char key, int x, int y)
{ {
caca_t *kk = gl_kk;
caca_display_t *dp = gl_d;


kk->drv.p->key = key;
dp->drv.p->key = key;
} }


static void gl_handle_special_key(int key, int x, int y) static void gl_handle_special_key(int key, int x, int y)
{ {
caca_t *kk = gl_kk;
caca_display_t *dp = gl_d;


kk->drv.p->special_key = key;
dp->drv.p->special_key = key;
} }


static void gl_handle_reshape(int w, int h) static void gl_handle_reshape(int w, int h)
{ {
caca_t *kk = gl_kk;
caca_display_t *dp = gl_d;


if(kk->drv.p->bit) /* Do not handle reshaping at the first time */
if(dp->drv.p->bit) /* Do not handle reshaping at the first time */
{ {
kk->drv.p->new_width = w;
kk->drv.p->new_height = h;
dp->drv.p->new_width = w;
dp->drv.p->new_height = h;


kk->resize.w = w / kk->drv.p->font_width;
kk->resize.h = (h / kk->drv.p->font_height) + 1;
dp->resize.w = w / dp->drv.p->font_width;
dp->resize.h = (h / dp->drv.p->font_height) + 1;


kk->resize.resized = 1;
dp->resize.resized = 1;
} }
else else
kk->drv.p->bit = 1;
dp->drv.p->bit = 1;
} }


static void gl_handle_mouse(int button, int state, int x, int y) static void gl_handle_mouse(int button, int state, int x, int y)
{ {
caca_t *kk = gl_kk;
kk->drv.p->mouse_clicked = 1;
kk->drv.p->mouse_button = button;
kk->drv.p->mouse_state = state;
kk->drv.p->mouse_x = x / kk->drv.p->font_width;
kk->drv.p->mouse_y = y / kk->drv.p->font_height;
kk->mouse.x = kk->drv.p->mouse_x;
kk->mouse.y = kk->drv.p->mouse_y;
kk->drv.p->mouse_changed = 1;
caca_display_t *dp = gl_d;
dp->drv.p->mouse_clicked = 1;
dp->drv.p->mouse_button = button;
dp->drv.p->mouse_state = state;
dp->drv.p->mouse_x = x / dp->drv.p->font_width;
dp->drv.p->mouse_y = y / dp->drv.p->font_height;
dp->mouse.x = dp->drv.p->mouse_x;
dp->mouse.y = dp->drv.p->mouse_y;
dp->drv.p->mouse_changed = 1;
} }


static void gl_handle_mouse_motion(int x, int y) static void gl_handle_mouse_motion(int x, int y)
{ {
caca_t *kk = gl_kk;
kk->drv.p->mouse_x = x / kk->drv.p->font_width;
kk->drv.p->mouse_y = y / kk->drv.p->font_height;
kk->mouse.x = kk->drv.p->mouse_x;
kk->mouse.y = kk->drv.p->mouse_y;
kk->drv.p->mouse_changed = 1;
caca_display_t *dp = gl_d;
dp->drv.p->mouse_x = x / dp->drv.p->font_width;
dp->drv.p->mouse_y = y / dp->drv.p->font_height;
dp->mouse.x = dp->drv.p->mouse_x;
dp->mouse.y = dp->drv.p->mouse_y;
dp->drv.p->mouse_changed = 1;
} }


#ifdef HAVE_GLUTCLOSEFUNC #ifdef HAVE_GLUTCLOSEFUNC
static void gl_handle_close(void) static void gl_handle_close(void)
{ {
caca_t *kk = gl_kk;
kk->drv.p->close = 1;
caca_display_t *dp = gl_d;
dp->drv.p->close = 1;
} }
#endif #endif


static void _display(void) static void _display(void)
{ {
caca_t *kk = gl_kk;
gl_display(kk);
caca_display_t *dp = gl_d;
gl_display(dp);
} }




@@ -490,24 +490,24 @@ static void _display(void)
* Driver initialisation * Driver initialisation
*/ */


int gl_install(caca_t *kk)
int gl_install(caca_display_t *dp)
{ {
#if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION) #if defined(HAVE_GETENV) && defined(GLUT_XLIB_IMPLEMENTATION)
if(!getenv("DISPLAY") || !*(getenv("DISPLAY"))) if(!getenv("DISPLAY") || !*(getenv("DISPLAY")))
return -1; return -1;
#endif #endif


kk->drv.driver = CACA_DRIVER_GL;
kk->drv.init_graphics = gl_init_graphics;
kk->drv.end_graphics = gl_end_graphics;
kk->drv.set_window_title = gl_set_window_title;
kk->drv.get_window_width = gl_get_window_width;
kk->drv.get_window_height = gl_get_window_height;
kk->drv.display = gl_display;
kk->drv.handle_resize = gl_handle_resize;
kk->drv.get_event = gl_get_event;
kk->drv.set_mouse = gl_set_mouse;
dp->drv.driver = CACA_DRIVER_GL;
dp->drv.init_graphics = gl_init_graphics;
dp->drv.end_graphics = gl_end_graphics;
dp->drv.set_window_title = gl_set_window_title;
dp->drv.get_window_width = gl_get_window_width;
dp->drv.get_window_height = gl_get_window_height;
dp->drv.display = gl_display;
dp->drv.handle_resize = gl_handle_resize;
dp->drv.get_event = gl_get_event;
dp->drv.set_mouse = gl_set_mouse;


return 0; return 0;
} }


+ 118
- 118
caca/driver_ncurses.c View File

@@ -50,7 +50,7 @@


#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
static RETSIGTYPE sigwinch_handler(int); static RETSIGTYPE sigwinch_handler(int);
static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */
static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
#endif #endif
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
static void ncurses_check_terminal(void); static void ncurses_check_terminal(void);
@@ -63,7 +63,7 @@ struct driver_private
mmask_t oldmask; mmask_t oldmask;
}; };


static int ncurses_init_graphics(caca_t *kk)
static int ncurses_init_graphics(caca_display_t *dp)
{ {
static int curses_colors[] = static int curses_colors[] =
{ {
@@ -90,14 +90,14 @@ static int ncurses_init_graphics(caca_t *kk)
mmask_t newmask; mmask_t newmask;
int fg, bg, max; int fg, bg, max;


kk->drv.p = malloc(sizeof(struct driver_private));
dp->drv.p = malloc(sizeof(struct driver_private));


#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
ncurses_check_terminal(); ncurses_check_terminal();
#endif #endif


#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
sigwinch_kk = kk;
sigwinch_d = dp;
signal(SIGWINCH, sigwinch_handler); signal(SIGWINCH, sigwinch_handler);
#endif #endif


@@ -111,7 +111,7 @@ static int ncurses_init_graphics(caca_t *kk)


/* Activate mouse */ /* Activate mouse */
newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS; newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
mousemask(newmask, &kk->drv.p->oldmask);
mousemask(newmask, &dp->drv.p->oldmask);
mouseinterval(-1); /* No click emulation */ mouseinterval(-1); /* No click emulation */


/* Set the escape delay to a ridiculously low value */ /* Set the escape delay to a ridiculously low value */
@@ -136,95 +136,95 @@ static int ncurses_init_graphics(caca_t *kk)
* colour pair to be redefined. */ * colour pair to be redefined. */
int col = ((max + 7 - fg) % max) + max * bg; int col = ((max + 7 - fg) % max) + max * bg;
init_pair(col, curses_colors[fg], curses_colors[bg]); init_pair(col, curses_colors[fg], curses_colors[bg]);
kk->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);
dp->drv.p->attr[fg + 16 * bg] = COLOR_PAIR(col);


if(max == 8) if(max == 8)
{ {
/* Bright fg on simple bg */ /* Bright fg on simple bg */
kk->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
dp->drv.p->attr[fg + 8 + 16 * bg] = A_BOLD | COLOR_PAIR(col);
/* Simple fg on bright bg */ /* Simple fg on bright bg */
kk->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
dp->drv.p->attr[fg + 16 * (bg + 8)] = A_BLINK
| COLOR_PAIR(col); | COLOR_PAIR(col);
/* Bright fg on bright bg */ /* Bright fg on bright bg */
kk->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
dp->drv.p->attr[fg + 8 + 16 * (bg + 8)] = A_BLINK | A_BOLD
| COLOR_PAIR(col); | COLOR_PAIR(col);
} }
} }


_cucul_set_size(kk->c, COLS, LINES);
_cucul_set_size(dp->cv, COLS, LINES);


return 0; return 0;
} }


static int ncurses_end_graphics(caca_t *kk)
static int ncurses_end_graphics(caca_display_t *dp)
{ {
mousemask(kk->drv.p->oldmask, NULL);
mousemask(dp->drv.p->oldmask, NULL);
curs_set(1); curs_set(1);
noraw(); noraw();
endwin(); endwin();


free(kk->drv.p);
free(dp->drv.p);


return 0; return 0;
} }


static int ncurses_set_window_title(caca_t *kk, char const *title)
static int ncurses_set_window_title(caca_display_t *dp, char const *title)
{ {
return 0; return 0;
} }


static unsigned int ncurses_get_window_width(caca_t *kk)
static unsigned int ncurses_get_window_width(caca_display_t *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->width * 6;
return dp->cv->width * 6;
} }


static unsigned int ncurses_get_window_height(caca_t *kk)
static unsigned int ncurses_get_window_height(caca_display_t *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->height * 10;
return dp->cv->height * 10;
} }


static void ncurses_display(caca_t *kk)
static void ncurses_display(caca_display_t *dp)
{ {
int x, y; int x, y;
uint32_t *attr = kk->c->attr;
uint32_t *chars = kk->c->chars;
for(y = 0; y < (int)kk->c->height; y++)
uint32_t *attr = dp->cv->attr;
uint32_t *chars = dp->cv->chars;
for(y = 0; y < (int)dp->cv->height; y++)
{ {
move(y, 0); move(y, 0);
for(x = kk->c->width; x--; )
for(x = dp->cv->width; x--; )
{ {
attrset(kk->drv.p->attr[_cucul_argb32_to_ansi8(*attr++)]);
attrset(dp->drv.p->attr[_cucul_argb32_to_ansi8(*attr++)]);
ncurses_write_utf32(*chars++); ncurses_write_utf32(*chars++);
} }
} }
refresh(); refresh();
} }


static void ncurses_handle_resize(caca_t *kk)
static void ncurses_handle_resize(caca_display_t *dp)
{ {
struct winsize size; struct winsize size;


if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
{ {
kk->resize.w = size.ws_col;
kk->resize.h = size.ws_row;
dp->resize.w = size.ws_col;
dp->resize.h = size.ws_row;
#if defined(HAVE_RESIZE_TERM) #if defined(HAVE_RESIZE_TERM)
resize_term(kk->resize.h, kk->resize.w);
resize_term(dp->resize.h, dp->resize.w);
#else #else
resizeterm(*kk->resize.h, *kk->resize.w);
resizeterm(*dp->resize.h, *dp->resize.w);
#endif #endif
wrefresh(curscr); wrefresh(curscr);
return; return;
} }


/* Fallback */ /* Fallback */
kk->resize.w = kk->c->width;
kk->resize.h = kk->c->height;
dp->resize.w = dp->cv->width;
dp->resize.h = dp->cv->height;
} }


static int ncurses_get_event(caca_t *kk, caca_event_t *ev)
static int ncurses_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
int intkey; int intkey;


@@ -251,128 +251,128 @@ static int ncurses_get_event(caca_t *kk, caca_event_t *ev)
{ {
case BUTTON1_PRESSED: case BUTTON1_PRESSED:
ev->data.mouse.button = 1; ev->data.mouse.button = 1;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
break; break;
case BUTTON1_RELEASED: case BUTTON1_RELEASED:
ev->data.mouse.button = 1; ev->data.mouse.button = 1;
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON1_CLICKED: case BUTTON1_CLICKED:
ev->data.mouse.button = 1; ev->data.mouse.button = 1;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON1_DOUBLE_CLICKED: case BUTTON1_DOUBLE_CLICKED:
ev->data.mouse.button = 1; ev->data.mouse.button = 1;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON1_TRIPLE_CLICKED: case BUTTON1_TRIPLE_CLICKED:
ev->data.mouse.button = 1; ev->data.mouse.button = 1;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON1_RESERVED_EVENT: case BUTTON1_RESERVED_EVENT:
break; break;


case BUTTON2_PRESSED: case BUTTON2_PRESSED:
ev->data.mouse.button = 2; ev->data.mouse.button = 2;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
break; break;
case BUTTON2_RELEASED: case BUTTON2_RELEASED:
ev->data.mouse.button = 2; ev->data.mouse.button = 2;
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON2_CLICKED: case BUTTON2_CLICKED:
ev->data.mouse.button = 2; ev->data.mouse.button = 2;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON2_DOUBLE_CLICKED: case BUTTON2_DOUBLE_CLICKED:
ev->data.mouse.button = 2; ev->data.mouse.button = 2;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON2_TRIPLE_CLICKED: case BUTTON2_TRIPLE_CLICKED:
ev->data.mouse.button = 2; ev->data.mouse.button = 2;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON2_RESERVED_EVENT: case BUTTON2_RESERVED_EVENT:
break; break;


case BUTTON3_PRESSED: case BUTTON3_PRESSED:
ev->data.mouse.button = 3; ev->data.mouse.button = 3;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
break; break;
case BUTTON3_RELEASED: case BUTTON3_RELEASED:
ev->data.mouse.button = 3; ev->data.mouse.button = 3;
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON3_CLICKED: case BUTTON3_CLICKED:
ev->data.mouse.button = 3; ev->data.mouse.button = 3;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON3_DOUBLE_CLICKED: case BUTTON3_DOUBLE_CLICKED:
ev->data.mouse.button = 3; ev->data.mouse.button = 3;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON3_TRIPLE_CLICKED: case BUTTON3_TRIPLE_CLICKED:
ev->data.mouse.button = 3; ev->data.mouse.button = 3;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON3_RESERVED_EVENT: case BUTTON3_RESERVED_EVENT:
break; break;


case BUTTON4_PRESSED: case BUTTON4_PRESSED:
ev->data.mouse.button = 4; ev->data.mouse.button = 4;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
break; break;
case BUTTON4_RELEASED: case BUTTON4_RELEASED:
ev->data.mouse.button = 4; ev->data.mouse.button = 4;
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON4_CLICKED: case BUTTON4_CLICKED:
ev->data.mouse.button = 4; ev->data.mouse.button = 4;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON4_DOUBLE_CLICKED: case BUTTON4_DOUBLE_CLICKED:
ev->data.mouse.button = 4; ev->data.mouse.button = 4;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON4_TRIPLE_CLICKED: case BUTTON4_TRIPLE_CLICKED:
ev->data.mouse.button = 4; ev->data.mouse.button = 4;
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(kk, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_PRESS; _push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; _push_event(dp, ev);
break; break;
case BUTTON4_RESERVED_EVENT: case BUTTON4_RESERVED_EVENT:
break; break;
@@ -381,16 +381,16 @@ static int ncurses_get_event(caca_t *kk, caca_event_t *ev)
break; break;
} }


if(kk->mouse.x == (unsigned int)mevent.x &&
kk->mouse.y == (unsigned int)mevent.y)
return _pop_event(kk, ev);
if(dp->mouse.x == (unsigned int)mevent.x &&
dp->mouse.y == (unsigned int)mevent.y)
return _pop_event(dp, ev);


kk->mouse.x = mevent.x;
kk->mouse.y = mevent.y;
dp->mouse.x = mevent.x;
dp->mouse.y = mevent.y;


ev->type = CACA_EVENT_MOUSE_MOTION; ev->type = CACA_EVENT_MOUSE_MOTION;
ev->data.mouse.x = kk->mouse.x;
ev->data.mouse.y = kk->mouse.y;
ev->data.mouse.x = dp->mouse.x;
ev->data.mouse.y = dp->mouse.y;
return 1; return 1;
} }


@@ -437,7 +437,7 @@ static int ncurses_get_event(caca_t *kk, caca_event_t *ev)
#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
static RETSIGTYPE sigwinch_handler(int sig) static RETSIGTYPE sigwinch_handler(int sig)
{ {
sigwinch_kk->resize.resized = 1;
sigwinch_d->resize.resized = 1;


signal(SIGWINCH, sigwinch_handler); signal(SIGWINCH, sigwinch_handler);
} }
@@ -481,7 +481,7 @@ static void ncurses_check_terminal(void)
} }
#endif #endif


static void ncurses_write_utf32(uint32_t c)
static void ncurses_write_utf32(uint32_t ch)
{ {
#if defined(HAVE_NCURSESW_NCURSES_H) #if defined(HAVE_NCURSESW_NCURSES_H)
static const uint8_t mark[7] = static const uint8_t mark[7] =
@@ -493,30 +493,30 @@ static void ncurses_write_utf32(uint32_t c)
int bytes; int bytes;
#endif #endif


if(c < 0x80)
if(ch < 0x80)
{ {
addch(c);
addch(ch);
return; return;
} }


#if defined(HAVE_NCURSESW_NCURSES_H) #if defined(HAVE_NCURSESW_NCURSES_H)
if(c < 0x10000)
if(ch < 0x10000)
{ {
addch(c); /* FIXME: doesn't work either */
addch(ch); /* FIXME: doesn't work either */
return; return;
} }


bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4;
bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
buf[bytes] = '\0'; buf[bytes] = '\0';
parser = buf + bytes; parser = buf + bytes;


switch(bytes) switch(bytes)
{ {
case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6;
case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6;
case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6;
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
} }
*--parser = c | mark[bytes];
*--parser = ch | mark[bytes];


addstr(buf); addstr(buf);
#else #else
@@ -528,19 +528,19 @@ static void ncurses_write_utf32(uint32_t c)
* Driver initialisation * Driver initialisation
*/ */


int ncurses_install(caca_t *kk)
int ncurses_install(caca_display_t *dp)
{ {
kk->drv.driver = CACA_DRIVER_NCURSES;
kk->drv.init_graphics = ncurses_init_graphics;
kk->drv.end_graphics = ncurses_end_graphics;
kk->drv.set_window_title = ncurses_set_window_title;
kk->drv.get_window_width = ncurses_get_window_width;
kk->drv.get_window_height = ncurses_get_window_height;
kk->drv.display = ncurses_display;
kk->drv.handle_resize = ncurses_handle_resize;
kk->drv.get_event = ncurses_get_event;
kk->drv.set_mouse = NULL;
dp->drv.driver = CACA_DRIVER_NCURSES;
dp->drv.init_graphics = ncurses_init_graphics;
dp->drv.end_graphics = ncurses_end_graphics;
dp->drv.set_window_title = ncurses_set_window_title;
dp->drv.get_window_width = ncurses_get_window_width;
dp->drv.get_window_height = ncurses_get_window_height;
dp->drv.display = ncurses_display;
dp->drv.handle_resize = ncurses_handle_resize;
dp->drv.get_event = ncurses_get_event;
dp->drv.set_mouse = NULL;


return 0; return 0;
} }


+ 27
- 27
caca/driver_raw.c View File

@@ -26,52 +26,52 @@
#include "cucul.h" #include "cucul.h"
#include "cucul_internals.h" #include "cucul_internals.h"


static int raw_init_graphics(caca_t *kk)
static int raw_init_graphics(caca_display_t *dp)
{ {
return 0; return 0;
} }


static int raw_end_graphics(caca_t *kk)
static int raw_end_graphics(caca_display_t *dp)
{ {
return 0; return 0;
} }


static int raw_set_window_title(caca_t *kk, char const *title)
static int raw_set_window_title(caca_display_t *dp, char const *title)
{ {
return 0; return 0;
} }


static unsigned int raw_get_window_width(caca_t *kk)
static unsigned int raw_get_window_width(caca_display_t *dp)
{ {
return 0; return 0;
} }


static unsigned int raw_get_window_height(caca_t *kk)
static unsigned int raw_get_window_height(caca_display_t *dp)
{ {
return 0; return 0;
} }


static void raw_display(caca_t *kk)
static void raw_display(caca_display_t *dp)
{ {
uint32_t *attr = kk->c->attr;
uint32_t *chars = kk->c->chars;
uint32_t *attr = dp->cv->attr;
uint32_t *chars = dp->cv->chars;
uint32_t w, h; uint32_t w, h;
unsigned int n; unsigned int n;


w = kk->c->width;
h = kk->c->height;
w = dp->cv->width;
h = dp->cv->height;


fprintf(stdout, "CACA%c%c%c%c%c%c%c%c", fprintf(stdout, "CACA%c%c%c%c%c%c%c%c",
(w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff, (w >> 24), (w >> 16) & 0xff, (w >> 8) & 0xff, w & 0xff,
(h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff); (h >> 24), (h >> 16) & 0xff, (h >> 8) & 0xff, h & 0xff);


for(n = kk->c->height * kk->c->width; n--; )
for(n = dp->cv->height * dp->cv->width; n--; )
{ {
uint32_t c = *chars++;
uint32_t ch = *chars++;
uint32_t a = *attr++; uint32_t a = *attr++;


fprintf(stdout, "%c%c%c%c%c%c%c%c", fprintf(stdout, "%c%c%c%c%c%c%c%c",
(c >> 24), (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff,
(ch >> 24), (ch >> 16) & 0xff, (ch >> 8) & 0xff, ch & 0xff,
(a >> 24), (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff); (a >> 24), (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff);
} }


@@ -79,12 +79,12 @@ static void raw_display(caca_t *kk)
fflush(stdout); fflush(stdout);
} }


static void raw_handle_resize(caca_t *kk)
static void raw_handle_resize(caca_display_t *dp)
{ {
; ;
} }


static int raw_get_event(caca_t *kk, caca_event_t *ev)
static int raw_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
ev->type = CACA_EVENT_NONE; ev->type = CACA_EVENT_NONE;
return 0; return 0;
@@ -94,19 +94,19 @@ static int raw_get_event(caca_t *kk, caca_event_t *ev)
* Driver initialisation * Driver initialisation
*/ */


int raw_install(caca_t *kk)
int raw_install(caca_display_t *dp)
{ {
kk->drv.driver = CACA_DRIVER_RAW;
kk->drv.init_graphics = raw_init_graphics;
kk->drv.end_graphics = raw_end_graphics;
kk->drv.set_window_title = raw_set_window_title;
kk->drv.get_window_width = raw_get_window_width;
kk->drv.get_window_height = raw_get_window_height;
kk->drv.display = raw_display;
kk->drv.handle_resize = raw_handle_resize;
kk->drv.get_event = raw_get_event;
kk->drv.set_mouse = NULL;
dp->drv.driver = CACA_DRIVER_RAW;
dp->drv.init_graphics = raw_init_graphics;
dp->drv.end_graphics = raw_end_graphics;
dp->drv.set_window_title = raw_set_window_title;
dp->drv.get_window_width = raw_get_window_width;
dp->drv.get_window_height = raw_get_window_height;
dp->drv.display = raw_display;
dp->drv.handle_resize = raw_handle_resize;
dp->drv.get_event = raw_get_event;
dp->drv.set_mouse = NULL;


return 0; return 0;
} }


+ 52
- 52
caca/driver_slang.c View File

@@ -106,20 +106,20 @@ static void slang_write_utf32(uint32_t);


#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
static RETSIGTYPE sigwinch_handler(int); static RETSIGTYPE sigwinch_handler(int);
static caca_t *sigwinch_kk; /* FIXME: we ought to get rid of this */
static caca_display_t *sigwinch_d; /* FIXME: we ought to get rid of this */
#endif #endif
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
static void slang_check_terminal(void); static void slang_check_terminal(void);
#endif #endif


static int slang_init_graphics(caca_t *kk)
static int slang_init_graphics(caca_display_t *dp)
{ {
#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) #if defined(HAVE_GETENV) && defined(HAVE_PUTENV)
slang_check_terminal(); slang_check_terminal();
#endif #endif


#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
sigwinch_kk = kk;
sigwinch_d = dp;
signal(SIGWINCH, sigwinch_handler); signal(SIGWINCH, sigwinch_handler);
#endif #endif


@@ -164,12 +164,12 @@ static int slang_init_graphics(caca_t *kk)
SLtt_utf8_enable(1); SLtt_utf8_enable(1);
#endif #endif


_cucul_set_size(kk->c, SLtt_Screen_Cols, SLtt_Screen_Rows);
_cucul_set_size(dp->cv, SLtt_Screen_Cols, SLtt_Screen_Rows);


return 0; return 0;
} }


static int slang_end_graphics(caca_t *kk)
static int slang_end_graphics(caca_display_t *dp)
{ {
SLtt_set_mouse_mode(0, 0); SLtt_set_mouse_mode(0, 0);
SLtt_set_cursor_visibility(1); SLtt_set_cursor_visibility(1);
@@ -179,35 +179,35 @@ static int slang_end_graphics(caca_t *kk)
return 0; return 0;
} }


static int slang_set_window_title(caca_t *kk, char const *title)
static int slang_set_window_title(caca_display_t *dp, char const *title)
{ {
/* FIXME */ /* FIXME */
return 0; return 0;
} }


static unsigned int slang_get_window_width(caca_t *kk)
static unsigned int slang_get_window_width(caca_display_t *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->width * 6;
return dp->cv->width * 6;
} }


static unsigned int slang_get_window_height(caca_t *kk)
static unsigned int slang_get_window_height(caca_display_t *dp)
{ {
/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->height * 10;
return dp->cv->height * 10;
} }


static void slang_display(caca_t *kk)
static void slang_display(caca_display_t *dp)
{ {
int x, y; int x, y;
uint32_t *attr = kk->c->attr;
uint32_t *chars = kk->c->chars;
for(y = 0; y < (int)kk->c->height; y++)
uint32_t *attr = dp->cv->attr;
uint32_t *chars = dp->cv->chars;
for(y = 0; y < (int)dp->cv->height; y++)
{ {
SLsmg_gotorc(y, 0); SLsmg_gotorc(y, 0);
for(x = kk->c->width; x--; )
for(x = dp->cv->width; x--; )
{ {
uint32_t c = *chars++;
uint32_t ch = *chars++;


#if defined(OPTIMISE_SLANG_PALETTE) #if defined(OPTIMISE_SLANG_PALETTE)
uint8_t fgcolor = _cucul_argb32_to_ansi4fg(*attr); uint8_t fgcolor = _cucul_argb32_to_ansi4fg(*attr);
@@ -218,7 +218,7 @@ static void slang_display(caca_t *kk)
if(fgcolor != bgcolor) if(fgcolor != bgcolor)
{ {
SLsmg_set_color(slang_assoc[_cucul_argb32_to_ansi8(*attr++)]); SLsmg_set_color(slang_assoc[_cucul_argb32_to_ansi8(*attr++)]);
slang_write_utf32(c);
slang_write_utf32(ch);
} }
else else
{ {
@@ -235,24 +235,24 @@ static void slang_display(caca_t *kk)
} }
#else #else
SLsmg_set_color(_cucul_argb32_to_ansi8(*attr++)); SLsmg_set_color(_cucul_argb32_to_ansi8(*attr++));
slang_write_utf32(c);
slang_write_utf32(ch);
#endif #endif
} }
} }
SLsmg_refresh(); SLsmg_refresh();
} }


static void slang_handle_resize(caca_t *kk)
static void slang_handle_resize(caca_display_t *dp)
{ {
SLtt_get_screen_size(); SLtt_get_screen_size();
kk->resize.w = SLtt_Screen_Cols;
kk->resize.h = SLtt_Screen_Rows;
dp->resize.w = SLtt_Screen_Cols;
dp->resize.h = SLtt_Screen_Rows;


if(kk->resize.w != kk->c->width || kk->resize.h != kk->c->height)
if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height)
SLsmg_reinit_smg(); SLsmg_reinit_smg();
} }


static int slang_get_event(caca_t *kk, caca_event_t *ev)
static int slang_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
int intkey; int intkey;


@@ -289,19 +289,19 @@ static int slang_get_event(caca_t *kk, caca_event_t *ev)


ev->data.mouse.button = button; ev->data.mouse.button = button;
ev->type = CACA_EVENT_MOUSE_PRESS; ev->type = CACA_EVENT_MOUSE_PRESS;
_push_event(kk, ev);
_push_event(dp, ev);
ev->type = CACA_EVENT_MOUSE_RELEASE; ev->type = CACA_EVENT_MOUSE_RELEASE;
_push_event(kk, ev);
_push_event(dp, ev);


if(kk->mouse.x == x && kk->mouse.y == y)
return _pop_event(kk, ev);
if(dp->mouse.x == x && dp->mouse.y == y)
return _pop_event(dp, ev);


kk->mouse.x = x;
kk->mouse.y = y;
dp->mouse.x = x;
dp->mouse.y = y;


ev->type = CACA_EVENT_MOUSE_MOTION; ev->type = CACA_EVENT_MOUSE_MOTION;
ev->data.mouse.x = kk->mouse.x;
ev->data.mouse.y = kk->mouse.y;
ev->data.mouse.x = dp->mouse.x;
ev->data.mouse.y = dp->mouse.y;
return 1; return 1;
} }


@@ -388,7 +388,7 @@ static void slang_init_palette(void)
#endif #endif
} }


static void slang_write_utf32(uint32_t c)
static void slang_write_utf32(uint32_t ch)
{ {
#ifdef HAVE_SLSMG_UTF8_ENABLE #ifdef HAVE_SLSMG_UTF8_ENABLE
static const uint8_t mark[7] = static const uint8_t mark[7] =
@@ -400,24 +400,24 @@ static void slang_write_utf32(uint32_t c)
int bytes; int bytes;
#endif #endif


if(c < 0x80)
if(ch < 0x80)
{ {
SLsmg_write_char(c);
SLsmg_write_char(ch);
return; return;
} }


#ifdef HAVE_SLSMG_UTF8_ENABLE #ifdef HAVE_SLSMG_UTF8_ENABLE
bytes = (c < 0x800) ? 2 : (c < 0x10000) ? 3 : 4;
bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
buf[bytes] = '\0'; buf[bytes] = '\0';
parser = buf + bytes; parser = buf + bytes;


switch(bytes) switch(bytes)
{ {
case 4: *--parser = (c | 0x80) & 0xbf; c >>= 6;
case 3: *--parser = (c | 0x80) & 0xbf; c >>= 6;
case 2: *--parser = (c | 0x80) & 0xbf; c >>= 6;
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
} }
*--parser = c | mark[bytes];
*--parser = ch | mark[bytes];


SLsmg_write_string(buf); SLsmg_write_string(buf);
#else #else
@@ -428,7 +428,7 @@ static void slang_write_utf32(uint32_t c)
#if defined(HAVE_SIGNAL) #if defined(HAVE_SIGNAL)
static RETSIGTYPE sigwinch_handler(int sig) static RETSIGTYPE sigwinch_handler(int sig)
{ {
sigwinch_kk->resize.resized = 1;
sigwinch_d->resize.resized = 1;


signal(SIGWINCH, sigwinch_handler); signal(SIGWINCH, sigwinch_handler);
} }
@@ -466,19 +466,19 @@ static void slang_check_terminal(void)
* Driver initialisation * Driver initialisation
*/ */


int slang_install(caca_t *kk)
int slang_install(caca_display_t *dp)
{ {
kk->drv.driver = CACA_DRIVER_SLANG;
kk->drv.init_graphics = slang_init_graphics;
kk->drv.end_graphics = slang_end_graphics;
kk->drv.set_window_title = slang_set_window_title;
kk->drv.get_window_width = slang_get_window_width;
kk->drv.get_window_height = slang_get_window_height;
kk->drv.display = slang_display;
kk->drv.handle_resize = slang_handle_resize;
kk->drv.get_event = slang_get_event;
kk->drv.set_mouse = NULL;
dp->drv.driver = CACA_DRIVER_SLANG;
dp->drv.init_graphics = slang_init_graphics;
dp->drv.end_graphics = slang_end_graphics;
dp->drv.set_window_title = slang_set_window_title;
dp->drv.get_window_width = slang_get_window_width;
dp->drv.get_window_height = slang_get_window_height;
dp->drv.display = slang_display;
dp->drv.handle_resize = slang_handle_resize;
dp->drv.get_event = slang_get_event;
dp->drv.set_mouse = NULL;


return 0; return 0;
} }


+ 26
- 26
caca/driver_vga.c View File

@@ -49,7 +49,7 @@ static uint8_t const vga_colors[][4] =
{ 0x3f, 0x3f, 0x3f, 0x3f }, { 0x3f, 0x3f, 0x3f, 0x3f },
}; };


static int vga_init_graphics(caca_t *kk)
static int vga_init_graphics(caca_display_t *dp)
{ {
int i; int i;
uint8_t tmp; uint8_t tmp;
@@ -74,12 +74,12 @@ static int vga_init_graphics(caca_t *kk)
outb(tmp, 0x3d5); outb(tmp, 0x3d5);


/* We don't have much choice */ /* We don't have much choice */
_cucul_set_size(kk->c, 80, 25);
_cucul_set_size(dp->cv, 80, 25);


return 0; return 0;
} }


static int vga_end_graphics(caca_t *kk)
static int vga_end_graphics(caca_display_t *dp)
{ {
uint8_t tmp; uint8_t tmp;


@@ -93,46 +93,46 @@ static int vga_end_graphics(caca_t *kk)
return 0; return 0;
} }


static int vga_set_window_title(caca_t *kk, char const *title)
static int vga_set_window_title(caca_display_t *dp, char const *title)
{ {
/* Unsupported, of course. */ /* Unsupported, of course. */
return 0; return 0;
} }


static unsigned int vga_get_window_width(caca_t *kk)
static unsigned int vga_get_window_width(caca_display_t *dp)
{ {
/* Fallback to a 320x200 screen */ /* Fallback to a 320x200 screen */
return 320; return 320;
} }


static unsigned int vga_get_window_height(caca_t *kk)
static unsigned int vga_get_window_height(caca_display_t *dp)
{ {
/* Fallback to a 320x200 screen */ /* Fallback to a 320x200 screen */
return 200; return 200;
} }


static void vga_display(caca_t *kk)
static void vga_display(caca_display_t *dp)
{ {
char *screen = (char *)(intptr_t)0x000b8000; char *screen = (char *)(intptr_t)0x000b8000;
uint32_t *attr = kk->c->attr;
uint32_t *chars = kk->c->chars;
uint32_t *attr = dp->cv->attr;
uint32_t *chars = dp->cv->chars;
int n; int n;


for(n = kk->c->height * kk->c->width; n--; )
for(n = dp->cv->height * dp->cv->width; n--; )
{ {
*screen++ = _cucul_utf32_to_cp437(*chars++); *screen++ = _cucul_utf32_to_cp437(*chars++);
*screen++ = _cucul_argb32_to_ansi8(*attr++); *screen++ = _cucul_argb32_to_ansi8(*attr++);
} }
} }


static void vga_handle_resize(caca_t *kk)
static void vga_handle_resize(caca_display_t *dp)
{ {
/* We know nothing about our window */ /* We know nothing about our window */
kk->resize.w = kk->c->width;
kk->resize.h = kk->c->height;
dp->resize.w = dp->cv->width;
dp->resize.h = dp->cv->height;
} }


static int vga_get_event(caca_t *kk, caca_event-t *ev)
static int vga_get_event(caca_display_t *dp, caca_event-t *ev)
{ {
/* FIXME */ /* FIXME */
ev->type = CACA_EVENT_NONE; ev->type = CACA_EVENT_NONE;
@@ -143,19 +143,19 @@ static int vga_get_event(caca_t *kk, caca_event-t *ev)
* Driver initialisation * Driver initialisation
*/ */


int vga_install(caca_t *kk)
int vga_install(caca_display_t *dp)
{ {
kk->drv.driver = CACA_DRIVER_VGA;
kk->drv.init_graphics = vga_init_graphics;
kk->drv.end_graphics = vga_end_graphics;
kk->drv.set_window_title = vga_set_window_title;
kk->drv.get_window_width = vga_get_window_width;
kk->drv.get_window_height = vga_get_window_height;
kk->drv.display = vga_display;
kk->drv.handle_resize = vga_handle_resize;
kk->drv.get_event = vga_get_event;
kk->drv.set_mouse = NULL;
dp->drv.driver = CACA_DRIVER_VGA;
dp->drv.init_graphics = vga_init_graphics;
dp->drv.end_graphics = vga_end_graphics;
dp->drv.set_window_title = vga_set_window_title;
dp->drv.get_window_width = vga_get_window_width;
dp->drv.get_window_height = vga_get_window_height;
dp->drv.display = vga_display;
dp->drv.handle_resize = vga_handle_resize;
dp->drv.get_event = vga_get_event;
dp->drv.set_mouse = NULL;


return 0; return 0;
} }


+ 83
- 83
caca/driver_win32.c View File

@@ -80,171 +80,171 @@ struct driver_private
CONSOLE_CURSOR_INFO cci; CONSOLE_CURSOR_INFO cci;
}; };


static int win32_init_graphics(caca_t *kk)
static int win32_init_graphics(caca_display_t *dp)
{ {
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
SMALL_RECT rect; SMALL_RECT rect;
COORD size; COORD size;


kk->drv.p = malloc(sizeof(struct driver_private));
dp->drv.p = malloc(sizeof(struct driver_private));


/* This call is allowed to fail in case we already have a console */ /* This call is allowed to fail in case we already have a console */
AllocConsole(); AllocConsole();


kk->drv.p->hin = GetStdHandle(STD_INPUT_HANDLE);
kk->drv.p->hout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
dp->drv.p->hin = GetStdHandle(STD_INPUT_HANDLE);
dp->drv.p->hout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(kk->drv.p->hout == INVALID_HANDLE_VALUE)
if(dp->drv.p->hout == INVALID_HANDLE_VALUE)
return -1; return -1;


GetConsoleCursorInfo(kk->drv.p->hout, &kk->drv.p->cci);
kk->drv.p->cci.bVisible = FALSE;
SetConsoleCursorInfo(kk->drv.p->hout, &kk->drv.p->cci);
GetConsoleCursorInfo(dp->drv.p->hout, &dp->drv.p->cci);
dp->drv.p->cci.bVisible = FALSE;
SetConsoleCursorInfo(dp->drv.p->hout, &dp->drv.p->cci);


SetConsoleMode(kk->drv.p->hout, ENABLE_MOUSE_INPUT);
SetConsoleMode(dp->drv.p->hout, ENABLE_MOUSE_INPUT);


kk->drv.p->screen =
dp->drv.p->screen =
CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL); 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
if(!kk->drv.p->screen || kk->drv.p->screen == INVALID_HANDLE_VALUE)
if(!dp->drv.p->screen || dp->drv.p->screen == INVALID_HANDLE_VALUE)
return -1; return -1;


/* Set the new console size */ /* Set the new console size */
size.X = kk->c->width;
size.Y = kk->c->height;
SetConsoleScreenBufferSize(kk->drv.p->screen, size);
size.X = dp->cv->width;
size.Y = dp->cv->height;
SetConsoleScreenBufferSize(dp->drv.p->screen, size);


rect.Left = rect.Top = 0; rect.Left = rect.Top = 0;
rect.Right = kk->c->width - 1;
rect.Bottom = kk->c->height - 1;
SetConsoleWindowInfo(kk->drv.p->screen, TRUE, &rect);
rect.Right = dp->cv->width - 1;
rect.Bottom = dp->cv->height - 1;
SetConsoleWindowInfo(dp->drv.p->screen, TRUE, &rect);


/* Report our new size to libcucul */ /* Report our new size to libcucul */
if(!GetConsoleScreenBufferInfo(kk->drv.p->screen, &csbi))
if(!GetConsoleScreenBufferInfo(dp->drv.p->screen, &csbi))
return -1; return -1;


_cucul_set_size(kk->c, csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
_cucul_set_size(dp->cv, csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1);


SetConsoleMode(kk->drv.p->screen, 0);
SetConsoleMode(dp->drv.p->screen, 0);


GetConsoleCursorInfo(kk->drv.p->screen, &kk->drv.p->cci);
kk->drv.p->cci.dwSize = 0;
kk->drv.p->cci.bVisible = FALSE;
SetConsoleCursorInfo(kk->drv.p->screen, &kk->drv.p->cci);
GetConsoleCursorInfo(dp->drv.p->screen, &dp->drv.p->cci);
dp->drv.p->cci.dwSize = 0;
dp->drv.p->cci.bVisible = FALSE;
SetConsoleCursorInfo(dp->drv.p->screen, &dp->drv.p->cci);


SetConsoleActiveScreenBuffer(kk->drv.p->screen);
SetConsoleActiveScreenBuffer(dp->drv.p->screen);


kk->drv.p->buffer = malloc(kk->c->width * kk->c->height
dp->drv.p->buffer = malloc(dp->cv->width * dp->cv->height
* sizeof(CHAR_INFO)); * sizeof(CHAR_INFO));
if(kk->drv.p->buffer == NULL)
if(dp->drv.p->buffer == NULL)
return -1; return -1;


return 0; return 0;
} }


static int win32_end_graphics(caca_t *kk)
static int win32_end_graphics(caca_display_t *dp)
{ {
SetConsoleActiveScreenBuffer(kk->drv.p->hout);
CloseHandle(kk->drv.p->screen);
SetConsoleActiveScreenBuffer(dp->drv.p->hout);
CloseHandle(dp->drv.p->screen);


SetConsoleTextAttribute(kk->drv.p->hout, FOREGROUND_INTENSITY
SetConsoleTextAttribute(dp->drv.p->hout, FOREGROUND_INTENSITY
| FOREGROUND_RED | FOREGROUND_RED
| FOREGROUND_GREEN | FOREGROUND_GREEN
| FOREGROUND_BLUE); | FOREGROUND_BLUE);
kk->drv.p->cci.bVisible = TRUE;
SetConsoleCursorInfo(kk->drv.p->hout, &kk->drv.p->cci);
CloseHandle(kk->drv.p->hout);
dp->drv.p->cci.bVisible = TRUE;
SetConsoleCursorInfo(dp->drv.p->hout, &dp->drv.p->cci);
CloseHandle(dp->drv.p->hout);


free(kk->drv.p);
free(dp->drv.p);


return 0; return 0;
} }


static int win32_set_window_title(caca_t *kk, char const *title)
static int win32_set_window_title(caca_display_t *dp, char const *title)
{ {
SetConsoleTitle(title); SetConsoleTitle(title);
return 0; return 0;
} }


static unsigned int win32_get_window_width(caca_t *kk)
static unsigned int win32_get_window_width(caca_display_t *dp)
{ {
/* FIXME */ /* FIXME */


/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->width * 6;
return dp->cv->width * 6;
} }


static unsigned int win32_get_window_height(caca_t *kk)
static unsigned int win32_get_window_height(caca_display_t *dp)
{ {
/* FIXME */ /* FIXME */


/* Fallback to a 6x10 font */ /* Fallback to a 6x10 font */
return kk->c->height * 10;
return dp->cv->height * 10;
} }


static void win32_display(caca_t *kk)
static void win32_display(caca_display_t *dp)
{ {
COORD size, pos; COORD size, pos;
SMALL_RECT rect; SMALL_RECT rect;
unsigned int i; unsigned int i;


/* Render everything to our screen buffer */ /* Render everything to our screen buffer */
for(i = 0; i < kk->c->width * kk->c->height; i++)
for(i = 0; i < dp->cv->width * dp->cv->height; i++)
{ {
uint32_t c = kk->c->chars[i];
uint32_t ch = dp->cv->chars[i];


#if 0 #if 0
if(c > 0x00000020 && c < 0x00000080)
kk->drv.p->buffer[i].Char.AsciiChar = (uint8_t)c;
if(ch > 0x00000020 && ch < 0x00000080)
dp->drv.p->buffer[i].Char.AsciiChar = (uint8_t)ch;
else else
kk->drv.p->buffer[i].Char.AsciiChar = ' ';
dp->drv.p->buffer[i].Char.AsciiChar = ' ';
#else #else
if(c > 0x00000020 && c < 0x00010000)
kk->drv.p->buffer[i].Char.UnicodeChar = (uint16_t)c;
if(ch > 0x00000020 && ch < 0x00010000)
dp->drv.p->buffer[i].Char.UnicodeChar = (uint16_t)ch;
else else
kk->drv.p->buffer[i].Char.UnicodeChar = (uint16_t)' ';
dp->drv.p->buffer[i].Char.UnicodeChar = (uint16_t)' ';
#endif #endif


kk->drv.p->buffer[i].Attributes =
win32_fg_palette[_cucul_argb32_to_ansi4fg(kk->c->attr[i])]
| win32_bg_palette[_cucul_argb32_to_ansi4bg(kk->c->attr[i])];
dp->drv.p->buffer[i].Attributes =
win32_fg_palette[_cucul_argb32_to_ansi4fg(dp->cv->attr[i])]
| win32_bg_palette[_cucul_argb32_to_ansi4bg(dp->cv->attr[i])];
} }


/* Blit the screen buffer */ /* Blit the screen buffer */
size.X = kk->c->width;
size.Y = kk->c->height;
size.X = dp->cv->width;
size.Y = dp->cv->height;
pos.X = pos.Y = 0; pos.X = pos.Y = 0;
rect.Left = rect.Top = 0; rect.Left = rect.Top = 0;
rect.Right = kk->c->width - 1;
rect.Bottom = kk->c->height - 1;
rect.Right = dp->cv->width - 1;
rect.Bottom = dp->cv->height - 1;
#if 0 #if 0
WriteConsoleOutput(kk->drv.p->screen, kk->drv.p->buffer, size, pos, &rect);
WriteConsoleOutput(dp->drv.p->screen, dp->drv.p->buffer, size, pos, &rect);
#else #else
WriteConsoleOutputW(kk->drv.p->screen, kk->drv.p->buffer, size, pos, &rect);
WriteConsoleOutputW(dp->drv.p->screen, dp->drv.p->buffer, size, pos, &rect);
#endif #endif
} }


static void win32_handle_resize(caca_t *kk)
static void win32_handle_resize(caca_display_t *dp)
{ {
/* FIXME: I don't know what to do here. */ /* FIXME: I don't know what to do here. */
kk->resize.w = kk->c->width;
kk->resize.h = kk->c->height;
dp->resize.w = dp->cv->width;
dp->resize.h = dp->cv->height;
} }


static int win32_get_event(caca_t *kk, caca_event_t *ev)
static int win32_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
INPUT_RECORD rec; INPUT_RECORD rec;
DWORD num; DWORD num;


for( ; ; ) for( ; ; )
{ {
GetNumberOfConsoleInputEvents(kk->drv.p->hin, &num);
GetNumberOfConsoleInputEvents(dp->drv.p->hin, &num);
if(num == 0) if(num == 0)
break; break;


ReadConsoleInput(kk->drv.p->hin, &rec, 1, &num);
ReadConsoleInput(dp->drv.p->hin, &rec, 1, &num);
if(rec.EventType == KEY_EVENT) if(rec.EventType == KEY_EVENT)
{ {
unsigned int event; unsigned int event;
@@ -287,16 +287,16 @@ static int win32_get_event(caca_t *kk, caca_event_t *ev)
{ {
COORD pos = rec.Event.MouseEvent.dwMousePosition; COORD pos = rec.Event.MouseEvent.dwMousePosition;


if(kk->mouse.x == (unsigned int)pos.X &&
kk->mouse.y == (unsigned int)pos.Y)
if(dp->mouse.x == (unsigned int)pos.X &&
dp->mouse.y == (unsigned int)pos.Y)
continue; continue;


kk->mouse.x = pos.X;
kk->mouse.y = pos.Y;
dp->mouse.x = pos.X;
dp->mouse.y = pos.Y;


ev->type = CACA_EVENT_MOUSE_MOTION; ev->type = CACA_EVENT_MOUSE_MOTION;
ev->data.mouse.x = kk->mouse.x;
ev->data.mouse.y = kk->mouse.y;
ev->data.mouse.x = dp->mouse.x;
ev->data.mouse.y = dp->mouse.y;
return 1; return 1;
} }
#if 0 #if 0
@@ -331,19 +331,19 @@ static int win32_get_event(caca_t *kk, caca_event_t *ev)
* Driver initialisation * Driver initialisation
*/ */


int win32_install(caca_t *kk)
int win32_install(caca_display_t *dp)
{ {
kk->drv.driver = CACA_DRIVER_WIN32;
kk->drv.init_graphics = win32_init_graphics;
kk->drv.end_graphics = win32_end_graphics;
kk->drv.set_window_title = win32_set_window_title;
kk->drv.get_window_width = win32_get_window_width;
kk->drv.get_window_height = win32_get_window_height;
kk->drv.display = win32_display;
kk->drv.handle_resize = win32_handle_resize;
kk->drv.get_event = win32_get_event;
kk->drv.set_mouse = NULL;
dp->drv.driver = CACA_DRIVER_WIN32;
dp->drv.init_graphics = win32_init_graphics;
dp->drv.end_graphics = win32_end_graphics;
dp->drv.set_window_title = win32_set_window_title;
dp->drv.get_window_width = win32_get_window_width;
dp->drv.get_window_height = win32_get_window_height;
dp->drv.display = win32_display;
dp->drv.handle_resize = win32_handle_resize;
dp->drv.get_event = win32_get_event;
dp->drv.set_mouse = NULL;


return 0; return 0;
} }


+ 200
- 200
caca/driver_x11.c View File

@@ -59,7 +59,7 @@ struct driver_private
#endif #endif
}; };


static int x11_init_graphics(caca_t *kk)
static int x11_init_graphics(caca_display_t *dp)
{ {
Colormap colormap; Colormap colormap;
XSetWindowAttributes x11_winattr; XSetWindowAttributes x11_winattr;
@@ -69,7 +69,7 @@ static int x11_init_graphics(caca_t *kk)
unsigned int width = 0, height = 0; unsigned int width = 0, height = 0;
int i; int i;


kk->drv.p = malloc(sizeof(struct driver_private));
dp->drv.p = malloc(sizeof(struct driver_private));


#if defined(HAVE_GETENV) #if defined(HAVE_GETENV)
geometry = getenv("CACA_GEOMETRY"); geometry = getenv("CACA_GEOMETRY");
@@ -78,10 +78,10 @@ static int x11_init_graphics(caca_t *kk)
#endif #endif


if(width && height) if(width && height)
_cucul_set_size(kk->c, width, height);
_cucul_set_size(dp->cv, width, height);


kk->drv.p->dpy = XOpenDisplay(NULL);
if(kk->drv.p->dpy == NULL)
dp->drv.p->dpy = XOpenDisplay(NULL);
if(dp->drv.p->dpy == NULL)
return -1; return -1;


#if defined(HAVE_GETENV) #if defined(HAVE_GETENV)
@@ -101,18 +101,18 @@ static int x11_init_graphics(caca_t *kk)
if(!*parser) if(!*parser)
{ {
XSetErrorHandler(old_error_handler); XSetErrorHandler(old_error_handler);
XCloseDisplay(kk->drv.p->dpy);
XCloseDisplay(dp->drv.p->dpy);
return -1; return -1;
} }


kk->drv.p->font = XLoadFont(kk->drv.p->dpy, *parser);
if(!kk->drv.p->font)
dp->drv.p->font = XLoadFont(dp->drv.p->dpy, *parser);
if(!dp->drv.p->font)
continue; continue;


kk->drv.p->font_struct = XQueryFont(kk->drv.p->dpy, kk->drv.p->font);
if(!kk->drv.p->font_struct)
dp->drv.p->font_struct = XQueryFont(dp->drv.p->dpy, dp->drv.p->font);
if(!dp->drv.p->font_struct)
{ {
XUnloadFont(kk->drv.p->dpy, kk->drv.p->font);
XUnloadFont(dp->drv.p->dpy, dp->drv.p->font);
continue; continue;
} }


@@ -122,170 +122,170 @@ static int x11_init_graphics(caca_t *kk)
/* Reset the default X11 error handler */ /* Reset the default X11 error handler */
XSetErrorHandler(old_error_handler); XSetErrorHandler(old_error_handler);


kk->drv.p->font_width = kk->drv.p->font_struct->max_bounds.width;
kk->drv.p->font_height = kk->drv.p->font_struct->max_bounds.ascent
+ kk->drv.p->font_struct->max_bounds.descent;
kk->drv.p->font_offset = kk->drv.p->font_struct->max_bounds.descent;
dp->drv.p->font_width = dp->drv.p->font_struct->max_bounds.width;
dp->drv.p->font_height = dp->drv.p->font_struct->max_bounds.ascent
+ dp->drv.p->font_struct->max_bounds.descent;
dp->drv.p->font_offset = dp->drv.p->font_struct->max_bounds.descent;


colormap = DefaultColormap(kk->drv.p->dpy, DefaultScreen(kk->drv.p->dpy));
colormap = DefaultColormap(dp->drv.p->dpy, DefaultScreen(dp->drv.p->dpy));
for(i = 0x000; i < 0x1000; i++) for(i = 0x000; i < 0x1000; i++)
{ {
XColor color; XColor color;
color.red = ((i & 0xf00) >> 8) * 0x1111; color.red = ((i & 0xf00) >> 8) * 0x1111;
color.green = ((i & 0x0f0) >> 4) * 0x1111; color.green = ((i & 0x0f0) >> 4) * 0x1111;
color.blue = (i & 0x00f) * 0x1111; color.blue = (i & 0x00f) * 0x1111;
XAllocColor(kk->drv.p->dpy, colormap, &color);
kk->drv.p->colors[i] = color.pixel;
XAllocColor(dp->drv.p->dpy, colormap, &color);
dp->drv.p->colors[i] = color.pixel;
} }


x11_winattr.backing_store = Always; x11_winattr.backing_store = Always;
x11_winattr.background_pixel = kk->drv.p->colors[0x000];
x11_winattr.background_pixel = dp->drv.p->colors[0x000];
x11_winattr.event_mask = ExposureMask | StructureNotifyMask; x11_winattr.event_mask = ExposureMask | StructureNotifyMask;


kk->drv.p->window =
XCreateWindow(kk->drv.p->dpy, DefaultRootWindow(kk->drv.p->dpy), 0, 0,
kk->c->width * kk->drv.p->font_width,
kk->c->height * kk->drv.p->font_height,
dp->drv.p->window =
XCreateWindow(dp->drv.p->dpy, DefaultRootWindow(dp->drv.p->dpy), 0, 0,
dp->cv->width * dp->drv.p->font_width,
dp->cv->height * dp->drv.p->font_height,
0, 0, InputOutput, 0, 0, 0, InputOutput, 0,
CWBackingStore | CWBackPixel | CWEventMask, CWBackingStore | CWBackPixel | CWEventMask,
&x11_winattr); &x11_winattr);


kk->drv.p->wm_protocols =
XInternAtom(kk->drv.p->dpy, "WM_PROTOCOLS", True);
kk->drv.p->wm_delete_window =
XInternAtom(kk->drv.p->dpy, "WM_DELETE_WINDOW", True);
dp->drv.p->wm_protocols =
XInternAtom(dp->drv.p->dpy, "WM_PROTOCOLS", True);
dp->drv.p->wm_delete_window =
XInternAtom(dp->drv.p->dpy, "WM_DELETE_WINDOW", True);


if(kk->drv.p->wm_protocols != None && kk->drv.p->wm_delete_window != None)
XSetWMProtocols(kk->drv.p->dpy, kk->drv.p->window,
&kk->drv.p->wm_delete_window, 1);
if(dp->drv.p->wm_protocols != None && dp->drv.p->wm_delete_window != None)
XSetWMProtocols(dp->drv.p->dpy, dp->drv.p->window,
&dp->drv.p->wm_delete_window, 1);


XStoreName(kk->drv.p->dpy, kk->drv.p->window, "caca for X");
XStoreName(dp->drv.p->dpy, dp->drv.p->window, "caca for X");


XSelectInput(kk->drv.p->dpy, kk->drv.p->window, StructureNotifyMask);
XMapWindow(kk->drv.p->dpy, kk->drv.p->window);
XSelectInput(dp->drv.p->dpy, dp->drv.p->window, StructureNotifyMask);
XMapWindow(dp->drv.p->dpy, dp->drv.p->window);


kk->drv.p->gc = XCreateGC(kk->drv.p->dpy, kk->drv.p->window, 0, NULL);
XSetForeground(kk->drv.p->dpy, kk->drv.p->gc, kk->drv.p->colors[0x888]);
XSetFont(kk->drv.p->dpy, kk->drv.p->gc, kk->drv.p->font);
dp->drv.p->gc = XCreateGC(dp->drv.p->dpy, dp->drv.p->window, 0, NULL);
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc, dp->drv.p->colors[0x888]);
XSetFont(dp->drv.p->dpy, dp->drv.p->gc, dp->drv.p->font);


for(;;) for(;;)
{ {
XEvent xevent; XEvent xevent;
XNextEvent(kk->drv.p->dpy, &xevent);
XNextEvent(dp->drv.p->dpy, &xevent);
if (xevent.type == MapNotify) if (xevent.type == MapNotify)
break; break;
} }


#if defined(HAVE_X11_XKBLIB_H) #if defined(HAVE_X11_XKBLIB_H)
/* Disable autorepeat */ /* Disable autorepeat */
XkbSetDetectableAutoRepeat(kk->drv.p->dpy, True, &kk->drv.p->autorepeat);
if(!kk->drv.p->autorepeat)
XAutoRepeatOff(kk->drv.p->dpy);
XkbSetDetectableAutoRepeat(dp->drv.p->dpy, True, &dp->drv.p->autorepeat);
if(!dp->drv.p->autorepeat)
XAutoRepeatOff(dp->drv.p->dpy);
#endif #endif


kk->drv.p->event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
dp->drv.p->event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
| ButtonReleaseMask | PointerMotionMask | StructureNotifyMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask
| ExposureMask; | ExposureMask;


XSelectInput(kk->drv.p->dpy, kk->drv.p->window, kk->drv.p->event_mask);
XSelectInput(dp->drv.p->dpy, dp->drv.p->window, dp->drv.p->event_mask);


XSync(kk->drv.p->dpy, False);
XSync(dp->drv.p->dpy, False);


kk->drv.p->pixmap = XCreatePixmap(kk->drv.p->dpy, kk->drv.p->window,
kk->c->width * kk->drv.p->font_width,
kk->c->height * kk->drv.p->font_height,
DefaultDepth(kk->drv.p->dpy,
DefaultScreen(kk->drv.p->dpy)));
kk->drv.p->pointer = None;
dp->drv.p->pixmap = XCreatePixmap(dp->drv.p->dpy, dp->drv.p->window,
dp->cv->width * dp->drv.p->font_width,
dp->cv->height * dp->drv.p->font_height,
DefaultDepth(dp->drv.p->dpy,
DefaultScreen(dp->drv.p->dpy)));
dp->drv.p->pointer = None;


return 0; return 0;
} }


static int x11_end_graphics(caca_t *kk)
static int x11_end_graphics(caca_display_t *dp)
{ {
XSync(kk->drv.p->dpy, False);
XSync(dp->drv.p->dpy, False);
#if defined(HAVE_X11_XKBLIB_H) #if defined(HAVE_X11_XKBLIB_H)
if(!kk->drv.p->autorepeat)
XAutoRepeatOn(kk->drv.p->dpy);
if(!dp->drv.p->autorepeat)
XAutoRepeatOn(dp->drv.p->dpy);
#endif #endif
XFreePixmap(kk->drv.p->dpy, kk->drv.p->pixmap);
XFreeFont(kk->drv.p->dpy, kk->drv.p->font_struct);
XFreeGC(kk->drv.p->dpy, kk->drv.p->gc);
XUnmapWindow(kk->drv.p->dpy, kk->drv.p->window);
XDestroyWindow(kk->drv.p->dpy, kk->drv.p->window);
XCloseDisplay(kk->drv.p->dpy);
XFreePixmap(dp->drv.p->dpy, dp->drv.p->pixmap);
XFreeFont(dp->drv.p->dpy, dp->drv.p->font_struct);
XFreeGC(dp->drv.p->dpy, dp->drv.p->gc);
XUnmapWindow(dp->drv.p->dpy, dp->drv.p->window);
XDestroyWindow(dp->drv.p->dpy, dp->drv.p->window);
XCloseDisplay(dp->drv.p->dpy);


free(kk->drv.p);
free(dp->drv.p);


return 0; return 0;
} }


static int x11_set_window_title(caca_t *kk, char const *title)
static int x11_set_window_title(caca_display_t *dp, char const *title)
{ {
XStoreName(kk->drv.p->dpy, kk->drv.p->window, title);
XStoreName(dp->drv.p->dpy, dp->drv.p->window, title);
return 0; return 0;
} }


static unsigned int x11_get_window_width(caca_t *kk)
static unsigned int x11_get_window_width(caca_display_t *dp)
{ {
return kk->c->width * kk->drv.p->font_width;
return dp->cv->width * dp->drv.p->font_width;
} }


static unsigned int x11_get_window_height(caca_t *kk)
static unsigned int x11_get_window_height(caca_display_t *dp)
{ {
return kk->c->height * kk->drv.p->font_height;
return dp->cv->height * dp->drv.p->font_height;
} }


static void x11_display(caca_t *kk)
static void x11_display(caca_display_t *dp)
{ {
unsigned int x, y, len; unsigned int x, y, len;


/* First draw the background colours. Splitting the process in two /* First draw the background colours. Splitting the process in two
* loops like this is actually slightly faster. */ * loops like this is actually slightly faster. */
for(y = 0; y < kk->c->height; y++)
for(y = 0; y < dp->cv->height; y++)
{ {
for(x = 0; x < kk->c->width; x += len)
for(x = 0; x < dp->cv->width; x += len)
{ {
uint32_t *attr = kk->c->attr + x + y * kk->c->width;
uint32_t *attr = dp->cv->attr + x + y * dp->cv->width;
uint16_t bg = _cucul_argb32_to_rgb12bg(*attr); uint16_t bg = _cucul_argb32_to_rgb12bg(*attr);


len = 1; len = 1;
while(x + len < kk->c->width
while(x + len < dp->cv->width
&& _cucul_argb32_to_rgb12bg(attr[len]) == bg) && _cucul_argb32_to_rgb12bg(attr[len]) == bg)
len++; len++;


XSetForeground(kk->drv.p->dpy, kk->drv.p->gc,
kk->drv.p->colors[bg]);
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->gc,
x * kk->drv.p->font_width, y * kk->drv.p->font_height,
len * kk->drv.p->font_width, kk->drv.p->font_height);
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc,
dp->drv.p->colors[bg]);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->gc,
x * dp->drv.p->font_width, y * dp->drv.p->font_height,
len * dp->drv.p->font_width, dp->drv.p->font_height);
} }
} }


/* Then print the foreground characters */ /* Then print the foreground characters */
for(y = 0; y < kk->c->height; y++)
for(y = 0; y < dp->cv->height; y++)
{ {
unsigned int yoff = (y + 1) * kk->drv.p->font_height
- kk->drv.p->font_offset;
uint32_t *chars = kk->c->chars + y * kk->c->width;
unsigned int yoff = (y + 1) * dp->drv.p->font_height
- dp->drv.p->font_offset;
uint32_t *chars = dp->cv->chars + y * dp->cv->width;


for(x = 0; x < kk->c->width; x++, chars++)
for(x = 0; x < dp->cv->width; x++, chars++)
{ {
uint32_t *attr = kk->c->attr + x + y * kk->c->width;
uint32_t *attr = dp->cv->attr + x + y * dp->cv->width;


/* Skip spaces */ /* Skip spaces */
if(*chars == 0x00000020) if(*chars == 0x00000020)
continue; continue;


XSetForeground(kk->drv.p->dpy, kk->drv.p->gc,
kk->drv.p->colors[_cucul_argb32_to_rgb12fg(*attr)]);
XSetForeground(dp->drv.p->dpy, dp->drv.p->gc,
dp->drv.p->colors[_cucul_argb32_to_rgb12fg(*attr)]);


/* Plain ASCII, no problem. */ /* Plain ASCII, no problem. */
if(*chars > 0x00000020 && *chars < 0x00000080) if(*chars > 0x00000020 && *chars < 0x00000080)
{ {
char c = (uint8_t)*chars;
XDrawString(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->gc,
x * kk->drv.p->font_width, yoff, &c, 1);
char ch = (uint8_t)*chars;
XDrawString(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->gc,
x * dp->drv.p->font_width, yoff, &ch, 1);
continue; continue;
} }


@@ -295,46 +295,46 @@ static void x11_display(caca_t *kk)
switch(*chars) switch(*chars)
{ {
case 0x00002580: /* ▀ */ case 0x00002580: /* ▀ */
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
x * kk->drv.p->font_width,
y * kk->drv.p->font_height,
kk->drv.p->font_width,
kk->drv.p->font_height / 2);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
x * dp->drv.p->font_width,
y * dp->drv.p->font_height,
dp->drv.p->font_width,
dp->drv.p->font_height / 2);
break; break;
case 0x00002584: /* ▄ */ case 0x00002584: /* ▄ */
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
x * kk->drv.p->font_width,
(y + 1) * kk->drv.p->font_height
- kk->drv.p->font_height / 2,
kk->drv.p->font_width,
kk->drv.p->font_height / 2);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
x * dp->drv.p->font_width,
(y + 1) * dp->drv.p->font_height
- dp->drv.p->font_height / 2,
dp->drv.p->font_width,
dp->drv.p->font_height / 2);
break; break;
case 0x00002588: /* █ */ case 0x00002588: /* █ */
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
x * kk->drv.p->font_width,
y * kk->drv.p->font_height,
kk->drv.p->font_width,
kk->drv.p->font_height);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
x * dp->drv.p->font_width,
y * dp->drv.p->font_height,
dp->drv.p->font_width,
dp->drv.p->font_height);
break; break;
case 0x0000258c: /* ▌ */ case 0x0000258c: /* ▌ */
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
x * kk->drv.p->font_width,
y * kk->drv.p->font_height,
kk->drv.p->font_width / 2,
kk->drv.p->font_height);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
x * dp->drv.p->font_width,
y * dp->drv.p->font_height,
dp->drv.p->font_width / 2,
dp->drv.p->font_height);
break; break;
case 0x00002590: /* ▐ */ case 0x00002590: /* ▐ */
XFillRectangle(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
(x + 1) * kk->drv.p->font_width
- kk->drv.p->font_width / 2,
y * kk->drv.p->font_height,
kk->drv.p->font_width / 2,
kk->drv.p->font_height);
XFillRectangle(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
(x + 1) * dp->drv.p->font_width
- dp->drv.p->font_width / 2,
y * dp->drv.p->font_height,
dp->drv.p->font_width / 2,
dp->drv.p->font_height);
break; break;
case 0x00002593: /* ▓ */ case 0x00002593: /* ▓ */
case 0x00002592: /* ▒ */ case 0x00002592: /* ▒ */
@@ -342,74 +342,74 @@ static void x11_display(caca_t *kk)
{ {
/* FIXME: this sucks utterly */ /* FIXME: this sucks utterly */
int i, j, k = *chars - 0x00002591; int i, j, k = *chars - 0x00002591;
for(j = kk->drv.p->font_height; j--; )
for(i = kk->drv.p->font_width; i--; )
for(j = dp->drv.p->font_height; j--; )
for(i = dp->drv.p->font_width; i--; )
{ {
if(((i + 2 * (j & 1)) & 3) > k) if(((i + 2 * (j & 1)) & 3) > k)
continue; continue;


XDrawPoint(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
x * kk->drv.p->font_width + i,
y * kk->drv.p->font_height + j);
XDrawPoint(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
x * dp->drv.p->font_width + i,
y * dp->drv.p->font_height + j);
} }
break; break;
} }
default: default:
{ {
char c;
c = '?';
XDrawString(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->gc,
x * kk->drv.p->font_width, yoff, &c, 1);
char ch;
ch = '?';
XDrawString(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->gc,
x * dp->drv.p->font_width, yoff, &ch, 1);
break; break;
} }
} }
} }
} }


XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, kk->drv.p->window,
kk->drv.p->gc, 0, 0,
kk->c->width * kk->drv.p->font_width,
kk->c->height * kk->drv.p->font_height,
XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap, dp->drv.p->window,
dp->drv.p->gc, 0, 0,
dp->cv->width * dp->drv.p->font_width,
dp->cv->height * dp->drv.p->font_height,
0, 0); 0, 0);
XFlush(kk->drv.p->dpy);
XFlush(dp->drv.p->dpy);
} }


static void x11_handle_resize(caca_t *kk)
static void x11_handle_resize(caca_display_t *dp)
{ {
Pixmap new_pixmap; Pixmap new_pixmap;


new_pixmap = XCreatePixmap(kk->drv.p->dpy, kk->drv.p->window,
kk->resize.w * kk->drv.p->font_width,
kk->resize.h * kk->drv.p->font_height,
DefaultDepth(kk->drv.p->dpy,
DefaultScreen(kk->drv.p->dpy)));
XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap, new_pixmap,
kk->drv.p->gc, 0, 0,
kk->resize.w * kk->drv.p->font_width,
kk->resize.h * kk->drv.p->font_height, 0, 0);
XFreePixmap(kk->drv.p->dpy, kk->drv.p->pixmap);
kk->drv.p->pixmap = new_pixmap;
new_pixmap = XCreatePixmap(dp->drv.p->dpy, dp->drv.p->window,
dp->resize.w * dp->drv.p->font_width,
dp->resize.h * dp->drv.p->font_height,
DefaultDepth(dp->drv.p->dpy,
DefaultScreen(dp->drv.p->dpy)));
XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap, new_pixmap,
dp->drv.p->gc, 0, 0,
dp->resize.w * dp->drv.p->font_width,
dp->resize.h * dp->drv.p->font_height, 0, 0);
XFreePixmap(dp->drv.p->dpy, dp->drv.p->pixmap);
dp->drv.p->pixmap = new_pixmap;
} }


static int x11_get_event(caca_t *kk, caca_event_t *ev)
static int x11_get_event(caca_display_t *dp, caca_event_t *ev)
{ {
XEvent xevent; XEvent xevent;
char key; char key;


while(XCheckWindowEvent(kk->drv.p->dpy, kk->drv.p->window,
kk->drv.p->event_mask, &xevent) == True)
while(XCheckWindowEvent(dp->drv.p->dpy, dp->drv.p->window,
dp->drv.p->event_mask, &xevent) == True)
{ {
KeySym keysym; KeySym keysym;


/* Expose event */ /* Expose event */
if(xevent.type == Expose) if(xevent.type == Expose)
{ {
XCopyArea(kk->drv.p->dpy, kk->drv.p->pixmap,
kk->drv.p->window, kk->drv.p->gc, 0, 0,
kk->c->width * kk->drv.p->font_width,
kk->c->height * kk->drv.p->font_height, 0, 0);
XCopyArea(dp->drv.p->dpy, dp->drv.p->pixmap,
dp->drv.p->window, dp->drv.p->gc, 0, 0,
dp->cv->width * dp->drv.p->font_width,
dp->cv->height * dp->drv.p->font_height, 0, 0);
continue; continue;
} }


@@ -418,17 +418,17 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev)
{ {
unsigned int w, h; unsigned int w, h;


w = (xevent.xconfigure.width + kk->drv.p->font_width / 3)
/ kk->drv.p->font_width;
h = (xevent.xconfigure.height + kk->drv.p->font_height / 3)
/ kk->drv.p->font_height;
w = (xevent.xconfigure.width + dp->drv.p->font_width / 3)
/ dp->drv.p->font_width;
h = (xevent.xconfigure.height + dp->drv.p->font_height / 3)
/ dp->drv.p->font_height;


if(!w || !h || (w == kk->c->width && h == kk->c->height))
if(!w || !h || (w == dp->cv->width && h == dp->cv->height))
continue; continue;


kk->resize.w = w;
kk->resize.h = h;
kk->resize.resized = 1;
dp->resize.w = w;
dp->resize.h = h;
dp->resize.resized = 1;


continue; continue;
} }
@@ -436,23 +436,23 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev)
/* Check for mouse motion events */ /* Check for mouse motion events */
if(xevent.type == MotionNotify) if(xevent.type == MotionNotify)
{ {
unsigned int newx = xevent.xmotion.x / kk->drv.p->font_width;
unsigned int newy = xevent.xmotion.y / kk->drv.p->font_height;
unsigned int newx = xevent.xmotion.x / dp->drv.p->font_width;
unsigned int newy = xevent.xmotion.y / dp->drv.p->font_height;


if(newx >= kk->c->width)
newx = kk->c->width - 1;
if(newy >= kk->c->height)
newy = kk->c->height - 1;
if(newx >= dp->cv->width)
newx = dp->cv->width - 1;
if(newy >= dp->cv->height)
newy = dp->cv->height - 1;


if(kk->mouse.x == newx && kk->mouse.y == newy)
if(dp->mouse.x == newx && dp->mouse.y == newy)
continue; continue;


kk->mouse.x = newx;
kk->mouse.y = newy;
dp->mouse.x = newx;
dp->mouse.y = newy;


ev->type = CACA_EVENT_MOUSE_MOTION; ev->type = CACA_EVENT_MOUSE_MOTION;
ev->data.mouse.x = kk->mouse.x;
ev->data.mouse.y = kk->mouse.y;
ev->data.mouse.x = dp->mouse.x;
ev->data.mouse.y = dp->mouse.y;
return 1; return 1;
} }


@@ -488,7 +488,7 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev)
return 1; return 1;
} }


keysym = XKeycodeToKeysym(kk->drv.p->dpy, xevent.xkey.keycode, 0);
keysym = XKeycodeToKeysym(dp->drv.p->dpy, xevent.xkey.keycode, 0);
switch(keysym) switch(keysym)
{ {
case XK_F1: ev->data.key.ch = CACA_KEY_F1; break; case XK_F1: ev->data.key.ch = CACA_KEY_F1; break;
@@ -519,12 +519,12 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev)
return 1; return 1;
} }


while(XCheckTypedEvent(kk->drv.p->dpy, ClientMessage, &xevent))
while(XCheckTypedEvent(dp->drv.p->dpy, ClientMessage, &xevent))
{ {
if(xevent.xclient.message_type != kk->drv.p->wm_protocols)
if(xevent.xclient.message_type != dp->drv.p->wm_protocols)
continue; continue;


if((Atom)xevent.xclient.data.l[0] == kk->drv.p->wm_delete_window)
if((Atom)xevent.xclient.data.l[0] == dp->drv.p->wm_delete_window)
{ {
ev->type = CACA_EVENT_QUIT; ev->type = CACA_EVENT_QUIT;
return 1; return 1;
@@ -535,7 +535,7 @@ static int x11_get_event(caca_t *kk, caca_event_t *ev)
return 0; return 0;
} }


static void x11_set_mouse(caca_t *kk, int flags)
static void x11_set_mouse(caca_display_t *dp, int flags)
{ {
Cursor no_ptr; Cursor no_ptr;
Pixmap bm_no; Pixmap bm_no;
@@ -545,26 +545,26 @@ static void x11_set_mouse(caca_t *kk, int flags)


if(flags) if(flags)
{ {
XDefineCursor(kk->drv.p->dpy,kk->drv.p->window, 0);
XDefineCursor(dp->drv.p->dpy,dp->drv.p->window, 0);
return; return;
} }


colormap = DefaultColormap(kk->drv.p->dpy, DefaultScreen(kk->drv.p->dpy));
if(!XAllocNamedColor(kk->drv.p->dpy, colormap, "black", &black, &dummy))
colormap = DefaultColormap(dp->drv.p->dpy, DefaultScreen(dp->drv.p->dpy));
if(!XAllocNamedColor(dp->drv.p->dpy, colormap, "black", &black, &dummy))
{ {
return; return;
} }
bm_no = XCreateBitmapFromData(kk->drv.p->dpy, kk->drv.p->window,
bm_no = XCreateBitmapFromData(dp->drv.p->dpy, dp->drv.p->window,
empty, 8, 8); empty, 8, 8);
no_ptr = XCreatePixmapCursor(kk->drv.p->dpy, bm_no, bm_no,
no_ptr = XCreatePixmapCursor(dp->drv.p->dpy, bm_no, bm_no,
&black, &black, 0, 0); &black, &black, 0, 0);
XDefineCursor(kk->drv.p->dpy, kk->drv.p->window, no_ptr);
XFreeCursor(kk->drv.p->dpy, no_ptr);
XDefineCursor(dp->drv.p->dpy, dp->drv.p->window, no_ptr);
XFreeCursor(dp->drv.p->dpy, no_ptr);
if(bm_no != None) if(bm_no != None)
XFreePixmap(kk->drv.p->dpy, bm_no);
XFreeColors(kk->drv.p->dpy, colormap, &black.pixel, 1, 0);
XFreePixmap(dp->drv.p->dpy, bm_no);
XFreeColors(dp->drv.p->dpy, colormap, &black.pixel, 1, 0);


XSync(kk->drv.p->dpy, False);
XSync(dp->drv.p->dpy, False);
} }


/* /*
@@ -581,24 +581,24 @@ static int x11_error_handler(Display *dpy, XErrorEvent *xevent)
* Driver initialisation * Driver initialisation
*/ */


int x11_install(caca_t *kk)
int x11_install(caca_display_t *dp)
{ {
#if defined(HAVE_GETENV) #if defined(HAVE_GETENV)
if(!getenv("DISPLAY") || !*(getenv("DISPLAY"))) if(!getenv("DISPLAY") || !*(getenv("DISPLAY")))
return -1; return -1;
#endif #endif


kk->drv.driver = CACA_DRIVER_X11;
kk->drv.init_graphics = x11_init_graphics;
kk->drv.end_graphics = x11_end_graphics;
kk->drv.set_window_title = x11_set_window_title;
kk->drv.get_window_width = x11_get_window_width;
kk->drv.get_window_height = x11_get_window_height;
kk->drv.display = x11_display;
kk->drv.handle_resize = x11_handle_resize;
kk->drv.get_event = x11_get_event;
kk->drv.set_mouse = x11_set_mouse;
dp->drv.driver = CACA_DRIVER_X11;
dp->drv.init_graphics = x11_init_graphics;
dp->drv.end_graphics = x11_end_graphics;
dp->drv.set_window_title = x11_set_window_title;
dp->drv.get_window_width = x11_get_window_width;
dp->drv.get_window_height = x11_get_window_height;
dp->drv.display = x11_display;
dp->drv.handle_resize = x11_handle_resize;
dp->drv.get_event = x11_get_event;
dp->drv.set_mouse = x11_set_mouse;


return 0; return 0;
} }


+ 60
- 60
caca/event.c View File

@@ -26,8 +26,8 @@
#include "caca.h" #include "caca.h"
#include "caca_internals.h" #include "caca_internals.h"


static int _get_next_event(caca_t *, caca_event_t *);
static int _lowlevel_event(caca_t *, caca_event_t *);
static int _get_next_event(caca_display_t *, caca_event_t *);
static int _lowlevel_event(caca_display_t *, caca_event_t *);


#if !defined(_DOXYGEN_SKIP_ME) #if !defined(_DOXYGEN_SKIP_ME)
/* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the /* If no new key was pressed after AUTOREPEAT_THRESHOLD usec, assume the
@@ -50,13 +50,13 @@ static int _lowlevel_event(caca_t *, caca_event_t *);
* if no more events are pending in the queue. A negative value causes the * if no more events are pending in the queue. A negative value causes the
* function to wait indefinitely until a matching event is received. * function to wait indefinitely until a matching event is received.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \param event_mask Bitmask of requested events. * \param event_mask Bitmask of requested events.
* \param timeout A timeout value in microseconds * \param timeout A timeout value in microseconds
* \param ev A pointer to a caca_event structure. * \param ev A pointer to a caca_event structure.
* \return The next matching event in the queue, or 0 if no event is pending. * \return The next matching event in the queue, or 0 if no event is pending.
*/ */
int caca_get_event(caca_t *kk, unsigned int event_mask,
int caca_get_event(caca_display_t *dp, unsigned int event_mask,
caca_event_t *ev, int timeout) caca_event_t *ev, int timeout)
{ {
caca_timer_t timer; caca_timer_t timer;
@@ -70,7 +70,7 @@ int caca_get_event(caca_t *kk, unsigned int event_mask,


for( ; ; ) for( ; ; )
{ {
int ret = _get_next_event(kk, ev);
int ret = _get_next_event(dp, ev);


/* If we got the event we wanted, return */ /* If we got the event we wanted, return */
if(ev->type & event_mask) if(ev->type & event_mask)
@@ -108,15 +108,15 @@ int caca_get_event(caca_t *kk, unsigned int event_mask,
* drivers are being used, because mouse position is only detected when * drivers are being used, because mouse position is only detected when
* the mouse is clicked. Other drivers such as X11 work well. * the mouse is clicked. Other drivers such as X11 work well.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \return The X mouse coordinate. * \return The X mouse coordinate.
*/ */
unsigned int caca_get_mouse_x(caca_t *kk)
unsigned int caca_get_mouse_x(caca_display_t *dp)
{ {
if(kk->mouse.x >= kk->c->width)
kk->mouse.x = kk->c->width - 1;
if(dp->mouse.x >= dp->cv->width)
dp->mouse.x = dp->cv->width - 1;


return kk->mouse.x;
return dp->mouse.x;
} }


/** \brief Return the Y mouse coordinate. /** \brief Return the Y mouse coordinate.
@@ -126,22 +126,22 @@ unsigned int caca_get_mouse_x(caca_t *kk)
* drivers are being used, because mouse position is only detected when * drivers are being used, because mouse position is only detected when
* the mouse is clicked. Other drivers such as X11 work well. * the mouse is clicked. Other drivers such as X11 work well.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \return The Y mouse coordinate. * \return The Y mouse coordinate.
*/ */
unsigned int caca_get_mouse_y(caca_t *kk)
unsigned int caca_get_mouse_y(caca_display_t *dp)
{ {
if(kk->mouse.y >= kk->c->height)
kk->mouse.y = kk->c->height - 1;
if(dp->mouse.y >= dp->cv->height)
dp->mouse.y = dp->cv->height - 1;


return kk->mouse.y;
return dp->mouse.y;
} }


/* /*
* XXX: The following functions are local. * XXX: The following functions are local.
*/ */


static int _get_next_event(caca_t *kk, caca_event_t *ev)
static int _get_next_event(caca_display_t *dp, caca_event_t *ev)
{ {
#if defined(USE_SLANG) || defined(USE_NCURSES) #if defined(USE_SLANG) || defined(USE_NCURSES)
unsigned int ticks; unsigned int ticks;
@@ -149,112 +149,112 @@ static int _get_next_event(caca_t *kk, caca_event_t *ev)
int ret; int ret;


/* If we are about to return a resize event, acknowledge it */ /* If we are about to return a resize event, acknowledge it */
if(kk->resize.resized)
if(dp->resize.resized)
{ {
kk->resize.resized = 0;
_caca_handle_resize(kk);
dp->resize.resized = 0;
_caca_handle_resize(dp);
ev->type = CACA_EVENT_RESIZE; ev->type = CACA_EVENT_RESIZE;
ev->data.resize.w = kk->c->width;
ev->data.resize.h = kk->c->height;
ev->data.resize.w = dp->cv->width;
ev->data.resize.h = dp->cv->height;
return 1; return 1;
} }


ret = _lowlevel_event(kk, ev);
ret = _lowlevel_event(dp, ev);


#if defined(USE_SLANG) #if defined(USE_SLANG)
if(kk->drv.driver != CACA_DRIVER_SLANG)
if(dp->drv.driver != CACA_DRIVER_SLANG)
#endif #endif
#if defined(USE_NCURSES) #if defined(USE_NCURSES)
if(kk->drv.driver != CACA_DRIVER_NCURSES)
if(dp->drv.driver != CACA_DRIVER_NCURSES)
#endif #endif
return ret; return ret;


#if defined(USE_SLANG) || defined(USE_NCURSES) #if defined(USE_SLANG) || defined(USE_NCURSES)
/* Simulate long keypresses using autorepeat features */ /* Simulate long keypresses using autorepeat features */
ticks = _caca_getticks(&kk->events.key_timer);
kk->events.last_key_ticks += ticks;
kk->events.autorepeat_ticks += ticks;
ticks = _caca_getticks(&dp->events.key_timer);
dp->events.last_key_ticks += ticks;
dp->events.autorepeat_ticks += ticks;


/* Handle autorepeat */ /* Handle autorepeat */
if(kk->events.last_key_event.type
&& kk->events.autorepeat_ticks > AUTOREPEAT_TRIGGER
&& kk->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD
&& kk->events.autorepeat_ticks > AUTOREPEAT_RATE)
if(dp->events.last_key_event.type
&& dp->events.autorepeat_ticks > AUTOREPEAT_TRIGGER
&& dp->events.autorepeat_ticks > AUTOREPEAT_THRESHOLD
&& dp->events.autorepeat_ticks > AUTOREPEAT_RATE)
{ {
_push_event(kk, ev);
kk->events.autorepeat_ticks -= AUTOREPEAT_RATE;
*ev = kk->events.last_key_event;
_push_event(dp, ev);
dp->events.autorepeat_ticks -= AUTOREPEAT_RATE;
*ev = dp->events.last_key_event;
return 1; return 1;
} }


/* We are in autorepeat mode and the same key was just pressed, ignore /* We are in autorepeat mode and the same key was just pressed, ignore
* this event and return the next one by calling ourselves. */ * this event and return the next one by calling ourselves. */
if(ev->type == CACA_EVENT_KEY_PRESS if(ev->type == CACA_EVENT_KEY_PRESS
&& kk->events.last_key_event.type
&& ev->data.key.ch == kk->events.last_key_event.data.key.ch
&& ev->data.key.ucs4 == kk->events.last_key_event.data.key.ucs4)
&& dp->events.last_key_event.type
&& ev->data.key.ch == dp->events.last_key_event.data.key.ch
&& ev->data.key.ucs4 == dp->events.last_key_event.data.key.ucs4)
{ {
kk->events.last_key_ticks = 0;
return _get_next_event(kk, ev);
dp->events.last_key_ticks = 0;
return _get_next_event(dp, ev);
} }


/* We are in autorepeat mode, but key has expired or a new key was /* 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 */ * pressed - store our event and return a key release event first */
if(kk->events.last_key_event.type
&& (kk->events.last_key_ticks > AUTOREPEAT_THRESHOLD
if(dp->events.last_key_event.type
&& (dp->events.last_key_ticks > AUTOREPEAT_THRESHOLD
|| (ev->type & CACA_EVENT_KEY_PRESS))) || (ev->type & CACA_EVENT_KEY_PRESS)))
{ {
_push_event(kk, ev);
*ev = kk->events.last_key_event;
_push_event(dp, ev);
*ev = dp->events.last_key_event;
ev->type = CACA_EVENT_KEY_RELEASE; ev->type = CACA_EVENT_KEY_RELEASE;
kk->events.last_key_event.type = CACA_EVENT_NONE;
dp->events.last_key_event.type = CACA_EVENT_NONE;
return 1; return 1;
} }


/* A new key was pressed, enter autorepeat mode */ /* A new key was pressed, enter autorepeat mode */
if(ev->type & CACA_EVENT_KEY_PRESS) if(ev->type & CACA_EVENT_KEY_PRESS)
{ {
kk->events.last_key_ticks = 0;
kk->events.autorepeat_ticks = 0;
kk->events.last_key_event = *ev;
dp->events.last_key_ticks = 0;
dp->events.autorepeat_ticks = 0;
dp->events.last_key_event = *ev;
} }


return ev->type ? 1 : 0; return ev->type ? 1 : 0;
#endif #endif
} }


static int _lowlevel_event(caca_t *kk, caca_event_t *ev)
static int _lowlevel_event(caca_display_t *dp, caca_event_t *ev)
{ {
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
int ret = _pop_event(kk, ev);
int ret = _pop_event(dp, ev);


if(ret) if(ret)
return ret; return ret;
#endif #endif


return kk->drv.get_event(kk, ev);
return dp->drv.get_event(dp, ev);
} }


#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL) #if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
void _push_event(caca_t *kk, caca_event_t *ev)
void _push_event(caca_display_t *dp, caca_event_t *ev)
{ {
if(!ev->type || kk->events.queue == EVENTBUF_LEN)
if(!ev->type || dp->events.queue == EVENTBUF_LEN)
return; return;
kk->events.buf[kk->events.queue] = *ev;
kk->events.queue++;
dp->events.buf[dp->events.queue] = *ev;
dp->events.queue++;
} }


int _pop_event(caca_t *kk, caca_event_t *ev)
int _pop_event(caca_display_t *dp, caca_event_t *ev)
{ {
int i; int i;


if(kk->events.queue == 0)
if(dp->events.queue == 0)
return 0; return 0;


*ev = kk->events.buf[0];
for(i = 1; i < kk->events.queue; i++)
kk->events.buf[i - 1] = kk->events.buf[i];
kk->events.queue--;
*ev = dp->events.buf[0];
for(i = 1; i < dp->events.queue; i++)
dp->events.buf[i - 1] = dp->events.buf[i];
dp->events.queue--;


return 1; return 1;
} }


+ 39
- 39
caca/graphics.c View File

@@ -27,13 +27,13 @@
* If libcaca runs in a window, try to change its title. This works with * If libcaca runs in a window, try to change its title. This works with
* the X11 and Win32 drivers. * the X11 and Win32 drivers.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \param title The desired window title. * \param title The desired window title.
* \return 0 upon success, a non-zero value if an error occurs. * \return 0 upon success, a non-zero value if an error occurs.
*/ */
int caca_set_window_title(caca_t *kk, char const *title)
int caca_set_window_title(caca_display_t *dp, char const *title)
{ {
return kk->drv.set_window_title(kk, title);
return dp->drv.set_window_title(dp, title);
} }


/** \brief Get the window width. /** \brief Get the window width.
@@ -43,12 +43,12 @@ int caca_set_window_title(caca_t *kk, char const *title)
* or if there is no way to know the font size, most drivers will assume a * or if there is no way to know the font size, most drivers will assume a
* 6x10 font is being used. Note that the units are not necessarily pixels. * 6x10 font is being used. Note that the units are not necessarily pixels.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \return The window width. * \return The window width.
*/ */
unsigned int caca_get_window_width(caca_t *kk)
unsigned int caca_get_window_width(caca_display_t *dp)
{ {
return kk->drv.get_window_width(kk);
return dp->drv.get_window_width(dp);
} }


/** \brief Get the window height. /** \brief Get the window height.
@@ -58,12 +58,12 @@ unsigned int caca_get_window_width(caca_t *kk)
* or if there is no way to know the font size, assume a 6x10 font is being * or if there is no way to know the font size, assume a 6x10 font is being
* used. Note that the units are not necessarily pixels. * used. Note that the units are not necessarily pixels.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \return The window height. * \return The window height.
*/ */
unsigned int caca_get_window_height(caca_t *kk)
unsigned int caca_get_window_height(caca_display_t *dp)
{ {
return kk->drv.get_window_height(kk);
return dp->drv.get_window_height(dp);
} }


/** \brief Set the refresh delay. /** \brief Set the refresh delay.
@@ -75,12 +75,12 @@ unsigned int caca_get_window_height(caca_t *kk)
* If the argument is zero, constant framerate is disabled. This is the * If the argument is zero, constant framerate is disabled. This is the
* default behaviour. * default behaviour.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \param usec The refresh delay in microseconds. * \param usec The refresh delay in microseconds.
*/ */
void caca_set_delay(caca_t *kk, unsigned int usec)
void caca_set_delay(caca_display_t *dp, unsigned int usec)
{ {
kk->delay = usec;
dp->delay = usec;
} }


/** \brief Get the average rendering time. /** \brief Get the average rendering time.
@@ -91,12 +91,12 @@ void caca_set_delay(caca_t *kk, unsigned int usec)
* rendering time will not be considerably shorter than the requested delay * rendering time will not be considerably shorter than the requested delay
* even if the real rendering time was shorter. * even if the real rendering time was shorter.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \return The render time in microseconds. * \return The render time in microseconds.
*/ */
unsigned int caca_get_rendertime(caca_t *kk)
unsigned int caca_get_rendertime(caca_display_t *dp)
{ {
return kk->rendertime;
return dp->rendertime;
} }


/** \brief Flush pending changes and redraw the screen. /** \brief Flush pending changes and redraw the screen.
@@ -111,41 +111,41 @@ unsigned int caca_get_rendertime(caca_t *kk)
* set with caca_set_delay(), the second call will wait a bit before * set with caca_set_delay(), the second call will wait a bit before
* performing the screen refresh. * performing the screen refresh.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
*/ */
void caca_display(caca_t *kk)
void caca_display(caca_display_t *dp)
{ {
#if !defined(_DOXYGEN_SKIP_ME) #if !defined(_DOXYGEN_SKIP_ME)
#define IDLE_USEC 10000 #define IDLE_USEC 10000
#endif #endif
int ticks = kk->lastticks + _caca_getticks(&kk->timer);
int ticks = dp->lastticks + _caca_getticks(&dp->timer);


kk->drv.display(kk);
dp->drv.display(dp);


/* Once the display is finished, we can ack resizes */ /* Once the display is finished, we can ack resizes */
if(kk->resize.resized)
if(dp->resize.resized)
{ {
kk->resize.resized = 0;
_caca_handle_resize(kk);
dp->resize.resized = 0;
_caca_handle_resize(dp);
} }


/* Wait until kk->delay + time of last call */
ticks += _caca_getticks(&kk->timer);
for(ticks += _caca_getticks(&kk->timer);
ticks + IDLE_USEC < (int)kk->delay;
ticks += _caca_getticks(&kk->timer))
/* Wait until dp->delay + time of last call */
ticks += _caca_getticks(&dp->timer);
for(ticks += _caca_getticks(&dp->timer);
ticks + IDLE_USEC < (int)dp->delay;
ticks += _caca_getticks(&dp->timer))
{ {
_caca_sleep(IDLE_USEC); _caca_sleep(IDLE_USEC);
} }


/* Update the sliding mean of the render time */ /* Update the sliding mean of the render time */
kk->rendertime = (7 * kk->rendertime + ticks) / 8;
dp->rendertime = (7 * dp->rendertime + ticks) / 8;


kk->lastticks = ticks - kk->delay;
dp->lastticks = ticks - dp->delay;


/* If we drifted too much, it's bad, bad, bad. */ /* If we drifted too much, it's bad, bad, bad. */
if(kk->lastticks > (int)kk->delay)
kk->lastticks = 0;
if(dp->lastticks > (int)dp->delay)
dp->lastticks = 0;
} }


/** \brief Show or hide the mouse pointer. /** \brief Show or hide the mouse pointer.
@@ -153,26 +153,26 @@ void caca_display(caca_t *kk)
* This function shows or hides the mouse pointer, for devices that * This function shows or hides the mouse pointer, for devices that
* support it. * support it.
* *
* \param kk The libcaca graphical context.
* \param dp The libcaca graphical context.
* \param flag 0 hides the pointer, 1 shows the system's default pointer * \param flag 0 hides the pointer, 1 shows the system's default pointer
* (usually an arrow). Other values are reserved for future use. * (usually an arrow). Other values are reserved for future use.
*/ */
void caca_set_mouse(caca_t *kk, int flag)
void caca_set_mouse(caca_display_t *dp, int flag)
{ {
if(kk->drv.set_mouse)
kk->drv.set_mouse(kk, flag);
if(dp->drv.set_mouse)
dp->drv.set_mouse(dp, flag);
} }


/* /*
* XXX: following functions are local * XXX: following functions are local
*/ */


void _caca_handle_resize(caca_t *kk)
void _caca_handle_resize(caca_display_t *dp)
{ {
kk->drv.handle_resize(kk);
dp->drv.handle_resize(dp);


/* Tell libcucul we changed size */ /* Tell libcucul we changed size */
if(kk->resize.w != kk->c->width || kk->resize.h != kk->c->height)
_cucul_set_size(kk->c, kk->resize.w, kk->resize.h);
if(dp->resize.w != dp->cv->width || dp->resize.h != dp->cv->height)
_cucul_set_size(dp->cv, dp->resize.w, dp->resize.h);
} }



+ 18
- 18
cpp/caca++.cpp View File

@@ -25,61 +25,61 @@ Caca::Caca(void)
{ {


} }
Caca::Caca(Cucul *c)
Caca::Caca(Cucul *cv)
{ {
kk = caca_attach(c->get_cucul_canvas_t());
if(!kk) throw -1;
dp = caca_attach(cv->get_cucul_canvas_t());
if(!dp) throw -1;
} }
Caca::~Caca() Caca::~Caca()
{ {
caca_detach(kk);
caca_detach(dp);
} }
void Caca::attach(Cucul *c)
void Caca::attach(Cucul *cv)
{ {
kk = caca_attach(c->get_cucul_canvas_t());
if(!kk) throw -1;
dp = caca_attach(cv->get_cucul_canvas_t());
if(!dp) throw -1;
} }
void Caca::detach () void Caca::detach ()
{ {
caca_detach(kk);
caca_detach(dp);
} }
void Caca::set_delay (unsigned int d) void Caca::set_delay (unsigned int d)
{ {
caca_set_delay(kk, d);
caca_set_delay(dp, d);
} }
void Caca::display () void Caca::display ()
{ {
caca_display(kk);
caca_display(dp);
} }
unsigned int Caca::get_rendertime () unsigned int Caca::get_rendertime ()
{ {
return caca_get_rendertime(kk);
return caca_get_rendertime(dp);
} }
unsigned int Caca::get_window_width () unsigned int Caca::get_window_width ()
{ {
return caca_get_window_width(kk);
return caca_get_window_width(dp);
} }
unsigned int Caca::get_window_height () unsigned int Caca::get_window_height ()
{ {
return caca_get_window_height(kk);
return caca_get_window_height(dp);
} }
int Caca::set_window_title (char const *s) int Caca::set_window_title (char const *s)
{ {
return caca_set_window_title(kk, s);
return caca_set_window_title(dp, s);
} }
int Caca::get_event (unsigned int g, Event *n, int aa) int Caca::get_event (unsigned int g, Event *n, int aa)
{ {
return caca_get_event(kk, g, n->e, aa);
return caca_get_event(dp, g, n->e, aa);
} }
unsigned int Caca::get_mouse_x () unsigned int Caca::get_mouse_x ()
{ {
return caca_get_mouse_x(kk);
return caca_get_mouse_x(dp);
} }
unsigned int Caca::get_mouse_y () unsigned int Caca::get_mouse_y ()
{ {
return caca_get_mouse_x(kk);
return caca_get_mouse_x(dp);
} }
void Caca::set_mouse (int v) void Caca::set_mouse (int v)
{ {
caca_set_mouse(kk, v);
caca_set_mouse(dp, v);
} }

+ 1
- 1
cpp/caca++.h View File

@@ -72,7 +72,7 @@ class Caca {


private: private:
caca_t *kk;
caca_display_t *dp;
}; };






+ 45
- 45
cpp/cucul++.cpp View File

@@ -20,43 +20,43 @@


Cucul::Cucul() Cucul::Cucul()
{ {
c = cucul_create(0,0);
if(!c) throw -1;
cv = cucul_create(0,0);
if(!cv) throw -1;
} }
Cucul::Cucul(int width, int height) Cucul::Cucul(int width, int height)
{ {
c = cucul_create(width, height);
if(!c) throw -1;
cv = cucul_create(width, height);
if(!cv) throw -1;
} }
Cucul::~Cucul() Cucul::~Cucul()
{ {
if(c) {
cucul_free(c);
if(cv) {
cucul_free(cv);
} }
} }


cucul_canvas_t *Cucul::get_cucul_canvas_t() cucul_canvas_t *Cucul::get_cucul_canvas_t()
{ {
return c;
return cv;
} }






void Cucul::set_size(unsigned int width, unsigned int height) void Cucul::set_size(unsigned int width, unsigned int height)
{ {
cucul_set_size (c, width, height);
cucul_set_size (cv, width, height);
} }
unsigned int Cucul::get_width(void) unsigned int Cucul::get_width(void)
{ {
return cucul_get_width (c);
return cucul_get_width (cv);
} }
unsigned int Cucul::get_height(void) unsigned int Cucul::get_height(void)
{ {
return cucul_get_height (c);
return cucul_get_height (cv);
} }
void Cucul::set_color(unsigned int f, unsigned int b) void Cucul::set_color(unsigned int f, unsigned int b)
{ {
cucul_set_color (c, f, b);
cucul_set_color (cv, f, b);
} }
char const * Cucul::get_color_name (unsigned int color) char const * Cucul::get_color_name (unsigned int color)
{ {
@@ -64,11 +64,11 @@ char const * Cucul::get_color_name (unsigned int color)
} }
void Cucul::putchar (int x, int y, char ch) void Cucul::putchar (int x, int y, char ch)
{ {
cucul_putchar (c, x, y, ch);
cucul_putchar (cv, x, y, ch);
} }
void Cucul::putstr (int x, int y, char *str) void Cucul::putstr (int x, int y, char *str)
{ {
cucul_putstr(c, x, y, str);
cucul_putstr(cv, x, y, str);
} }
void Cucul::printf ( int x , int y , char const * format,...) void Cucul::printf ( int x , int y , char const * format,...)
{ {
@@ -91,102 +91,102 @@ void Cucul::printf ( int x , int y , char const * format,...)


void Cucul::clear () void Cucul::clear ()
{ {
cucul_clear(c);
cucul_clear(cv);
} }


void Cucul::blit ( int x, int y, Cucul* c1, Cucul* c2) void Cucul::blit ( int x, int y, Cucul* c1, Cucul* c2)
{ {
cucul_blit(c, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t());
cucul_blit(cv, x, y, c1->get_cucul_canvas_t(), c2->get_cucul_canvas_t());
} }


void Cucul::invert () void Cucul::invert ()
{ {
cucul_invert(c);
cucul_invert(cv);
} }


void Cucul::flip () void Cucul::flip ()
{ {
cucul_flip(c);
cucul_flip(cv);
} }


void Cucul::flop () void Cucul::flop ()
{ {
cucul_flop(c);
cucul_flop(cv);
} }


void Cucul::rotate () void Cucul::rotate ()
{ {
cucul_rotate(c);
cucul_rotate(cv);
} }


void Cucul::draw_line (int x1 , int y1, int x2, int y2, char const *ch) void Cucul::draw_line (int x1 , int y1, int x2, int y2, char const *ch)
{ {
cucul_draw_line(c, x1,y1,x2,y2, ch);
cucul_draw_line(cv, x1,y1,x2,y2, ch);
} }
void Cucul::draw_polyline (int const x[], int const y[], int f, char const *ch) void Cucul::draw_polyline (int const x[], int const y[], int f, char const *ch)
{ {
cucul_draw_polyline(c, x, y, f, ch);
cucul_draw_polyline(cv, x, y, f, ch);
} }
void Cucul::draw_thin_line (int x1 , int y1, int x2, int y2) void Cucul::draw_thin_line (int x1 , int y1, int x2, int y2)
{ {
cucul_draw_thin_line(c, x1, y1, x2, y2);
cucul_draw_thin_line(cv, x1, y1, x2, y2);
} }


void Cucul::draw_thin_polyline ( int const x[], int const y[], int f) void Cucul::draw_thin_polyline ( int const x[], int const y[], int f)
{ {
cucul_draw_thin_polyline(c, x, y, f);
cucul_draw_thin_polyline(cv, x, y, f);
} }
void Cucul::draw_circle ( int x, int y, int d, char const *ch) void Cucul::draw_circle ( int x, int y, int d, char const *ch)
{ {
cucul_draw_circle(c, x, y, d, ch);
cucul_draw_circle(cv, x, y, d, ch);
} }


void Cucul::draw_ellipse ( int x, int y, int d1, int d2, char const *ch) void Cucul::draw_ellipse ( int x, int y, int d1, int d2, char const *ch)
{ {
cucul_draw_ellipse(c, x, y, d1, d2, ch);
cucul_draw_ellipse(cv, x, y, d1, d2, ch);
} }


void Cucul::draw_thin_ellipse ( int x, int y, int d1, int d2) void Cucul::draw_thin_ellipse ( int x, int y, int d1, int d2)
{ {
cucul_draw_thin_ellipse(c, x, y, d1, d2);
cucul_draw_thin_ellipse(cv, x, y, d1, d2);
} }


void Cucul::fill_ellipse ( int x, int y, int d1, int d2, char const *ch) void Cucul::fill_ellipse ( int x, int y, int d1, int d2, char const *ch)
{ {
cucul_fill_ellipse(c, x, y, d1, d2, ch);
cucul_fill_ellipse(cv, x, y, d1, d2, ch);
} }


void Cucul::draw_box ( int x, int y, int w, int h, char const *ch) void Cucul::draw_box ( int x, int y, int w, int h, char const *ch)
{ {
cucul_draw_box(c, x, y, w, h, ch);
cucul_draw_box(cv, x, y, w, h, ch);
} }
void Cucul::draw_thin_box ( int x, int y, int w, int h) void Cucul::draw_thin_box ( int x, int y, int w, int h)
{ {
cucul_draw_thin_box(c, x, y, w, h);
cucul_draw_thin_box(cv, x, y, w, h);
} }


void Cucul::fill_box ( int x, int y, int w, int h, char const *ch) void Cucul::fill_box ( int x, int y, int w, int h, char const *ch)
{ {
cucul_fill_box(c, x, y, w, h, ch);
cucul_fill_box(cv, x, y, w, h, ch);
} }


void Cucul::draw_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, char const *ch) void Cucul::draw_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, char const *ch)
{ {
cucul_draw_triangle(c, x1, y1, x2, y2, x3, y3, ch);
cucul_draw_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
} }


void Cucul::draw_thin_triangle ( int x1, int y1, int x2, int y2, int x3, int y3) void Cucul::draw_thin_triangle ( int x1, int y1, int x2, int y2, int x3, int y3)
{ {
cucul_draw_thin_triangle(c, x1, y1, x2, y2, x3, y3);
cucul_draw_thin_triangle(cv, x1, y1, x2, y2, x3, y3);
} }


void Cucul::fill_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, const char *ch) void Cucul::fill_triangle ( int x1, int y1, int x2, int y2, int x3, int y3, const char *ch)
{ {
cucul_fill_triangle(c, x1, y1, x2, y2, x3, y3, ch);
cucul_fill_triangle(cv, x1, y1, x2, y2, x3, y3, ch);
} }


int Cucul::rand (int min, int max) int Cucul::rand (int min, int max)
@@ -228,7 +228,7 @@ int Cucul::get_sprite_dy (Cucul::Sprite const *s, int v)


void Cucul::draw_sprite ( int x, int y, Cucul::Sprite const *s, int v) void Cucul::draw_sprite ( int x, int y, Cucul::Sprite const *s, int v)
{ {
cucul_draw_sprite(c, x, y, s->sprite, v);
cucul_draw_sprite(cv, x, y, s->sprite, v);
} }


void Cucul::free_sprite (Cucul::Sprite *s) void Cucul::free_sprite (Cucul::Sprite *s)
@@ -268,9 +268,9 @@ void Cucul::set_dither_invert ( Cucul::Dither *d, int i)
cucul_set_dither_invert(d->dither, i); cucul_set_dither_invert(d->dither, i);
} }


void Cucul::set_dither_antialias ( Cucul::Dither *d, char const *c)
void Cucul::set_dither_antialias ( Cucul::Dither *d, char const *cv)
{ {
cucul_set_dither_antialias(d->dither, c);
cucul_set_dither_antialias(d->dither, cv);
} }
char const *const * Cucul::get_dither_antialias_list ( Cucul::Dither const *d) char const *const * Cucul::get_dither_antialias_list ( Cucul::Dither const *d)
@@ -278,9 +278,9 @@ char const *const * Cucul::get_dither_antialias_list ( Cucul::Dither const *d)
return cucul_get_dither_antialias_list(d->dither); return cucul_get_dither_antialias_list(d->dither);
} }


void Cucul::set_dither_color ( Cucul::Dither *d, char const *c)
void Cucul::set_dither_color ( Cucul::Dither *d, char const *cv)
{ {
cucul_set_dither_color(d->dither, c);
cucul_set_dither_color(d->dither, cv);
} }


char const *const * Cucul::get_dither_color_list ( Cucul::Dither const *d) char const *const * Cucul::get_dither_color_list ( Cucul::Dither const *d)
@@ -288,9 +288,9 @@ char const *const * Cucul::get_dither_color_list ( Cucul::Dither const *d)
return cucul_get_dither_color_list(d->dither); return cucul_get_dither_color_list(d->dither);
} }
void Cucul::set_dither_charset ( Cucul::Dither *d, char const *c)
void Cucul::set_dither_charset ( Cucul::Dither *d, char const *cv)
{ {
cucul_set_dither_charset(d->dither, c);
cucul_set_dither_charset(d->dither, cv);
} }


char const *const * Cucul::get_dither_charset_list ( Cucul::Dither const *d) char const *const * Cucul::get_dither_charset_list ( Cucul::Dither const *d)
@@ -298,9 +298,9 @@ char const *const * Cucul::get_dither_charset_list ( Cucul::Dither const *d)
return cucul_get_dither_charset_list(d->dither); return cucul_get_dither_charset_list(d->dither);
} }
void Cucul::set_dither_mode ( Cucul::Dither *d, char const *c)
void Cucul::set_dither_mode ( Cucul::Dither *d, char const *cv)
{ {
cucul_set_dither_mode(d->dither, c);
cucul_set_dither_mode(d->dither, cv);
} }


char const *const * Cucul::get_dither_mode_list ( Cucul::Dither const *d) char const *const * Cucul::get_dither_mode_list ( Cucul::Dither const *d)
@@ -310,7 +310,7 @@ char const *const * Cucul::get_dither_mode_list ( Cucul::Dither const *d)


void Cucul::dither_bitmap ( int x, int y, int w, int h, Cucul::Dither const *d, void *v) void Cucul::dither_bitmap ( int x, int y, int w, int h, Cucul::Dither const *d, void *v)
{ {
cucul_dither_bitmap(c, x, y, w, h, d->dither, v);
cucul_dither_bitmap(cv, x, y, w, h, d->dither, v);
} }


void Cucul::free_dither ( Cucul::Dither *d) void Cucul::free_dither ( Cucul::Dither *d)
@@ -342,7 +342,7 @@ unsigned int Cucul::get_font_height ( Cucul::Font *f)


void Cucul::render_canvas (Cucul::Font *f, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w) void Cucul::render_canvas (Cucul::Font *f, unsigned char *buf, unsigned int x, unsigned int y, unsigned int w)
{ {
cucul_render_canvas(c, f->font, buf, x,y,w);
cucul_render_canvas(cv, f->font, buf, x,y,w);
} }


void Cucul::free_font ( Cucul::Font *f) void Cucul::free_font ( Cucul::Font *f)
@@ -353,7 +353,7 @@ void Cucul::free_font ( Cucul::Font *f)
Cucul::Buffer * Cucul::create_export (char const *buf) Cucul::Buffer * Cucul::create_export (char const *buf)
{ {
Cucul::Buffer *b = new Cucul::Buffer(); Cucul::Buffer *b = new Cucul::Buffer();
b->buffer = cucul_create_export(c, buf);
b->buffer = cucul_create_export(cv, buf);
return b; return b;
} }




+ 2
- 2
cpp/cucul++.h View File

@@ -65,7 +65,7 @@ class Cucul {
void set_color(unsigned int f, unsigned int b); void set_color(unsigned int f, unsigned int b);
char const * get_color_name (unsigned int color); char const * get_color_name (unsigned int color);
void printf ( int x , int y , char const * format,...); void printf ( int x , int y , char const * format,...);
void putchar (int x, int y, char c);
void putchar (int x, int y, char ch);
void putstr (int x, int y, char *str); void putstr (int x, int y, char *str);
void clear (); void clear ();
void blit ( int, int, Cucul* c1, Cucul* c2); void blit ( int, int, Cucul* c1, Cucul* c2);
@@ -126,7 +126,7 @@ class Cucul {
cucul_canvas_t *get_cucul_canvas_t(); cucul_canvas_t *get_cucul_canvas_t();


private: private:
cucul_canvas_t *c;
cucul_canvas_t *cv;




}; };


+ 23
- 23
cucul/box.c View File

@@ -26,7 +26,7 @@


/** \brief Draw a box on the canvas using the given character. /** \brief Draw a box on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the upper-left corner of the box. * \param x1 X coordinate of the upper-left corner of the box.
* \param y1 Y coordinate of the upper-left corner of the box. * \param y1 Y coordinate of the upper-left corner of the box.
* \param x2 X coordinate of the lower-right corner of the box. * \param x2 X coordinate of the lower-right corner of the box.
@@ -34,25 +34,25 @@
* \param str UTF-8 string containing the character to use to draw the box. * \param str UTF-8 string containing the character to use to draw the box.
* \return void * \return void
*/ */
void cucul_draw_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
void cucul_draw_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
char const *str) char const *str)
{ {
cucul_draw_line(c, x1, y1, x1, y2, str);
cucul_draw_line(c, x1, y2, x2, y2, str);
cucul_draw_line(c, x2, y2, x2, y1, str);
cucul_draw_line(c, x2, y1, x1, y1, str);
cucul_draw_line(cv, x1, y1, x1, y2, str);
cucul_draw_line(cv, x1, y2, x2, y2, str);
cucul_draw_line(cv, x2, y2, x2, y1, str);
cucul_draw_line(cv, x2, y1, x1, y1, str);
} }


/** \brief Draw a thin box on the canvas. /** \brief Draw a thin box on the canvas.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the upper-left corner of the box. * \param x1 X coordinate of the upper-left corner of the box.
* \param y1 Y coordinate of the upper-left corner of the box. * \param y1 Y coordinate of the upper-left corner of the box.
* \param x2 X coordinate of the lower-right corner of the box. * \param x2 X coordinate of the lower-right corner of the box.
* \param y2 Y coordinate of the lower-right corner of the box. * \param y2 Y coordinate of the lower-right corner of the box.
* \return void * \return void
*/ */
void cucul_draw_thin_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
void cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
{ {
int x, y, xmax, ymax; int x, y, xmax, ymax;


@@ -68,8 +68,8 @@ void cucul_draw_thin_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
y1 = y2; y2 = tmp; y1 = y2; y2 = tmp;
} }


xmax = c->width - 1;
ymax = c->height - 1;
xmax = cv->width - 1;
ymax = cv->height - 1;


if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
return; return;
@@ -77,37 +77,37 @@ void cucul_draw_thin_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
/* Draw edges */ /* Draw edges */
if(y1 >= 0) if(y1 >= 0)
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
_cucul_putchar32(c, x, y1, (uint32_t)'-');
_cucul_putchar32(cv, x, y1, (uint32_t)'-');


if(y2 <= ymax) if(y2 <= ymax)
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++) for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
_cucul_putchar32(c, x, y2, (uint32_t)'-');
_cucul_putchar32(cv, x, y2, (uint32_t)'-');


if(x1 >= 0) if(x1 >= 0)
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
_cucul_putchar32(c, x1, y, (uint32_t)'|');
_cucul_putchar32(cv, x1, y, (uint32_t)'|');


if(x2 <= xmax) if(x2 <= xmax)
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++) for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
_cucul_putchar32(c, x2, y, (uint32_t)'|');
_cucul_putchar32(cv, x2, y, (uint32_t)'|');


/* Draw corners */ /* Draw corners */
if(x1 >= 0 && y1 >= 0) if(x1 >= 0 && y1 >= 0)
_cucul_putchar32(c, x1, y1, (uint32_t)',');
_cucul_putchar32(cv, x1, y1, (uint32_t)',');


if(x1 >= 0 && y2 <= ymax) if(x1 >= 0 && y2 <= ymax)
_cucul_putchar32(c, x1, y2, (uint32_t)'`');
_cucul_putchar32(cv, x1, y2, (uint32_t)'`');


if(x2 <= xmax && y1 >= 0) if(x2 <= xmax && y1 >= 0)
_cucul_putchar32(c, x2, y1, (uint32_t)'.');
_cucul_putchar32(cv, x2, y1, (uint32_t)'.');


if(x2 <= xmax && y2 <= ymax) if(x2 <= xmax && y2 <= ymax)
_cucul_putchar32(c, x2, y2, (uint32_t)'\'');
_cucul_putchar32(cv, x2, y2, (uint32_t)'\'');
} }


/** \brief Fill a box on the canvas using the given character. /** \brief Fill a box on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the upper-left corner of the box. * \param x1 X coordinate of the upper-left corner of the box.
* \param y1 Y coordinate of the upper-left corner of the box. * \param y1 Y coordinate of the upper-left corner of the box.
* \param x2 X coordinate of the lower-right corner of the box. * \param x2 X coordinate of the lower-right corner of the box.
@@ -115,7 +115,7 @@ void cucul_draw_thin_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
* \param str UTF-8 string containing the character to fill the box with. * \param str UTF-8 string containing the character to fill the box with.
* \return void * \return void
*/ */
void cucul_fill_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
void cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
char const *str) char const *str)
{ {
int x, y, xmax, ymax; int x, y, xmax, ymax;
@@ -133,8 +133,8 @@ void cucul_fill_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
y1 = y2; y2 = tmp; y1 = y2; y2 = tmp;
} }


xmax = c->width - 1;
ymax = c->height - 1;
xmax = cv->width - 1;
ymax = cv->height - 1;


if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
return; return;
@@ -148,6 +148,6 @@ void cucul_fill_box(cucul_canvas_t *c, int x1, int y1, int x2, int y2,


for(y = y1; y <= y2; y++) for(y = y1; y <= y2; y++)
for(x = x1; x <= x2; x++) for(x = x1; x <= x2; x++)
_cucul_putchar32(c, x, y, ch);
_cucul_putchar32(cv, x, y, ch);
} }



+ 35
- 35
cucul/canvas.c View File

@@ -46,22 +46,22 @@
* replaced with a space. To print a sequence of bytes forming an UTF-8 * replaced with a space. To print a sequence of bytes forming an UTF-8
* character, use cucul_putstr() instead. * character, use cucul_putstr() instead.
* *
* \param c A handle to the libcucul canvas.
* \param cv A handle to the libcucul canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param ch The character to print. * \param ch The character to print.
*/ */
void cucul_putchar(cucul_canvas_t *c, int x, int y, char ch)
void cucul_putchar(cucul_canvas_t *cv, int x, int y, char ch)
{ {
if(x < 0 || x >= (int)c->width ||
y < 0 || y >= (int)c->height)
if(x < 0 || x >= (int)cv->width ||
y < 0 || y >= (int)cv->height)
return; return;


if((unsigned char)ch < 0x20 || (unsigned char)ch > 0x7f) if((unsigned char)ch < 0x20 || (unsigned char)ch > 0x7f)
ch = 0x20; ch = 0x20;


c->chars[x + y * c->width] = ch;
c->attr[x + y * c->width] = (c->bgcolor << 16) | c->fgcolor;
cv->chars[x + y * cv->width] = ch;
cv->attr[x + y * cv->width] = (cv->bgcolor << 16) | cv->fgcolor;
} }


/** \brief Print a string. /** \brief Print a string.
@@ -71,17 +71,17 @@ void cucul_putchar(cucul_canvas_t *c, int x, int y, char ch)
* the canvas boundaries (eg. a negative Y coordinate) and the string will * the canvas boundaries (eg. a negative Y coordinate) and the string will
* be cropped accordingly if it is too long. * be cropped accordingly if it is too long.
* *
* \param c A handle to the libcucul canvas.
* \param cv A handle to the libcucul canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param s The string to print. * \param s The string to print.
*/ */
void cucul_putstr(cucul_canvas_t *c, int x, int y, char const *s)
void cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s)
{ {
uint32_t *chars, *attr; uint32_t *chars, *attr;
unsigned int len; unsigned int len;


if(y < 0 || y >= (int)c->height || x >= (int)c->width)
if(y < 0 || y >= (int)cv->height || x >= (int)cv->width)
return; return;


len = _cucul_strlen_utf8(s); len = _cucul_strlen_utf8(s);
@@ -95,16 +95,16 @@ void cucul_putstr(cucul_canvas_t *c, int x, int y, char const *s)
x = 0; x = 0;
} }


chars = c->chars + x + y * c->width;
attr = c->attr + x + y * c->width;
chars = cv->chars + x + y * cv->width;
attr = cv->attr + x + y * cv->width;


if(x + len >= c->width)
len = c->width - x;
if(x + len >= cv->width)
len = cv->width - x;


while(len) while(len)
{ {
*chars++ = _cucul_utf8_to_utf32(s); *chars++ = _cucul_utf8_to_utf32(s);
*attr++ = (c->bgcolor << 16) | c->fgcolor;
*attr++ = (cv->bgcolor << 16) | cv->fgcolor;


s = _cucul_skip_utf8(s, 1); s = _cucul_skip_utf8(s, 1);
len--; len--;
@@ -119,34 +119,34 @@ void cucul_putstr(cucul_canvas_t *c, int x, int y, char const *s)
* be cropped accordingly if it is too long. The syntax of the format * be cropped accordingly if it is too long. The syntax of the format
* string is the same as for the C printf() function. * string is the same as for the C printf() function.
* *
* \param c A handle to the libcucul canvas.
* \param cv A handle to the libcucul canvas.
* \param x X coordinate. * \param x X coordinate.
* \param y Y coordinate. * \param y Y coordinate.
* \param format The format string to print. * \param format The format string to print.
* \param ... Arguments to the format string. * \param ... Arguments to the format string.
*/ */
void cucul_printf(cucul_canvas_t *c, int x, int y, char const *format, ...)
void cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...)
{ {
char tmp[BUFSIZ]; char tmp[BUFSIZ];
char *buf = tmp; char *buf = tmp;
va_list args; va_list args;


if(y < 0 || y >= (int)c->height || x >= (int)c->width)
if(y < 0 || y >= (int)cv->height || x >= (int)cv->width)
return; return;


if(c->width - x + 1 > BUFSIZ)
buf = malloc(c->width - x + 1);
if(cv->width - x + 1 > BUFSIZ)
buf = malloc(cv->width - x + 1);


va_start(args, format); va_start(args, format);
#if defined(HAVE_VSNPRINTF) #if defined(HAVE_VSNPRINTF)
vsnprintf(buf, c->width - x + 1, format, args);
vsnprintf(buf, cv->width - x + 1, format, args);
#else #else
vsprintf(buf, format, args); vsprintf(buf, format, args);
#endif #endif
buf[c->width - x] = '\0';
buf[cv->width - x] = '\0';
va_end(args); va_end(args);


cucul_putstr(c, x, y, buf);
cucul_putstr(cv, x, y, buf);


if(buf != tmp) if(buf != tmp)
free(buf); free(buf);
@@ -156,20 +156,20 @@ void cucul_printf(cucul_canvas_t *c, int x, int y, char const *format, ...)
* *
* This function clears the canvas using a black background. * This function clears the canvas using a black background.
*/ */
void cucul_clear(cucul_canvas_t *c)
void cucul_clear(cucul_canvas_t *cv)
{ {
uint16_t oldfg = c->fgcolor;
uint16_t oldbg = c->bgcolor;
int y = c->height;
uint16_t oldfg = cv->fgcolor;
uint16_t oldbg = cv->bgcolor;
int y = cv->height;


cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);


/* We could use SLsmg_cls() etc., but drawing empty lines is much faster */ /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
while(y--) while(y--)
cucul_putstr(c, 0, y, c->empty_line);
cucul_putstr(cv, 0, y, cv->empty_line);


c->fgcolor = oldfg;
c->bgcolor = oldbg;
cv->fgcolor = oldfg;
cv->bgcolor = oldbg;
} }


/** \brief Blit a canvas onto another one. /** \brief Blit a canvas onto another one.
@@ -230,13 +230,13 @@ void cucul_blit(cucul_canvas_t *dst, int x, int y,
* XXX: The following functions are not exported * XXX: The following functions are not exported
*/ */


void _cucul_putchar32(cucul_canvas_t *c, int x, int y, uint32_t ch)
void _cucul_putchar32(cucul_canvas_t *cv, int x, int y, uint32_t ch)
{ {
if(x < 0 || x >= (int)c->width ||
y < 0 || y >= (int)c->height)
if(x < 0 || x >= (int)cv->width ||
y < 0 || y >= (int)cv->height)
return; return;


c->chars[x + y * c->width] = ch;
c->attr[x + y * c->width] = (c->bgcolor << 16) | c->fgcolor;
cv->chars[x + y * cv->width] = ch;
cv->attr[x + y * cv->width] = (cv->bgcolor << 16) | cv->fgcolor;
} }



+ 13
- 13
cucul/charset.c View File

@@ -145,37 +145,37 @@ static uint32_t const cp437_lookup2[] =
0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0 0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0
}; };


uint8_t _cucul_utf32_to_cp437(uint32_t c)
uint8_t _cucul_utf32_to_cp437(uint32_t ch)
{ {
unsigned int i; unsigned int i;


if(c < 0x00000020)
if(ch < 0x00000020)
return '?'; return '?';


if(c < 0x00000080)
return c;
if(ch < 0x00000080)
return ch;


for(i = 0; i < sizeof(cp437_lookup1) / sizeof(*cp437_lookup1); i++) for(i = 0; i < sizeof(cp437_lookup1) / sizeof(*cp437_lookup1); i++)
if(cp437_lookup1[i] == c)
if(cp437_lookup1[i] == ch)
return 0x01 + i; return 0x01 + i;


for(i = 0; i < sizeof(cp437_lookup2) / sizeof(*cp437_lookup2); i++) for(i = 0; i < sizeof(cp437_lookup2) / sizeof(*cp437_lookup2); i++)
if(cp437_lookup2[i] == c)
if(cp437_lookup2[i] == ch)
return 0x7f + i; return 0x7f + i;


return '?'; return '?';
} }


uint32_t _cucul_cp437_to_utf32(uint8_t c)
uint32_t _cucul_cp437_to_utf32(uint8_t ch)
{ {
if(c > 0x7f)
return cp437_lookup2[c - 0x7f];
if(ch > 0x7f)
return cp437_lookup2[ch - 0x7f];


if(c >= 0x20)
return (uint32_t)c;
if(ch >= 0x20)
return (uint32_t)ch;


if(c > 0)
return cp437_lookup1[c - 0x01];
if(ch > 0)
return cp437_lookup1[ch - 0x01];


return 0x00000000; return 0x00000000;
} }


+ 8
- 8
cucul/colour.c View File

@@ -36,17 +36,17 @@ static const uint16_t ansitab[16] =
* Color values are those defined in \e cucul.h, such as CUCUL_COLOR_RED * Color values are those defined in \e cucul.h, such as CUCUL_COLOR_RED
* or CUCUL_COLOR_TRANSPARENT. * or CUCUL_COLOR_TRANSPARENT.
* *
* \param c A handle to the libcucul canvas.
* \param cv A handle to the libcucul canvas.
* \param fg The requested foreground colour. * \param fg The requested foreground colour.
* \param bg The requested background colour. * \param bg The requested background colour.
*/ */
void cucul_set_color(cucul_canvas_t *c, unsigned char fg, unsigned char bg)
void cucul_set_color(cucul_canvas_t *cv, unsigned char fg, unsigned char bg)
{ {
if(fg > 0x20 || bg > 0x20) if(fg > 0x20 || bg > 0x20)
return; return;


c->fgcolor = fg;
c->bgcolor = bg;
cv->fgcolor = fg;
cv->bgcolor = bg;
} }


/** \brief Set the default colour pair (truecolor version). /** \brief Set the default colour pair (truecolor version).
@@ -59,11 +59,11 @@ void cucul_set_color(cucul_canvas_t *c, unsigned char fg, unsigned char bg)
* instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is * instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is
* white with 50% alpha (A=8 R=15 G=15 B=15). * white with 50% alpha (A=8 R=15 G=15 B=15).
* *
* \param c A handle to the libcucul canvas.
* \param cv A handle to the libcucul canvas.
* \param fg The requested foreground colour. * \param fg The requested foreground colour.
* \param bg The requested background colour. * \param bg The requested background colour.
*/ */
void cucul_set_truecolor(cucul_canvas_t *c, unsigned int fg, unsigned int bg)
void cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg)
{ {
if(fg > 0xffff || bg > 0xffff) if(fg > 0xffff || bg > 0xffff)
return; return;
@@ -74,8 +74,8 @@ void cucul_set_truecolor(cucul_canvas_t *c, unsigned int fg, unsigned int bg)
if(bg < 0x100) if(bg < 0x100)
bg += 0x100; bg += 0x100;


c->fgcolor = fg;
c->bgcolor = bg;
cv->fgcolor = fg;
cv->bgcolor = bg;
} }


/* /*


+ 31
- 31
cucul/conic.c View File

@@ -29,7 +29,7 @@ static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t);


/** \brief Draw a circle on the canvas using the given character. /** \brief Draw a circle on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x Center X coordinate. * \param x Center X coordinate.
* \param y Center Y coordinate. * \param y Center Y coordinate.
* \param r Circle radius. * \param r Circle radius.
@@ -37,7 +37,7 @@ static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t);
* to draw the circle outline. * to draw the circle outline.
* \return void * \return void
*/ */
void cucul_draw_circle(cucul_canvas_t *c, int x, int y, int r, char const *str)
void cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, char const *str)
{ {
int test, dx, dy; int test, dx, dy;
uint32_t ch = _cucul_utf8_to_utf32(str); uint32_t ch = _cucul_utf8_to_utf32(str);
@@ -45,8 +45,8 @@ void cucul_draw_circle(cucul_canvas_t *c, int x, int y, int r, char const *str)
/* Optimized Bresenham. Kick ass. */ /* Optimized Bresenham. Kick ass. */
for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++)
{ {
ellipsepoints(c, x, y, dx, dy, ch);
ellipsepoints(c, x, y, dy, dx, ch);
ellipsepoints(cv, x, y, dx, dy, ch);
ellipsepoints(cv, x, y, dy, dx, ch);


test += test > 0 ? dx - dy-- : dx; test += test > 0 ? dx - dy-- : dx;
} }
@@ -54,7 +54,7 @@ void cucul_draw_circle(cucul_canvas_t *c, int x, int y, int r, char const *str)


/** \brief Fill an ellipse on the canvas using the given character. /** \brief Fill an ellipse on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param xo Center X coordinate. * \param xo Center X coordinate.
* \param yo Center Y coordinate. * \param yo Center Y coordinate.
* \param a Ellipse X radius. * \param a Ellipse X radius.
@@ -63,7 +63,7 @@ void cucul_draw_circle(cucul_canvas_t *c, int x, int y, int r, char const *str)
* to fill the ellipse. * to fill the ellipse.
* \return void * \return void
*/ */
void cucul_fill_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
void cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
char const *str) char const *str)
{ {
int d2; int d2;
@@ -80,15 +80,15 @@ void cucul_fill_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
else else
{ {
d1 += b*b*(2*x*1) + a*a*(-2*y+2); d1 += b*b*(2*x*1) + a*a*(-2*y+2);
cucul_draw_line(c, xo - x, yo - y, xo + x, yo - y, str);
cucul_draw_line(c, xo - x, yo + y, xo + x, yo + y, str);
cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, str);
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, str);
y--; y--;
} }
x++; x++;
} }


cucul_draw_line(c, xo - x, yo - y, xo + x, yo - y, str);
cucul_draw_line(c, xo - x, yo + y, xo + x, yo + y, str);
cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, str);
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, str);


d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
while(y > 0) while(y > 0)
@@ -104,14 +104,14 @@ void cucul_fill_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
} }


y--; y--;
cucul_draw_line(c, xo - x, yo - y, xo + x, yo - y, str);
cucul_draw_line(c, xo - x, yo + y, xo + x, yo + y, str);
cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, str);
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, str);
} }
} }


/** \brief Draw an ellipse on the canvas using the given character. /** \brief Draw an ellipse on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param xo Center X coordinate. * \param xo Center X coordinate.
* \param yo Center Y coordinate. * \param yo Center Y coordinate.
* \param a Ellipse X radius. * \param a Ellipse X radius.
@@ -120,7 +120,7 @@ void cucul_fill_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
* to draw the ellipse outline. * to draw the ellipse outline.
* \return void * \return void
*/ */
void cucul_draw_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
void cucul_draw_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b,
char const *str) char const *str)
{ {
int d2; int d2;
@@ -129,7 +129,7 @@ void cucul_draw_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
int d1 = b*b - (a*a*b) + (a*a/4); int d1 = b*b - (a*a*b) + (a*a/4);
uint32_t ch = _cucul_utf8_to_utf32(str); uint32_t ch = _cucul_utf8_to_utf32(str);


ellipsepoints(c, xo, yo, x, y, ch);
ellipsepoints(cv, xo, yo, x, y, ch);


while(a*a*y - a*a/2 > b*b*(x+1)) while(a*a*y - a*a/2 > b*b*(x+1))
{ {
@@ -143,7 +143,7 @@ void cucul_draw_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
y--; y--;
} }
x++; x++;
ellipsepoints(c, xo, yo, x, y, ch);
ellipsepoints(cv, xo, yo, x, y, ch);
} }


d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
@@ -160,20 +160,20 @@ void cucul_draw_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b,
} }


y--; y--;
ellipsepoints(c, xo, yo, x, y, ch);
ellipsepoints(cv, xo, yo, x, y, ch);
} }
} }


/** \brief Draw a thin ellipse on the canvas. /** \brief Draw a thin ellipse on the canvas.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param xo Center X coordinate. * \param xo Center X coordinate.
* \param yo Center Y coordinate. * \param yo Center Y coordinate.
* \param a Ellipse X radius. * \param a Ellipse X radius.
* \param b Ellipse Y radius. * \param b Ellipse Y radius.
* \return void * \return void
*/ */
void cucul_draw_thin_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b)
void cucul_draw_thin_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b)
{ {
/* FIXME: this is not correct */ /* FIXME: this is not correct */
int d2; int d2;
@@ -181,7 +181,7 @@ void cucul_draw_thin_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b)
int y = b; int y = b;
int d1 = b*b - (a*a*b) + (a*a/4); int d1 = b*b - (a*a*b) + (a*a/4);


ellipsepoints(c, xo, yo, x, y, '-');
ellipsepoints(cv, xo, yo, x, y, '-');


while(a*a*y - a*a/2 > b*b*(x+1)) while(a*a*y - a*a/2 > b*b*(x+1))
{ {
@@ -195,7 +195,7 @@ void cucul_draw_thin_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b)
y--; y--;
} }
x++; x++;
ellipsepoints(c, xo, yo, x, y, '-');
ellipsepoints(cv, xo, yo, x, y, '-');
} }


d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b; d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
@@ -212,34 +212,34 @@ void cucul_draw_thin_ellipse(cucul_canvas_t *c, int xo, int yo, int a, int b)
} }


y--; y--;
ellipsepoints(c, xo, yo, x, y, '|');
ellipsepoints(cv, xo, yo, x, y, '|');
} }
} }


static void ellipsepoints(cucul_canvas_t *c, int xo, int yo, int x, int y,
static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y,
uint32_t ch) uint32_t ch)
{ {
uint8_t b = 0; uint8_t b = 0;


if(xo + x >= 0 && xo + x < (int)c->width)
if(xo + x >= 0 && xo + x < (int)cv->width)
b |= 0x1; b |= 0x1;
if(xo - x >= 0 && xo - x < (int)c->width)
if(xo - x >= 0 && xo - x < (int)cv->width)
b |= 0x2; b |= 0x2;
if(yo + y >= 0 && yo + y < (int)c->height)
if(yo + y >= 0 && yo + y < (int)cv->height)
b |= 0x4; b |= 0x4;
if(yo - y >= 0 && yo - y < (int)c->height)
if(yo - y >= 0 && yo - y < (int)cv->height)
b |= 0x8; b |= 0x8;


if((b & (0x1|0x4)) == (0x1|0x4)) if((b & (0x1|0x4)) == (0x1|0x4))
_cucul_putchar32(c, xo + x, yo + y, ch);
_cucul_putchar32(cv, xo + x, yo + y, ch);


if((b & (0x2|0x4)) == (0x2|0x4)) if((b & (0x2|0x4)) == (0x2|0x4))
_cucul_putchar32(c, xo - x, yo + y, ch);
_cucul_putchar32(cv, xo - x, yo + y, ch);


if((b & (0x1|0x8)) == (0x1|0x8)) if((b & (0x1|0x8)) == (0x1|0x8))
_cucul_putchar32(c, xo + x, yo - y, ch);
_cucul_putchar32(cv, xo + x, yo - y, ch);


if((b & (0x2|0x8)) == (0x2|0x8)) if((b & (0x2|0x8)) == (0x2|0x8))
_cucul_putchar32(c, xo - x, yo - y, ch);
_cucul_putchar32(cv, xo - x, yo - y, ch);
} }



+ 57
- 56
cucul/cucul.c View File

@@ -43,33 +43,33 @@
*/ */
cucul_canvas_t * cucul_create(unsigned int width, unsigned int height) cucul_canvas_t * cucul_create(unsigned int width, unsigned int height)
{ {
cucul_canvas_t *c = malloc(sizeof(cucul_canvas_t));
cucul_canvas_t *cv = malloc(sizeof(cucul_canvas_t));


c->refcount = 0;
cv->refcount = 0;


c->fgcolor = CUCUL_COLOR_LIGHTGRAY;
c->bgcolor = CUCUL_COLOR_BLACK;
cv->fgcolor = CUCUL_COLOR_LIGHTGRAY;
cv->bgcolor = CUCUL_COLOR_BLACK;


c->width = c->height = 0;
c->chars = NULL;
c->attr = NULL;
c->empty_line = c->scratch_line = NULL;
cv->width = cv->height = 0;
cv->chars = NULL;
cv->attr = NULL;
cv->empty_line = cv->scratch_line = NULL;


/* Initialise to a default size. 80x32 is arbitrary but matches AAlib's /* Initialise to a default size. 80x32 is arbitrary but matches AAlib's
* default X11 window. When a graphic driver attaches to us, it can set * default X11 window. When a graphic driver attaches to us, it can set
* a different size. */ * a different size. */
if(width && height) if(width && height)
_cucul_set_size(c, width, height);
_cucul_set_size(cv, width, height);
else else
_cucul_set_size(c, 80, 32);
_cucul_set_size(cv, 80, 32);


if(_cucul_init_dither()) if(_cucul_init_dither())
{ {
free(c);
free(cv);
return NULL; return NULL;
} }


return c;
return cv;
} }


/** \brief Load a memory area into a canvas. /** \brief Load a memory area into a canvas.
@@ -83,7 +83,7 @@ cucul_canvas_t * cucul_create(unsigned int width, unsigned int height)
*/ */
cucul_canvas_t *cucul_load(void *data, unsigned int size) cucul_canvas_t *cucul_load(void *data, unsigned int size)
{ {
cucul_canvas_t *c;
cucul_canvas_t *cv;
uint8_t *buf = (uint8_t *)data; uint8_t *buf = (uint8_t *)data;
unsigned int width, height, n; unsigned int width, height, n;


@@ -108,24 +108,24 @@ cucul_canvas_t *cucul_load(void *data, unsigned int size)
|| buf[size - 2] != 'A' || buf[size - 1] != 'C') || buf[size - 2] != 'A' || buf[size - 1] != 'C')
return NULL; return NULL;


c = cucul_create(width, height);
cv = cucul_create(width, height);


if(!c)
if(!cv)
return NULL; return NULL;


for(n = height * width; n--; ) for(n = height * width; n--; )
{ {
c->chars[n] = ((uint32_t)buf[12 + 8 * n] << 24)
cv->chars[n] = ((uint32_t)buf[12 + 8 * n] << 24)
| ((uint32_t)buf[13 + 8 * n] << 16) | ((uint32_t)buf[13 + 8 * n] << 16)
| ((uint32_t)buf[14 + 8 * n] << 8) | ((uint32_t)buf[14 + 8 * n] << 8)
| (uint32_t)buf[15 + 8 * n]; | (uint32_t)buf[15 + 8 * n];
c->attr[n] = ((uint32_t)buf[16 + 8 * n] << 24)
cv->attr[n] = ((uint32_t)buf[16 + 8 * n] << 24)
| ((uint32_t)buf[17 + 8 * n] << 16) | ((uint32_t)buf[17 + 8 * n] << 16)
| ((uint32_t)buf[18 + 8 * n] << 8) | ((uint32_t)buf[18 + 8 * n] << 8)
| (uint32_t)buf[19 + 8 * n]; | (uint32_t)buf[19 + 8 * n];
} }


return c;
return cv;
} }


/** \brief Resize a canvas. /** \brief Resize a canvas.
@@ -143,40 +143,40 @@ cucul_canvas_t *cucul_load(void *data, unsigned int size)
* resize through user interaction. See the caca_event() documentation * resize through user interaction. See the caca_event() documentation
* for more about this. * for more about this.
* *
* \param c A libcucul canvas
* \param cv A libcucul canvas
* \param width The desired canvas width * \param width The desired canvas width
* \param height The desired canvas height * \param height The desired canvas height
*/ */
void cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height)
void cucul_set_size(cucul_canvas_t *cv, unsigned int width, unsigned int height)
{ {
if(c->refcount)
if(cv->refcount)
return; return;


_cucul_set_size(c, width, height);
_cucul_set_size(cv, width, height);
} }


/** \brief Get the canvas width. /** \brief Get the canvas width.
* *
* This function returns the current canvas width, in character cells. * This function returns the current canvas width, in character cells.
* *
* \param c A libcucul canvas
* \param cv A libcucul canvas
* \return The canvas width. * \return The canvas width.
*/ */
unsigned int cucul_get_width(cucul_canvas_t *c)
unsigned int cucul_get_width(cucul_canvas_t *cv)
{ {
return c->width;
return cv->width;
} }


/** \brief Get the canvas height. /** \brief Get the canvas height.
* *
* This function returns the current canvas height, in character cells. * This function returns the current canvas height, in character cells.
* *
* \param c A libcucul canvas
* \param cv A libcucul canvas
* \return The canvas height. * \return The canvas height.
*/ */
unsigned int cucul_get_height(cucul_canvas_t *c)
unsigned int cucul_get_height(cucul_canvas_t *cv)
{ {
return c->height;
return cv->height;
} }


/** \brief Translate a colour index into the colour's name. /** \brief Translate a colour index into the colour's name.
@@ -221,19 +221,19 @@ char const *cucul_get_color_name(unsigned int color)
* cucul_free() has been called, no other \e libcucul functions may be used * cucul_free() has been called, no other \e libcucul functions may be used
* unless a new call to cucul_create() is done. * unless a new call to cucul_create() is done.
* *
* \param c A libcucul canvas
* \param cv A libcucul canvas
*/ */
void cucul_free(cucul_canvas_t *c)
void cucul_free(cucul_canvas_t *cv)
{ {
_cucul_end_dither(); _cucul_end_dither();


free(c->empty_line);
free(c->scratch_line);
free(cv->empty_line);
free(cv->scratch_line);


free(c->chars);
free(c->attr);
free(cv->chars);
free(cv->attr);


free(c);
free(cv);
} }


/** \brief Generate a random integer within a range. /** \brief Generate a random integer within a range.
@@ -290,23 +290,24 @@ void cucul_free_buffer(cucul_buffer_t *buf)
* XXX: The following functions are local. * XXX: The following functions are local.
*/ */


void _cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height)
void _cucul_set_size(cucul_canvas_t *cv, unsigned int width,
unsigned int height)
{ {
unsigned int x, y, old_width, old_height, new_size, old_size; unsigned int x, y, old_width, old_height, new_size, old_size;


old_width = c->width;
old_height = c->height;
old_width = cv->width;
old_height = cv->height;
old_size = old_width * old_height; old_size = old_width * old_height;


c->width = width;
c->height = height;
cv->width = width;
cv->height = height;
new_size = width * height; new_size = width * height;


/* Step 1: if new area is bigger, resize the memory area now. */ /* Step 1: if new area is bigger, resize the memory area now. */
if(new_size > old_size) if(new_size > old_size)
{ {
c->chars = realloc(c->chars, new_size * sizeof(uint32_t));
c->attr = realloc(c->attr, new_size * sizeof(uint32_t));
cv->chars = realloc(cv->chars, new_size * sizeof(uint32_t));
cv->attr = realloc(cv->attr, new_size * sizeof(uint32_t));
} }


/* Step 2: move line data if necessary. */ /* Step 2: move line data if necessary. */
@@ -324,14 +325,14 @@ void _cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height)
{ {
for(x = old_width; x--; ) for(x = old_width; x--; )
{ {
c->chars[y * width + x] = c->chars[y * old_width + x];
c->attr[y * width + x] = c->attr[y * old_width + x];
cv->chars[y * width + x] = cv->chars[y * old_width + x];
cv->attr[y * width + x] = cv->attr[y * old_width + x];
} }


/* Zero the end of the line */ /* Zero the end of the line */
for(x = width - old_width; x--; ) for(x = width - old_width; x--; )
c->chars[y * width + old_width + x] = (uint32_t)' ';
memset(c->attr + y * width + old_width, 0,
cv->chars[y * width + old_width + x] = (uint32_t)' ';
memset(cv->attr + y * width + old_width, 0,
(width - old_width) * 4); (width - old_width) * 4);
} }
} }
@@ -345,8 +346,8 @@ void _cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height)
{ {
for(x = 0; x < width; x++) for(x = 0; x < width; x++)
{ {
c->chars[y * width + x] = c->chars[y * old_width + x];
c->attr[y * width + x] = c->attr[y * old_width + x];
cv->chars[y * width + x] = cv->chars[y * old_width + x];
cv->attr[y * width + x] = cv->attr[y * old_width + x];
} }
} }
} }
@@ -356,26 +357,26 @@ void _cucul_set_size(cucul_canvas_t *c, unsigned int width, unsigned int height)
{ {
/* Zero the bottom of the screen */ /* Zero the bottom of the screen */
for(x = (height - old_height) * width; x--; ) for(x = (height - old_height) * width; x--; )
c->chars[old_height * width + x] = (uint32_t)' ';
memset(c->attr + old_height * width, 0,
cv->chars[old_height * width + x] = (uint32_t)' ';
memset(cv->attr + old_height * width, 0,
(height - old_height) * width * 4); (height - old_height) * width * 4);
} }


/* Step 4: if new area is smaller, resize memory area now. */ /* Step 4: if new area is smaller, resize memory area now. */
if(new_size <= old_size) if(new_size <= old_size)
{ {
c->chars = realloc(c->chars, new_size * sizeof(uint32_t));
c->attr = realloc(c->attr, new_size * sizeof(uint32_t));
cv->chars = realloc(cv->chars, new_size * sizeof(uint32_t));
cv->attr = realloc(cv->attr, new_size * sizeof(uint32_t));
} }


/* Recompute the scratch line and the empty line */ /* Recompute the scratch line and the empty line */
if(width != old_width) if(width != old_width)
{ {
c->empty_line = realloc(c->empty_line, width + 1);
memset(c->empty_line, ' ', width);
c->empty_line[width] = '\0';
cv->empty_line = realloc(cv->empty_line, width + 1);
memset(cv->empty_line, ' ', width);
cv->empty_line[width] = '\0';


c->scratch_line = realloc(c->scratch_line, width + 1);
cv->scratch_line = realloc(cv->scratch_line, width + 1);
} }
} }



+ 7
- 7
cucul/dither.c View File

@@ -693,7 +693,7 @@ char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
* Dither a bitmap at the given coordinates. The dither can be of any size * Dither a bitmap at the given coordinates. The dither can be of any size
* and will be stretched to the text area. * and will be stretched to the text area.
* *
* \param c A handle to the libcucul canvas.
* \param cv A handle to the libcucul canvas.
* \param x1 X coordinate of the upper-left corner of the drawing area. * \param x1 X coordinate of the upper-left corner of the drawing area.
* \param y1 Y coordinate of the upper-left corner of the drawing area. * \param y1 Y coordinate of the upper-left corner of the drawing area.
* \param x2 X coordinate of the lower-right corner of the drawing area. * \param x2 X coordinate of the lower-right corner of the drawing area.
@@ -701,7 +701,7 @@ char const * const * cucul_get_dither_mode_list(cucul_dither_t const *d)
* \param d Dither object to be drawn. * \param d Dither object to be drawn.
* \param pixels Bitmap's pixels. * \param pixels Bitmap's pixels.
*/ */
void cucul_dither_bitmap(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
void cucul_dither_bitmap(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
cucul_dither_t const *d, void *pixels) cucul_dither_t const *d, void *pixels)
{ {
int *floyd_steinberg, *fs_r, *fs_g, *fs_b; int *floyd_steinberg, *fs_r, *fs_g, *fs_b;
@@ -730,19 +730,19 @@ void cucul_dither_bitmap(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
deltay = y2 - y1 + 1; deltay = y2 - y1 + 1;
dchmax = d->glyph_count; dchmax = d->glyph_count;


fs_length = ((int)c->width <= x2 ? (int)c->width : x2) + 1;
fs_length = ((int)cv->width <= x2 ? (int)cv->width : x2) + 1;
floyd_steinberg = malloc(3 * (fs_length + 2) * sizeof(int)); floyd_steinberg = malloc(3 * (fs_length + 2) * sizeof(int));
memset(floyd_steinberg, 0, 3 * (fs_length + 2) * sizeof(int)); memset(floyd_steinberg, 0, 3 * (fs_length + 2) * sizeof(int));
fs_r = floyd_steinberg + 1; fs_r = floyd_steinberg + 1;
fs_g = fs_r + fs_length + 2; fs_g = fs_r + fs_length + 2;
fs_b = fs_g + fs_length + 2; fs_b = fs_g + fs_length + 2;


for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)c->height; y++)
for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)cv->height; y++)
{ {
int remain_r = 0, remain_g = 0, remain_b = 0; int remain_r = 0, remain_g = 0, remain_b = 0;


for(x = x1 > 0 ? x1 : 0, d->init_dither(y); for(x = x1 > 0 ? x1 : 0, d->init_dither(y);
x <= x2 && x <= (int)c->width;
x <= x2 && x <= (int)cv->width;
x++) x++)
{ {
unsigned int i; unsigned int i;
@@ -936,8 +936,8 @@ void cucul_dither_bitmap(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
} }


/* Now output the character */ /* Now output the character */
cucul_set_color(c, outfg, outbg);
cucul_putstr(c, x, y, outch);
cucul_set_color(cv, outfg, outbg);
cucul_putstr(cv, x, y, outch);


d->increment_dither(); d->increment_dither();
} }


+ 62
- 62
cucul/export.c View File

@@ -59,10 +59,10 @@ static void export_tga(cucul_canvas_t *, cucul_buffer_t *);
* *
* \li \e "tga": export a TGA image. * \li \e "tga": export a TGA image.
* *
* \param c A libcucul canvas
* \param cv A libcucul canvas
* \param format A string describing the requested output format. * \param format A string describing the requested output format.
*/ */
cucul_buffer_t * cucul_create_export(cucul_canvas_t *c, char const *format)
cucul_buffer_t * cucul_create_export(cucul_canvas_t *cv, char const *format)
{ {
cucul_buffer_t *ex; cucul_buffer_t *ex;


@@ -71,19 +71,19 @@ cucul_buffer_t * cucul_create_export(cucul_canvas_t *c, char const *format)
ex->data = NULL; ex->data = NULL;


if(!strcasecmp("ansi", format)) if(!strcasecmp("ansi", format))
export_ansi(c, ex);
export_ansi(cv, ex);
else if(!strcasecmp("html", format)) else if(!strcasecmp("html", format))
export_html(c, ex);
export_html(cv, ex);
else if(!strcasecmp("html3", format)) else if(!strcasecmp("html3", format))
export_html3(c, ex);
export_html3(cv, ex);
else if(!strcasecmp("irc", format)) else if(!strcasecmp("irc", format))
export_irc(c, ex);
export_irc(cv, ex);
else if(!strcasecmp("ps", format)) else if(!strcasecmp("ps", format))
export_ps(c, ex);
export_ps(cv, ex);
else if(!strcasecmp("svg", format)) else if(!strcasecmp("svg", format))
export_svg(c, ex);
export_svg(cv, ex);
else if(!strcasecmp("tga", format)) else if(!strcasecmp("tga", format))
export_tga(c, ex);
export_tga(cv, ex);


if(ex->size == 0) if(ex->size == 0)
{ {
@@ -125,7 +125,7 @@ char const * const * cucul_get_export_list(void)
*/ */


/* Generate ANSI representation of current canvas. */ /* Generate ANSI representation of current canvas. */
static void export_ansi(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_ansi(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
static uint8_t const palette[] = static uint8_t const palette[] =
{ {
@@ -139,20 +139,20 @@ static void export_ansi(cucul_canvas_t *c, cucul_buffer_t *ex)
/* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus /* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus
* 4 max bytes for a UTF-8 character). * 4 max bytes for a UTF-8 character).
* Add height*9 to that (zeroes color at the end and jump to next line) */ * Add height*9 to that (zeroes color at the end and jump to next line) */
ex->size = (c->height * 9) + (c->width * c->height * 23);
ex->size = (cv->height * 9) + (cv->width * cv->height * 23);
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


cur = ex->data; cur = ex->data;


for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *linechar = c->chars + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;
uint32_t *linechar = cv->chars + y * cv->width;


uint8_t prevfg = -1; uint8_t prevfg = -1;
uint8_t prevbg = -1; uint8_t prevbg = -1;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])]; uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])];
uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])]; uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])];
@@ -192,7 +192,7 @@ static void export_ansi(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Generate HTML representation of current canvas. */ /* Generate HTML representation of current canvas. */
static void export_html(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_html(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
char *cur; char *cur;
unsigned int x, y, len; unsigned int x, y, len;
@@ -202,7 +202,7 @@ static void export_html(cucul_canvas_t *c, cucul_buffer_t *ex)
* A glyph: 47 chars for "<span style="color:#xxx;background-color:#xxx">" * A glyph: 47 chars for "<span style="color:#xxx;background-color:#xxx">"
* up to 9 chars for "&#xxxxxx;", far less for pure ASCII * up to 9 chars for "&#xxxxxx;", far less for pure ASCII
* 7 chars for "</span>" */ * 7 chars for "</span>" */
ex->size = 1000 + c->height * (7 + c->width * (47 + 9 + 7));
ex->size = 1000 + cv->height * (7 + cv->width * (47 + 9 + 7));
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


cur = ex->data; cur = ex->data;
@@ -215,12 +215,12 @@ static void export_html(cucul_canvas_t *c, cucul_buffer_t *ex)
cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n", cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
"font-family: monospace, fixed; font-weight: bold;"); "font-family: monospace, fixed; font-weight: bold;");


for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *linechar = c->chars + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;
uint32_t *linechar = cv->chars + y * cv->width;


for(x = 0; x < c->width; x += len)
for(x = 0; x < cv->width; x += len)
{ {
cur += sprintf(cur, "<span style=\"color:#%.03x;" cur += sprintf(cur, "<span style=\"color:#%.03x;"
"background-color:#%.03x\">", "background-color:#%.03x\">",
@@ -228,7 +228,7 @@ static void export_html(cucul_canvas_t *c, cucul_buffer_t *ex)
_cucul_argb32_to_rgb12bg(lineattr[x])); _cucul_argb32_to_rgb12bg(lineattr[x]));


for(len = 0; for(len = 0;
x + len < c->width && lineattr[x + len] == lineattr[x];
x + len < cv->width && lineattr[x + len] == lineattr[x];
len++) len++)
{ {
if(linechar[x + len] <= 0x00000020) if(linechar[x + len] <= 0x00000020)
@@ -255,7 +255,7 @@ static void export_html(cucul_canvas_t *c, cucul_buffer_t *ex)
* but permits viewing in old browsers (or limited ones such as links). It * but permits viewing in old browsers (or limited ones such as links). It
* will not work under gecko (mozilla rendering engine) unless you set a * will not work under gecko (mozilla rendering engine) unless you set a
* correct header. */ * correct header. */
static void export_html3(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_html3(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
char *cur; char *cur;
unsigned int x, y, len; unsigned int x, y, len;
@@ -265,30 +265,30 @@ static void export_html3(cucul_canvas_t *c, cucul_buffer_t *ex)
* A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>" * A glyph: 40 chars for "<td bgcolor=#xxxxxx><font color=#xxxxxx>"
* up to 9 chars for "&#xxxxxx;", far less for pure ASCII * up to 9 chars for "&#xxxxxx;", far less for pure ASCII
* 12 chars for "</font></td>" */ * 12 chars for "</font></td>" */
ex->size = 1000 + c->height * (10 + c->width * (40 + 9 + 12));
ex->size = 1000 + cv->height * (10 + cv->width * (40 + 9 + 12));
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


cur = ex->data; cur = ex->data;


/* Table */ /* Table */
cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n", cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n",
c->height);
cv->height);


for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *linechar = c->chars + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;
uint32_t *linechar = cv->chars + y * cv->width;


cur += sprintf(cur, "<tr>"); cur += sprintf(cur, "<tr>");


for(x = 0; x < c->width; x += len)
for(x = 0; x < cv->width; x += len)
{ {
unsigned int i; unsigned int i;


/* Use colspan option to factor cells with same attributes /* Use colspan option to factor cells with same attributes
* (see below) */ * (see below) */
len = 1; len = 1;
while(x + len < c->width && lineattr[x + len] == lineattr[x])
while(x + len < cv->width && lineattr[x + len] == lineattr[x])
len++; len++;


cur += sprintf(cur, "<td bgcolor=#%.06x", cur += sprintf(cur, "<td bgcolor=#%.06x",
@@ -324,7 +324,7 @@ static void export_html3(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Export a text file with IRC colours */ /* Export a text file with IRC colours */
static void export_irc(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_irc(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
static uint8_t const palette[] = static uint8_t const palette[] =
{ {
@@ -338,25 +338,25 @@ static void export_irc(cucul_canvas_t *c, cucul_buffer_t *ex)
/* 11 bytes assumed for max length per pixel. Worst case scenario: /* 11 bytes assumed for max length per pixel. Worst case scenario:
* ^Cxx,yy 6 bytes * ^Cxx,yy 6 bytes
* ^B^B 2 bytes * ^B^B 2 bytes
* c 1 byte
* ch 1 byte
* \r\n 2 bytes * \r\n 2 bytes
* In real life, the average bytes per pixel value will be around 5. * In real life, the average bytes per pixel value will be around 5.
*/ */


ex->size = 2 + (c->width * c->height * 11);
ex->size = 2 + (cv->width * cv->height * 11);
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


cur = ex->data; cur = ex->data;


for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *linechar = c->chars + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;
uint32_t *linechar = cv->chars + y * cv->width;


uint8_t prevfg = -1; uint8_t prevfg = -1;
uint8_t prevbg = -1; uint8_t prevbg = -1;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])]; uint8_t fg = palette[_cucul_argb32_to_ansi4fg(lineattr[x])];
uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])]; uint8_t bg = palette[_cucul_argb32_to_ansi4bg(lineattr[x])];
@@ -399,7 +399,7 @@ static void export_irc(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Export a PostScript document. */ /* Export a PostScript document. */
static void export_ps(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_ps(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
static char const *ps_header = static char const *ps_header =
"%!\n" "%!\n"
@@ -430,7 +430,7 @@ static void export_ps(cucul_canvas_t *c, cucul_buffer_t *ex)
unsigned int x, y; unsigned int x, y;


/* 200 is arbitrary but should be ok */ /* 200 is arbitrary but should be ok */
ex->size = strlen(ps_header) + (c->width * c->height * 200);
ex->size = strlen(ps_header) + (cv->width * cv->height * 200);
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


cur = ex->data; cur = ex->data;
@@ -439,11 +439,11 @@ static void export_ps(cucul_canvas_t *c, cucul_buffer_t *ex)
cur += sprintf(cur, "%s", ps_header); cur += sprintf(cur, "%s", ps_header);


/* Background, drawn using csquare macro defined in header */ /* Background, drawn using csquare macro defined in header */
for(y = c->height; y--; )
for(y = cv->height; y--; )
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
uint8_t argb[8]; uint8_t argb[8];
_cucul_argb32_to_argb4(*lineattr++, argb); _cucul_argb32_to_argb4(*lineattr++, argb);
@@ -454,17 +454,17 @@ static void export_ps(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Return to beginning of the line, and jump to the next one */ /* Return to beginning of the line, and jump to the next one */
cur += sprintf(cur, "-%d 1 translate\n", c->width);
cur += sprintf(cur, "-%d 1 translate\n", cv->width);
} }


cur += sprintf(cur, "grestore\n"); /* Restore transformation matrix */ cur += sprintf(cur, "grestore\n"); /* Restore transformation matrix */


for(y = c->height; y--; )
for(y = cv->height; y--; )
{ {
uint32_t *lineattr = c->attr + (c->height - y - 1) * c->width;
uint32_t *linechar = c->chars + (c->height - y - 1) * c->width;
uint32_t *lineattr = cv->attr + (cv->height - y - 1) * cv->width;
uint32_t *linechar = cv->chars + (cv->height - y - 1) * cv->width;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
uint8_t argb[8]; uint8_t argb[8];
uint32_t ch = *linechar++; uint32_t ch = *linechar++;
@@ -504,7 +504,7 @@ static void export_ps(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Export an SVG vector image */ /* Export an SVG vector image */
static void export_svg(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_svg(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
static char const svg_header[] = static char const svg_header[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -517,23 +517,23 @@ static void export_svg(cucul_canvas_t *c, cucul_buffer_t *ex)
unsigned int x, y; unsigned int x, y;


/* 200 is arbitrary but should be ok */ /* 200 is arbitrary but should be ok */
ex->size = strlen(svg_header) + (c->width * c->height * 200);
ex->size = strlen(svg_header) + (cv->width * cv->height * 200);
ex->data = malloc(ex->size); ex->data = malloc(ex->size);


cur = ex->data; cur = ex->data;


/* Header */ /* Header */
cur += sprintf(cur, svg_header, c->width * 6, c->height * 10,
c->width * 6, c->height * 10);
cur += sprintf(cur, svg_header, cv->width * 6, cv->height * 10,
cv->width * 6, cv->height * 10);


cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"12\">\n"); cur += sprintf(cur, " <g id=\"mainlayer\" font-size=\"12\">\n");


/* Background */ /* Background */
for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\"" cur += sprintf(cur, "<rect style=\"fill:#%.03x\" x=\"%d\" y=\"%d\""
" width=\"6\" height=\"10\"/>\n", " width=\"6\" height=\"10\"/>\n",
@@ -543,12 +543,12 @@ static void export_svg(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Text */ /* Text */
for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *lineattr = c->attr + y * c->width;
uint32_t *linechar = c->chars + y * c->width;
uint32_t *lineattr = cv->attr + y * cv->width;
uint32_t *linechar = cv->chars + y * cv->width;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
uint32_t ch = *linechar++; uint32_t ch = *linechar++;


@@ -601,7 +601,7 @@ static void export_svg(cucul_canvas_t *c, cucul_buffer_t *ex)
} }


/* Export a TGA image */ /* Export a TGA image */
static void export_tga(cucul_canvas_t *c, cucul_buffer_t *ex)
static void export_tga(cucul_canvas_t *cv, cucul_buffer_t *ex)
{ {
char const * const * fontlist; char const * const * fontlist;
char * cur; char * cur;
@@ -614,8 +614,8 @@ static void export_tga(cucul_canvas_t *c, cucul_buffer_t *ex)


f = cucul_load_font(fontlist[0], 0); f = cucul_load_font(fontlist[0], 0);


w = cucul_get_width(c) * cucul_get_font_width(f);
h = cucul_get_height(c) * cucul_get_font_height(f);
w = cucul_get_width(cv) * cucul_get_font_width(f);
h = cucul_get_height(cv) * cucul_get_font_height(f);


ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */ ex->size = w * h * 4 + 18; /* 32 bpp + 18 bytes for the header */
ex->data = malloc(ex->size); ex->data = malloc(ex->size);
@@ -643,7 +643,7 @@ static void export_tga(cucul_canvas_t *c, cucul_buffer_t *ex)
/* Color Map Data: no colormap */ /* Color Map Data: no colormap */


/* Image Data */ /* Image Data */
cucul_render_canvas(c, f, cur, w, h, 4 * w);
cucul_render_canvas(cv, f, cur, w, h, 4 * w);


/* Swap bytes. What a waste of time. */ /* Swap bytes. What a waste of time. */
for(i = 0; i < w * h * 4; i += 4) for(i = 0; i < w * h * 4; i += 4)


+ 10
- 10
cucul/font.c View File

@@ -259,21 +259,21 @@ void cucul_free_font(cucul_font_t *f)
* This function renders the given canvas on an image buffer using a specific * This function renders the given canvas on an image buffer using a specific
* font. The pixel format is fixed (32-bit ARGB, 8 bits for each component). * font. The pixel format is fixed (32-bit ARGB, 8 bits for each component).
* *
* The required image width can be computed using \e cucul_get_width(c) and
* The required image width can be computed using \e cucul_get_width(cv) and
* \e cucul_get_font_width(f). The required height can be computed using * \e cucul_get_font_width(f). The required height can be computed using
* \e cucul_get_height(c) and \e cucul_get_font_height(f).
* \e cucul_get_height(cv) and \e cucul_get_font_height(f).
* *
* Glyphs that do not fit in the image buffer are currently not rendered at * Glyphs that do not fit in the image buffer are currently not rendered at
* all. They may be cropped instead in future versions. * all. They may be cropped instead in future versions.
* *
* \param c The canvas to render
* \param cv The canvas to render
* \param f The font, as returned by \e cucul_load_font() * \param f The font, as returned by \e cucul_load_font()
* \param buf The image buffer * \param buf The image buffer
* \param width The width (in pixels) of the image buffer * \param width The width (in pixels) of the image buffer
* \param height The height (in pixels) of the image buffer * \param height The height (in pixels) of the image buffer
* \param pitch The pitch (in bytes) of an image buffer line. * \param pitch The pitch (in bytes) of an image buffer line.
*/ */
void cucul_render_canvas(cucul_canvas_t *c, cucul_font_t *f,
void cucul_render_canvas(cucul_canvas_t *cv, cucul_font_t *f,
void *buf, unsigned int width, void *buf, unsigned int width,
unsigned int height, unsigned int pitch) unsigned int height, unsigned int pitch)
{ {
@@ -283,15 +283,15 @@ void cucul_render_canvas(cucul_canvas_t *c, cucul_font_t *f,
if(f->header.bpp != 8) if(f->header.bpp != 8)
glyph = malloc(f->header.width * f->header.height); glyph = malloc(f->header.width * f->header.height);


if(width < c->width * f->header.width)
if(width < cv->width * f->header.width)
xmax = width / f->header.width; xmax = width / f->header.width;
else else
xmax = c->width;
xmax = cv->width;


if(height < c->height * f->header.height)
if(height < cv->height * f->header.height)
ymax = height / f->header.height; ymax = height / f->header.height;
else else
ymax = c->height;
ymax = cv->height;


for(y = 0; y < ymax; y++) for(y = 0; y < ymax; y++)
{ {
@@ -300,8 +300,8 @@ void cucul_render_canvas(cucul_canvas_t *c, cucul_font_t *f,
uint8_t argb[8]; uint8_t argb[8];
unsigned int starty = y * f->header.height; unsigned int starty = y * f->header.height;
unsigned int startx = x * f->header.width; unsigned int startx = x * f->header.width;
uint32_t ch = c->chars[y * c->width + x];
uint32_t attr = c->attr[y * c->width + x];
uint32_t ch = cv->chars[y * cv->width + x];
uint32_t attr = cv->attr[y * cv->width + x];
unsigned int b, i, j; unsigned int b, i, j;
struct glyph_info *g; struct glyph_info *g;




+ 35
- 34
cucul/line.c View File

@@ -42,7 +42,7 @@ static void draw_thin_line(cucul_canvas_t*, struct line*);


/** \brief Draw a line on the canvas using the given character. /** \brief Draw a line on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -50,7 +50,7 @@ static void draw_thin_line(cucul_canvas_t*, struct line*);
* \param str UTF-8 string containing the character to use to draw the line. * \param str UTF-8 string containing the character to use to draw the line.
* \return void * \return void
*/ */
void cucul_draw_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
void cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
char const *str) char const *str)
{ {
struct line s; struct line s;
@@ -60,7 +60,7 @@ void cucul_draw_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
s.y2 = y2; s.y2 = y2;
s.ch = _cucul_utf8_to_utf32(str); s.ch = _cucul_utf8_to_utf32(str);
s.draw = draw_solid_line; s.draw = draw_solid_line;
clip_line(c, &s);
clip_line(cv, &s);
} }


/** \brief Draw a polyline. /** \brief Draw a polyline.
@@ -70,15 +70,15 @@ void cucul_draw_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
* draw a polygon you need to specify the starting point at the end of the * draw a polygon you need to specify the starting point at the end of the
* list as well. * list as well.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x Array of X coordinates. Must have \p n + 1 elements. * \param x Array of X coordinates. Must have \p n + 1 elements.
* \param y Array of Y coordinates. Must have \p n + 1 elements. * \param y Array of Y coordinates. Must have \p n + 1 elements.
* \param n Number of lines to draw. * \param n Number of lines to draw.
* \param str UTF-8 string containing the character to use to draw the lines. * \param str UTF-8 string containing the character to use to draw the lines.
* \return void * \return void
*/ */
void cucul_draw_polyline(cucul_canvas_t *c, int const x[], int const y[], int n,
char const *str)
void cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[],
int n, char const *str)
{ {
int i; int i;
struct line s; struct line s;
@@ -91,20 +91,20 @@ void cucul_draw_polyline(cucul_canvas_t *c, int const x[], int const y[], int n,
s.y1 = y[i]; s.y1 = y[i];
s.x2 = x[i+1]; s.x2 = x[i+1];
s.y2 = y[i+1]; s.y2 = y[i+1];
clip_line(c, &s);
clip_line(cv, &s);
} }
} }


/** \brief Draw a thin line on the canvas, using ASCII art. /** \brief Draw a thin line on the canvas, using ASCII art.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
* \param y2 Y coordinate of the second point. * \param y2 Y coordinate of the second point.
* \return void * \return void
*/ */
void cucul_draw_thin_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
void cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
{ {
struct line s; struct line s;
s.x1 = x1; s.x1 = x1;
@@ -112,7 +112,7 @@ void cucul_draw_thin_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
s.x2 = x2; s.x2 = x2;
s.y2 = y2; s.y2 = y2;
s.draw = draw_thin_line; s.draw = draw_thin_line;
clip_line(c, &s);
clip_line(cv, &s);
} }


/** \brief Draw an ASCII art thin polyline. /** \brief Draw an ASCII art thin polyline.
@@ -122,13 +122,14 @@ void cucul_draw_thin_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
* to draw a polygon you need to specify the starting point at the end of * to draw a polygon you need to specify the starting point at the end of
* the list as well. * the list as well.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x Array of X coordinates. Must have \p n + 1 elements. * \param x Array of X coordinates. Must have \p n + 1 elements.
* \param y Array of Y coordinates. Must have \p n + 1 elements. * \param y Array of Y coordinates. Must have \p n + 1 elements.
* \param n Number of lines to draw. * \param n Number of lines to draw.
* \return void * \return void
*/ */
void cucul_draw_thin_polyline(cucul_canvas_t *c, int const x[], int const y[], int n)
void cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[],
int n)
{ {
int i; int i;
struct line s; struct line s;
@@ -140,7 +141,7 @@ void cucul_draw_thin_polyline(cucul_canvas_t *c, int const x[], int const y[], i
s.y1 = y[i]; s.y1 = y[i];
s.x2 = x[i+1]; s.x2 = x[i+1];
s.y2 = y[i+1]; s.y2 = y[i+1];
clip_line(c, &s);
clip_line(cv, &s);
} }
} }


@@ -149,12 +150,12 @@ void cucul_draw_thin_polyline(cucul_canvas_t *c, int const x[], int const y[], i
*/ */


/* Generic Cohen-Sutherland line clipping function. */ /* Generic Cohen-Sutherland line clipping function. */
static void clip_line(cucul_canvas_t *c, struct line* s)
static void clip_line(cucul_canvas_t *cv, struct line* s)
{ {
uint8_t bits1, bits2; uint8_t bits1, bits2;


bits1 = clip_bits(c, s->x1, s->y1);
bits2 = clip_bits(c, s->x2, s->y2);
bits1 = clip_bits(cv, s->x1, s->y1);
bits2 = clip_bits(cv, s->x2, s->y2);


if(bits1 & bits2) if(bits1 & bits2)
return; return;
@@ -162,13 +163,13 @@ static void clip_line(cucul_canvas_t *c, struct line* s)
if(bits1 == 0) if(bits1 == 0)
{ {
if(bits2 == 0) if(bits2 == 0)
s->draw(c, s);
s->draw(cv, s);
else else
{ {
int tmp; int tmp;
tmp = s->x1; s->x1 = s->x2; s->x2 = tmp; tmp = s->x1; s->x1 = s->x2; s->x2 = tmp;
tmp = s->y1; s->y1 = s->y2; s->y2 = tmp; tmp = s->y1; s->y1 = s->y2; s->y2 = tmp;
clip_line(c, s);
clip_line(cv, s);
} }


return; return;
@@ -181,7 +182,7 @@ static void clip_line(cucul_canvas_t *c, struct line* s)
} }
else if(bits1 & (1<<1)) else if(bits1 & (1<<1))
{ {
int xmax = c->width - 1;
int xmax = cv->width - 1;
s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1); s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1);
s->x1 = xmax; s->x1 = xmax;
} }
@@ -192,27 +193,27 @@ static void clip_line(cucul_canvas_t *c, struct line* s)
} }
else if(bits1 & (1<<3)) else if(bits1 & (1<<3))
{ {
int ymax = c->height - 1;
int ymax = cv->height - 1;
s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1); s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1);
s->y1 = ymax; s->y1 = ymax;
} }


clip_line(c, s);
clip_line(cv, s);
} }


/* Helper function for clip_line(). */ /* Helper function for clip_line(). */
static uint8_t clip_bits(cucul_canvas_t *c, int x, int y)
static uint8_t clip_bits(cucul_canvas_t *cv, int x, int y)
{ {
uint8_t b = 0; uint8_t b = 0;


if(x < 0) if(x < 0)
b |= (1<<0); b |= (1<<0);
else if(x >= (int)c->width)
else if(x >= (int)cv->width)
b |= (1<<1); b |= (1<<1);


if(y < 0) if(y < 0)
b |= (1<<2); b |= (1<<2);
else if(y >= (int)c->height)
else if(y >= (int)cv->height)
b |= (1<<3); b |= (1<<3);


return b; return b;
@@ -220,7 +221,7 @@ static uint8_t clip_bits(cucul_canvas_t *c, int x, int y)


/* Solid line drawing function, using Bresenham's mid-point line /* Solid line drawing function, using Bresenham's mid-point line
* scan-conversion algorithm. */ * scan-conversion algorithm. */
static void draw_solid_line(cucul_canvas_t *c, struct line* s)
static void draw_solid_line(cucul_canvas_t *cv, struct line* s)
{ {
int x1, y1, x2, y2; int x1, y1, x2, y2;
int dx, dy; int dx, dy;
@@ -242,7 +243,7 @@ static void draw_solid_line(cucul_canvas_t *c, struct line* s)


for(; dx>=0; dx--) for(; dx>=0; dx--)
{ {
_cucul_putchar32(c, x1, y1, s->ch);
_cucul_putchar32(cv, x1, y1, s->ch);
if(delta > 0) if(delta > 0)
{ {
x1 += xinc; x1 += xinc;
@@ -264,7 +265,7 @@ static void draw_solid_line(cucul_canvas_t *c, struct line* s)


for(; dy >= 0; dy--) for(; dy >= 0; dy--)
{ {
_cucul_putchar32(c, x1, y1, s->ch);
_cucul_putchar32(cv, x1, y1, s->ch);
if(delta > 0) if(delta > 0)
{ {
x1 += xinc; x1 += xinc;
@@ -282,7 +283,7 @@ static void draw_solid_line(cucul_canvas_t *c, struct line* s)


/* Thin line drawing function, using Bresenham's mid-point line /* Thin line drawing function, using Bresenham's mid-point line
* scan-conversion algorithm and ASCII art graphics. */ * scan-conversion algorithm and ASCII art graphics. */
static void draw_thin_line(cucul_canvas_t *c, struct line* s)
static void draw_thin_line(cucul_canvas_t *cv, struct line* s)
{ {
uint32_t charmapx[2], charmapy[2]; uint32_t charmapx[2], charmapy[2];
int x1, y1, x2, y2; int x1, y1, x2, y2;
@@ -329,7 +330,7 @@ static void draw_thin_line(cucul_canvas_t *c, struct line* s)
{ {
if(delta > 0) if(delta > 0)
{ {
_cucul_putchar32(c, x1, y1, charmapy[1]);
_cucul_putchar32(cv, x1, y1, charmapy[1]);
x1++; x1++;
y1 += yinc; y1 += yinc;
delta += dpru; delta += dpru;
@@ -338,9 +339,9 @@ static void draw_thin_line(cucul_canvas_t *c, struct line* s)
else else
{ {
if(prev) if(prev)
_cucul_putchar32(c, x1, y1, charmapy[0]);
_cucul_putchar32(cv, x1, y1, charmapy[0]);
else else
_cucul_putchar32(c, x1, y1, (uint32_t)'-');
_cucul_putchar32(cv, x1, y1, (uint32_t)'-');
x1++; x1++;
delta += dpr; delta += dpr;
prev = 0; prev = 0;
@@ -357,15 +358,15 @@ static void draw_thin_line(cucul_canvas_t *c, struct line* s)
{ {
if(delta > 0) if(delta > 0)
{ {
_cucul_putchar32(c, x1, y1, charmapx[0]);
_cucul_putchar32(c, x1 + 1, y1, charmapx[1]);
_cucul_putchar32(cv, x1, y1, charmapx[0]);
_cucul_putchar32(cv, x1 + 1, y1, charmapx[1]);
x1++; x1++;
y1 += yinc; y1 += yinc;
delta += dpru; delta += dpru;
} }
else else
{ {
_cucul_putchar32(c, x1, y1, (uint32_t)'|');
_cucul_putchar32(cv, x1, y1, (uint32_t)'|');
y1 += yinc; y1 += yinc;
delta += dpr; delta += dpr;
} }


+ 8
- 7
cucul/sprite.c View File

@@ -246,14 +246,15 @@ int cucul_get_sprite_dy(cucul_sprite_t const *sprite, int f)
/** \brief Draw a sprite's specific frame at the given coordinates. If the /** \brief Draw a sprite's specific frame at the given coordinates. If the
* frame does not exist, nothing is displayed. * frame does not exist, nothing is displayed.
* *
* \param c A libcucul canvas
* \param cv A libcucul canvas
* \param x The X coordinate. * \param x The X coordinate.
* \param y The Y coordinate. * \param y The Y coordinate.
* \param sprite The sprite. * \param sprite The sprite.
* \param f The frame index. * \param f The frame index.
* \return void * \return void
*/ */
void cucul_draw_sprite(cucul_canvas_t *c, int x, int y, cucul_sprite_t const *sprite, int f)
void cucul_draw_sprite(cucul_canvas_t *cv, int x, int y,
cucul_sprite_t const *sprite, int f)
{ {
int i, j; int i, j;
unsigned int oldfg, oldbg; unsigned int oldfg, oldbg;
@@ -267,8 +268,8 @@ void cucul_draw_sprite(cucul_canvas_t *c, int x, int y, cucul_sprite_t const *sp


frame = &sprite->frames[f]; frame = &sprite->frames[f];


oldfg = c->fgcolor;
oldbg = c->bgcolor;
oldfg = cv->fgcolor;
oldbg = cv->bgcolor;


for(j = 0; j < frame->h; j++) for(j = 0; j < frame->h; j++)
{ {
@@ -277,14 +278,14 @@ void cucul_draw_sprite(cucul_canvas_t *c, int x, int y, cucul_sprite_t const *sp
int col = frame->color[frame->w * j + i]; int col = frame->color[frame->w * j + i];
if(col >= 0) if(col >= 0)
{ {
cucul_set_color(c, col, CUCUL_COLOR_BLACK);
cucul_putchar(c, x + i - frame->dx, y + j - frame->dy,
cucul_set_color(cv, col, CUCUL_COLOR_BLACK);
cucul_putchar(cv, x + i - frame->dx, y + j - frame->dy,
frame->chars[frame->w * j + i]); frame->chars[frame->w * j + i]);
} }
} }
} }


cucul_set_color(c, oldfg, oldbg);
cucul_set_color(cv, oldfg, oldbg);
} }


/** \brief Free the memory associated with a sprite. /** \brief Free the memory associated with a sprite.


+ 26
- 26
cucul/transform.c View File

@@ -32,14 +32,14 @@ static uint32_t rotatechar(uint32_t ch);
* This function inverts a canvas' colours (black becomes white, red * This function inverts a canvas' colours (black becomes white, red
* becomes cyan, etc.) without changing the characters in it. * becomes cyan, etc.) without changing the characters in it.
* *
* \param c The canvas to invert.
* \param cv The canvas to invert.
*/ */
void cucul_invert(cucul_canvas_t *c)
void cucul_invert(cucul_canvas_t *cv)
{ {
uint32_t *attr = c->attr;
uint32_t *attr = cv->attr;
unsigned int i; unsigned int i;


for(i = c->height * c->width; i--; )
for(i = cv->height * cv->width; i--; )
{ {
*attr = *attr ^ 0x000f000f; *attr = *attr ^ 0x000f000f;
attr++; attr++;
@@ -51,18 +51,18 @@ void cucul_invert(cucul_canvas_t *c)
* This function flips a canvas horizontally, choosing characters that * This function flips a canvas horizontally, choosing characters that
* look like the mirrored version wherever possible. * look like the mirrored version wherever possible.
* *
* \param c The canvas to flip.
* \param cv The canvas to flip.
*/ */
void cucul_flip(cucul_canvas_t *c)
void cucul_flip(cucul_canvas_t *cv)
{ {
unsigned int y; unsigned int y;


for(y = 0; y < c->height; y++)
for(y = 0; y < cv->height; y++)
{ {
uint32_t *cleft = c->chars + y * c->width;
uint32_t *cright = cleft + c->width - 1;
uint32_t *aleft = c->attr + y * c->width;
uint32_t *aright = aleft + c->width - 1;
uint32_t *cleft = cv->chars + y * cv->width;
uint32_t *cright = cleft + cv->width - 1;
uint32_t *aleft = cv->attr + y * cv->width;
uint32_t *aright = aleft + cv->width - 1;


while(cleft < cright) while(cleft < cright)
{ {
@@ -88,18 +88,18 @@ void cucul_flip(cucul_canvas_t *c)
* This function flips a canvas vertically, choosing characters that * This function flips a canvas vertically, choosing characters that
* look like the mirrored version wherever possible. * look like the mirrored version wherever possible.
* *
* \param c The canvas to flop.
* \param cv The canvas to flop.
*/ */
void cucul_flop(cucul_canvas_t *c)
void cucul_flop(cucul_canvas_t *cv)
{ {
unsigned int x; unsigned int x;


for(x = 0; x < c->width; x++)
for(x = 0; x < cv->width; x++)
{ {
uint32_t *ctop = c->chars + x;
uint32_t *cbottom = ctop + c->width * (c->height - 1);
uint32_t *atop = c->attr + x;
uint32_t *abottom = atop + c->width * (c->height - 1);
uint32_t *ctop = cv->chars + x;
uint32_t *cbottom = ctop + cv->width * (cv->height - 1);
uint32_t *atop = cv->attr + x;
uint32_t *abottom = atop + cv->width * (cv->height - 1);


while(ctop < cbottom) while(ctop < cbottom)
{ {
@@ -112,8 +112,8 @@ void cucul_flop(cucul_canvas_t *c)
/* Swap characters */ /* Swap characters */
ch = *cbottom; *cbottom = flopchar(*ctop); *ctop = flopchar(ch); ch = *cbottom; *cbottom = flopchar(*ctop); *ctop = flopchar(ch);


ctop += c->width; cbottom -= c->width;
atop += c->width; abottom -= c->width;
ctop += cv->width; cbottom -= cv->width;
atop += cv->width; abottom -= cv->width;
} }


if(ctop == cbottom) if(ctop == cbottom)
@@ -127,14 +127,14 @@ void cucul_flop(cucul_canvas_t *c)
* choosing characters that look like the mirrored version wherever * choosing characters that look like the mirrored version wherever
* possible. * possible.
* *
* \param c The canvas to rotate.
* \param cv The canvas to rotate.
*/ */
void cucul_rotate(cucul_canvas_t *c)
void cucul_rotate(cucul_canvas_t *cv)
{ {
uint32_t *cbegin = c->chars;
uint32_t *cend = cbegin + c->width * c->height - 1;
uint32_t *abegin = c->attr;
uint32_t *aend = abegin + c->width * c->height - 1;
uint32_t *cbegin = cv->chars;
uint32_t *cend = cbegin + cv->width * cv->height - 1;
uint32_t *abegin = cv->attr;
uint32_t *aend = abegin + cv->width * cv->height - 1;


while(cbegin < cend) while(cbegin < cend)
{ {


+ 18
- 18
cucul/triangle.c View File

@@ -26,7 +26,7 @@


/** \brief Draw a triangle on the canvas using the given character. /** \brief Draw a triangle on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -37,17 +37,17 @@
* to draw the triangle outline. * to draw the triangle outline.
* \return void * \return void
*/ */
void cucul_draw_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
void cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
int x3, int y3, char const *str) int x3, int y3, char const *str)
{ {
cucul_draw_line(c, x1, y1, x2, y2, str);
cucul_draw_line(c, x2, y2, x3, y3, str);
cucul_draw_line(c, x3, y3, x1, y1, str);
cucul_draw_line(cv, x1, y1, x2, y2, str);
cucul_draw_line(cv, x2, y2, x3, y3, str);
cucul_draw_line(cv, x3, y3, x1, y1, str);
} }


/** \brief Draw a thin triangle on the canvas. /** \brief Draw a thin triangle on the canvas.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -56,17 +56,17 @@ void cucul_draw_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
* \param y3 Y coordinate of the third point. * \param y3 Y coordinate of the third point.
* \return void * \return void
*/ */
void cucul_draw_thin_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
int x3, int y3)
void cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1,
int x2, int y2, int x3, int y3)
{ {
cucul_draw_thin_line(c, x1, y1, x2, y2);
cucul_draw_thin_line(c, x2, y2, x3, y3);
cucul_draw_thin_line(c, x3, y3, x1, y1);
cucul_draw_thin_line(cv, x1, y1, x2, y2);
cucul_draw_thin_line(cv, x2, y2, x3, y3);
cucul_draw_thin_line(cv, x3, y3, x1, y1);
} }


/** \brief Fill a triangle on the canvas using the given character. /** \brief Fill a triangle on the canvas using the given character.
* *
* \param c The handle to the libcucul canvas.
* \param cv The handle to the libcucul canvas.
* \param x1 X coordinate of the first point. * \param x1 X coordinate of the first point.
* \param y1 Y coordinate of the first point. * \param y1 Y coordinate of the first point.
* \param x2 X coordinate of the second point. * \param x2 X coordinate of the second point.
@@ -77,7 +77,7 @@ void cucul_draw_thin_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
* to fill the triangle. * to fill the triangle.
* \return void * \return void
*/ */
void cucul_fill_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
void cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
int x3, int y3, char const *str) int x3, int y3, char const *str)
{ {
int x, y, xa, xb, xmax, ymax; int x, y, xa, xb, xmax, ymax;
@@ -86,13 +86,13 @@ void cucul_fill_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
/* Bubble-sort y1 <= y2 <= y3 */ /* Bubble-sort y1 <= y2 <= y3 */
if(y1 > y2) if(y1 > y2)
{ {
cucul_fill_triangle(c, x2, y2, x1, y1, x3, y3, str);
cucul_fill_triangle(cv, x2, y2, x1, y1, x3, y3, str);
return; return;
} }


if(y2 > y3) if(y2 > y3)
{ {
cucul_fill_triangle(c, x1, y1, x3, y3, x2, y2, str);
cucul_fill_triangle(cv, x1, y1, x3, y3, x2, y2, str);
return; return;
} }


@@ -101,8 +101,8 @@ void cucul_fill_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
x2 *= 4; x2 *= 4;
x3 *= 4; x3 *= 4;


xmax = c->width - 1;
ymax = c->height - 1;
xmax = cv->width - 1;
ymax = cv->height - 1;


ch = _cucul_utf8_to_utf32(str); ch = _cucul_utf8_to_utf32(str);


@@ -136,7 +136,7 @@ void cucul_fill_triangle(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
if(xb > xmax) xb = xmax; if(xb > xmax) xb = xmax;


for(x = xa; x <= xb; x++) for(x = xa; x <= xb; x++)
_cucul_putchar32(c, x, y, ch);
_cucul_putchar32(cv, x, y, ch);
} }
} }



+ 19
- 19
src/aafire.c View File

@@ -39,8 +39,8 @@
#endif #endif
#define MAXTABLE (256*5) #define MAXTABLE (256*5)
#ifdef LIBCACA #ifdef LIBCACA
static cucul_canvas_t *c;
static caca_t *kk;
static cucul_canvas_t *cv;
static caca_display_t *dp;
static int XSIZ, YSIZ; static int XSIZ, YSIZ;
static cucul_dither_t *cucul_dither; static cucul_dither_t *cucul_dither;
static char *bitmap; static char *bitmap;
@@ -100,21 +100,21 @@ initialize (void)
#endif #endif


#ifdef LIBCACA #ifdef LIBCACA
c = cucul_create(80, 32);
if (!c)
cv = cucul_create(80, 32);
if (!cv)
{ {
printf ("Failed to initialize libcucul\n"); printf ("Failed to initialize libcucul\n");
exit (1); exit (1);
} }
kk = caca_attach(c);
if (!kk)
dp = caca_attach(cv);
if (!dp)
{ {
printf ("Failed to initialize libcaca\n"); printf ("Failed to initialize libcaca\n");
exit (1); exit (1);
} }
caca_set_delay(kk, 10000);
XSIZ = cucul_get_width(c) * 2;
YSIZ = cucul_get_height(c) * 2 - 4;
caca_set_delay(dp, 10000);
XSIZ = cucul_get_width(cv) * 2;
YSIZ = cucul_get_height(cv) * 2 - 4;
#else #else
context = aa_autoinit (&aa_defparams); context = aa_autoinit (&aa_defparams);
if (context == NULL) if (context == NULL)
@@ -142,8 +142,8 @@ initialize (void)
#ifdef LIBCACA #ifdef LIBCACA
cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0); cucul_dither = cucul_create_dither(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
cucul_set_dither_palette(cucul_dither, r, g, b, a); cucul_set_dither_palette(cucul_dither, r, g, b, a);
bitmap = malloc(4 * cucul_get_width(c) * cucul_get_height(c) * sizeof(char));
memset(bitmap, 0, 4 * cucul_get_width(c) * cucul_get_height(c));
bitmap = malloc(4 * cucul_get_width(cv) * cucul_get_height(cv) * sizeof(char));
memset(bitmap, 0, 4 * cucul_get_width(cv) * cucul_get_height(cv));
#else #else
aa_hidecursor (context); aa_hidecursor (context);
#endif #endif
@@ -152,8 +152,8 @@ static void
uninitialize (void) uninitialize (void)
{ {
#ifdef LIBCACA #ifdef LIBCACA
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);
#else #else
aa_close (context); aa_close (context);
#endif #endif
@@ -235,14 +235,14 @@ drawfire (void)
firemain (); firemain ();
#ifdef LIBCACA #ifdef LIBCACA
paused: paused:
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_dither, bitmap); cucul_dither, bitmap);
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2,
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- "); " -=[ Powered by libcaca ]=- ");
caca_display(kk);
caca_display(dp);
/*XSIZ = caca_get_width() * 2; /*XSIZ = caca_get_width() * 2;
YSIZ = caca_get_height() * 2 - 4;*/ YSIZ = caca_get_height() * 2 - 4;*/
#else #else
@@ -266,7 +266,7 @@ game (void)
{ {
#ifdef LIBCACA #ifdef LIBCACA
caca_event_t ev; caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.ch) switch(ev.data.key.ch)
{ {


+ 17
- 17
src/cacaball.c View File

@@ -42,9 +42,9 @@ static unsigned char metaball[METASIZE * METASIZE];


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
cucul_canvas_t *c; caca_t *kk;
cucul_canvas_t *cv; caca_display_t *dp;
unsigned int r[256], g[256], b[256], a[256]; unsigned int r[256], g[256], b[256], a[256];
float d[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS];
float dd[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS];
unsigned int x[METABALLS], y[METABALLS]; unsigned int x[METABALLS], y[METABALLS];
cucul_dither_t *cucul_dither; cucul_dither_t *cucul_dither;
float i = 10.0, j = 17.0, k = 11.0; float i = 10.0, j = 17.0, k = 11.0;
@@ -53,14 +53,14 @@ int main(int argc, char **argv)
double frameOffset40[360]; double frameOffset40[360];
double frameOffset80[360]; double frameOffset80[360];


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;
kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


caca_set_delay(kk, 20000);
caca_set_delay(dp, 20000);


/* Make the palette eatable by libcaca */ /* Make the palette eatable by libcaca */
for(p = 0; p < 256; p++) for(p = 0; p < 256; p++)
@@ -77,7 +77,7 @@ int main(int argc, char **argv)


for(p = 0; p < METABALLS; p++) for(p = 0; p < METABALLS; p++)
{ {
d[p] = cucul_rand(0, 100);
dd[p] = cucul_rand(0, 100);
di[p] = (float)cucul_rand(500, 4000) / 6000.0; di[p] = (float)cucul_rand(500, 4000) / 6000.0;
dj[p] = (float)cucul_rand(500, 4000) / 6000.0; dj[p] = (float)cucul_rand(500, 4000) / 6000.0;
dk[p] = (float)cucul_rand(500, 4000) / 6000.0; dk[p] = (float)cucul_rand(500, 4000) / 6000.0;
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
for(;;) for(;;)
{ {
caca_event_t ev; caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.ch) switch(ev.data.key.ch)
{ {
@@ -133,7 +133,7 @@ int main(int argc, char **argv)
for(p = 0; p < METABALLS; p++) for(p = 0; p < METABALLS; p++)
{ {
float u = di[p] * i + dj[p] * j + dk[p] * sin(di[p] * k); float u = di[p] * i + dj[p] * j + dk[p] * sin(di[p] * k);
float v = d[p] + di[p] * j + dj[p] * k + dk[p] * sin(dk[p] * i);
float v = dd[p] + di[p] * j + dj[p] * k + dk[p] * sin(dk[p] * i);
u = sin(i + u * 2.1) * (1.0 + sin(u)); u = sin(i + u * 2.1) * (1.0 + sin(u));
v = sin(j + v * 1.9) * (1.0 + sin(v)); v = sin(j + v * 1.9) * (1.0 + sin(v));
x[p] = (XSIZ - METASIZE) / 2 + u * (XSIZ - METASIZE) / 4; x[p] = (XSIZ - METASIZE) / 2 + u * (XSIZ - METASIZE) / 4;
@@ -153,21 +153,21 @@ int main(int argc, char **argv)


paused: paused:
/* Draw our virtual buffer to screen, letting libcucul resize it */ /* Draw our virtual buffer to screen, letting libcucul resize it */
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ)); cucul_dither, pixels + (METASIZE / 2) * (1 + XSIZ));
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2,
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- "); " -=[ Powered by libcaca ]=- ");


caca_display(kk);
caca_display(dp);
} }


/* End, bye folks */ /* End, bye folks */
end: end:
cucul_free_dither(cucul_dither); cucul_free_dither(cucul_dither);
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 14
- 14
src/cacamoir.c View File

@@ -37,19 +37,19 @@ static void draw_line(int, int, char);


int main (int argc, char **argv) int main (int argc, char **argv)
{ {
cucul_canvas_t *c; caca_t *kk;
cucul_canvas_t *cv; caca_display_t *dp;
unsigned int red[256], green[256], blue[256], alpha[256]; unsigned int red[256], green[256], blue[256], alpha[256];
cucul_dither_t *dither; cucul_dither_t *dither;
int i, x, y, frame = 0, pause = 0; int i, x, y, frame = 0, pause = 0;


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;
kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


caca_set_delay(kk, 20000);
caca_set_delay(dp, 20000);


/* Fill various tables */ /* Fill various tables */
for(i = 0 ; i < 256; i++) for(i = 0 ; i < 256; i++)
@@ -69,7 +69,7 @@ int main (int argc, char **argv)
for(;;) for(;;)
{ {
caca_event_t ev; caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.ch) switch(ev.data.key.ch)
{ {
@@ -106,19 +106,19 @@ int main (int argc, char **argv)
frame++; frame++;


paused: paused:
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, screen); dither, screen);
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2,
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- "); " -=[ Powered by libcaca ]=- ");
caca_display(kk);
caca_display(dp);
} }


end: end:
cucul_free_dither(dither); cucul_free_dither(dither);
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 18
- 18
src/cacaplas.c View File

@@ -40,23 +40,23 @@ static void do_plasma(unsigned char *,


int main (int argc, char **argv) int main (int argc, char **argv)
{ {
cucul_canvas_t *c, *c2, *mask; caca_t *kk;
cucul_canvas_t *cv, *c2, *mask; caca_display_t *dp;
unsigned int red[256], green[256], blue[256], alpha[256]; unsigned int red[256], green[256], blue[256], alpha[256];
double r[3], R[6]; double r[3], R[6];
cucul_dither_t *dither; cucul_dither_t *dither;
int i, x, y, frame = 0, pause = 0; int i, x, y, frame = 0, pause = 0;


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;
kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


caca_set_delay(kk, 20000);
caca_set_delay(dp, 20000);


c2 = cucul_create(cucul_get_width(c), cucul_get_height(c));
mask = cucul_create(cucul_get_width(c), cucul_get_height(c));
c2 = cucul_create(cucul_get_width(cv), cucul_get_height(cv));
mask = cucul_create(cucul_get_width(cv), cucul_get_height(cv));


/* Fill various tables */ /* Fill various tables */
for(i = 0 ; i < 256; i++) for(i = 0 ; i < 256; i++)
@@ -85,7 +85,7 @@ int main (int argc, char **argv)
for(;;) for(;;)
{ {
caca_event_t ev; caca_event_t ev;
if(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.ch) switch(ev.data.key.ch)
{ {
@@ -119,26 +119,26 @@ int main (int argc, char **argv)
frame++; frame++;


paused: paused:
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, screen); dither, screen);


cucul_blit(c2, 0, 0, c, NULL);
cucul_blit(c2, 0, 0, cv, NULL);
cucul_invert(c2); cucul_invert(c2);




cucul_blit(c, 0, 0, c2, mask);
cucul_blit(cv, 0, 0, c2, mask);


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, cucul_get_width(c) - 30, cucul_get_height(c) - 2,
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, cucul_get_width(cv) - 30, cucul_get_height(cv) - 2,
" -=[ Powered by libcaca ]=- "); " -=[ Powered by libcaca ]=- ");
caca_display(kk);
caca_display(dp);
} }


end: end:
cucul_free_dither(dither); cucul_free_dither(dither);
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 9
- 9
src/cacaplay.c View File

@@ -27,8 +27,8 @@ int main(int argc, char **argv)
{ {
struct stat statbuf; struct stat statbuf;
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;
void *buffer; void *buffer;
int fd; int fd;


@@ -53,28 +53,28 @@ int main(int argc, char **argv)


buffer = malloc(statbuf.st_size); buffer = malloc(statbuf.st_size);
read(fd, buffer, statbuf.st_size); read(fd, buffer, statbuf.st_size);
c = cucul_load(buffer, statbuf.st_size);
cv = cucul_load(buffer, statbuf.st_size);
free(buffer); free(buffer);


if(!c)
if(!cv)
{ {
fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]); fprintf(stderr, "%s: invalid caca file %s.\n", argv[0], argv[1]);
return 1; return 1;
} }


kk = caca_attach(c);
dp = caca_attach(cv);


caca_display(kk);
caca_display(dp);


while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1))
while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1))
{ {
if(ev.data.key.ch == CACA_KEY_ESCAPE) if(ev.data.key.ch == CACA_KEY_ESCAPE)
break; break;
} }


/* Clean up */ /* Clean up */
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 65
- 65
src/cacaview.c View File

@@ -41,7 +41,7 @@
#define PAD_STEP 0.15 #define PAD_STEP 0.15


/* libcucul/libcaca contexts */ /* libcucul/libcaca contexts */
cucul_canvas_t *c; caca_t *kk;
cucul_canvas_t *cv; caca_display_t *dp;


/* Local functions */ /* Local functions */
static void print_status(void); static void print_status(void);
@@ -68,25 +68,25 @@ int main(int argc, char **argv)
int i; int i;


/* Initialise libcucul */ /* Initialise libcucul */
c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
{ {
fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
return 1; return 1;
} }


kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
{ {
fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]); fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
return 1; return 1;
} }


/* Set the window title */ /* Set the window title */
caca_set_window_title(kk, "cacaview");
caca_set_window_title(dp, "cacaview");


ww = cucul_get_width(c);
wh = cucul_get_height(c);
ww = cucul_get_width(cv);
wh = cucul_get_height(cv);


/* Fill the zoom table */ /* Fill the zoom table */
zoomtab[0] = 1.0; zoomtab[0] = 1.0;
@@ -131,9 +131,9 @@ int main(int argc, char **argv)
int event; int event;


if(update) if(update)
event = caca_get_event(kk, event_mask, &ev, 0);
event = caca_get_event(dp, event_mask, &ev, 0);
else else
event = caca_get_event(kk, event_mask, &ev, -1);
event = caca_get_event(dp, event_mask, &ev, -1);


while(event) while(event)
{ {
@@ -170,44 +170,44 @@ int main(int argc, char **argv)
break; break;
#if 0 /* FIXME */ #if 0 /* FIXME */
case 'b': case 'b':
i = 1 + cucul_get_feature(c, CUCUL_BACKGROUND);
i = 1 + cucul_get_feature(cv, CUCUL_BACKGROUND);
if(i > CUCUL_BACKGROUND_MAX) i = CUCUL_BACKGROUND_MIN; if(i > CUCUL_BACKGROUND_MAX) i = CUCUL_BACKGROUND_MIN;
cucul_set_feature(c, i);
cucul_set_feature(cv, i);
new_status = STATUS_BACKGROUND; new_status = STATUS_BACKGROUND;
update = 1; update = 1;
break; break;
case 'B': case 'B':
i = -1 + cucul_get_feature(c, CUCUL_BACKGROUND);
i = -1 + cucul_get_feature(cv, CUCUL_BACKGROUND);
if(i < CUCUL_BACKGROUND_MIN) i = CUCUL_BACKGROUND_MAX; if(i < CUCUL_BACKGROUND_MIN) i = CUCUL_BACKGROUND_MAX;
cucul_set_feature(c, i);
cucul_set_feature(cv, i);
new_status = STATUS_BACKGROUND; new_status = STATUS_BACKGROUND;
update = 1; update = 1;
break; break;
case 'a': case 'a':
i = 1 + cucul_get_feature(c, CUCUL_ANTIALIASING);
i = 1 + cucul_get_feature(cv, CUCUL_ANTIALIASING);
if(i > CUCUL_ANTIALIASING_MAX) i = CUCUL_ANTIALIASING_MIN; if(i > CUCUL_ANTIALIASING_MAX) i = CUCUL_ANTIALIASING_MIN;
cucul_set_feature(c, i);
cucul_set_feature(cv, i);
new_status = STATUS_ANTIALIASING; new_status = STATUS_ANTIALIASING;
update = 1; update = 1;
break; break;
case 'A': case 'A':
i = -1 + cucul_get_feature(c, CUCUL_ANTIALIASING);
i = -1 + cucul_get_feature(cv, CUCUL_ANTIALIASING);
if(i < CUCUL_ANTIALIASING_MIN) i = CUCUL_ANTIALIASING_MAX; if(i < CUCUL_ANTIALIASING_MIN) i = CUCUL_ANTIALIASING_MAX;
cucul_set_feature(c, i);
cucul_set_feature(cv, i);
new_status = STATUS_ANTIALIASING; new_status = STATUS_ANTIALIASING;
update = 1; update = 1;
break; break;
case 'd': case 'd':
i = 1 + cucul_get_feature(c, CUCUL_DITHERING);
i = 1 + cucul_get_feature(cv, CUCUL_DITHERING);
if(i > CUCUL_DITHERING_MAX) i = CUCUL_DITHERING_MIN; if(i > CUCUL_DITHERING_MAX) i = CUCUL_DITHERING_MIN;
cucul_set_feature(c, i);
cucul_set_feature(cv, i);
new_status = STATUS_DITHERING; new_status = STATUS_DITHERING;
update = 1; update = 1;
break; break;
case 'D': case 'D':
i = -1 + cucul_get_feature(c, CUCUL_DITHERING);
i = -1 + cucul_get_feature(cv, CUCUL_DITHERING);
if(i < CUCUL_DITHERING_MIN) i = CUCUL_DITHERING_MAX; if(i < CUCUL_DITHERING_MIN) i = CUCUL_DITHERING_MAX;
cucul_set_feature(c, i);
cucul_set_feature(cv, i);
new_status = STATUS_DITHERING; new_status = STATUS_DITHERING;
update = 1; update = 1;
break; break;
@@ -273,7 +273,7 @@ int main(int argc, char **argv)
} }
else if(ev.type == CACA_EVENT_RESIZE) else if(ev.type == CACA_EVENT_RESIZE)
{ {
caca_display(kk);
caca_display(dp);
ww = ev.data.resize.w; ww = ev.data.resize.w;
wh = ev.data.resize.h; wh = ev.data.resize.h;
update = 1; update = 1;
@@ -286,7 +286,7 @@ int main(int argc, char **argv)
if(help || new_help) if(help || new_help)
help = new_help; help = new_help;


event = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0);
event = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
} }


if(items && reload) if(items && reload)
@@ -301,11 +301,11 @@ int main(int argc, char **argv)


sprintf(buffer, " Loading `%s'... ", list[current]); sprintf(buffer, " Loading `%s'... ", list[current]);
buffer[ww] = '\0'; buffer[ww] = '\0';
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, (ww - strlen(buffer)) / 2, wh / 2, buffer);
caca_display(kk);
ww = cucul_get_width(c);
wh = cucul_get_height(c);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, (ww - strlen(buffer)) / 2, wh / 2, buffer);
caca_display(dp);
ww = cucul_get_width(cv);
wh = cucul_get_height(cv);


if(im) if(im)
unload_image(im); unload_image(im);
@@ -321,12 +321,12 @@ int main(int argc, char **argv)
free(buffer); free(buffer);
} }


cucul_clear(c);
cucul_clear(cv);


if(!items) if(!items)
{ {
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_printf(c, ww / 2 - 5, wh / 2, " No image. ");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_printf(cv, ww / 2 - 5, wh / 2, " No image. ");
} }
else if(!im) else if(!im)
{ {
@@ -345,8 +345,8 @@ int main(int argc, char **argv)


sprintf(buffer, ERROR_STRING, list[current]); sprintf(buffer, ERROR_STRING, list[current]);
buffer[ww] = '\0'; buffer[ww] = '\0';
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, (ww - strlen(buffer)) / 2, wh / 2, buffer);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, (ww - strlen(buffer)) / 2, wh / 2, buffer);
free(buffer); free(buffer);
} }
else else
@@ -365,7 +365,7 @@ int main(int argc, char **argv)
ww * (1.0 + xfactor) / 2, ww * (1.0 + xfactor) / 2,
y + height * (1.0 + yfactor) / 2); y + height * (1.0 + yfactor) / 2);


cucul_dither_bitmap(c, ww * (1.0 - xfactor) * xdelta,
cucul_dither_bitmap(cv, ww * (1.0 - xfactor) * xdelta,
y + height * (1.0 - yfactor) * ydelta, y + height * (1.0 - yfactor) * ydelta,
ww * (xdelta + (1.0 - xdelta) * xfactor), ww * (xdelta + (1.0 - xdelta) * xfactor),
y + height * (ydelta + (1.0 - ydelta) * yfactor), y + height * (ydelta + (1.0 - ydelta) * yfactor),
@@ -377,20 +377,20 @@ int main(int argc, char **argv)
print_status(); print_status();


#if 0 /* FIXME */ #if 0 /* FIXME */
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
switch(status) switch(status)
{ {
case STATUS_ANTIALIASING: case STATUS_ANTIALIASING:
cucul_printf(c, 0, wh - 1, "Antialiasing: %s",
cucul_get_feature_name(cucul_get_feature(c, CUCUL_ANTIALIASING)));
cucul_printf(cv, 0, wh - 1, "Antialiasing: %s",
cucul_get_feature_name(cucul_get_feature(cv, CUCUL_ANTIALIASING)));
break; break;
case STATUS_DITHERING: case STATUS_DITHERING:
cucul_printf(c, 0, wh - 1, "Dithering: %s",
cucul_get_feature_name(cucul_get_feature(c, CUCUL_DITHERING)));
cucul_printf(cv, 0, wh - 1, "Dithering: %s",
cucul_get_feature_name(cucul_get_feature(cv, CUCUL_DITHERING)));
break; break;
case STATUS_BACKGROUND: case STATUS_BACKGROUND:
cucul_printf(c, 0, wh - 1, "Background: %s",
cucul_get_feature_name(cucul_get_feature(c, CUCUL_BACKGROUND)));
cucul_printf(cv, 0, wh - 1, "Background: %s",
cucul_get_feature_name(cucul_get_feature(cv, CUCUL_BACKGROUND)));
break; break;
} }
#endif #endif
@@ -401,33 +401,33 @@ int main(int argc, char **argv)
print_help(ww - 26, 2); print_help(ww - 26, 2);
} }


caca_display(kk);
caca_display(dp);
update = 0; update = 0;
} }


/* Clean up */ /* Clean up */
if(im) if(im)
unload_image(im); unload_image(im);
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


static void print_status(void) static void print_status(void)
{ {
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(c, 0, 0, ww - 1, 0, " ");
cucul_draw_line(c, 0, wh - 2, ww - 1, wh - 2, "-");
cucul_putstr(c, 0, 0, "q:Quit np:Next/Prev +-x:Zoom gG:Gamma "
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(cv, 0, 0, ww - 1, 0, " ");
cucul_draw_line(cv, 0, wh - 2, ww - 1, wh - 2, "-");
cucul_putstr(cv, 0, 0, "q:Quit np:Next/Prev +-x:Zoom gG:Gamma "
"hjkl:Move d:Dither a:Antialias"); "hjkl:Move d:Dither a:Antialias");
cucul_putstr(c, ww - strlen("?:Help"), 0, "?:Help");
cucul_printf(c, 3, wh - 2, "cacaview %s", VERSION);
cucul_printf(c, ww - 30, wh - 2, "(gamma: %#.3g)", GAMMA(g));
cucul_printf(c, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom);
cucul_putstr(cv, ww - strlen("?:Help"), 0, "?:Help");
cucul_printf(cv, 3, wh - 2, "cacaview %s", VERSION);
cucul_printf(cv, ww - 30, wh - 2, "(gamma: %#.3g)", GAMMA(g));
cucul_printf(cv, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom);


cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_line(c, 0, wh - 1, ww - 1, wh - 1, " ");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_line(cv, 0, wh - 1, ww - 1, wh - 1, " ");
} }


static void print_help(int x, int y) static void print_help(int x, int y)
@@ -454,10 +454,10 @@ static void print_help(int x, int y)


int i; int i;


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);


for(i = 0; help[i]; i++) for(i = 0; help[i]; i++)
cucul_putstr(c, x, y + i, help[i]);
cucul_putstr(cv, x, y + i, help[i]);
} }


static void set_zoom(int new_zoom) static void set_zoom(int new_zoom)
@@ -472,13 +472,13 @@ static void set_zoom(int new_zoom)
if(zoom > ZOOM_MAX) zoom = ZOOM_MAX; if(zoom > ZOOM_MAX) zoom = ZOOM_MAX;
if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX; if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX;


ww = cucul_get_width(c);
ww = cucul_get_width(cv);
height = fullscreen ? wh : wh - 3; height = fullscreen ? wh : wh - 3;


xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom]; xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom];
yfactor = xfactor * ww / height * im->h / im->w yfactor = xfactor * ww / height * im->h / im->w
* cucul_get_height(c) / cucul_get_width(c)
* caca_get_window_width(kk) / caca_get_window_height(kk);
* cucul_get_height(cv) / cucul_get_width(cv)
* caca_get_window_width(dp) / caca_get_window_height(dp);


if(yfactor > xfactor) if(yfactor > xfactor)
{ {
@@ -506,17 +506,17 @@ static void draw_checkers(int x1, int y1, int x2, int y2)
{ {
int xn, yn; int xn, yn;


if(x2 + 1 > (int)cucul_get_width(c)) x2 = cucul_get_width(c) - 1;
if(y2 + 1 > (int)cucul_get_height(c)) y2 = cucul_get_height(c) - 1;
if(x2 + 1 > (int)cucul_get_width(cv)) x2 = cucul_get_width(cv) - 1;
if(y2 + 1 > (int)cucul_get_height(cv)) y2 = cucul_get_height(cv) - 1;


for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++) for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++)
for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++) for(xn = x1 > 0 ? x1 : 0; xn <= x2; xn++)
{ {
if((((xn - x1) / 5) ^ ((yn - y1) / 3)) & 1) if((((xn - x1) / 5) ^ ((yn - y1) / 3)) & 1)
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY);
else else
cucul_set_color(c, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY);
cucul_putchar(c, xn, yn, ' ');
cucul_set_color(cv, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY);
cucul_putchar(cv, xn, yn, ' ');
} }
} }



+ 9
- 9
src/img2irc.c View File

@@ -23,7 +23,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
/* libcucul context */ /* libcucul context */
cucul_canvas_t *c;
cucul_canvas_t *cv;
cucul_buffer_t *export; cucul_buffer_t *export;
struct image *i; struct image *i;
int cols = 56, lines; int cols = 56, lines;
@@ -34,8 +34,8 @@ int main(int argc, char **argv)
return 1; return 1;
} }


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
{ {
fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]); fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
return 1; return 1;
@@ -45,25 +45,25 @@ int main(int argc, char **argv)
if(!i) if(!i)
{ {
fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]); fprintf(stderr, "%s: unable to load %s\n", argv[0], argv[1]);
cucul_free(c);
cucul_free(cv);
return 1; return 1;
} }


/* Assume a 6×10 font */ /* Assume a 6×10 font */
lines = cols * i->h * 6 / i->w / 10; lines = cols * i->h * 6 / i->w / 10;


cucul_set_size(c, cols, lines);
cucul_clear(c);
cucul_dither_bitmap(c, 0, 0, cols - 1, lines - 1, i->dither, i->pixels);
cucul_set_size(cv, cols, lines);
cucul_clear(cv);
cucul_dither_bitmap(cv, 0, 0, cols - 1, lines - 1, i->dither, i->pixels);


unload_image(i); unload_image(i);


export = cucul_create_export(c, "irc");
export = cucul_create_export(cv, "irc");
fwrite(cucul_get_buffer_data(export), fwrite(cucul_get_buffer_data(export),
cucul_get_buffer_size(export), 1, stdout); cucul_get_buffer_size(export), 1, stdout);
cucul_free_buffer(export); cucul_free_buffer(export);


cucul_free(c);
cucul_free(cv);


return 0; return 0;
} }


+ 15
- 15
test/colors.c View File

@@ -22,38 +22,38 @@


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;
caca_event_t ev; caca_event_t ev;
int i, j; int i, j;


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;


kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


cucul_clear(c);
cucul_clear(cv);
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_printf(c, 4, i + (i >= 8 ? 4 : 3), "'%c': %i (%s)",
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_printf(cv, 4, i + (i >= 8 ? 4 : 3), "'%cv': %i (%s)",
'a' + i, i, cucul_get_color_name(i)); 'a' + i, i, cucul_get_color_name(i));
for(j = 0; j < 16; j++) for(j = 0; j < 16; j++)
{ {
cucul_set_color(c, i, j);
cucul_putstr(c, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3),
cucul_set_color(cv, i, j);
cucul_putstr(cv, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3),
"# "); "# ");
} }
} }


caca_display(kk);
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_display(dp);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 136
- 136
test/demo.c View File

@@ -37,22 +37,22 @@ int outline = 0;
int dithering = 0; int dithering = 0;
cucul_sprite_t *sprite = NULL; cucul_sprite_t *sprite = NULL;


cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
void (*demo)(void) = NULL; void (*demo)(void) = NULL;
int quit = 0; int quit = 0;


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;
kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


caca_set_delay(kk, 40000);
caca_set_delay(dp, 40000);


/* Initialize data */ /* Initialize data */
sprite = cucul_load_sprite(DATADIR "/caca.txt"); sprite = cucul_load_sprite(DATADIR "/caca.txt");
@@ -62,11 +62,11 @@ int main(int argc, char **argv)
sprite = cucul_load_sprite("examples/caca.txt"); sprite = cucul_load_sprite("examples/caca.txt");


/* Disable cursor */ /* Disable cursor */
caca_set_mouse(kk, 0);
caca_set_mouse(dp, 0);


/* Main menu */ /* Main menu */
display_menu(); display_menu();
caca_display(kk);
caca_display(dp);


/* Go ! */ /* Go ! */
while(!quit) while(!quit)
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
caca_event_t ev; caca_event_t ev;
int menu = 0, mouse = 0, xmouse = 0, ymouse = 0; int menu = 0, mouse = 0, xmouse = 0, ymouse = 0;


while(caca_get_event(kk, CACA_EVENT_ANY, &ev, 0))
while(caca_get_event(dp, CACA_EVENT_ANY, &ev, 0))
{ {
if(demo && (ev.type & CACA_EVENT_KEY_PRESS)) if(demo && (ev.type & CACA_EVENT_KEY_PRESS))
{ {
@@ -104,7 +104,7 @@ int main(int argc, char **argv)
case 'd': case 'd':
case 'D': case 'D':
dithering = (dithering + 1) % 5; dithering = (dithering + 1) % 5;
cucul_set_feature(c, dithering);
cucul_set_feature(cv, dithering);
display_menu(); display_menu();
break; break;
#endif #endif
@@ -142,7 +142,7 @@ int main(int argc, char **argv)
} }


if(demo) if(demo)
cucul_clear(c);
cucul_clear(cv);
} }
else if(ev.type & CACA_EVENT_MOUSE_MOTION) else if(ev.type & CACA_EVENT_MOUSE_MOTION)
{ {
@@ -161,11 +161,11 @@ int main(int argc, char **argv)
display_menu(); display_menu();
if(mouse && !demo) if(mouse && !demo)
{ {
cucul_set_color(c, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
cucul_putstr(c, xmouse, ymouse, ".");
cucul_putstr(c, xmouse, ymouse + 1, "|\\");
cucul_set_color(cv, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
cucul_putstr(cv, xmouse, ymouse, ".");
cucul_putstr(cv, xmouse, ymouse + 1, "|\\");
} }
caca_display(kk);
caca_display(dp);
mouse = menu = 0; mouse = menu = 0;
} }


@@ -173,58 +173,58 @@ int main(int argc, char **argv)
{ {
demo(); demo();


cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(c, 1, 1, cucul_get_width(c) - 2, cucul_get_height(c) - 2);
cucul_printf(c, 4, 1, "[%i.%i fps]----",
1000000 / caca_get_rendertime(kk),
(10000000 / caca_get_rendertime(kk)) % 10);
caca_display(kk);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 1, 1, cucul_get_width(cv) - 2, cucul_get_height(cv) - 2);
cucul_printf(cv, 4, 1, "[%i.%i fps]----",
1000000 / caca_get_rendertime(dp),
(10000000 / caca_get_rendertime(dp)) % 10);
caca_display(dp);
} }
} }


/* Clean up */ /* Clean up */
cucul_free_sprite(sprite); cucul_free_sprite(sprite);
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


static void display_menu(void) static void display_menu(void)
{ {
int xo = cucul_get_width(c) - 2;
int yo = cucul_get_height(c) - 2;
cucul_clear(c);
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(c, 1, 1, xo, yo);
cucul_putstr(c, (xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
cucul_putstr(c, (xo - strlen("==============")) / 2, 4, "==============");
cucul_putstr(c, 4, 6, "demos:");
cucul_putstr(c, 4, 7, "'f': full");
cucul_putstr(c, 4, 8, "'1': dots");
cucul_putstr(c, 4, 9, "'2': lines");
cucul_putstr(c, 4, 10, "'3': boxes");
cucul_putstr(c, 4, 11, "'4': triangles");
cucul_putstr(c, 4, 12, "'5': ellipses");
cucul_putstr(c, 4, 13, "'c': colour");
cucul_putstr(c, 4, 14, "'r': render");
int xo = cucul_get_width(cv) - 2;
int yo = cucul_get_height(cv) - 2;
cucul_clear(cv);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 1, 1, xo, yo);
cucul_putstr(cv, (xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
cucul_putstr(cv, (xo - strlen("==============")) / 2, 4, "==============");
cucul_putstr(cv, 4, 6, "demos:");
cucul_putstr(cv, 4, 7, "'f': full");
cucul_putstr(cv, 4, 8, "'1': dots");
cucul_putstr(cv, 4, 9, "'2': lines");
cucul_putstr(cv, 4, 10, "'3': boxes");
cucul_putstr(cv, 4, 11, "'4': triangles");
cucul_putstr(cv, 4, 12, "'5': ellipses");
cucul_putstr(cv, 4, 13, "'c': colour");
cucul_putstr(cv, 4, 14, "'r': render");
if(sprite) if(sprite)
cucul_putstr(c, 4, 15, "'s': sprites");
cucul_putstr(cv, 4, 15, "'s': sprites");


cucul_putstr(c, 4, 16, "settings:");
cucul_printf(c, 4, 17, "'o': outline: %s",
cucul_putstr(cv, 4, 16, "settings:");
cucul_printf(cv, 4, 17, "'o': outline: %s",
outline == 0 ? "none" : outline == 1 ? "solid" : "thin"); outline == 0 ? "none" : outline == 1 ? "solid" : "thin");
cucul_printf(c, 4, 18, "'b': drawing boundaries: %s",
cucul_printf(cv, 4, 18, "'b': drawing boundaries: %s",
bounds == 0 ? "screen" : "infinite"); bounds == 0 ? "screen" : "infinite");
//cucul_printf(c, 4, 19, "'d': dithering (%s)",
//cucul_printf(cv, 4, 19, "'d': dithering (%s)",
// cucul_get_feature_name(dithering)); // cucul_get_feature_name(dithering));


cucul_putstr(c, 4, yo - 2, "'q': quit");
cucul_putstr(cv, 4, yo - 2, "'q': quit");


caca_display(kk);
caca_display(dp);
} }


static void demo_all(void) static void demo_all(void)
@@ -235,99 +235,99 @@ static void demo_all(void)


i++; i++;


cucul_clear(c);
cucul_clear(cv);


/* Draw the sun */ /* Draw the sun */
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
xo = cucul_get_width(c) / 4;
yo = cucul_get_height(c) / 4 + 5 * sin(0.03*i);
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
xo = cucul_get_width(cv) / 4;
yo = cucul_get_height(cv) / 4 + 5 * sin(0.03*i);


for(j = 0; j < 16; j++) for(j = 0; j < 16; j++)
{ {
xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8); xa = xo - (30 + sin(0.03*i) * 8) * sin(0.03*i + M_PI*j/8);
ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8); ya = yo + (15 + sin(0.03*i) * 4) * cos(0.03*i + M_PI*j/8);
cucul_draw_thin_line(c, xo, yo, xa, ya);
cucul_draw_thin_line(cv, xo, yo, xa, ya);
} }


j = 15 + sin(0.03*i) * 8; j = 15 + sin(0.03*i) * 8;
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_fill_ellipse(c, xo, yo, j, j / 2, "#");
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_ellipse(c, xo, yo, j, j / 2, "#");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_fill_ellipse(cv, xo, yo, j, j / 2, "#");
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_ellipse(cv, xo, yo, j, j / 2, "#");


/* Draw the pyramid */ /* Draw the pyramid */
xo = cucul_get_width(c) * 5 / 8;
xo = cucul_get_width(cv) * 5 / 8;
yo = 2; yo = 2;


xa = cucul_get_width(c) / 8 + sin(0.03*i) * 5;
ya = cucul_get_height(c) / 2 + cos(0.03*i) * 5;
xa = cucul_get_width(cv) / 8 + sin(0.03*i) * 5;
ya = cucul_get_height(cv) / 2 + cos(0.03*i) * 5;


xb = cucul_get_width(c) - 10 - cos(0.02*i) * 10;
yb = cucul_get_height(c) * 3 / 4 - 5 + sin(0.02*i) * 5;
xb = cucul_get_width(cv) - 10 - cos(0.02*i) * 10;
yb = cucul_get_height(cv) * 3 / 4 - 5 + sin(0.02*i) * 5;


xc = cucul_get_width(c) / 4 - sin(0.02*i) * 5;
yc = cucul_get_height(c) * 3 / 4 + cos(0.02*i) * 5;
xc = cucul_get_width(cv) / 4 - sin(0.02*i) * 5;
yc = cucul_get_height(cv) * 3 / 4 + cos(0.02*i) * 5;


cucul_set_color(c, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
cucul_fill_triangle(c, xo, yo, xb, yb, xa, ya, "%");
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(c, xo, yo, xb, yb, xa, ya);
cucul_set_color(cv, CUCUL_COLOR_GREEN, CUCUL_COLOR_BLACK);
cucul_fill_triangle(cv, xo, yo, xb, yb, xa, ya, "%");
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(cv, xo, yo, xb, yb, xa, ya);


cucul_set_color(c, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
cucul_fill_triangle(c, xa, ya, xb, yb, xc, yc, "#");
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(c, xa, ya, xb, yb, xc, yc);
cucul_set_color(cv, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, "#");
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);


cucul_set_color(c, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
cucul_fill_triangle(c, xo, yo, xb, yb, xc, yc, "%");
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(c, xo, yo, xb, yb, xc, yc);
cucul_set_color(cv, CUCUL_COLOR_BLUE, CUCUL_COLOR_BLACK);
cucul_fill_triangle(cv, xo, yo, xb, yb, xc, yc, "%");
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(cv, xo, yo, xb, yb, xc, yc);


/* Draw a background triangle */ /* Draw a background triangle */
xa = 2; xa = 2;
ya = 2; ya = 2;


xb = cucul_get_width(c) - 3;
yb = cucul_get_height(c) / 2;
xb = cucul_get_width(cv) - 3;
yb = cucul_get_height(cv) / 2;


xc = cucul_get_width(c) / 3;
yc = cucul_get_height(c) - 3;
xc = cucul_get_width(cv) / 3;
yc = cucul_get_height(cv) - 3;


cucul_set_color(c, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(c, xa, ya, xb, yb, xc, yc);
cucul_set_color(cv, CUCUL_COLOR_CYAN, CUCUL_COLOR_BLACK);
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);


xo = cucul_get_width(c) / 2 + cos(0.027*i) * cucul_get_width(c) / 3;
yo = cucul_get_height(c) / 2 - sin(0.027*i) * cucul_get_height(c) / 2;
xo = cucul_get_width(cv) / 2 + cos(0.027*i) * cucul_get_width(cv) / 3;
yo = cucul_get_height(cv) / 2 - sin(0.027*i) * cucul_get_height(cv) / 2;


cucul_draw_thin_line(c, xa, ya, xo, yo);
cucul_draw_thin_line(c, xb, yb, xo, yo);
cucul_draw_thin_line(c, xc, yc, xo, yo);
cucul_draw_thin_line(cv, xa, ya, xo, yo);
cucul_draw_thin_line(cv, xb, yb, xo, yo);
cucul_draw_thin_line(cv, xc, yc, xo, yo);


/* Draw a sprite on the pyramid */ /* Draw a sprite on the pyramid */
cucul_draw_sprite(c, xo, yo, sprite, 0);
cucul_draw_sprite(cv, xo, yo, sprite, 0);


/* Draw a trail behind the foreground sprite */ /* Draw a trail behind the foreground sprite */
for(j = i - 60; j < i; j++) for(j = i - 60; j < i; j++)
{ {
int delta = cucul_rand(-5, 5); int delta = cucul_rand(-5, 5);
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_putchar(c, cucul_get_width(c) / 2
+ cos(0.02*j) * (delta + cucul_get_width(c) / 4),
cucul_get_height(c) / 2
+ sin(0.02*j) * (delta + cucul_get_height(c) / 3),
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_putchar(cv, cucul_get_width(cv) / 2
+ cos(0.02*j) * (delta + cucul_get_width(cv) / 4),
cucul_get_height(cv) / 2
+ sin(0.02*j) * (delta + cucul_get_height(cv) / 3),
'#'); '#');
} }


/* Draw foreground sprite */ /* Draw foreground sprite */
cucul_draw_sprite(c, cucul_get_width(c) / 2 + cos(0.02*i) * cucul_get_width(c) / 4,
cucul_get_height(c) / 2 + sin(0.02*i) * cucul_get_height(c) / 3,
cucul_draw_sprite(cv, cucul_get_width(cv) / 2 + cos(0.02*i) * cucul_get_width(cv) / 4,
cucul_get_height(cv) / 2 + sin(0.02*i) * cucul_get_height(cv) / 3,
sprite, 0); sprite, 0);
} }


static void demo_dots(void) static void demo_dots(void)
{ {
int xmax = cucul_get_width(c) - 1;
int ymax = cucul_get_height(c) - 1;
int xmax = cucul_get_width(cv) - 1;
int ymax = cucul_get_height(cv) - 1;
int i; int i;
static char chars[10] = static char chars[10] =
{ {
@@ -337,8 +337,8 @@ static void demo_dots(void)
for(i = 1000; i--;) for(i = 1000; i--;)
{ {
/* Putpixel */ /* Putpixel */
cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_putchar(c, cucul_rand(0, xmax), cucul_rand(0, ymax),
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_putchar(cv, cucul_rand(0, xmax), cucul_rand(0, ymax),
chars[cucul_rand(0, 9)]); chars[cucul_rand(0, 9)]);
} }
} }
@@ -348,24 +348,24 @@ static void demo_color(void)
int i, j; int i, j;
char buf[BUFSIZ]; char buf[BUFSIZ];


cucul_clear(c);
cucul_clear(cv);
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
sprintf(buf, "'%c': %i (%s)", 'a' + i, i, cucul_get_color_name(i)); sprintf(buf, "'%c': %i (%s)", 'a' + i, i, cucul_get_color_name(i));
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(c, 4, i + (i >= 8 ? 4 : 3), buf);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 4, i + (i >= 8 ? 4 : 3), buf);
for(j = 0; j < 16; j++) for(j = 0; j < 16; j++)
{ {
cucul_set_color(c, i, j);
cucul_putstr(c, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# ");
cucul_set_color(cv, i, j);
cucul_putstr(cv, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# ");
} }
} }
} }


static void demo_lines(void) static void demo_lines(void)
{ {
int w = cucul_get_width(c);
int h = cucul_get_height(c);
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int xa, ya, xb, yb; int xa, ya, xb, yb;


if(bounds) if(bounds)
@@ -379,17 +379,17 @@ static void demo_lines(void)
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1); xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1);
} }


cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
if(outline > 1) if(outline > 1)
cucul_draw_thin_line(c, xa, ya, xb, yb);
cucul_draw_thin_line(cv, xa, ya, xb, yb);
else else
cucul_draw_line(c, xa, ya, xb, yb, "#");
cucul_draw_line(cv, xa, ya, xb, yb, "#");
} }


static void demo_boxes(void) static void demo_boxes(void)
{ {
int w = cucul_get_width(c);
int h = cucul_get_height(c);
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int xa, ya, xb, yb; int xa, ya, xb, yb;


if(bounds) if(bounds)
@@ -403,20 +403,20 @@ static void demo_boxes(void)
xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1); xb = cucul_rand(0, w - 1); yb = cucul_rand(0, h - 1);
} }


cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_fill_box(c, xa, ya, xb, yb, "#");
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_fill_box(cv, xa, ya, xb, yb, "#");


cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
if(outline == 2) if(outline == 2)
cucul_draw_thin_box(c, xa, ya, xb, yb);
cucul_draw_thin_box(cv, xa, ya, xb, yb);
else if(outline == 1) else if(outline == 1)
cucul_draw_box(c, xa, ya, xb, yb, "#");
cucul_draw_box(cv, xa, ya, xb, yb, "#");
} }


static void demo_ellipses(void) static void demo_ellipses(void)
{ {
int w = cucul_get_width(c);
int h = cucul_get_height(c);
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int x, y, a, b; int x, y, a, b;


if(bounds) if(bounds)
@@ -434,20 +434,20 @@ static void demo_ellipses(void)
} while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h); } while(x - a < 0 || x + a >= w || y - b < 0 || y + b >= h);
} }


cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_fill_ellipse(c, x, y, a, b, "#");
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_fill_ellipse(cv, x, y, a, b, "#");


cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
if(outline == 2) if(outline == 2)
cucul_draw_thin_ellipse(c, x, y, a, b);
cucul_draw_thin_ellipse(cv, x, y, a, b);
else if(outline == 1) else if(outline == 1)
cucul_draw_ellipse(c, x, y, a, b, "#");
cucul_draw_ellipse(cv, x, y, a, b, "#");
} }


static void demo_triangles(void) static void demo_triangles(void)
{ {
int w = cucul_get_width(c);
int h = cucul_get_height(c);
int w = cucul_get_width(cv);
int h = cucul_get_height(cv);
int xa, ya, xb, yb, xc, yc; int xa, ya, xb, yb, xc, yc;


if(bounds) if(bounds)
@@ -464,20 +464,20 @@ static void demo_triangles(void)
xc = cucul_rand(0, w - 1); yc = cucul_rand(0, h - 1); xc = cucul_rand(0, w - 1); yc = cucul_rand(0, h - 1);
} }


cucul_set_color(c, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_fill_triangle(c, xa, ya, xb, yb, xc, yc, "#");
cucul_set_color(cv, cucul_rand(0, 15), cucul_rand(0, 15));
cucul_fill_triangle(cv, xa, ya, xb, yb, xc, yc, "#");


cucul_set_color(c, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
cucul_set_color(cv, cucul_rand(0, 15), CUCUL_COLOR_BLACK);
if(outline == 2) if(outline == 2)
cucul_draw_thin_triangle(c, xa, ya, xb, yb, xc, yc);
cucul_draw_thin_triangle(cv, xa, ya, xb, yb, xc, yc);
else if(outline == 1) else if(outline == 1)
cucul_draw_triangle(c, xa, ya, xb, yb, xc, yc, "#");
cucul_draw_triangle(cv, xa, ya, xb, yb, xc, yc, "#");
} }


static void demo_sprites(void) static void demo_sprites(void)
{ {
cucul_draw_sprite(c, cucul_rand(0, cucul_get_width(c) - 1),
cucul_rand(0, cucul_get_height(c) - 1), sprite, 0);
cucul_draw_sprite(cv, cucul_rand(0, cucul_get_width(cv) - 1),
cucul_rand(0, cucul_get_height(cv) - 1), sprite, 0);
} }


#if 0 #if 0
@@ -503,7 +503,7 @@ static void demo_render(void)
cucul_set_dither_invert(dither, 1); cucul_set_dither_invert(dither, 1);
//dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000); //dither = cucul_create_dither(16, 256, 256, 2 * 256, 0xf800, 0x07e0, 0x001f, 0x0000);
dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_dither_bitmap(c, 0, 0, cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0, cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, buffer); dither, buffer);
cucul_free_dither(dither); cucul_free_dither(dither);
} }
@@ -548,7 +548,7 @@ static void demo_render(void)


dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); dither = cucul_create_dither(32, 256, 256, 4 * 256, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
cucul_set_dither_invert(dither, 1); cucul_set_dither_invert(dither, 1);
cucul_dither_bitmap(c, 0, 0, cucul_get_width(c) - 1, cucul_get_height(c) - 1, dither, (char *)buffer);
cucul_dither_bitmap(cv, 0, 0, cucul_get_width(cv) - 1, cucul_get_height(cv) - 1, dither, (char *)buffer);
cucul_free_dither(dither); cucul_free_dither(dither);
} }




+ 11
- 11
test/dithering.c View File

@@ -35,13 +35,13 @@ char density[] = " ',+:;o&%w$W@#";
int main(void) int main(void)
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;
int neara, dista, nearb, distb, dist; int neara, dista, nearb, distb, dist;
int x, y; int x, y;


c = cucul_create(0, 0);
kk = caca_attach(c);
cv = cucul_create(0, 0);
dp = caca_attach(cv);


for(x = 0; x < 100; x++) for(x = 0; x < 100; x++)
for(y = 0; y < 100; y++) for(y = 0; y < 100; y++)
@@ -116,18 +116,18 @@ int main(void)
ch = density[distb * 2 * 13 / (dista + distb)]; ch = density[distb * 2 * 13 / (dista + distb)];
else else
ch = density[dista * 2 * 13 / (dista + distb)]; ch = density[dista * 2 * 13 / (dista + distb)];
cucul_set_color(c, points[nearb], points[neara]);
cucul_set_color(cv, points[nearb], points[neara]);


cucul_putchar(c, x * cucul_get_width(c) / 100,
(100 - y) * cucul_get_height(c) / 100, ch);
cucul_putchar(cv, x * cucul_get_width(cv) / 100,
(100 - y) * cucul_get_height(cv) / 100, ch);
} }


caca_display(kk);
caca_display(dp);


caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 32
- 32
test/event.c View File

@@ -20,8 +20,8 @@
#include "cucul.h" #include "cucul.h"
#include "caca.h" #include "caca.h"


static cucul_canvas_t *c;
static caca_t *kk;
static cucul_canvas_t *cv;
static caca_display_t *dp;


static void print_event(int, int, caca_event_t *); static void print_event(int, int, caca_event_t *);


@@ -30,22 +30,22 @@ int main(int argc, char **argv)
caca_event_t *events; caca_event_t *events;
int i, h, quit; int i, h, quit;


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;
kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


h = cucul_get_height(c) - 1;
h = cucul_get_height(cv) - 1;


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(c, 0, 0, cucul_get_width(c) - 1, 0, " ");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_width(cv) - 1, 0, " ");


cucul_draw_line(c, 0, h, cucul_get_width(c) - 1, h, " ");
cucul_putstr(c, 0, h, "type \"quit\" to exit");
cucul_draw_line(cv, 0, h, cucul_get_width(cv) - 1, h, " ");
cucul_putstr(cv, 0, h, "type \"quit\" to exit");


caca_display(kk);
caca_display(dp);


events = malloc(h * sizeof(caca_event_t)); events = malloc(h * sizeof(caca_event_t));
memset(events, 0, h * sizeof(caca_event_t)); memset(events, 0, h * sizeof(caca_event_t));
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
{ {
caca_event_t ev; caca_event_t ev;
static char const * quit_string[] = { "", "q", "qu", "qui", "quit" }; static char const * quit_string[] = { "", "q", "qu", "qui", "quit" };
int ret = caca_get_event(kk, CACA_EVENT_ANY, &ev, -1);
int ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, -1);


if(!ret) if(!ret)
continue; continue;
@@ -77,31 +77,31 @@ int main(int argc, char **argv)
memmove(events + 1, events, (h - 1) * sizeof(caca_event_t)); memmove(events + 1, events, (h - 1) * sizeof(caca_event_t));
events[0] = ev; events[0] = ev;


ret = caca_get_event(kk, CACA_EVENT_ANY, &ev, 0);
ret = caca_get_event(dp, CACA_EVENT_ANY, &ev, 0);
} }
while(ret); while(ret);


cucul_clear(c);
cucul_clear(cv);


/* Print current event */ /* Print current event */
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(c, 0, 0, cucul_get_width(c) - 1, 0, " ");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_draw_line(cv, 0, 0, cucul_get_width(cv) - 1, 0, " ");
print_event(0, 0, events); print_event(0, 0, events);


cucul_draw_line(c, 0, h, cucul_get_width(c) - 1, h, " ");
cucul_printf(c, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);
cucul_draw_line(cv, 0, h, cucul_get_width(cv) - 1, h, " ");
cucul_printf(cv, 0, h, "type \"quit\" to exit: %s", quit_string[quit]);


/* Print previous events */ /* Print previous events */
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
for(i = 1; i < h && events[i].type; i++) for(i = 1; i < h && events[i].type; i++)
print_event(0, i, events + i); print_event(0, i, events + i);


caca_display(kk);
caca_display(dp);
} }


/* Clean up */ /* Clean up */
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }
@@ -113,39 +113,39 @@ static void print_event(int x, int y, caca_event_t *ev)
switch(ev->type) switch(ev->type)
{ {
case CACA_EVENT_NONE: case CACA_EVENT_NONE:
cucul_printf(c, x, y, "CACA_EVENT_NONE");
cucul_printf(cv, x, y, "CACA_EVENT_NONE");
break; break;
case CACA_EVENT_KEY_PRESS: case CACA_EVENT_KEY_PRESS:
character = ev->data.key.ch; character = ev->data.key.ch;
cucul_printf(c, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%c)", character,
cucul_printf(cv, x, y, "CACA_EVENT_KEY_PRESS 0x%02x (%cv)", character,
(character > 0x1f && character < 0x80) ? character : '?'); (character > 0x1f && character < 0x80) ? character : '?');
break; break;
case CACA_EVENT_KEY_RELEASE: case CACA_EVENT_KEY_RELEASE:
character = ev->data.key.ch; character = ev->data.key.ch;
cucul_printf(c, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%c)", character,
cucul_printf(cv, x, y, "CACA_EVENT_KEY_RELEASE 0x%02x (%cv)", character,
(character > 0x1f && character < 0x80) ? character : '?'); (character > 0x1f && character < 0x80) ? character : '?');
break; break;
case CACA_EVENT_MOUSE_MOTION: case CACA_EVENT_MOUSE_MOTION:
cucul_printf(c, x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_MOTION %u %u",
ev->data.mouse.x, ev->data.mouse.y); ev->data.mouse.x, ev->data.mouse.y);
break; break;
case CACA_EVENT_MOUSE_PRESS: case CACA_EVENT_MOUSE_PRESS:
cucul_printf(c, x, y, "CACA_EVENT_MOUSE_PRESS %u",
cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_PRESS %u",
ev->data.mouse.button); ev->data.mouse.button);
break; break;
case CACA_EVENT_MOUSE_RELEASE: case CACA_EVENT_MOUSE_RELEASE:
cucul_printf(c, x, y, "CACA_EVENT_MOUSE_RELEASE %u",
cucul_printf(cv, x, y, "CACA_EVENT_MOUSE_RELEASE %u",
ev->data.mouse.button); ev->data.mouse.button);
break; break;
case CACA_EVENT_RESIZE: case CACA_EVENT_RESIZE:
cucul_printf(c, x, y, "CACA_EVENT_RESIZE %u %u",
cucul_printf(cv, x, y, "CACA_EVENT_RESIZE %u %u",
ev->data.resize.w, ev->data.resize.h); ev->data.resize.w, ev->data.resize.h);
break; break;
case CACA_EVENT_QUIT: case CACA_EVENT_QUIT:
cucul_printf(c, x, y, "CACA_EVENT_QUIT");
cucul_printf(cv, x, y, "CACA_EVENT_QUIT");
break; break;
default: default:
cucul_printf(c, x, y, "CACA_EVENT_UNKNOWN");
cucul_printf(cv, x, y, "CACA_EVENT_UNKNOWN");
} }
} }



+ 16
- 16
test/export.c View File

@@ -34,7 +34,7 @@ uint32_t pixels[256*256];


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *c;
cucul_canvas_t *cv;
cucul_dither_t *dither; cucul_dither_t *dither;
cucul_buffer_t *buffer; cucul_buffer_t *buffer;
char const * const * exports, * const * p; char const * const * exports, * const * p;
@@ -65,7 +65,7 @@ int main(int argc, char *argv[])
exit(-1); exit(-1);
} }


c = cucul_create(WIDTH, HEIGHT);
cv = cucul_create(WIDTH, HEIGHT);


for(y = 0; y < 256; y++) for(y = 0; y < 256; y++)
{ {
@@ -80,34 +80,34 @@ int main(int argc, char *argv[])


dither = cucul_create_dither(32, 256, 256, 4 * 256, dither = cucul_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, pixels); dither, pixels);
cucul_free_dither(dither); cucul_free_dither(dither);


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(c, 0, 0, WIDTH - 1, HEIGHT - 1);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 0, 0, WIDTH - 1, HEIGHT - 1);


cucul_set_color(c, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
cucul_fill_ellipse(c, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
cucul_putstr(c, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
cucul_putstr(c, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
cucul_fill_ellipse(cv, WIDTH / 2, HEIGHT / 2, WIDTH / 4, HEIGHT / 4, " ");
cucul_putstr(cv, WIDTH / 2 - 5, HEIGHT / 2 - 2, "(\") \\o/ <&>");
cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
cucul_putstr(c, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
cucul_putstr(cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");


for(x = 0; x < 16; x++) for(x = 0; x < 16; x++)
{ {
cucul_set_truecolor(c, 0xff00 | x, 0xf00f | (x << 4));
cucul_putstr(c, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
cucul_set_truecolor(cv, 0xff00 | x, 0xf00f | (x << 4));
cucul_putstr(cv, WIDTH / 2 - 7 + x, HEIGHT / 2 + 5, "#");
} }


buffer = cucul_create_export(c, argv[1]);
buffer = cucul_create_export(cv, argv[1]);
fwrite(cucul_get_buffer_data(buffer), fwrite(cucul_get_buffer_data(buffer),
cucul_get_buffer_size(buffer), 1, stdout); cucul_get_buffer_size(buffer), 1, stdout);
cucul_free_buffer(buffer); cucul_free_buffer(buffer);


cucul_free(c);
cucul_free(cv);


return 0; return 0;
} }


+ 20
- 20
test/font.c View File

@@ -34,8 +34,8 @@ typedef unsigned int uint32_t;


int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;
cucul_font_t *f; cucul_font_t *f;
cucul_dither_t *d; cucul_dither_t *d;
caca_event_t ev; caca_event_t ev;
@@ -44,15 +44,15 @@ int main(int argc, char *argv[])
char const * const * fonts; char const * const * fonts;


/* Create a canvas */ /* Create a canvas */
c = cucul_create(8, 2);
cv = cucul_create(8, 2);


/* Draw stuff on our canvas */ /* Draw stuff on our canvas */
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(c, 0, 0, "ABcde");
cucul_set_color(c, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
cucul_putstr(c, 5, 0, "\\o/");
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, 0, 1, "&$âøÿØ?!");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 0, 0, "ABcde");
cucul_set_color(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 5, 0, "\\o/");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, 0, 1, "&$âøÿØ?!");


/* Load a libcucul internal font */ /* Load a libcucul internal font */
fonts = cucul_get_font_list(); fonts = cucul_get_font_list();
@@ -69,16 +69,16 @@ int main(int argc, char *argv[])
} }


/* Create our bitmap buffer (32-bit ARGB) */ /* Create our bitmap buffer (32-bit ARGB) */
w = cucul_get_width(c) * cucul_get_font_width(f);
h = cucul_get_height(c) * cucul_get_font_height(f);
w = cucul_get_width(cv) * cucul_get_font_width(f);
h = cucul_get_height(cv) * cucul_get_font_height(f);
buf = malloc(4 * w * h); buf = malloc(4 * w * h);


/* Render the canvas onto our image buffer */ /* Render the canvas onto our image buffer */
cucul_render_canvas(c, f, buf, w, h, 4 * w);
cucul_render_canvas(cv, f, buf, w, h, 4 * w);


/* Just for fun, render the image using libcaca */ /* Just for fun, render the image using libcaca */
cucul_set_size(c, 80, 32);
kk = caca_attach(c);
cucul_set_size(cv, 80, 32);
dp = caca_attach(cv);


#if defined(HAVE_ENDIAN_H) #if defined(HAVE_ENDIAN_H)
if(__BYTE_ORDER == __BIG_ENDIAN) if(__BYTE_ORDER == __BIG_ENDIAN)
@@ -93,18 +93,18 @@ int main(int argc, char *argv[])
d = cucul_create_dither(32, w, h, 4 * w, d = cucul_create_dither(32, w, h, 4 * w,
0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff); 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff);


cucul_dither_bitmap(c, 0, 0, cucul_get_width(c) - 1,
cucul_get_height(c) - 1, d, buf);
caca_display(kk);
cucul_dither_bitmap(cv, 0, 0, cucul_get_width(cv) - 1,
cucul_get_height(cv) - 1, d, buf);
caca_display(dp);


caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


/* Free everything */ /* Free everything */
caca_detach(kk);
caca_detach(dp);
free(buf); free(buf);
cucul_free_dither(d); cucul_free_dither(d);
cucul_free_font(f); cucul_free_font(f);
cucul_free(c);
cucul_free(cv);


return 0; return 0;
} }


+ 20
- 20
test/gamma.c View File

@@ -34,17 +34,17 @@ uint32_t buffer[256 * 4];
int main(void) int main(void)
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c, *gg, *mask;
caca_t *kk;
cucul_canvas_t *cv, *cw, *mask;
caca_display_t *dp;
cucul_dither_t *left, *right; cucul_dither_t *left, *right;
float gam = 1.0; float gam = 1.0;
int x; int x;


c = cucul_create(0, 0);
kk = caca_attach(c);
cv = cucul_create(0, 0);
dp = caca_attach(cv);


gg = cucul_create(cucul_get_width(c), cucul_get_height(c));
mask = cucul_create(cucul_get_width(c), cucul_get_height(c));
cw = cucul_create(cucul_get_width(cv), cucul_get_height(cv));
mask = cucul_create(cucul_get_width(cv), cucul_get_height(cv));


for(x = 0; x < 256; x++) for(x = 0; x < 256; x++)
{ {
@@ -58,11 +58,11 @@ int main(void)
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
right = cucul_create_dither(32, 256, 4, 4 * 256, right = cucul_create_dither(32, 256, 4, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
caca_set_delay(kk, 20000);
caca_set_delay(dp, 20000);


for(x = 0; ; x++) for(x = 0; ; x++)
{ {
int ret = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0);
int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);


if(ret) if(ret)
{ {
@@ -77,18 +77,18 @@ int main(void)
} }


/* Resize the spare canvas, just in case the main one changed */ /* Resize the spare canvas, just in case the main one changed */
cucul_set_size(gg, cucul_get_width(c), cucul_get_height(c));
cucul_set_size(mask, cucul_get_width(c), cucul_get_height(c));
cucul_set_size(cw, cucul_get_width(cv), cucul_get_height(cv));
cucul_set_size(mask, cucul_get_width(cv), cucul_get_height(cv));


/* Draw the regular dither on the main canvas */ /* Draw the regular dither on the main canvas */
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
left, buffer); left, buffer);


/* Draw the gamma-modified dither on the spare canvas */ /* Draw the gamma-modified dither on the spare canvas */
cucul_set_dither_gamma(right, gam); cucul_set_dither_gamma(right, gam);
cucul_dither_bitmap(gg, 0, 0,
cucul_get_width(gg) - 1, cucul_get_height(gg) - 1,
cucul_dither_bitmap(cw, 0, 0,
cucul_get_width(cw) - 1, cucul_get_height(cw) - 1,
right, buffer); right, buffer);


/* Draw something on the mask */ /* Draw something on the mask */
@@ -102,20 +102,20 @@ int main(void)
cucul_get_height(mask) / 2, "#"); cucul_get_height(mask) / 2, "#");


/* Blit the spare canvas onto the first one */ /* Blit the spare canvas onto the first one */
cucul_blit(c, 0, 0, gg, mask);
cucul_blit(cv, 0, 0, cw, mask);


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_printf(c, 2, 1,
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_printf(cv, 2, 1,
"gamma=%g - use arrows to change, Esc to quit", gam); "gamma=%g - use arrows to change, Esc to quit", gam);


caca_display(kk);
caca_display(dp);
} }


cucul_free_dither(left); cucul_free_dither(left);
cucul_free_dither(right); cucul_free_dither(right);


caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 10
- 10
test/hsv.c View File

@@ -29,14 +29,14 @@ uint32_t buffer[256*256];
int main(void) int main(void)
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;


cucul_dither_t *dither; cucul_dither_t *dither;
int x, y; int x, y;


c = cucul_create(0, 0);
kk = caca_attach(c);
cv = cucul_create(0, 0);
dp = caca_attach(cv);


for(y = 0; y < 256; y++) for(y = 0; y < 256; y++)
for(x = 0; x < 256; x++) for(x = 0; x < 256; x++)
@@ -46,17 +46,17 @@ int main(void)


dither = cucul_create_dither(32, 256, 256, 4 * 256, dither = cucul_create_dither(32, 256, 256, 4 * 256,
0x00ff0000, 0x0000ff00, 0x000000ff, 0x0); 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
cucul_dither_bitmap(c, 0, 0,
cucul_get_width(c) - 1, cucul_get_height(c) - 1,
cucul_dither_bitmap(cv, 0, 0,
cucul_get_width(cv) - 1, cucul_get_height(cv) - 1,
dither, buffer); dither, buffer);
cucul_free_dither(dither); cucul_free_dither(dither);


caca_display(kk);
caca_display(dp);


caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 27
- 27
test/spritedit.c View File

@@ -22,8 +22,8 @@


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;


int quit = 0; int quit = 0;
cucul_sprite_t *sprite; cucul_sprite_t *sprite;
@@ -37,19 +37,19 @@ int main(int argc, char **argv)
return 1; return 1;
} }


c = cucul_create(0, 0);
if(!c)
cv = cucul_create(0, 0);
if(!cv)
return 1; return 1;
kk = caca_attach(c);
if(!kk)
dp = caca_attach(cv);
if(!dp)
return 1; return 1;


sprite = cucul_load_sprite(argv[1]); sprite = cucul_load_sprite(argv[1]);


if(!sprite) if(!sprite)
{ {
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);
fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]); fprintf(stderr, "%s: could not open `%s'.\n", argv[0], argv[1]);
return 1; return 1;
} }
@@ -61,7 +61,7 @@ int main(int argc, char **argv)
int xa, ya, xb, yb; int xa, ya, xb, yb;
char buf[BUFSIZ]; char buf[BUFSIZ];


while(caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0))
while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
{ {
switch(ev.data.key.ch) switch(ev.data.key.ch)
{ {
@@ -100,43 +100,43 @@ int main(int argc, char **argv)
} }




cucul_clear(c);
cucul_clear(cv);


cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(c, 0, 0, cucul_get_width(c) - 1, cucul_get_height(c) - 1);
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 0, 0, cucul_get_width(cv) - 1, cucul_get_height(cv) - 1);


cucul_putstr(c, 3, 0, "[ Sprite editor for libcaca ]");
cucul_putstr(cv, 3, 0, "[ Sprite editor for libcaca ]");


sprintf(buf, "sprite `%s'", argv[1]); sprintf(buf, "sprite `%s'", argv[1]);
cucul_putstr(c, 3, 2, buf);
cucul_putstr(cv, 3, 2, buf);
sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1); sprintf(buf, "frame %i/%i", frame, cucul_get_sprite_frames(sprite) - 1);
cucul_putstr(c, 3, 3, buf);
cucul_putstr(cv, 3, 3, buf);


/* Crosshair */ /* Crosshair */
cucul_draw_thin_line(c, 57, 2, 57, 18);
cucul_draw_thin_line(c, 37, 10, 77, 10);
cucul_putchar(c, 57, 10, '+');
cucul_draw_thin_line(cv, 57, 2, 57, 18);
cucul_draw_thin_line(cv, 37, 10, 77, 10);
cucul_putchar(cv, 57, 10, '+');


/* Boxed sprite */ /* Boxed sprite */
xa = -1 - cucul_get_sprite_dx(sprite, frame); xa = -1 - cucul_get_sprite_dx(sprite, frame);
ya = -1 - cucul_get_sprite_dy(sprite, frame); ya = -1 - cucul_get_sprite_dy(sprite, frame);
xb = xa + 1 + cucul_get_sprite_width(sprite, frame); xb = xa + 1 + cucul_get_sprite_width(sprite, frame);
yb = ya + 1 + cucul_get_sprite_height(sprite, frame); yb = ya + 1 + cucul_get_sprite_height(sprite, frame);
cucul_set_color(c, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
cucul_fill_box(c, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(c, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
cucul_draw_sprite(c, 57, 10, sprite, frame);
cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_BLACK);
cucul_fill_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb, " ");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_draw_thin_box(cv, 57 + xa, 10 + ya, 57 + xb, 10 + yb);
cucul_draw_sprite(cv, 57, 10, sprite, frame);


/* Free sprite */ /* Free sprite */
cucul_draw_sprite(c, 20, 10, sprite, frame);
cucul_draw_sprite(cv, 20, 10, sprite, frame);


caca_display(kk);
caca_display(dp);
} }


/* Clean up */ /* Clean up */
caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 17
- 17
test/transform.c View File

@@ -50,12 +50,12 @@ static char const *duck[] =
int main(void) int main(void)
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c, *normal, *flip, *flop, *rotate;
caca_t *kk;
cucul_canvas_t *cv, *normal, *flip, *flop, *rotate;
caca_display_t *dp;
int i; int i;


c = cucul_create(0, 0);
kk = caca_attach(c);
cv = cucul_create(0, 0);
dp = caca_attach(cv);


normal = cucul_create(70, 6); normal = cucul_create(70, 6);
flip = cucul_create(70, 6); flip = cucul_create(70, 6);
@@ -96,26 +96,26 @@ int main(void)
cucul_rotate(rotate); cucul_rotate(rotate);


/* Blit the transformed canvas onto the main canvas */ /* Blit the transformed canvas onto the main canvas */
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, 0, 0, "normal");
cucul_blit(c, 10, 0, normal, NULL);
cucul_putstr(c, 0, 6, "flip");
cucul_blit(c, 10, 6, flip, NULL);
cucul_putstr(c, 0, 12, "flop");
cucul_blit(c, 10, 12, flop, NULL);
cucul_putstr(c, 0, 18, "rotate");
cucul_blit(c, 10, 18, rotate, NULL);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, 0, 0, "normal");
cucul_blit(cv, 10, 0, normal, NULL);
cucul_putstr(cv, 0, 6, "flip");
cucul_blit(cv, 10, 6, flip, NULL);
cucul_putstr(cv, 0, 12, "flop");
cucul_blit(cv, 10, 12, flop, NULL);
cucul_putstr(cv, 0, 18, "rotate");
cucul_blit(cv, 10, 18, rotate, NULL);


caca_display(kk);
caca_display(dp);


caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(kk);
caca_detach(dp);
cucul_free(rotate); cucul_free(rotate);
cucul_free(flop); cucul_free(flop);
cucul_free(flip); cucul_free(flip);
cucul_free(normal); cucul_free(normal);
cucul_free(c);
cucul_free(cv);


return 0; return 0;
} }


+ 12
- 12
test/truecolor.c View File

@@ -27,13 +27,13 @@ typedef unsigned int uint32_t;
int main(void) int main(void)
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c;
caca_t *kk;
cucul_canvas_t *cv;
caca_display_t *dp;


int x, y; int x, y;


c = cucul_create(32, 16);
kk = caca_attach(c);
cv = cucul_create(32, 16);
dp = caca_attach(cv);


for(y = 0; y < 16; y++) for(y = 0; y < 16; y++)
for(x = 0; x < 16; x++) for(x = 0; x < 16; x++)
@@ -41,19 +41,19 @@ int main(void)
uint16_t bgcolor = 0xff00 | (y << 4) | x; uint16_t bgcolor = 0xff00 | (y << 4) | x;
uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8); uint16_t fgcolor = 0xf000 | ((15 - y) << 4) | ((15 - x) << 8);


cucul_set_truecolor(c, fgcolor, bgcolor);
cucul_putstr(c, x * 2, y, "CA");
cucul_set_truecolor(cv, fgcolor, bgcolor);
cucul_putstr(cv, x * 2, y, "CA");
} }


cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
cucul_putstr(c, 2, 1, " truecolor libcaca ");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_LIGHTBLUE);
cucul_putstr(cv, 2, 1, " truecolor libcaca ");


caca_display(kk);
caca_display(dp);


caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);


caca_detach(kk);
cucul_free(c);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


+ 64
- 64
test/unicode.c View File

@@ -27,70 +27,70 @@ typedef unsigned int uint32_t;
int main(void) int main(void)
{ {
caca_event_t ev; caca_event_t ev;
cucul_canvas_t *c;
caca_t *kk;
c = cucul_create(0, 0);
kk = caca_attach(c);
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, 1, 1, "Basic Unicode support");
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(c, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
cucul_putstr(c, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
cucul_putstr(c, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
cucul_putstr(c, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, 1, 7, "Gradient glyphs");
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(c, 31, 8, " 0%");
cucul_putstr(c, 31, 9, " 25%");
cucul_putstr(c, 31, 10, " 50%");
cucul_putstr(c, 31, 11, " 75%");
cucul_putstr(c, 31, 12, "100%");
cucul_set_color(c, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTGREEN);
cucul_putstr(c, 1, 8, " ");
cucul_putstr(c, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_putstr(c, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_putstr(c, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_putstr(c, 1, 12, "█████████████████████████████");
cucul_set_color(c, CUCUL_COLOR_LIGHTGREEN, CUCUL_COLOR_LIGHTRED);
cucul_putstr(c, 36, 8, "█████████████████████████████");
cucul_putstr(c, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_putstr(c, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_putstr(c, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_putstr(c, 36, 12, " ");
cucul_set_color(c, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(c, 1, 14, "Double width characters");
cucul_set_color(c, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
cucul_putstr(c, 1, 15, "| ドラゴン ボーレ |");
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(c, 1, 16, "| ()()()() ()()() |");
cucul_set_color(c, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_putstr(c, 1, 17, "| ドラゴン");
cucul_putstr(c, 10, 17, "ボーレ |");
cucul_set_color(c, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(c, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
cucul_putstr(c, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
cucul_putstr(c, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
cucul_putstr(c, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟");
caca_display(kk);
caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_detach(kk);
cucul_free(c);
cucul_canvas_t *cv;
caca_display_t *dp;
cv = cucul_create(0, 0);
dp = caca_attach(cv);
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, 1, 1, "Basic Unicode support");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
cucul_putstr(cv, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
cucul_putstr(cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
cucul_putstr(cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, 1, 7, "Gradient glyphs");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 31, 8, " 0%");
cucul_putstr(cv, 31, 9, " 25%");
cucul_putstr(cv, 31, 10, " 50%");
cucul_putstr(cv, 31, 11, " 75%");
cucul_putstr(cv, 31, 12, "100%");
cucul_set_color(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_LIGHTGREEN);
cucul_putstr(cv, 1, 8, " ");
cucul_putstr(cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_putstr(cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_putstr(cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_putstr(cv, 1, 12, "█████████████████████████████");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGREEN, CUCUL_COLOR_LIGHTRED);
cucul_putstr(cv, 36, 8, "█████████████████████████████");
cucul_putstr(cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
cucul_putstr(cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
cucul_putstr(cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
cucul_putstr(cv, 36, 12, " ");
cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
cucul_putstr(cv, 1, 14, "Double width characters");
cucul_set_color(cv, CUCUL_COLOR_LIGHTRED, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 1, 15, "| ドラゴン ボーレ |");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 1, 16, "| ()()()() ()()() |");
cucul_set_color(cv, CUCUL_COLOR_YELLOW, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 1, 17, "| ドラゴン");
cucul_putstr(cv, 10, 17, "ボーレ |");
cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
cucul_putstr(cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
cucul_putstr(cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
cucul_putstr(cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
cucul_putstr(cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟");
caca_display(dp);
caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
caca_detach(dp);
cucul_free(cv);


return 0; return 0;
} }


Loading…
Cancel
Save