Changeset 524


Ignore:
Timestamp:
Mar 5, 2006, 7:43:13 PM (15 years ago)
Author:
Sam Hocevar
Message:

A new low-level text management library (canvas for ultrafast compositing

of unicode letters) is now separated from the higher level rendering and I/O
(that is, libcaca). This commit totally breaks the API, but once everything
is polished I will think about source-level backward compatibility. Most
drivers are broken, but X11 still sorta works.

The new design is much more object-oriented and allows having several

active renderers at the same time, changing renderers on the fly, and more
important, having no renderer at all (useful for converters, or when you
want to do your own renderer).

And in case you are still wondering, the libcucul acronym has "Unicode"

because I want to support at least a subset of Unicode. There are awesome
glyphs in it, including the ones inherited from Codepage 437 such as
"gray 25%" that are used in DOS and Win32 ANSI art.

Location:
libcaca/trunk
Files:
4 added
30 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/configure.ac

    r487 r524  
    1414
    1515AC_LIBTOOL_WIN32_DLL
    16 AC_DISABLE_SHARED
    1716AM_PROG_LIBTOOL
    1817
     
    175174AC_SUBST(MATH_LIBS)
    176175AC_SUBST(CACA_LIBS)
     176AC_SUBST(CUCUL_LIBS)
    177177
    178178# Optimizations
  • libcaca/trunk/doc/doxygen.cfg.in

    r298 r524  
    6363#---------------------------------------------------------------------------
    6464INPUT                  = @top_srcdir@/src
    65 FILE_PATTERNS          = *.c \
    66                          caca.h
     65FILE_PATTERNS          = *.c cucul.h caca.h
    6766RECURSIVE              = YES
    6867EXCLUDE                = ../src/config.h
  • libcaca/trunk/examples

    • Property svn:ignore
      •  

        old new  
        33.libs
        44.deps
        5 cacademo
        6 cacademo.exe
        75caca-spritedit
        86caca-spritedit.exe
  • libcaca/trunk/examples/Makefile.am

    r475 r524  
    55EXTRA_DIST = caca.txt
    66
    7 bin_PROGRAMS = cacademo cacafire cacaball cacaplas cacaview cacamoir
    8 
    9 cacademo_SOURCES = demo.c
    10 cacademo_LDADD = ../src/libcaca.la @CACA_LIBS@ @MATH_LIBS@
    11 cacademo_CPPFLAGS = -I$(top_srcdir)/src -DDATADIR=\"$(pkgdatadir)\"
     7bin_PROGRAMS = cacafire cacaball cacaplas cacaview cacamoir
    128
    139cacafire_SOURCES = aafire.c
  • libcaca/trunk/examples/aafire.c

    r514 r524  
    3838#define MAXTABLE (256*5)
    3939#ifdef LIBCACA
     40static cucul_t *qq;
     41static caca_t *kk;
    4042static int XSIZ, YSIZ;
    41 static struct caca_bitmap *caca_bitmap;
     43static struct cucul_bitmap *cucul_bitmap;
    4244static char *bitmap;
    4345static int pause = 0;
     
    9799
    98100#ifdef LIBCACA
    99   if (caca_init())
     101  qq = cucul_init();
     102  if (!qq)
     103    {
     104      printf ("Failed to initialize libcucul\n");
     105      exit (1);
     106    }
     107  kk = caca_attach(qq);
     108  if (!kk)
    100109    {
    101110      printf ("Failed to initialize libcaca\n");
    102111      exit (1);
    103112    }
    104   caca_set_delay(10000);
    105   XSIZ = caca_get_width() * 2;
    106   YSIZ = caca_get_height() * 2 - 4;
     113  caca_set_delay(kk, 10000);
     114  XSIZ = cucul_get_width(qq) * 2;
     115  YSIZ = cucul_get_height(qq) * 2 - 4;
    107116#else
    108117  context = aa_autoinit (&aa_defparams);
     
    130139
    131140#ifdef LIBCACA
    132   caca_bitmap = caca_create_bitmap(8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
    133   caca_set_bitmap_palette(caca_bitmap, r, g, b, a);
    134   bitmap = malloc(4 * caca_get_width() * caca_get_height() * sizeof(char));
    135   memset(bitmap, 0, 4 * caca_get_width() * caca_get_height());
     141  cucul_bitmap = cucul_create_bitmap(qq, 8, XSIZ, YSIZ - 2, XSIZ, 0, 0, 0, 0);
     142  cucul_set_bitmap_palette(qq, cucul_bitmap, r, g, b, a);
     143  bitmap = malloc(4 * cucul_get_width(qq) * cucul_get_height(qq) * sizeof(char));
     144  memset(bitmap, 0, 4 * cucul_get_width(qq) * cucul_get_height(qq));
    136145#else
    137146  aa_hidecursor (context);
     
    142151{
    143152#ifdef LIBCACA
    144   caca_end();
     153  caca_detach(kk);
     154  cucul_end(qq);
    145155#else
    146156  aa_close (context);
     
    224234#ifdef LIBCACA
    225235paused:
    226   caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
    227                    caca_bitmap, bitmap);
    228   caca_refresh();
     236  cucul_draw_bitmap(qq, 0, 0,
     237                    cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
     238                    cucul_bitmap, bitmap);
     239  caca_refresh(kk);
    229240  /*XSIZ = caca_get_width() * 2;
    230241  YSIZ = caca_get_height() * 2 - 4;*/
     
    249260    {
    250261#ifdef LIBCACA
    251       switch (caca_get_event(CACA_EVENT_KEY_PRESS))
     262      switch (caca_get_event(kk, CACA_EVENT_KEY_PRESS))
    252263        {
    253264          case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: return;
  • libcaca/trunk/examples/cacaball.c

    r522 r524  
    2323#endif
    2424
     25#include "cucul.h"
    2526#include "caca.h"
    2627
     
    4344int main(int argc, char **argv)
    4445{
     46    cucul_t *qq; caca_t *kk;
    4547    unsigned int r[256], g[256], b[256], a[256];
    4648    float d[METABALLS], di[METABALLS], dj[METABALLS], dk[METABALLS];
    4749    unsigned int x[METABALLS], y[METABALLS];
    48     struct caca_bitmap *caca_bitmap;
     50    struct cucul_bitmap *cucul_bitmap;
    4951    float i = 10.0, j = 17.0, k = 11.0;
    5052    int p, frame = 0, pause = 0;
    5153
    52     if(caca_init())
     54    qq = cucul_init();
     55    if(!qq)
    5356        return 1;
    54 
    55     caca_set_delay(20000);
     57    kk = caca_attach(qq);
     58    if(!kk)
     59        return 1;
     60
     61    caca_set_delay(kk, 20000);
    5662
    5763    /* Make the palette eatable by libcaca */
     
    6066    r[255] = g[255] = b[255] = 0xfff;
    6167
    62     /* Create a libcaca bitmap smaller than our pixel buffer, so that we
     68    /* Create a libcucul bitmap smaller than our pixel buffer, so that we
    6369     * display only the interesting part of it */
    64     caca_bitmap = caca_create_bitmap(8, XSIZ - METASIZE, YSIZ - METASIZE,
    65                                      XSIZ, 0, 0, 0, 0);
     70    cucul_bitmap = cucul_create_bitmap(qq, 8, XSIZ - METASIZE, YSIZ - METASIZE,
     71                                       XSIZ, 0, 0, 0, 0);
    6672
    6773    /* Generate ball sprite */
     
    7076    for(p = 0; p < METABALLS; p++)
    7177    {
    72         d[p] = caca_rand(0, 100);
    73         di[p] = (float)caca_rand(500, 4000) / 6000.0;
    74         dj[p] = (float)caca_rand(500, 4000) / 6000.0;
    75         dk[p] = (float)caca_rand(500, 4000) / 6000.0;
     78        d[p] = cucul_rand(0, 100);
     79        di[p] = (float)cucul_rand(500, 4000) / 6000.0;
     80        dj[p] = (float)cucul_rand(500, 4000) / 6000.0;
     81        dk[p] = (float)cucul_rand(500, 4000) / 6000.0;
    7682    }
    7783
     
    7985    for(;;)
    8086    {
    81         switch(caca_get_event(CACA_EVENT_KEY_PRESS))
     87        switch(caca_get_event(kk, CACA_EVENT_KEY_PRESS))
    8288        {
    8389            case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end;
     
    110116
    111117        /* Set the palette */
    112         caca_set_bitmap_palette(caca_bitmap, r, g, b, a);
     118        cucul_set_bitmap_palette(qq, cucul_bitmap, r, g, b, a);
    113119
    114120        /* Silly paths for our balls */
     
    135141
    136142paused:
    137         /* Draw our virtual buffer to screen, letting libcaca resize it */
    138         caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
    139                          caca_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ));
    140         caca_refresh();
     143        /* Draw our virtual buffer to screen, letting libcucul resize it */
     144        cucul_draw_bitmap(qq, 0, 0,
     145                          cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
     146                          cucul_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ));
     147        caca_refresh(kk);
    141148    }
    142149
    143150    /* End, bye folks */
    144151end:
    145     caca_free_bitmap(caca_bitmap);
    146     caca_end();
     152    cucul_free_bitmap(qq, cucul_bitmap);
     153    caca_detach(kk);
     154    cucul_end(qq);
    147155
    148156    return 0;
  • libcaca/trunk/examples/cacamoir.c

    r522 r524  
    1717#include <string.h>
    1818
     19#include "cucul.h"
    1920#include "caca.h"
    2021
     
    3536int main (int argc, char **argv)
    3637{
     38    cucul_t *qq; caca_t *kk;
    3739    unsigned int red[256], green[256], blue[256], alpha[256];
    38     struct caca_bitmap *bitmap;
     40    struct cucul_bitmap *bitmap;
    3941    int i, x, y, frame = 0, pause = 0;
    4042
    41     if(caca_init() < 0)
     43    qq = cucul_init();
     44    if(!qq)
     45        return 1;
     46    kk = caca_attach(qq);
     47    if(!kk)
    4248        return 1;
    4349
    44     caca_set_delay(20000);
     50    caca_set_delay(kk, 20000);
    4551
    4652    /* Fill various tables */
     
    5561        draw_disc(i, (i / DISCTHICKNESS) % 2);
    5662
    57     /* Create a libcaca bitmap */
    58     bitmap = caca_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
     63    /* Create a libcucul bitmap */
     64    bitmap = cucul_create_bitmap(qq, 8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
    5965
    6066    /* Main loop */
    6167    for(;;)
    6268    {
    63         switch(caca_get_event(CACA_EVENT_KEY_PRESS))
     69        switch(caca_get_event(kk, CACA_EVENT_KEY_PRESS))
    6470        {
    6571            case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end;
     
    8187        blue[1] = 0.5 * (1 + cos(0.05 * frame + 5.0)) * 0xfff;
    8288
    83         caca_set_bitmap_palette(bitmap, red, green, blue, alpha);
     89        cucul_set_bitmap_palette(qq, bitmap, red, green, blue, alpha);
    8490
    8591        /* Draw circles */
     
    95101
    96102paused:
    97         caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
    98                          bitmap, screen);
    99         caca_refresh();
     103        cucul_draw_bitmap(qq, 0, 0,
     104                          cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
     105                          bitmap, screen);
     106        caca_refresh(kk);
    100107    }
    101108
    102109end:
    103     caca_free_bitmap(bitmap);
    104     caca_end();
     110    cucul_free_bitmap(qq, bitmap);
     111    caca_detach(kk);
     112    cucul_end(qq);
    105113
    106114    return 0;
  • libcaca/trunk/examples/cacaplas.c

    r522 r524  
    2121#endif
    2222
     23#include "cucul.h"
    2324#include "caca.h"
    2425
     
    3839int main (int argc, char **argv)
    3940{
     41    cucul_t *qq; caca_t *kk;
    4042    unsigned int red[256], green[256], blue[256], alpha[256];
    4143    double r[3], R[6];
    42     struct caca_bitmap *bitmap;
     44    struct cucul_bitmap *bitmap;
    4345    int i, x, y, frame = 0, pause = 0;
    4446
    45     if(caca_init() < 0)
     47    qq = cucul_init();
     48    if(!qq)
     49        return 1;
     50    kk = caca_attach(qq);
     51    if(!kk)
    4652        return 1;
    4753
    48     caca_set_delay(20000);
     54    caca_set_delay(kk, 20000);
    4955
    5056    /* Fill various tables */
     
    5359
    5460    for(i = 0; i < 3; i++)
    55         r[i] = (double)(caca_rand(1, 1000)) / 60000 * M_PI;
     61        r[i] = (double)(cucul_rand(1, 1000)) / 60000 * M_PI;
    5662
    5763    for(i = 0; i < 6; i++)
    58         R[i] = (double)(caca_rand(1, 1000)) / 10000;
     64        R[i] = (double)(cucul_rand(1, 1000)) / 10000;
    5965
    6066    for(y = 0 ; y < TABLEY ; y++)
     
    6874    }
    6975
    70     /* Create a libcaca bitmap */
    71     bitmap = caca_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
     76    /* Create a libcucul bitmap */
     77    bitmap = cucul_create_bitmap(qq, 8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0);
    7278
    7379    /* Main loop */
    7480    for(;;)
    7581    {
    76         switch(caca_get_event(CACA_EVENT_KEY_PRESS))
     82        switch(caca_get_event(kk, CACA_EVENT_KEY_PRESS))
    7783        {
    7884            case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end;
     
    9399
    94100        /* Set the palette */
    95         caca_set_bitmap_palette(bitmap, red, green, blue, alpha);
     101        cucul_set_bitmap_palette(qq, bitmap, red, green, blue, alpha);
    96102
    97103        do_plasma(screen,
     
    105111
    106112paused:
    107         caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1,
    108                          bitmap, screen);
    109         caca_refresh();
     113        cucul_draw_bitmap(qq, 0, 0,
     114                          cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
     115                          bitmap, screen);
     116        caca_refresh(kk);
    110117    }
    111118
    112119end:
    113     caca_free_bitmap(bitmap);
    114     caca_end();
     120    cucul_free_bitmap(qq, bitmap);
     121    caca_detach(kk);
     122    cucul_end(qq);
    115123
    116124    return 0;
  • libcaca/trunk/examples/cacaview.c

    r522 r524  
    2828#endif
    2929
     30#include "cucul.h"
    3031#include "caca.h"
    3132
     
    4142#define ZOOM_MAX 50
    4243#define PAD_STEP 0.15
     44
     45/* libcucul/libcaca contexts */
     46cucul_t *qq; caca_t *kk;
    4347
    4448/* Local functions */
     
    6064#endif
    6165char *pixels = NULL;
    62 struct caca_bitmap *bitmap = NULL;
     66struct cucul_bitmap *bitmap = NULL;
    6367unsigned int w, h, depth, bpp, rmask, gmask, bmask, amask;
    6468#if !defined(HAVE_IMLIB2_H)
     
    7983    int i;
    8084
    81     /* Initialise libcaca */
    82     if(caca_init())
     85    /* Initialise libcucul */
     86    qq = cucul_init();
     87    if(!qq)
     88    {
     89        fprintf(stderr, "%s: unable to initialise libcucul\n", argv[0]);
     90        return 1;
     91    }
     92
     93    kk = caca_attach(qq);
     94    if(!kk)
    8395    {
    8496        fprintf(stderr, "%s: unable to initialise libcaca\n", argv[0]);
     
    8799
    88100    /* Set the window title */
    89     caca_set_window_title("cacaview");
    90 
    91     ww = caca_get_width();
    92     wh = caca_get_height();
     101    caca_set_window_title(kk, "cacaview");
     102
     103    ww = cucul_get_width(qq);
     104    wh = cucul_get_height(qq);
    93105
    94106    /* Fill the zoom table */
     
    128140
    129141        if(update)
    130             event = caca_get_event(event_mask);
     142            event = caca_get_event(kk, event_mask);
    131143        else
    132             event = caca_wait_event(event_mask);
     144            event = caca_wait_event(kk, event_mask);
    133145
    134146        while(event)
     
    166178                break;
    167179            case 'b':
    168                 i = 1 + caca_get_feature(CACA_BACKGROUND);
    169                 if(i > CACA_BACKGROUND_MAX) i = CACA_BACKGROUND_MIN;
    170                 caca_set_feature(i);
     180                i = 1 + cucul_get_feature(qq, CUCUL_BACKGROUND);
     181                if(i > CUCUL_BACKGROUND_MAX) i = CUCUL_BACKGROUND_MIN;
     182                cucul_set_feature(qq, i);
    171183                new_status = STATUS_BACKGROUND;
    172184                update = 1;
    173185                break;
    174186            case 'B':
    175                 i = -1 + caca_get_feature(CACA_BACKGROUND);
    176                 if(i < CACA_BACKGROUND_MIN) i = CACA_BACKGROUND_MAX;
    177                 caca_set_feature(i);
     187                i = -1 + cucul_get_feature(qq, CUCUL_BACKGROUND);
     188                if(i < CUCUL_BACKGROUND_MIN) i = CUCUL_BACKGROUND_MAX;
     189                cucul_set_feature(qq, i);
    178190                new_status = STATUS_BACKGROUND;
    179191                update = 1;
    180192                break;
    181193            case 'a':
    182                 i = 1 + caca_get_feature(CACA_ANTIALIASING);
    183                 if(i > CACA_ANTIALIASING_MAX) i = CACA_ANTIALIASING_MIN;
    184                 caca_set_feature(i);
     194                i = 1 + cucul_get_feature(qq, CUCUL_ANTIALIASING);
     195                if(i > CUCUL_ANTIALIASING_MAX) i = CUCUL_ANTIALIASING_MIN;
     196                cucul_set_feature(qq, i);
    185197                new_status = STATUS_ANTIALIASING;
    186198                update = 1;
    187199                break;
    188200            case 'A':
    189                 i = -1 + caca_get_feature(CACA_ANTIALIASING);
    190                 if(i < CACA_ANTIALIASING_MIN) i = CACA_ANTIALIASING_MAX;
    191                 caca_set_feature(i);
     201                i = -1 + cucul_get_feature(qq, CUCUL_ANTIALIASING);
     202                if(i < CUCUL_ANTIALIASING_MIN) i = CUCUL_ANTIALIASING_MAX;
     203                cucul_set_feature(qq, i);
    192204                new_status = STATUS_ANTIALIASING;
    193205                update = 1;
    194206                break;
    195207            case 'd':
    196                 i = 1 + caca_get_feature(CACA_DITHERING);
    197                 if(i > CACA_DITHERING_MAX) i = CACA_DITHERING_MIN;
    198                 caca_set_feature(i);
     208                i = 1 + cucul_get_feature(qq, CUCUL_DITHERING);
     209                if(i > CUCUL_DITHERING_MAX) i = CUCUL_DITHERING_MIN;
     210                cucul_set_feature(qq, i);
    199211                new_status = STATUS_DITHERING;
    200212                update = 1;
    201213                break;
    202214            case 'D':
    203                 i = -1 + caca_get_feature(CACA_DITHERING);
    204                 if(i < CACA_DITHERING_MIN) i = CACA_DITHERING_MAX;
    205                 caca_set_feature(i);
     215                i = -1 + cucul_get_feature(qq, CUCUL_DITHERING);
     216                if(i < CUCUL_DITHERING_MIN) i = CUCUL_DITHERING_MAX;
     217                cucul_set_feature(qq, i);
    206218                new_status = STATUS_DITHERING;
    207219                update = 1;
     
    259271            else if(event == CACA_EVENT_RESIZE)
    260272            {
    261                 caca_refresh();
    262                 ww = caca_get_width();
    263                 wh = caca_get_height();
     273                caca_refresh(kk);
     274                ww = cucul_get_width(qq);
     275                wh = cucul_get_height(qq);
    264276                update = 1;
    265277                set_zoom(zoom);
     
    272284                help = new_help;
    273285
    274             event = caca_get_event(CACA_EVENT_KEY_PRESS);
     286            event = caca_get_event(kk, CACA_EVENT_KEY_PRESS);
    275287        }
    276288
     
    287299            sprintf(buffer, " Loading `%s'... ", list[current]);
    288300            buffer[ww] = '\0';
    289             caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
    290             caca_putstr((ww - strlen(buffer)) / 2, wh / 2, buffer);
    291             caca_refresh();
    292             ww = caca_get_width();
    293             wh = caca_get_height();
     301            cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
     302            cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer);
     303            caca_refresh(kk);
     304            ww = cucul_get_width(qq);
     305            wh = cucul_get_height(qq);
    294306
    295307            unload_image();
     
    305317        }
    306318
    307         caca_clear();
     319        cucul_clear(qq);
    308320
    309321        if(!items)
    310322        {
    311             caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
    312             caca_printf(ww / 2 - 5, wh / 2, " No image. ");
     323            cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
     324            cucul_printf(qq, ww / 2 - 5, wh / 2, " No image. ");
    313325        }
    314326        else if(!pixels)
     
    329341            sprintf(buffer, ERROR_STRING, list[current]);
    330342            buffer[ww] = '\0';
    331             caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
    332             caca_putstr((ww - strlen(buffer)) / 2, wh / 2, buffer);
     343            cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
     344            cucul_putstr(qq, (ww - strlen(buffer)) / 2, wh / 2, buffer);
    333345            free(buffer);
    334346        }
     
    349361                          y + height * (1.0 + yfactor) / 2);
    350362
    351             caca_draw_bitmap(ww * (1.0 - xfactor) * xdelta,
    352                              y + height * (1.0 - yfactor) * ydelta,
    353                              ww * (xdelta + (1.0 - xdelta) * xfactor),
    354                              y + height * (ydelta + (1.0 - ydelta) * yfactor),
    355                              bitmap, pixels);
     363            cucul_draw_bitmap(qq, ww * (1.0 - xfactor) * xdelta,
     364                              y + height * (1.0 - yfactor) * ydelta,
     365                              ww * (xdelta + (1.0 - xdelta) * xfactor),
     366                              y + height * (ydelta + (1.0 - ydelta) * yfactor),
     367                              bitmap, pixels);
    356368        }
    357369
     
    360372            print_status();
    361373
    362             caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
     374            cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
    363375            switch(status)
    364376            {
    365377                case STATUS_ANTIALIASING:
    366                     caca_printf(0, wh - 1, "Antialiasing: %s",
    367                   caca_get_feature_name(caca_get_feature(CACA_ANTIALIASING)));
     378                    cucul_printf(qq, 0, wh - 1, "Antialiasing: %s",
     379                  cucul_get_feature_name(cucul_get_feature(qq, CUCUL_ANTIALIASING)));
    368380                    break;
    369381                case STATUS_DITHERING:
    370                     caca_printf(0, wh - 1, "Dithering: %s",
    371                   caca_get_feature_name(caca_get_feature(CACA_DITHERING)));
     382                    cucul_printf(qq, 0, wh - 1, "Dithering: %s",
     383                  cucul_get_feature_name(cucul_get_feature(qq, CUCUL_DITHERING)));
    372384                    break;
    373385                case STATUS_BACKGROUND:
    374                     caca_printf(0, wh - 1, "Background: %s",
    375                   caca_get_feature_name(caca_get_feature(CACA_BACKGROUND)));
     386                    cucul_printf(qq, 0, wh - 1, "Background: %s",
     387                  cucul_get_feature_name(cucul_get_feature(qq, CUCUL_BACKGROUND)));
    376388                    break;
    377389            }
     
    383395        }
    384396
    385         caca_refresh();
     397        caca_refresh(kk);
    386398        update = 0;
    387399    }
     
    389401    /* Clean up */
    390402    unload_image();
    391     caca_end();
     403    caca_detach(kk);
     404    cucul_end(qq);
    392405
    393406    return 0;
     
    396409static void print_status(void)
    397410{
    398     caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
    399     caca_draw_line(0, 0, ww - 1, 0, ' ');
    400     caca_draw_line(0, wh - 2, ww - 1, wh - 2, '-');
    401     caca_putstr(0, 0, "q:Quit  np:Next/Prev  +-x:Zoom  "
    402                       "hjkl:Move  d:Dithering  a:Antialias");
    403     caca_putstr(ww - strlen("?:Help"), 0, "?:Help");
    404     caca_printf(3, wh - 2, "cacaview %s", VERSION);
    405     caca_printf(ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom);
    406 
    407     caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
    408     caca_draw_line(0, wh - 1, ww - 1, wh - 1, ' ');
     411    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
     412    cucul_draw_line(qq, 0, 0, ww - 1, 0, ' ');
     413    cucul_draw_line(qq, 0, wh - 2, ww - 1, wh - 2, '-');
     414    cucul_putstr(qq, 0, 0, "q:Quit  np:Next/Prev  +-x:Zoom  "
     415                           "hjkl:Move  d:Dithering  a:Antialias");
     416    cucul_putstr(qq, ww - strlen("?:Help"), 0, "?:Help");
     417    cucul_printf(qq, 3, wh - 2, "cacaview %s", VERSION);
     418    cucul_printf(qq, ww - 14, wh - 2, "(zoom: %s%i)", zoom > 0 ? "+" : "", zoom);
     419
     420    cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
     421    cucul_draw_line(qq, 0, wh - 1, ww - 1, wh - 1, ' ');
    409422}
    410423
     
    431444    int i;
    432445
    433     caca_set_color(CACA_COLOR_WHITE, CACA_COLOR_BLUE);
     446    cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
    434447
    435448    for(i = 0; help[i]; i++)
    436         caca_putstr(x, y + i, help[i]);
     449        cucul_putstr(qq, x, y + i, help[i]);
    437450}
    438451
     
    446459    if(zoom < -ZOOM_MAX) zoom = -ZOOM_MAX;
    447460
    448     ww = caca_get_width();
     461    ww = cucul_get_width(qq);
    449462    height = fullscreen ? wh : wh - 3;
    450463
    451464    xfactor = (zoom < 0) ? 1.0 / zoomtab[-zoom] : zoomtab[zoom];
    452465    yfactor = xfactor * ww / height * h / w
    453                * caca_get_height() / caca_get_width()
    454                * caca_get_window_width() / caca_get_window_height();
     466               * cucul_get_height(qq) / cucul_get_width(qq)
     467               * caca_get_window_width(kk) / caca_get_window_height(kk);
    455468
    456469    if(yfactor > xfactor)
     
    475488#endif
    476489    if(bitmap)
    477         caca_free_bitmap(bitmap);
     490        cucul_free_bitmap(qq, bitmap);
    478491    bitmap = NULL;
    479492}
     
    499512    depth = 4;
    500513
    501     /* Create the libcaca bitmap */
    502     bitmap = caca_create_bitmap(bpp, w, h, depth * w,
    503                                 rmask, gmask, bmask, amask);
     514    /* Create the libcucul bitmap */
     515    bitmap = cucul_create_bitmap(qq, bpp, w, h, depth * w,
     516                                 rmask, gmask, bmask, amask);
    504517    if(!bitmap)
    505518    {
     
    686699    int xn, yn;
    687700
    688     if(x2 + 1 > (int)caca_get_width()) x2 = caca_get_width() - 1;
    689     if(y2 + 1 > (int)caca_get_height()) y2 = caca_get_height() - 1;
     701    if(x2 + 1 > (int)cucul_get_width(qq)) x2 = cucul_get_width(qq) - 1;
     702    if(y2 + 1 > (int)cucul_get_height(qq)) y2 = cucul_get_height(qq) - 1;
    690703
    691704    for(yn = y1 > 0 ? y1 : 0; yn <= y2; yn++)
     
    693706    {
    694707        if((((xn - x1) / 5) ^ ((yn - y1) / 3)) & 1)
    695             caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_DARKGRAY);
     708            cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY);
    696709        else
    697             caca_set_color(CACA_COLOR_DARKGRAY, CACA_COLOR_LIGHTGRAY);
    698         caca_putchar(xn, yn, ' ');
     710            cucul_set_color(qq, CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY);
     711        cucul_putchar(qq, xn, yn, ' ');
    699712    }
    700713}
  • libcaca/trunk/src/Makefile.am

    r475 r524  
    11# $Id$
    22
    3 include_HEADERS = caca.h
     3include_HEADERS = cucul.h caca.h
    44
    5 lib_LTLIBRARIES = libcaca.la
    6 libcaca_la_SOURCES = \
    7         caca.c \
    8         caca.h \
    9         caca_internals.h \
    10         graphics.c \
    11         event.c \
     5lib_LTLIBRARIES = libcucul.la libcaca.la
     6
     7libcucul_la_SOURCES = \
     8        cucul.c \
     9        cucul.h \
     10        cucul_internals.h \
     11        char.c \
    1212        math.c \
    1313        line.c \
     
    1717        sprite.c \
    1818        bitmap.c \
     19        export.c \
    1920        time.c \
    2021        $(NULL)
     22libcucul_la_LDFLAGS = -no-undefined
     23libcucul_la_LIBADD = @CUCUL_LIBS@
     24
     25libcaca_la_SOURCES = \
     26        caca.c \
     27        caca.h \
     28        caca_internals.h \
     29        graphics.c \
     30        event.c \
     31        $(NULL)
    2132libcaca_la_LDFLAGS = -no-undefined
    22 libcaca_la_LIBADD = @CACA_LIBS@
     33libcaca_la_LIBADD = libcucul.la @CACA_LIBS@
    2334
    24 if NEED_PIC
    25 libcaca_pic_a = libcaca_pic.a
    26 endif
    27 lib_LIBRARIES = $(libcaca_pic_a)
    28 libcaca_pic_a_SOURCES = $(libcaca_la_SOURCES)
    29 libcaca_pic_a_CPPFLAGS = -fPIC -DPIC
    30 
  • libcaca/trunk/src/bitmap.c

    r522 r524  
    3737#include <string.h>
    3838
     39#include "cucul.h"
     40#include "cucul_internals.h"
    3941#include "caca.h"
    4042#include "caca_internals.h"
    41 
    42 /*
    43  * Global variables
    44  */
    45 #if !defined(_DOXYGEN_SKIP_ME)
    46 enum caca_feature _caca_background;
    47 enum caca_feature _caca_dithering;
    48 enum caca_feature _caca_antialiasing;
    49 #endif
    5043
    5144/*
     
    5851#endif
    5952static unsigned char hsv_distances[LOOKUP_VAL][LOOKUP_SAT][LOOKUP_HUE];
    60 static enum caca_color lookup_colors[8];
     53static enum cucul_color lookup_colors[8];
    6154
    6255static int const hsv_palette[] =
     
    124117static void mask2shift(unsigned int, int *, int *);
    125118
    126 static void get_rgba_default(struct caca_bitmap const *, uint8_t *, int, int,
     119static void get_rgba_default(struct cucul_bitmap const *, uint8_t *, int, int,
    127120                             unsigned int *, unsigned int *, unsigned int *,
    128121                             unsigned int *);
     
    152145
    153146#if !defined(_DOXYGEN_SKIP_ME)
    154 struct caca_bitmap
     147struct cucul_bitmap
    155148{
    156149    int bpp, has_palette, has_alpha;
     
    159152    int rright, gright, bright, aright;
    160153    int rleft, gleft, bleft, aleft;
    161     void (*get_hsv)(struct caca_bitmap *, char *, int, int);
     154    void (*get_hsv)(struct cucul_bitmap *, char *, int, int);
    162155    int red[256], green[256], blue[256], alpha[256];
    163156    float gamma;
     
    197190 * pitch) and pixel mask values. If the depth is 8 bits per pixel, the mask
    198191 * values are ignored and the colour palette should be set using the
    199  * caca_set_bitmap_palette() function. For depths greater than 8 bits per
     192 * cucul_set_bitmap_palette() function. For depths greater than 8 bits per
    200193 * pixel, a zero alpha mask causes the alpha values to be ignored.
    201194 *
     
    210203 * \return Bitmap object, or NULL upon error.
    211204 */
    212 struct caca_bitmap *caca_create_bitmap(unsigned int bpp, unsigned int w,
     205struct cucul_bitmap *cucul_create_bitmap(cucul_t *qq,
     206                                       unsigned int bpp, unsigned int w,
    213207                                       unsigned int h, unsigned int pitch,
    214208                                       unsigned int rmask, unsigned int gmask,
    215209                                       unsigned int bmask, unsigned int amask)
    216210{
    217     struct caca_bitmap *bitmap;
     211    struct cucul_bitmap *bitmap;
    218212    int i;
    219213
     
    222216        return NULL;
    223217
    224     bitmap = malloc(sizeof(struct caca_bitmap));
     218    bitmap = malloc(sizeof(struct cucul_bitmap));
    225219    if(!bitmap)
    226220        return NULL;
     
    280274 * \param alpha Array of 256 alpha values.
    281275 */
    282 void caca_set_bitmap_palette(struct caca_bitmap *bitmap,
    283                              unsigned int red[], unsigned int green[],
    284                              unsigned int blue[], unsigned int alpha[])
     276void cucul_set_bitmap_palette(cucul_t *qq, struct cucul_bitmap *bitmap,
     277                              unsigned int red[], unsigned int green[],
     278                              unsigned int blue[], unsigned int alpha[])
    285279{
    286280    int i, has_alpha = 0;
     
    318312 * \param gamma Gamma value.
    319313 */
    320 void caca_set_bitmap_gamma(struct caca_bitmap *bitmap, float gamma)
     314void cucul_set_bitmap_gamma(cucul_t *qq, struct cucul_bitmap *bitmap, float gamma)
    321315{
    322316    int i;
     
    328322
    329323    for(i = 0; i < 4096; i++)
    330         bitmap->gammatab[i] = 4096.0 * caca_powf((float)i / 4096.0, 1.0 / gamma);
     324        bitmap->gammatab[i] = 4096.0 * cucul_powf((float)i / 4096.0, 1.0 / gamma);
    331325}
    332326
     
    334328 * \brief Free the memory associated with a bitmap.
    335329 *
    336  * Free the memory allocated by caca_create_bitmap().
     330 * Free the memory allocated by cucul_create_bitmap().
    337331 *
    338332 * \param bitmap Bitmap object.
    339333 */
    340 void caca_free_bitmap(struct caca_bitmap *bitmap)
     334void cucul_free_bitmap(cucul_t *qq, struct cucul_bitmap *bitmap)
    341335{
    342336    if(!bitmap)
     
    346340}
    347341
    348 static void get_rgba_default(struct caca_bitmap const *bitmap, uint8_t *pixels,
     342static void get_rgba_default(struct cucul_bitmap const *bitmap, uint8_t *pixels,
    349343                             int x, int y, unsigned int *r, unsigned int *g,
    350344                             unsigned int *b, unsigned int *a)
     
    451445 * \param pixels Bitmap's pixels.
    452446 */
    453 void caca_draw_bitmap(int x1, int y1, int x2, int y2,
    454                       struct caca_bitmap const *bitmap, void *pixels)
     447void cucul_draw_bitmap(cucul_t *qq, int x1, int y1, int x2, int y2,
     448                       struct cucul_bitmap const *bitmap, void *pixels)
    455449{
    456450    /* Current dithering method */
     
    502496    deltay = y2 - y1 + 1;
    503497
    504     switch(_caca_dithering)
    505     {
    506     case CACA_DITHERING_NONE:
     498    switch(qq->dithering)
     499    {
     500    case CUCUL_DITHERING_NONE:
    507501        _init_dither = init_no_dither;
    508502        _get_dither = get_no_dither;
     
    510504        break;
    511505
    512     case CACA_DITHERING_ORDERED2:
     506    case CUCUL_DITHERING_ORDERED2:
    513507        _init_dither = init_ordered2_dither;
    514508        _get_dither = get_ordered2_dither;
     
    516510        break;
    517511
    518     case CACA_DITHERING_ORDERED4:
     512    case CUCUL_DITHERING_ORDERED4:
    519513        _init_dither = init_ordered4_dither;
    520514        _get_dither = get_ordered4_dither;
     
    522516        break;
    523517
    524     case CACA_DITHERING_ORDERED8:
     518    case CUCUL_DITHERING_ORDERED8:
    525519        _init_dither = init_ordered8_dither;
    526520        _get_dither = get_ordered8_dither;
     
    528522        break;
    529523
    530     case CACA_DITHERING_RANDOM:
     524    case CUCUL_DITHERING_RANDOM:
    531525        _init_dither = init_random_dither;
    532526        _get_dither = get_random_dither;
     
    534528        break;
    535529
    536     case CACA_DITHERING_FSTEIN:
     530    case CUCUL_DITHERING_FSTEIN:
    537531        _init_dither = init_no_dither;
    538532        _get_dither = get_no_dither;
     
    545539    }
    546540
    547     fs_length = ((int)_caca_width <= x2 ? (int)_caca_width : x2) + 1;
     541    fs_length = ((int)qq->width <= x2 ? (int)qq->width : x2) + 1;
    548542    floyd_steinberg = malloc(3 * (fs_length + 2) * sizeof(int));
    549543    memset(floyd_steinberg, 0, 3 * (fs_length + 2) * sizeof(int));
     
    552546    fs_b = fs_g + fs_length + 2;
    553547
    554     for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)_caca_height; y++)
     548    for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= (int)qq->height; y++)
    555549    {
    556550        int remain_r = 0, remain_g = 0, remain_b = 0;
    557551
    558552        for(x = x1 > 0 ? x1 : 0, _init_dither(y);
    559             x <= x2 && x <= (int)_caca_width;
     553            x <= x2 && x <= (int)qq->width;
    560554            x++)
    561555    {
     
    567561        int error[3];
    568562
    569         enum caca_color outfg = 0, outbg = 0;
     563        enum cucul_color outfg = 0, outbg = 0;
    570564        char outch;
    571565
     
    573567
    574568        /* First get RGB */
    575         if(_caca_antialiasing == CACA_ANTIALIASING_PREFILTER)
     569        if(qq->antialiasing == CUCUL_ANTIALIASING_PREFILTER)
    576570        {
    577571            fromx = (x - x1) * w / deltax;
     
    624618        }
    625619
    626         if(_caca_dithering == CACA_DITHERING_FSTEIN)
     620        if(qq->dithering == CUCUL_DITHERING_FSTEIN)
    627621        {
    628622            r += remain_r;
     
    654648        bg_b = rgb_palette[outbg * 3 + 2];
    655649
    656         if(_caca_background == CACA_BACKGROUND_SOLID)
     650        if(qq->background == CUCUL_BACKGROUND_SOLID)
    657651        {
    658652            distmin = INT_MAX;
     
    693687            outch = density_chars[4 * ch];
    694688
    695             if(_caca_dithering == CACA_DITHERING_FSTEIN)
     689            if(qq->dithering == CUCUL_DITHERING_FSTEIN)
    696690            {
    697691                error[0] = r - (fg_r * ch + bg_r * ((2*DCHMAX-1) - ch)) / (2*DCHMAX-1);
     
    704698            unsigned int lum = r; if(g > lum) lum = g; if(b > lum) lum = b;
    705699            outfg = outbg;
    706             outbg = CACA_COLOR_BLACK;
     700            outbg = CUCUL_COLOR_BLACK;
    707701
    708702            ch = lum * DCHMAX / 0x1000;
     
    713707            outch = density_chars[4 * ch];
    714708
    715             if(_caca_dithering == CACA_DITHERING_FSTEIN)
     709            if(qq->dithering == CUCUL_DITHERING_FSTEIN)
    716710            {
    717711                error[0] = r - bg_r * ch / (DCHMAX-1);
     
    721715        }
    722716
    723         if(_caca_dithering == CACA_DITHERING_FSTEIN)
     717        if(qq->dithering == CUCUL_DITHERING_FSTEIN)
    724718        {
    725719            remain_r = fs_r[x+1] + 7 * error[0] / 16;
     
    738732
    739733        /* Now output the character */
    740         caca_set_color(outfg, outbg);
    741         caca_putchar(x, y, outch);
     734        cucul_set_color(qq, outfg, outbg);
     735        cucul_putchar(qq, x, y, outch);
    742736
    743737        _increment_dither();
     
    750744
    751745#if !defined(_DOXYGEN_SKIP_ME)
    752 int _caca_init_bitmap(void)
     746int _cucul_init_bitmap(void)
    753747{
    754748    unsigned int v, s, h;
    755749
    756750    /* These ones are constant */
    757     lookup_colors[0] = CACA_COLOR_BLACK;
    758     lookup_colors[1] = CACA_COLOR_DARKGRAY;
    759     lookup_colors[2] = CACA_COLOR_LIGHTGRAY;
    760     lookup_colors[3] = CACA_COLOR_WHITE;
     751    lookup_colors[0] = CUCUL_COLOR_BLACK;
     752    lookup_colors[1] = CUCUL_COLOR_DARKGRAY;
     753    lookup_colors[2] = CUCUL_COLOR_LIGHTGRAY;
     754    lookup_colors[3] = CUCUL_COLOR_WHITE;
    761755
    762756    /* These ones will be overwritten */
    763     lookup_colors[4] = CACA_COLOR_MAGENTA;
    764     lookup_colors[5] = CACA_COLOR_LIGHTMAGENTA;
    765     lookup_colors[6] = CACA_COLOR_RED;
    766     lookup_colors[7] = CACA_COLOR_LIGHTRED;
     757    lookup_colors[4] = CUCUL_COLOR_MAGENTA;
     758    lookup_colors[5] = CUCUL_COLOR_LIGHTMAGENTA;
     759    lookup_colors[6] = CUCUL_COLOR_RED;
     760    lookup_colors[7] = CUCUL_COLOR_LIGHTRED;
    767761
    768762    for(v = 0; v < LOOKUP_VAL; v++)
     
    808802}
    809803
    810 int _caca_end_bitmap(void)
     804int _cucul_end_bitmap(void)
    811805{
    812806    return 0;
     
    942936static unsigned int get_random_dither(void)
    943937{
    944     return caca_rand(0x00, 0xff);
     938    return cucul_rand(0x00, 0xff);
    945939}
    946940
  • libcaca/trunk/src/box.c

    r522 r524  
    2020#include "config.h"
    2121
     22#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
     23#   include <inttypes.h>
     24#else
     25typedef unsigned char uint8_t;
     26#endif
     27
    2228#include <stdlib.h>
    2329
    24 #include "caca.h"
    25 #include "caca_internals.h"
     30#include "cucul.h"
     31#include "cucul_internals.h"
    2632
    2733/**
     
    3541 * \return void
    3642 */
    37 void caca_draw_box(int x1, int y1, int x2, int y2, char c)
     43void cucul_draw_box(cucul_t *qq, int x1, int y1, int x2, int y2, char c)
    3844{
    39     caca_draw_line(x1, y1, x1, y2, c);
    40     caca_draw_line(x1, y2, x2, y2, c);
    41     caca_draw_line(x2, y2, x2, y1, c);
    42     caca_draw_line(x2, y1, x1, y1, c);
     45    cucul_draw_line(qq, x1, y1, x1, y2, c);
     46    cucul_draw_line(qq, x1, y2, x2, y2, c);
     47    cucul_draw_line(qq, x2, y2, x2, y1, c);
     48    cucul_draw_line(qq, x2, y1, x1, y1, c);
    4349}
    4450
     
    5258 * \return void
    5359 */
    54 void caca_draw_thin_box(int x1, int y1, int x2, int y2)
     60void cucul_draw_thin_box(cucul_t *qq, int x1, int y1, int x2, int y2)
    5561{
    5662    int x, y, xmax, ymax;
     
    6874    }
    6975
    70     xmax = _caca_width - 1;
    71     ymax = _caca_height - 1;
     76    xmax = qq->width - 1;
     77    ymax = qq->height - 1;
    7278
    7379    if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
     
    7783    if(y1 >= 0)
    7884        for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
    79             caca_putchar(x, y1, '-');
     85            cucul_putchar(qq, x, y1, '-');
    8086
    8187    if(y2 <= ymax)
    8288        for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
    83             caca_putchar(x, y2, '-');
     89            cucul_putchar(qq, x, y2, '-');
    8490
    8591    if(x1 >= 0)
    8692        for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
    87             caca_putchar(x1, y, '|');
     93            cucul_putchar(qq, x1, y, '|');
    8894
    8995    if(x2 <= xmax)
    9096        for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
    91             caca_putchar(x2, y, '|');
     97            cucul_putchar(qq, x2, y, '|');
    9298
    9399    /* Draw corners */
    94100    if(x1 >= 0 && y1 >= 0)
    95         caca_putchar(x1, y1, ',');
     101        cucul_putchar(qq, x1, y1, ',');
    96102
    97103    if(x1 >= 0 && y2 <= ymax)
    98         caca_putchar(x1, y2, '`');
     104        cucul_putchar(qq, x1, y2, '`');
    99105
    100106    if(x2 <= xmax && y1 >= 0)
    101         caca_putchar(x2, y1, '.');
     107        cucul_putchar(qq, x2, y1, '.');
    102108
    103109    if(x2 <= xmax && y2 <= ymax)
    104         caca_putchar(x2, y2, '\'');
     110        cucul_putchar(qq, x2, y2, '\'');
    105111}
    106112
     
    115121 * \return void
    116122 */
    117 void caca_fill_box(int x1, int y1, int x2, int y2, char c)
     123void cucul_fill_box(cucul_t *qq, int x1, int y1, int x2, int y2, char c)
    118124{
    119125    int x, y, xmax, ymax;
     
    131137    }
    132138
    133     xmax = _caca_width - 1;
    134     ymax = _caca_height - 1;
     139    xmax = qq->width - 1;
     140    ymax = qq->height - 1;
    135141
    136142    if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
     
    144150    for(y = y1; y <= y2; y++)
    145151        for(x = x1; x <= x2; x++)
    146             caca_putchar(x, y, c);
     152            cucul_putchar(qq, x, y, c);
    147153}
    148154
  • libcaca/trunk/src/caca.c

    r522 r524  
    2222#include "config.h"
    2323
     24#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
     25#   include <inttypes.h>
     26#else
     27typedef unsigned char uint8_t;
     28#endif
     29
    2430#if defined(USE_SLANG)
    2531#   if defined(HAVE_SLANG_SLANG_H)
     
    5258#include <string.h>
    5359
     60#include "cucul.h"
     61#include "cucul_internals.h"
    5462#include "caca.h"
    5563#include "caca_internals.h"
    5664
    57 static void caca_init_driver(void);
    58 static void caca_init_features(void);
    59 static void caca_init_terminal(void);
    60 
    61 #if !defined(_DOXYGEN_SKIP_ME)
    62 enum caca_driver _caca_driver;
    63 #endif
     65static void caca_init_driver(caca_t *kk);
     66static void caca_init_terminal(caca_t *kk);
    6467
    6568#if defined(USE_NCURSES)
     
    7174#endif
    7275
    73 /** \brief Initialise \e libcaca.
    74  *
    75  *  This function initialises internal \e libcaca structures and the backend
    76  *  that will be used for subsequent graphical operations. It must be the
    77  *  first \e libcaca function to be called in a function. caca_end() should
    78  *  be called at the end of the program to free all allocated resources.
    79  *
    80  *  \return 0 upon success, a non-zero value if an error occurs.
    81  */
    82 int caca_init(void)
     76caca_t * caca_attach(cucul_t * qq)
    8377{
     78    caca_t *kk = malloc(sizeof(caca_t));
     79
    8480#if defined(USE_NCURSES)
    8581    mmask_t newmask;
    8682#endif
    8783
    88     caca_init_driver();
    89 
    90     if(_caca_driver == CACA_DRIVER_NONE)
    91         return -1;
    92 
    93     caca_init_features();
    94     caca_init_terminal();
    95 
    96 #if defined(USE_SLANG)
    97     if(_caca_driver == CACA_DRIVER_SLANG)
     84    caca_init_driver(kk);
     85
     86    if(kk->driver == CACA_DRIVER_NONE)
     87        return NULL;
     88
     89    caca_init_terminal(kk);
     90
     91#if defined(USE_SLANG)
     92    if(kk->driver == CACA_DRIVER_SLANG)
    9893    {
    9994        /* Initialise slang library */
     
    10499        {
    105100            SLsig_unblock_signals();
    106             return -1;
     101            return NULL;
    107102        }
    108103
     
    112107        {
    113108            SLsig_unblock_signals();
    114             return -1;
     109            return NULL;
    115110        }
    116111
     
    130125#endif
    131126#if defined(USE_NCURSES)
    132     if(_caca_driver == CACA_DRIVER_NCURSES)
     127    if(kk->driver == CACA_DRIVER_NCURSES)
    133128    {
    134129        initscr();
     
    151146#endif
    152147#if defined(USE_CONIO)
    153     if(_caca_driver == CACA_DRIVER_CONIO)
     148    if(kk->driver == CACA_DRIVER_CONIO)
    154149    {
    155150        _wscroll = 0;
     
    160155#endif
    161156#if defined(USE_X11)
    162     if(_caca_driver == CACA_DRIVER_X11)
     157    if(kk->driver == CACA_DRIVER_X11)
    163158    {
    164159        /* Nothing to do */
    165     }
    166     else
    167 #endif
    168 #if defined(USE_WIN32)
    169     if(_caca_driver == CACA_DRIVER_WIN32)
     160        kk->x11.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
     161              | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask
     162              | ExposureMask;
     163    }
     164    else
     165#endif
     166#if defined(USE_WIN32)
     167    if(kk->driver == CACA_DRIVER_WIN32)
    170168    {
    171169        /* This call is allowed to fail in cas we already have a console */
     
    178176
    179177        if(win32_hout == INVALID_HANDLE_VALUE)
    180             return -1;
     178            return NULL;
    181179
    182180        GetConsoleCursorInfo(win32_hout, &cci);
     
    189187#endif
    190188#if defined(USE_GL)
    191     if(_caca_driver == CACA_DRIVER_GL)
     189    if(kk->driver == CACA_DRIVER_GL)
    192190    {
    193191        /* Nothing to do */
     
    195193    else
    196194#endif
    197 #if defined(USE_NULL)
    198     if(_caca_driver == CACA_DRIVER_NULL)
    199     {
    200         /* Nothing to do */
    201     }
    202     else
    203 #endif
    204195    {
    205196        /* Dummy */
    206197    }
    207198
    208     if(_caca_init_graphics())
    209         return -1;
    210 
    211     if(_caca_init_bitmap())
    212         return -1;
    213 
    214     return 0;
     199    qq->refcount++;
     200    kk->qq = qq;
     201
     202    kk->resize = 0;
     203    kk->resize_event = 0;
     204
     205    if(_caca_init_graphics(kk))
     206        return NULL;
     207
     208    return kk;
    215209}
    216210
    217 /** \brief Get the screen width.
    218  *
    219  *  This function returns the current screen width, in character cells.
    220  *
    221  *  \return The screen width.
    222  */
    223 unsigned int caca_get_width(void)
     211void caca_detach(caca_t *kk)
    224212{
    225     return _caca_width;
    226 }
    227 
    228 /** \brief Get the screen height.
    229  *
    230  *  This function returns the current screen height, in character cells.
    231  *
    232  *  \return The screen height.
    233  */
    234 unsigned int caca_get_height(void)
    235 {
    236     return _caca_height;
    237 }
    238 
    239 /** \brief Translate a colour index into the colour's name.
    240  *
    241  *  This function translates a caca_color enum into a human-readable
    242  *  description string of the associated colour.
    243  *
    244  *  \param color The colour value.
    245  *  \return A static string containing the colour's name.
    246  */
    247 char const *caca_get_color_name(enum caca_color color)
    248 {
    249     static char const *color_names[] =
    250     {
    251         "black",
    252         "blue",
    253         "green",
    254         "cyan",
    255         "red",
    256         "magenta",
    257         "brown",
    258         "light gray",
    259         "dark gray",
    260         "light blue",
    261         "light green",
    262         "light cyan",
    263         "light red",
    264         "light magenta",
    265         "yellow",
    266         "white",
    267     };
    268 
    269     if(color < 0 || color > 15)
    270         return "unknown";
    271 
    272     return color_names[color];
    273 }
    274 
    275 /** \brief Get the current value of a feature.
    276  *
    277  *  This function retrieves the value of an internal \e libcaca feature. A
    278  *  generic feature value is expected, such as CACA_ANTIALIASING.
    279  *
    280  *  \param feature The requested feature.
    281  *  \return The current value of the feature or CACA_FEATURE_UNKNOWN if an
    282  *          error occurred..
    283  */
    284 enum caca_feature caca_get_feature(enum caca_feature feature)
    285 {
    286     switch(feature)
    287     {
    288         case CACA_BACKGROUND:
    289             return _caca_background;
    290         case CACA_ANTIALIASING:
    291             return _caca_antialiasing;
    292         case CACA_DITHERING:
    293             return _caca_dithering;
    294 
    295         default:
    296             return CACA_FEATURE_UNKNOWN;
    297     }
    298 }
    299 
    300 /** \brief Set a feature.
    301  *
    302  *  This function sets an internal \e libcaca feature such as the antialiasing
    303  *  or dithering modes. If a specific feature such as CACA_DITHERING_RANDOM,
    304  *  caca_set_feature() will set it immediately. If a generic feature is given
    305  *  instead, such as CACA_DITHERING, the default value will be used instead.
    306  *
    307  *  \param feature The requested feature.
    308  */
    309 void caca_set_feature(enum caca_feature feature)
    310 {
    311     switch(feature)
    312     {
    313         case CACA_BACKGROUND:
    314             feature = CACA_BACKGROUND_SOLID;
    315         case CACA_BACKGROUND_BLACK:
    316         case CACA_BACKGROUND_SOLID:
    317             _caca_background = feature;
    318             break;
    319 
    320         case CACA_ANTIALIASING:
    321             feature = CACA_ANTIALIASING_PREFILTER;
    322         case CACA_ANTIALIASING_NONE:
    323         case CACA_ANTIALIASING_PREFILTER:
    324             _caca_antialiasing = feature;
    325             break;
    326 
    327         case CACA_DITHERING:
    328             feature = CACA_DITHERING_FSTEIN;
    329         case CACA_DITHERING_NONE:
    330         case CACA_DITHERING_ORDERED2:
    331         case CACA_DITHERING_ORDERED4:
    332         case CACA_DITHERING_ORDERED8:
    333         case CACA_DITHERING_RANDOM:
    334         case CACA_DITHERING_FSTEIN:
    335             _caca_dithering = feature;
    336             break;
    337 
    338         case CACA_FEATURE_UNKNOWN:
    339             break;
    340     }
    341 }
    342 
    343 /** \brief Translate a feature value into the feature's name.
    344  *
    345  *  This function translates a caca_feature enum into a human-readable
    346  *  description string of the associated feature.
    347  *
    348  *  \param feature The feature value.
    349  *  \return A static string containing the feature's name.
    350  */
    351 char const *caca_get_feature_name(enum caca_feature feature)
    352 {
    353     switch(feature)
    354     {
    355         case CACA_BACKGROUND_BLACK: return "black background";
    356         case CACA_BACKGROUND_SOLID: return "solid background";
    357 
    358         case CACA_ANTIALIASING_NONE:      return "no antialiasing";
    359         case CACA_ANTIALIASING_PREFILTER: return "prefilter antialiasing";
    360 
    361         case CACA_DITHERING_NONE:     return "no dithering";
    362         case CACA_DITHERING_ORDERED2: return "2x2 ordered dithering";
    363         case CACA_DITHERING_ORDERED4: return "4x4 ordered dithering";
    364         case CACA_DITHERING_ORDERED8: return "8x8 ordered dithering";
    365         case CACA_DITHERING_RANDOM:   return "random dithering";
    366         case CACA_DITHERING_FSTEIN:   return "Floyd-Steinberg dithering";
    367 
    368         default: return "unknown";
    369     }
    370 }
    371 
    372 /** \brief Uninitialise \e libcaca.
    373  *
    374  *  This function frees all resources allocated by caca_init(). After
    375  *  caca_end() has been called, no other \e libcaca functions may be used
    376  *  unless a new call to caca_init() is done.
    377  */
    378 void caca_end(void)
    379 {
    380     _caca_end_bitmap();
    381     _caca_end_graphics();
    382 
    383 #if defined(USE_SLANG)
    384     if(_caca_driver == CACA_DRIVER_SLANG)
     213    _caca_end_graphics(kk);
     214
     215#if defined(USE_SLANG)
     216    if(kk->driver == CACA_DRIVER_SLANG)
    385217    {
    386218        SLtt_set_mouse_mode(0, 0);
     
    392224#endif
    393225#if defined(USE_NCURSES)
    394     if(_caca_driver == CACA_DRIVER_NCURSES)
     226    if(kk->driver == CACA_DRIVER_NCURSES)
    395227    {
    396228        mousemask(oldmask, NULL);
     
    402234#endif
    403235#if defined(USE_CONIO)
    404     if(_caca_driver == CACA_DRIVER_CONIO)
     236    if(kk->driver == CACA_DRIVER_CONIO)
    405237    {
    406238        _wscroll = 1;
     
    414246#endif
    415247#if defined(USE_X11)
    416     if(_caca_driver == CACA_DRIVER_X11)
     248    if(kk->driver == CACA_DRIVER_X11)
    417249    {
    418250        /* Nothing to do */
     
    421253#endif
    422254#if defined(USE_WIN32)
    423     if(_caca_driver == CACA_DRIVER_WIN32)
     255    if(kk->driver == CACA_DRIVER_WIN32)
    424256    {
    425257        SetConsoleTextAttribute(win32_hout, FOREGROUND_INTENSITY
     
    434266#endif
    435267#if defined(USE_GL)
    436     if(_caca_driver == CACA_DRIVER_GL)
     268    if(kk->driver == CACA_DRIVER_GL)
    437269    {
    438270        /* Nothing to do */
     
    440272    else
    441273#endif
    442 #if defined(USE_NULL)
    443     if(_caca_driver == CACA_DRIVER_NULL)
    444     {
    445         /* Nothing to do */
    446     }
    447     else
    448 #endif
    449274    {
    450275        /* Dummy */
    451276    }
     277
     278    kk->qq->refcount--;
     279
     280    free(kk);
    452281}
    453282
     
    456285 */
    457286
    458 static void caca_init_driver(void)
     287static void caca_init_driver(caca_t *kk)
    459288{
    460289#if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP)
     
    466295#if defined(USE_WIN32)
    467296        if(!strcasecmp(var, "win32"))
    468             _caca_driver = CACA_DRIVER_WIN32;
     297            kk->driver = CACA_DRIVER_WIN32;
    469298        else
    470299#endif
    471300#if defined(USE_CONIO)
    472301        if(!strcasecmp(var, "conio"))
    473             _caca_driver = CACA_DRIVER_CONIO;
     302            kk->driver = CACA_DRIVER_CONIO;
    474303        else
    475304#endif
    476305#if defined(USE_X11)
    477306        if(!strcasecmp(var, "x11"))
    478             _caca_driver = CACA_DRIVER_X11;
     307            kk->driver = CACA_DRIVER_X11;
    479308        else
    480309#endif
    481310#if defined(USE_GL)
    482311        if(!strcasecmp(var, "gl"))
    483             _caca_driver = CACA_DRIVER_GL;
     312            kk->driver = CACA_DRIVER_GL;
    484313        else
    485314#endif
    486315#if defined(USE_SLANG)
    487316        if(!strcasecmp(var, "slang"))
    488             _caca_driver = CACA_DRIVER_SLANG;
     317            kk->driver = CACA_DRIVER_SLANG;
    489318        else
    490319#endif
    491320#if defined(USE_NCURSES)
    492321        if(!strcasecmp(var, "ncurses"))
    493             _caca_driver = CACA_DRIVER_NCURSES;
    494         else
    495 #endif
    496 #if defined(USE_NULL)
    497         if(!strcasecmp(var, "null"))
    498             _caca_driver = CACA_DRIVER_NULL;
    499         else
    500 #endif
    501 
    502             _caca_driver = CACA_DRIVER_NONE;
     322            kk->driver = CACA_DRIVER_NCURSES;
     323        else
     324#endif
     325
     326            kk->driver = CACA_DRIVER_NONE;
    503327
    504328        return;
     
    507331
    508332#if defined(USE_WIN32)
    509     _caca_driver = CACA_DRIVER_WIN32;
     333    kk->driver = CACA_DRIVER_WIN32;
    510334    return;
    511335#endif
    512336#if defined(USE_CONIO)
    513     _caca_driver = CACA_DRIVER_CONIO;
     337    kk->driver = CACA_DRIVER_CONIO;
    514338    return;
    515339#endif
     
    519343#endif
    520344    {
    521         _caca_driver = CACA_DRIVER_X11;
     345        kk->driver = CACA_DRIVER_X11;
    522346        return;
    523347    }
     
    528352#endif
    529353    {
    530         _caca_driver = CACA_DRIVER_GL;
     354        kk->driver = CACA_DRIVER_GL;
    531355        return;
    532356    }
    533357#endif
    534358#if defined(USE_SLANG)
    535     _caca_driver = CACA_DRIVER_SLANG;
    536     return;
    537 #endif
    538 #if defined(USE_NCURSES)
    539     _caca_driver = CACA_DRIVER_NCURSES;
    540     return;
    541 #endif
    542 #if defined(USE_NULL)
    543     _caca_driver = CACA_DRIVER_NULL;
    544     return;
    545 #endif
    546 
    547     _caca_driver = CACA_DRIVER_NONE;
     359    kk->driver = CACA_DRIVER_SLANG;
     360    return;
     361#endif
     362#if defined(USE_NCURSES)
     363    kk->driver = CACA_DRIVER_NCURSES;
     364    return;
     365#endif
     366
     367    kk->driver = CACA_DRIVER_NONE;
    548368    return;
    549369}
    550370
    551 static void caca_init_features(void)
    552 {
    553     /* FIXME: if strcasecmp isn't available, use strcmp */
    554 #if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP)
    555     char *var;
    556 #endif
    557 
    558     caca_set_feature(CACA_BACKGROUND);
    559     caca_set_feature(CACA_ANTIALIASING);
    560     caca_set_feature(CACA_DITHERING);
    561 
    562 #if defined(HAVE_GETENV) && defined(HAVE_STRCASECMP)
    563     if((var = getenv("CACA_BACKGROUND")) && *var)
    564     {
    565         if(!strcasecmp("black", var))
    566             caca_set_feature(CACA_BACKGROUND_BLACK);
    567         else if(!strcasecmp("solid", var))
    568             caca_set_feature(CACA_BACKGROUND_SOLID);
    569     }
    570 
    571     if((var = getenv("CACA_ANTIALIASING")) && *var)
    572     {
    573         if(!strcasecmp("none", var))
    574             caca_set_feature(CACA_ANTIALIASING_NONE);
    575         else if(!strcasecmp("prefilter", var))
    576             caca_set_feature(CACA_ANTIALIASING_PREFILTER);
    577     }
    578 
    579     if((var = getenv("CACA_DITHERING")) && *var)
    580     {
    581         if(!strcasecmp("none", var))
    582             caca_set_feature(CACA_DITHERING_NONE);
    583         else if(!strcasecmp("ordered2", var))
    584             caca_set_feature(CACA_DITHERING_ORDERED2);
    585         else if(!strcasecmp("ordered4", var))
    586             caca_set_feature(CACA_DITHERING_ORDERED4);
    587         else if(!strcasecmp("ordered8", var))
    588             caca_set_feature(CACA_DITHERING_ORDERED8);
    589         else if(!strcasecmp("random", var))
    590             caca_set_feature(CACA_DITHERING_RANDOM);
    591         else if(!strcasecmp("fstein", var))
    592             caca_set_feature(CACA_DITHERING_FSTEIN);
    593     }
    594 #endif
    595 }
    596 
    597 static void caca_init_terminal(void)
     371static void caca_init_terminal(caca_t *kk)
    598372{
    599373#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) && \
     
    603377
    604378#if defined(USE_SLANG)
    605     if(_caca_driver != CACA_DRIVER_SLANG)
    606 #endif
    607 #if defined(USE_NCURSES)
    608     if(_caca_driver != CACA_DRIVER_NCURSES)
     379    if(kk->driver != CACA_DRIVER_SLANG)
     380#endif
     381#if defined(USE_NCURSES)
     382    if(kk->driver != CACA_DRIVER_NCURSES)
    609383#endif
    610384    return;
     
    621395        {
    622396#if defined(USE_NCURSES)
    623             if(_caca_driver == CACA_DRIVER_NCURSES)
     397            if(kk->driver == CACA_DRIVER_NCURSES)
    624398            {
    625399                SCREEN *screen;
     
    639413        {
    640414#if defined(USE_NCURSES)
    641             if(_caca_driver == CACA_DRIVER_NCURSES)
     415            if(kk->driver == CACA_DRIVER_NCURSES)
    642416            {
    643417                SCREEN *screen;
  • libcaca/trunk/src/caca.h

    r522 r524  
    11/*
    22 *  libcaca       ASCII-Art library
    3  *  Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
    55 *
     
    3030 *  using the conio library, and on Windows systems using either slang or
    3131 *  ncurses (through Cygwin emulation) or conio. There is also a native X11
    32  *  driver, and an OpenGL driver (through freeglut) that does not require a 
     32 *  driver, and an OpenGL driver (through freeglut) that does not require a
    3333 *  text terminal.
    3434 *
     
    4141 *  \section api The libcaca API
    4242 *
    43  *  The complete \e libcaca programming interface is available from the
    44  *  caca.h header.
     43 *  \e libcaca relies on a low-level, device independent library, called
     44 *  \e libcucul. \e libcucul can be used alone as a simple ASCII and/or
     45 *  Unicode compositing canvas.
     46 *
     47 *  The complete \e libcucul and \e libcaca programming interface is
     48 *  available from the cucul.h and caca.h headers.
    4549 *
    4650 *  \section env Environment variables
    4751 *
    4852 *  Some environment variables can be used to change the behaviour of
    49  *  \e libcaca without having to modify the program which uses it. These
    50  *  variables are:
     53 *  \e libcaca or \e libcucul without having to modify the program which
     54 *  uses them. These variables are:
    5155 *
    5256 *  \li \b CACA_DRIVER: set the backend video driver. In order of preference:
     
    5862 *      - \c null uses nothing at all, and will display nothing as well.
    5963 *
    60  *  \li \b CACA_GEOMETRY: set the video display size. The format of this
    61  *      variable must be XxY, with X and Y being integer values. This option
    62  *      currently only works with the X11 and the GL driver.
    63  *
    64  *  \li \b CACA_FONT: set the rendered font. The format of this variable is
    65  *      implementation dependent, but since it currently only works with the
    66  *      X11 driver, an X11 font name such as "fixed" or "5x7" is expected.
    67  *
    68  *  \li \b CACA_BACKGROUND: set the background type.
     64 *  \li \b CUCUL_BACKGROUND: set the background type.
    6965 *      - \c solid uses solid coloured backgrounds for all characters. This
    7066 *        feature does not work with all terminal emulators. This is the
     
    7268 *      - \c black uses only black backgrounds to render characters.
    7369 *
    74  *  \li \b CACA_ANTIALIASING: set the antialiasing mode. Antialiasing
     70 *  \li \b CUCUL_ANTIALIASING: set the antialiasing mode. Antialiasing
    7571 *      smoothens the rendered image and avoids the commonly seen staircase
    7672 *      effect.
     
    7975 *        the default choice.
    8076 *
    81  *  \li \b CACA_DITHERING: set the dithering mode. Dithering is necessary
     77 *  \li \b CUCUL_DITHERING: set the dithering mode. Dithering is necessary
    8278 *      when rendering a picture that has more colours than the usually
    8379 *      available palette.
     
    8884 *      - \c ordered8 uses a 8x8 Bayer matrix for dithering.
    8985 *      - \c random uses random dithering.
     86 *
     87 *  \li \b CACA_GEOMETRY: set the video display size. The format of this
     88 *      variable must be XxY, with X and Y being integer values. This option
     89 *      currently only works with the X11 and the GL driver.
     90 *
     91 *  \li \b CACA_FONT: set the rendered font. The format of this variable is
     92 *      implementation dependent, but since it currently only works with the
     93 *      X11 driver, an X11 font name such as "fixed" or "5x7" is expected.
    9094 */
    9195
    9296#ifndef __CACA_H__
    9397#define __CACA_H__
     98
     99#include <cucul.h>
    94100
    95101#ifdef __cplusplus
    96102extern "C"
    97103{
    98 #endif
    99 
    100 /** \brief Colour definitions.
    101  *
    102  *  Colours that can be used with caca_set_color().
    103  */
    104 enum caca_color
    105 {
    106     CACA_COLOR_BLACK = 0, /**< The colour index for black. */
    107     CACA_COLOR_BLUE = 1, /**< The colour index for blue. */
    108     CACA_COLOR_GREEN = 2, /**< The colour index for green. */
    109     CACA_COLOR_CYAN = 3, /**< The colour index for cyan. */
    110     CACA_COLOR_RED = 4, /**< The colour index for red. */
    111     CACA_COLOR_MAGENTA = 5, /**< The colour index for magenta. */
    112     CACA_COLOR_BROWN = 6, /**< The colour index for brown. */
    113     CACA_COLOR_LIGHTGRAY = 7, /**< The colour index for light gray. */
    114     CACA_COLOR_DARKGRAY = 8, /**< The colour index for dark gray. */
    115     CACA_COLOR_LIGHTBLUE = 9, /**< The colour index for blue. */
    116     CACA_COLOR_LIGHTGREEN = 10, /**< The colour index for light green. */
    117     CACA_COLOR_LIGHTCYAN = 11, /**< The colour index for light cyan. */
    118     CACA_COLOR_LIGHTRED = 12, /**< The colour index for light red. */
    119     CACA_COLOR_LIGHTMAGENTA = 13, /**< The colour index for light magenta. */
    120     CACA_COLOR_YELLOW = 14, /**< The colour index for yellow. */
    121     CACA_COLOR_WHITE = 15 /**< The colour index for white. */
    122 };
    123 
    124 /** \brief Internal features.
    125  *
    126  *  Internal libcaca features such as the rendering method or the dithering
    127  *  mode.
    128  */
    129 enum caca_feature
    130 {
    131     CACA_BACKGROUND       = 0x10, /**< Properties of background characters. */
    132     CACA_BACKGROUND_BLACK = 0x11, /**< Draw only black backgrounds. */
    133     CACA_BACKGROUND_SOLID = 0x12, /**< Draw coloured solid backgorunds. */
    134 #define CACA_BACKGROUND_MIN 0x11 /**< First background property */
    135 #define CACA_BACKGROUND_MAX 0x12 /**< Last background property */
    136 
    137     CACA_ANTIALIASING           = 0x20, /**< Antialiasing features. */
    138     CACA_ANTIALIASING_NONE      = 0x21, /**< No antialiasing. */
    139     CACA_ANTIALIASING_PREFILTER = 0x22, /**< Prefilter antialiasing. */
    140 #define CACA_ANTIALIASING_MIN     0x21 /**< First antialiasing feature. */
    141 #define CACA_ANTIALIASING_MAX     0x22 /**< Last antialiasing feature. */
    142 
    143     CACA_DITHERING          = 0x30, /**< Dithering methods */
    144     CACA_DITHERING_NONE     = 0x31, /**< No dithering. */
    145     CACA_DITHERING_ORDERED2 = 0x32, /**< Ordered 2x2 Bayer dithering. */
    146     CACA_DITHERING_ORDERED4 = 0x33, /**< Ordered 4x4 Bayer dithering. */
    147     CACA_DITHERING_ORDERED8 = 0x34, /**< Ordered 8x8 Bayer dithering. */
    148     CACA_DITHERING_RANDOM   = 0x35, /**< Random dithering. */
    149     CACA_DITHERING_FSTEIN   = 0x36, /**< Floyd-Steinberg dithering. */
    150 #define CACA_DITHERING_MIN    0x31 /**< First dithering feature. */
    151 #define CACA_DITHERING_MAX    0x36 /**< Last dithering feature. */
    152 
    153     CACA_FEATURE_UNKNOWN = 0xffff /**< Unknown feature. */
    154 };
    155 
    156 /*
    157  * Backwards compatibility macros
    158  */
    159 #if !defined(_DOXYGEN_SKIP_ME)
    160 #define caca_dithering caca_feature
    161 #define caca_set_dithering caca_set_feature
    162 #define caca_get_dithering_name caca_get_feature_name
    163 #define CACA_DITHER_NONE    CACA_DITHERING_NONE
    164 #define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
    165 #define CACA_DITHER_RANDOM  CACA_DITHERING_RANDOM
    166104#endif
    167105
     
    229167};
    230168
     169typedef struct caca_context caca_t;
     170
    231171/** \defgroup basic Basic functions
    232172 *
     
    235175 *
    236176 *  @{ */
    237 int caca_init(void);
    238 void caca_set_delay(unsigned int);
    239 enum caca_feature caca_get_feature(enum caca_feature);
    240 void caca_set_feature(enum caca_feature);
    241 char const *caca_get_feature_name(enum caca_feature);
    242 unsigned int caca_get_rendertime(void);
    243 unsigned int caca_get_width(void);
    244 unsigned int caca_get_height(void);
    245 void caca_set_size(unsigned int width, unsigned int height);
    246 void caca_set_width(unsigned int width);
    247 void caca_set_height(unsigned int height);
    248 int caca_set_window_title(char const *);
    249 unsigned int caca_get_window_width(void);
    250 unsigned int caca_get_window_height(void);
    251 void caca_refresh(void);
    252 void caca_end(void);
     177caca_t * caca_attach(cucul_t *qq);
     178void caca_detach(caca_t *kk);
     179void caca_set_delay(caca_t *kk, unsigned int);
     180void caca_refresh(caca_t *kk);
     181unsigned int caca_get_rendertime(caca_t *kk);
     182unsigned int caca_get_window_width(caca_t *kk);
     183unsigned int caca_get_window_height(caca_t *kk);
     184void caca_set_size(caca_t *kk, unsigned int width, unsigned int height);
     185void caca_set_width(caca_t *kk, unsigned int width);
     186void caca_set_height(caca_t *kk, unsigned int height);
     187int caca_set_window_title(caca_t *kk, char const *);
    253188/*  @} */
    254189
     
    259194 *
    260195 *  @{ */
    261 unsigned int caca_get_event(unsigned int);
    262 unsigned int caca_wait_event(unsigned int);
    263 unsigned int caca_get_mouse_x(void);
    264 unsigned int caca_get_mouse_y(void);
    265 /*  @} */
    266 
    267 /** \defgroup char Character printing
    268  *
    269  *  These functions provide low-level character printing routines.
    270  *
    271  *  @{ */
    272 void caca_set_color(enum caca_color, enum caca_color);
    273 enum caca_color caca_get_fg_color(void);
    274 enum caca_color caca_get_bg_color(void);
    275 char const *caca_get_color_name(enum caca_color);
    276 void caca_putchar(int, int, char);
    277 void caca_putstr(int, int, char const *);
    278 void caca_printf(int, int, char const *, ...);
    279 void caca_get_screen(char *);
    280 void caca_clear(void);
    281 /*  @} */
    282 
    283 /** \defgroup prim Primitives drawing
    284  *
    285  *  These functions provide routines for primitive drawing, such as lines,
    286  *  boxes, triangles and ellipses.
    287  *
    288  *  @{ */
    289 void caca_draw_line(int, int, int, int, char);
    290 void caca_draw_polyline(int const x[], int const y[], int, char);
    291 void caca_draw_thin_line(int, int, int, int);
    292 void caca_draw_thin_polyline(int const x[], int const y[], int);
    293 
    294 void caca_draw_circle(int, int, int, char);
    295 void caca_draw_ellipse(int, int, int, int, char);
    296 void caca_draw_thin_ellipse(int, int, int, int);
    297 void caca_fill_ellipse(int, int, int, int, char);
    298 
    299 void caca_draw_box(int, int, int, int, char);
    300 void caca_draw_thin_box(int, int, int, int);
    301 void caca_fill_box(int, int, int, int, char);
    302 
    303 void caca_draw_triangle(int, int, int, int, int, int, char);
    304 void caca_draw_thin_triangle(int, int, int, int, int, int);
    305 void caca_fill_triangle(int, int, int, int, int, int, char);
    306 /*  @} */
    307 
    308 /** \defgroup math Mathematical functions
    309  *
    310  *  These functions provide a few useful math-related routines.
    311  *
    312  *  @{ */
    313 int caca_rand(int, int);
    314 unsigned int caca_sqrt(unsigned int);
    315 float caca_powf(float x, float y);
    316 /*  @} */
    317 
    318 /** \defgroup sprite Sprite handling
    319  *
    320  *  These functions provide high level routines for sprite loading, animation
    321  *  and rendering.
    322  *
    323  *  @{ */
    324 struct caca_sprite;
    325 struct caca_sprite * caca_load_sprite(char const *);
    326 int caca_get_sprite_frames(struct caca_sprite const *);
    327 int caca_get_sprite_width(struct caca_sprite const *, int);
    328 int caca_get_sprite_height(struct caca_sprite const *, int);
    329 int caca_get_sprite_dx(struct caca_sprite const *, int);
    330 int caca_get_sprite_dy(struct caca_sprite const *, int);
    331 void caca_draw_sprite(int, int, struct caca_sprite const *, int);
    332 void caca_free_sprite(struct caca_sprite *);
    333 /*  @} */
    334 
    335 /** \defgroup bitmap Bitmap handling
    336  *
    337  *  These functions provide high level routines for bitmap allocation and
    338  *  rendering.
    339  *
    340  *  @{ */
    341 struct caca_bitmap;
    342 struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
    343                                        unsigned int, unsigned int,
    344                                        unsigned int, unsigned int,
    345                                        unsigned int, unsigned int);
    346 void caca_set_bitmap_palette(struct caca_bitmap *,
    347                              unsigned int r[], unsigned int g[],
    348                              unsigned int b[], unsigned int a[]);
    349 void caca_set_bitmap_gamma(struct caca_bitmap *, float);
    350 void caca_draw_bitmap(int, int, int, int, struct caca_bitmap const *, void *);
    351 void caca_free_bitmap(struct caca_bitmap *);
    352 /*  @} */
    353 
    354 /** \defgroup exporter Exporters to various formats
    355  *
    356  *  These functions exports current image to various text formats
    357  *
    358  *  @{ */
    359 char* caca_get_html(void);
    360 char* caca_get_html3(void);
    361 char* caca_get_irc(void);
    362 char* caca_get_ansi(int trailing);
     196unsigned int caca_get_event(caca_t *kk, unsigned int);
     197unsigned int caca_wait_event(caca_t *kk, unsigned int);
     198unsigned int caca_get_mouse_x(caca_t *kk);
     199unsigned int caca_get_mouse_y(caca_t *kk);
    363200/*  @} */
    364201
  • libcaca/trunk/src/caca_internals.h

    r522 r524  
    2121#define __CACA_INTERNALS_H__
    2222
     23#if defined(USE_X11)
     24#include <X11/Xlib.h>
     25#endif
     26
    2327/* Graphics driver */
    2428enum caca_driver
     
    4246    CACA_DRIVER_GL = 6,
    4347#endif
    44 #if defined(USE_NULL)
    45     CACA_DRIVER_NULL = 7,
    46 #endif
    4748    CACA_DRIVER_NONE = 0
    4849};
     
    5556};
    5657
    57 extern enum caca_driver _caca_driver;
     58/* Internal caca context */
     59struct caca_context
     60{
     61    cucul_t *qq;
     62
     63    enum caca_driver driver;
     64    unsigned int width, height;
     65
     66    int resize;
     67    int resize_event;
     68
     69    unsigned int delay, rendertime;
     70
     71#if defined(USE_X11) && !defined(_DOXYGEN_SKIP_ME)
     72    struct x11
     73    {
     74        Display *dpy;
     75        Window window;
     76        Pixmap pixmap;
     77        GC gc;
     78        long int event_mask;
     79        int font_width, font_height;
     80        unsigned int new_width, new_height;
     81        int colors[16];
     82        Font font;
     83        XFontStruct *font_struct;
     84        int font_offset;
     85#if defined(HAVE_X11_XKBLIB_H)
     86        Bool detect_autorepeat;
     87#endif
     88    } x11;
     89#endif
     90};
    5891
    5992/* Initialisation functions */
    60 extern int _caca_init_graphics(void);
    61 extern int _caca_end_graphics(void);
    62 extern int _caca_init_bitmap(void);
    63 extern int _caca_end_bitmap(void);
     93extern int _caca_init_graphics(caca_t *kk);
     94extern int _caca_end_graphics(caca_t *kk);
    6495
    6596/* Timer functions */
     
    72103extern int _caca_resize;
    73104extern int _caca_resize_event;
    74 
    75 /* Internal libcaca features */
    76 extern enum caca_feature _caca_background;
    77 extern enum caca_feature _caca_dithering;
    78 extern enum caca_feature _caca_antialiasing;
    79 
    80 #if defined(USE_X11)
    81 #include <X11/Xlib.h>
    82 extern Display *x11_dpy;
    83 extern Window x11_window;
    84 extern Pixmap x11_pixmap;
    85 extern GC x11_gc;
    86 extern long int x11_event_mask;
    87 extern int x11_font_width, x11_font_height;
    88 extern unsigned int x11_new_width, x11_new_height;
    89 #endif
    90105
    91106#if defined(USE_WIN32)
  • libcaca/trunk/src/conic.c

    r522 r524  
    2929#include <stdlib.h>
    3030
    31 #include "caca.h"
    32 #include "caca_internals.h"
    33 
    34 static void ellipsepoints(int, int, int, int, char);
     31#include "cucul.h"
     32#include "cucul_internals.h"
     33
     34static void ellipsepoints(cucul_t *, int, int, int, int, char);
    3535
    3636/**
     
    4343 * \return void
    4444 */
    45 void caca_draw_circle(int x, int y, int r, char c)
     45void cucul_draw_circle(cucul_t *qq, int x, int y, int r, char c)
    4646{
    4747    int test, dx, dy;
     
    5050    for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++)
    5151    {
    52         ellipsepoints(x, y, dx, dy, c);
    53         ellipsepoints(x, y, dy, dx, c);
     52        ellipsepoints(qq, x, y, dx, dy, c);
     53        ellipsepoints(qq, x, y, dy, dx, c);
    5454
    5555        test += test > 0 ? dx - dy-- : dx;
     
    6767 * \return void
    6868 */
    69 void caca_fill_ellipse(int xo, int yo, int a, int b, char c)
     69void cucul_fill_ellipse(cucul_t *qq, int xo, int yo, int a, int b, char c)
    7070{
    7171    int d2;
     
    8383        {
    8484            d1 += b*b*(2*x*1) + a*a*(-2*y+2);
    85             caca_draw_line(xo - x, yo - y, xo + x, yo - y, c);
    86             caca_draw_line(xo - x, yo + y, xo + x, yo + y, c);
     85            cucul_draw_line(qq, xo - x, yo - y, xo + x, yo - y, c);
     86            cucul_draw_line(qq, xo - x, yo + y, xo + x, yo + y, c);
    8787            y--;
    8888        }
     
    9090    }
    9191
    92     caca_draw_line(xo - x, yo - y, xo + x, yo - y, c);
    93     caca_draw_line(xo - x, yo + y, xo + x, yo + y, c);
     92    cucul_draw_line(qq, xo - x, yo - y, xo + x, yo - y, c);
     93    cucul_draw_line(qq, xo - x, yo + y, xo + x, yo + y, c);
    9494
    9595    d2 = b*b*(x+0.5)*(x+0.5) + a*a*(y-1)*(y-1) - a*a*b*b;
     
    107107
    108108        y--;
    109         caca_draw_line(xo - x, yo - y, xo + x, yo - y, c);
    110         caca_draw_line(xo - x, yo + y, xo + x, yo + y, c);
     109        cucul_draw_line(qq, xo - x, yo - y, xo + x, yo - y, c);
     110        cucul_draw_line(qq, xo - x, yo + y, xo + x, yo + y, c);
    111111    }
    112112}
     
    122122 * \return void
    123123 */
    124 void caca_draw_ellipse(int xo, int yo, int a, int b, char c)
     124void cucul_draw_ellipse(cucul_t *qq, int xo, int yo, int a, int b, char c)
    125125{
    126126    int d2;
     
    129129    int d1 = b*b - (a*a*b) + (a*a/4);
    130130
    131     ellipsepoints(xo, yo, x, y, c);
     131    ellipsepoints(qq, xo, yo, x, y, c);
    132132
    133133    while(a*a*y - a*a/2 > b*b*(x+1))
     
    143143        }
    144144        x++;
    145         ellipsepoints(xo, yo, x, y, c);
     145        ellipsepoints(qq, xo, yo, x, y, c);
    146146    }
    147147
     
    160160
    161161        y--;
    162         ellipsepoints(xo, yo, x, y, c);
     162        ellipsepoints(qq, xo, yo, x, y, c);
    163163    }
    164164}
     
    173173 * \return void
    174174 */
    175 void caca_draw_thin_ellipse(int xo, int yo, int a, int b)
     175void cucul_draw_thin_ellipse(cucul_t *qq, int xo, int yo, int a, int b)
    176176{
    177177    /* FIXME: this is not correct */
     
    181181    int d1 = b*b - (a*a*b) + (a*a/4);
    182182
    183     ellipsepoints(xo, yo, x, y, '-');
     183    ellipsepoints(qq, xo, yo, x, y, '-');
    184184
    185185    while(a*a*y - a*a/2 > b*b*(x+1))
     
    195195        }
    196196        x++;
    197         ellipsepoints(xo, yo, x, y, '-');
     197        ellipsepoints(qq, xo, yo, x, y, '-');
    198198    }
    199199
     
    212212
    213213        y--;
    214         ellipsepoints(xo, yo, x, y, '|');
    215     }
    216 }
    217 
    218 static void ellipsepoints(int xo, int yo, int x, int y, char c)
     214        ellipsepoints(qq, xo, yo, x, y, '|');
     215    }
     216}
     217
     218static void ellipsepoints(cucul_t *qq, int xo, int yo, int x, int y, char c)
    219219{
    220220    uint8_t b = 0;
    221221
    222     if(xo + x >= 0 && xo + x < (int)_caca_width)
     222    if(xo + x >= 0 && xo + x < (int)qq->width)
    223223        b |= 0x1;
    224     if(xo - x >= 0 && xo - x < (int)_caca_width)
     224    if(xo - x >= 0 && xo - x < (int)qq->width)
    225225        b |= 0x2;
    226     if(yo + y >= 0 && yo + y < (int)_caca_height)
     226    if(yo + y >= 0 && yo + y < (int)qq->height)
    227227        b |= 0x4;
    228     if(yo - y >= 0 && yo - y < (int)_caca_height)
     228    if(yo - y >= 0 && yo - y < (int)qq->height)
    229229        b |= 0x8;
    230230
    231231    if((b & (0x1|0x4)) == (0x1|0x4))
    232         caca_putchar(xo + x, yo + y, c);
     232        cucul_putchar(qq, xo + x, yo + y, c);
    233233
    234234    if((b & (0x2|0x4)) == (0x2|0x4))
    235         caca_putchar(xo - x, yo + y, c);
     235        cucul_putchar(qq, xo - x, yo + y, c);
    236236
    237237    if((b & (0x1|0x8)) == (0x1|0x8))
    238         caca_putchar(xo + x, yo - y, c);
     238        cucul_putchar(qq, xo + x, yo - y, c);
    239239
    240240    if((b & (0x2|0x8)) == (0x2|0x8))
    241         caca_putchar(xo - x, yo - y, c);
    242 }
    243 
     241        cucul_putchar(qq, xo - x, yo - y, c);
     242}
     243
  • libcaca/trunk/src/cucul.h

    r522 r524  
    11/*
    2  *  libcaca       ASCII-Art library
    3  *  Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
     2 *  libcucul      Unicode canvas library
     3 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
    55 *
     
    1010 */
    1111
    12 /** \file caca.h
     12/** \file cucul.h
    1313 *  \version \$Id$
    1414 *  \author Sam Hocevar <sam@zoy.org>
    15  *  \brief The \e libcaca public header.
     15 *  \brief The \e libcucul public header.
    1616 *
    1717 *  This header contains the public types and functions that applications
    18  *  using \e libcaca may use.
    19  */
    20 
    21 /** \mainpage libcaca developer documentation
    22  *
    23  *  \section intro Introduction
    24  *
    25  *  \e libcaca is a graphics library that outputs text instead of pixels,
    26  *  so that it can work on older video cards or text terminals. It is not
    27  *  unlike the famous AAlib library. \e libcaca can use almost any virtual
    28  *  terminal to work, thus it should work on all Unix systems (including
    29  *  Mac OS X) using either the slang library or the ncurses library, on DOS
    30  *  using the conio library, and on Windows systems using either slang or
    31  *  ncurses (through Cygwin emulation) or conio. There is also a native X11
    32  *  driver, and an OpenGL driver (through freeglut) that does not require a
    33  *  text terminal.
    34  *
    35  *  \e libcaca is free software, released under the Do What The Fuck You
    36  *  Want To Public License. This ensures that no one, not even the \e libcaca
    37  *  developers, will ever have anything to say about what you do with the
    38  *  software. It used to be licensed under the GNU Lesser General Public
    39  *  License, but that was not free enough.
    40  *
    41  *  \section api The libcaca API
    42  *
    43  *  The complete \e libcaca programming interface is available from the
    44  *  caca.h header.
    45  *
    46  *  \section env Environment variables
    47  *
    48  *  Some environment variables can be used to change the behaviour of
    49  *  \e libcaca without having to modify the program which uses it. These
    50  *  variables are:
    51  *
    52  *  \li \b CACA_DRIVER: set the backend video driver. In order of preference:
    53  *      - \c conio uses the DOS conio.h interface.
    54  *      - \c ncurses uses the ncurses library.
    55  *      - \c slang uses the S-Lang library.
    56  *      - \c x11 uses the native X11 driver.
    57  *      - \c gl uses freeglut and opengl libraries.
    58  *      - \c null uses nothing at all, and will display nothing as well.
    59  *
    60  *  \li \b CACA_GEOMETRY: set the video display size. The format of this
    61  *      variable must be XxY, with X and Y being integer values. This option
    62  *      currently only works with the X11 and the GL driver.
    63  *
    64  *  \li \b CACA_FONT: set the rendered font. The format of this variable is
    65  *      implementation dependent, but since it currently only works with the
    66  *      X11 driver, an X11 font name such as "fixed" or "5x7" is expected.
    67  *
    68  *  \li \b CACA_BACKGROUND: set the background type.
    69  *      - \c solid uses solid coloured backgrounds for all characters. This
    70  *        feature does not work with all terminal emulators. This is the
    71  *        default choice.
    72  *      - \c black uses only black backgrounds to render characters.
    73  *
    74  *  \li \b CACA_ANTIALIASING: set the antialiasing mode. Antialiasing
    75  *      smoothens the rendered image and avoids the commonly seen staircase
    76  *      effect.
    77  *      - \c none disables antialiasing.
    78  *      - \c prefilter uses a simple prefilter antialiasing method. This is
    79  *        the default choice.
    80  *
    81  *  \li \b CACA_DITHERING: set the dithering mode. Dithering is necessary
    82  *      when rendering a picture that has more colours than the usually
    83  *      available palette.
    84  *      - \c none disables dithering.
    85  *      - \c ordered2 uses a 2x2 Bayer matrix for dithering.
    86  *      - \c ordered4 uses a 4x4 Bayer matrix for dithering. This is the
    87  *        default choice.
    88  *      - \c ordered8 uses a 8x8 Bayer matrix for dithering.
    89  *      - \c random uses random dithering.
    90  */
    91 
    92 #ifndef __CACA_H__
    93 #define __CACA_H__
     18 *  using \e libcucul may use.
     19 */
     20
     21#ifndef __CUCUL_H__
     22#define __CUCUL_H__
    9423
    9524#ifdef __cplusplus
     
    10231 *  Colours that can be used with caca_set_color().
    10332 */
    104 enum caca_color
     33enum cucul_color
    10534{
    106     CACA_COLOR_BLACK = 0, /**< The colour index for black. */
    107     CACA_COLOR_BLUE = 1, /**< The colour index for blue. */
    108     CACA_COLOR_GREEN = 2, /**< The colour index for green. */
    109     CACA_COLOR_CYAN = 3, /**< The colour index for cyan. */
    110     CACA_COLOR_RED = 4, /**< The colour index for red. */
    111     CACA_COLOR_MAGENTA = 5, /**< The colour index for magenta. */
    112     CACA_COLOR_BROWN = 6, /**< The colour index for brown. */
    113     CACA_COLOR_LIGHTGRAY = 7, /**< The colour index for light gray. */
    114     CACA_COLOR_DARKGRAY = 8, /**< The colour index for dark gray. */
    115     CACA_COLOR_LIGHTBLUE = 9, /**< The colour index for blue. */
    116     CACA_COLOR_LIGHTGREEN = 10, /**< The colour index for light green. */
    117     CACA_COLOR_LIGHTCYAN = 11, /**< The colour index for light cyan. */
    118     CACA_COLOR_LIGHTRED = 12, /**< The colour index for light red. */
    119     CACA_COLOR_LIGHTMAGENTA = 13, /**< The colour index for light magenta. */
    120     CACA_COLOR_YELLOW = 14, /**< The colour index for yellow. */
    121     CACA_COLOR_WHITE = 15 /**< The colour index for white. */
     35    CUCUL_COLOR_BLACK = 0, /**< The colour index for black. */
     36    CUCUL_COLOR_BLUE = 1, /**< The colour index for blue. */
     37    CUCUL_COLOR_GREEN = 2, /**< The colour index for green. */
     38    CUCUL_COLOR_CYAN = 3, /**< The colour index for cyan. */
     39    CUCUL_COLOR_RED = 4, /**< The colour index for red. */
     40    CUCUL_COLOR_MAGENTA = 5, /**< The colour index for magenta. */
     41    CUCUL_COLOR_BROWN = 6, /**< The colour index for brown. */
     42    CUCUL_COLOR_LIGHTGRAY = 7, /**< The colour index for light gray. */
     43    CUCUL_COLOR_DARKGRAY = 8, /**< The colour index for dark gray. */
     44    CUCUL_COLOR_LIGHTBLUE = 9, /**< The colour index for blue. */
     45    CUCUL_COLOR_LIGHTGREEN = 10, /**< The colour index for light green. */
     46    CUCUL_COLOR_LIGHTCYAN = 11, /**< The colour index for light cyan. */
     47    CUCUL_COLOR_LIGHTRED = 12, /**< The colour index for light red. */
     48    CUCUL_COLOR_LIGHTMAGENTA = 13, /**< The colour index for light magenta. */
     49    CUCUL_COLOR_YELLOW = 14, /**< The colour index for yellow. */
     50    CUCUL_COLOR_WHITE = 15 /**< The colour index for white. */
    12251};
    12352
     
    12756 *  mode.
    12857 */
    129 enum caca_feature
     58enum cucul_feature
    13059{
    131     CACA_BACKGROUND       = 0x10, /**< Properties of background characters. */
    132     CACA_BACKGROUND_BLACK = 0x11, /**< Draw only black backgrounds. */
    133     CACA_BACKGROUND_SOLID = 0x12, /**< Draw coloured solid backgorunds. */
    134 #define CACA_BACKGROUND_MIN 0x11 /**< First background property */
    135 #define CACA_BACKGROUND_MAX 0x12 /**< Last background property */
    136 
    137     CACA_ANTIALIASING           = 0x20, /**< Antialiasing features. */
    138     CACA_ANTIALIASING_NONE      = 0x21, /**< No antialiasing. */
    139     CACA_ANTIALIASING_PREFILTER = 0x22, /**< Prefilter antialiasing. */
    140 #define CACA_ANTIALIASING_MIN     0x21 /**< First antialiasing feature. */
    141 #define CACA_ANTIALIASING_MAX     0x22 /**< Last antialiasing feature. */
    142 
    143     CACA_DITHERING          = 0x30, /**< Dithering methods */
    144     CACA_DITHERING_NONE     = 0x31, /**< No dithering. */
    145     CACA_DITHERING_ORDERED2 = 0x32, /**< Ordered 2x2 Bayer dithering. */
    146     CACA_DITHERING_ORDERED4 = 0x33, /**< Ordered 4x4 Bayer dithering. */
    147     CACA_DITHERING_ORDERED8 = 0x34, /**< Ordered 8x8 Bayer dithering. */
    148     CACA_DITHERING_RANDOM   = 0x35, /**< Random dithering. */
    149     CACA_DITHERING_FSTEIN   = 0x36, /**< Floyd-Steinberg dithering. */
    150 #define CACA_DITHERING_MIN    0x31 /**< First dithering feature. */
    151 #define CACA_DITHERING_MAX    0x36 /**< Last dithering feature. */
    152 
    153     CACA_FEATURE_UNKNOWN = 0xffff /**< Unknown feature. */
     60    CUCUL_BACKGROUND       = 0x10, /**< Properties of background characters. */
     61    CUCUL_BACKGROUND_BLACK = 0x11, /**< Draw only black backgrounds. */
     62    CUCUL_BACKGROUND_SOLID = 0x12, /**< Draw coloured solid backgorunds. */
     63#define CUCUL_BACKGROUND_MIN 0x11 /**< First background property */
     64#define CUCUL_BACKGROUND_MAX 0x12 /**< Last background property */
     65
     66    CUCUL_ANTIALIASING           = 0x20, /**< Antialiasing features. */
     67    CUCUL_ANTIALIASING_NONE      = 0x21, /**< No antialiasing. */
     68    CUCUL_ANTIALIASING_PREFILTER = 0x22, /**< Prefilter antialiasing. */
     69#define CUCUL_ANTIALIASING_MIN     0x21 /**< First antialiasing feature. */
     70#define CUCUL_ANTIALIASING_MAX     0x22 /**< Last antialiasing feature. */
     71
     72    CUCUL_DITHERING          = 0x30, /**< Dithering methods */
     73    CUCUL_DITHERING_NONE     = 0x31, /**< No dithering. */
     74    CUCUL_DITHERING_ORDERED2 = 0x32, /**< Ordered 2x2 Bayer dithering. */
     75    CUCUL_DITHERING_ORDERED4 = 0x33, /**< Ordered 4x4 Bayer dithering. */
     76    CUCUL_DITHERING_ORDERED8 = 0x34, /**< Ordered 8x8 Bayer dithering. */
     77    CUCUL_DITHERING_RANDOM   = 0x35, /**< Random dithering. */
     78    CUCUL_DITHERING_FSTEIN   = 0x36, /**< Floyd-Steinberg dithering. */
     79#define CUCUL_DITHERING_MIN    0x31 /**< First dithering feature. */
     80#define CUCUL_DITHERING_MAX    0x36 /**< Last dithering feature. */
     81
     82    CUCUL_FEATURE_UNKNOWN = 0xffff /**< Unknown feature. */
    15483};
    15584
     
    15887 */
    15988#if !defined(_DOXYGEN_SKIP_ME)
    160 #define caca_dithering caca_feature
     89#define caca_dithering cucul_feature
    16190#define caca_set_dithering caca_set_feature
    16291#define caca_get_dithering_name caca_get_feature_name
    163 #define CACA_DITHER_NONE    CACA_DITHERING_NONE
    164 #define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
    165 #define CACA_DITHER_RANDOM  CACA_DITHERING_RANDOM
     92#define CACA_DITHER_NONE    CUCUL_DITHERING_NONE
     93#define CACA_DITHER_ORDERED CUCUL_DITHERING_ORDERED8
     94#define CACA_DITHER_RANDOM  CUCUL_DITHERING_RANDOM
    16695#endif
    16796
    168 /** \brief User events.
    169  *
    170  *  Event types returned by caca_get_event().
    171  */
    172 enum caca_event
    173 {
    174     CACA_EVENT_NONE =          0x00000000, /**< No event. */
    175     CACA_EVENT_KEY_PRESS =     0x01000000, /**< A key was pressed. */
    176     CACA_EVENT_KEY_RELEASE =   0x02000000, /**< A key was released. */
    177     CACA_EVENT_MOUSE_PRESS =   0x04000000, /**< A mouse button was pressed. */
    178     CACA_EVENT_MOUSE_RELEASE = 0x08000000, /**< A mouse button was released. */
    179     CACA_EVENT_MOUSE_MOTION =  0x10000000, /**< The mouse was moved. */
    180     CACA_EVENT_RESIZE =        0x20000000, /**< The window was resized. */
    181     CACA_EVENT_ANY =           0xff000000  /**< Bitmask for any event. */
    182 };
    183 
    184 /** \brief Special key values.
    185  *
    186  *  Special key values returned by caca_get_event() for which there is no
    187  *  ASCII equivalent.
    188  */
    189 enum caca_key
    190 {
    191     CACA_KEY_UNKNOWN = 0, /**< Unknown key. */
    192 
    193     /* The following keys have ASCII equivalents */
    194     CACA_KEY_BACKSPACE = 8, /**< The backspace key. */
    195     CACA_KEY_TAB = 9, /**< The tabulation key. */
    196     CACA_KEY_RETURN = 13, /**< The return key. */
    197     CACA_KEY_PAUSE = 19, /**< The pause key. */
    198     CACA_KEY_ESCAPE = 27, /**< The escape key. */
    199     CACA_KEY_DELETE = 127, /**< The delete key. */
    200 
    201     /* The following keys do not have ASCII equivalents but have been
    202      * chosen to match the SDL equivalents */
    203     CACA_KEY_UP = 273, /**< The up arrow key. */
    204     CACA_KEY_DOWN = 274, /**< The down arrow key. */
    205     CACA_KEY_LEFT = 275, /**< The left arrow key. */
    206     CACA_KEY_RIGHT = 276, /**< The right arrow key. */
    207 
    208     CACA_KEY_INSERT = 277, /**< The insert key. */
    209     CACA_KEY_HOME = 278, /**< The home key. */
    210     CACA_KEY_END = 279, /**< The end key. */
    211     CACA_KEY_PAGEUP = 280, /**< The page up key. */
    212     CACA_KEY_PAGEDOWN = 281, /**< The page down key. */
    213 
    214     CACA_KEY_F1 = 282, /**< The F1 key. */
    215     CACA_KEY_F2 = 283, /**< The F2 key. */
    216     CACA_KEY_F3 = 284, /**< The F3 key. */
    217     CACA_KEY_F4 = 285, /**< The F4 key. */
    218     CACA_KEY_F5 = 286, /**< The F5 key. */
    219     CACA_KEY_F6 = 287, /**< The F6 key. */
    220     CACA_KEY_F7 = 288, /**< The F7 key. */
    221     CACA_KEY_F8 = 289, /**< The F8 key. */
    222     CACA_KEY_F9 = 290, /**< The F9 key. */
    223     CACA_KEY_F10 = 291, /**< The F10 key. */
    224     CACA_KEY_F11 = 292, /**< The F11 key. */
    225     CACA_KEY_F12 = 293, /**< The F12 key. */
    226     CACA_KEY_F13 = 294, /**< The F13 key. */
    227     CACA_KEY_F14 = 295, /**< The F14 key. */
    228     CACA_KEY_F15 = 296 /**< The F15 key. */
    229 };
     97typedef struct cucul_context cucul_t;
    23098
    23199/** \defgroup basic Basic functions
     
    235103 *
    236104 *  @{ */
    237 int caca_init(void);
    238 void caca_set_delay(unsigned int);
    239 enum caca_feature caca_get_feature(enum caca_feature);
    240 void caca_set_feature(enum caca_feature);
    241 char const *caca_get_feature_name(enum caca_feature);
    242 unsigned int caca_get_rendertime(void);
    243 unsigned int caca_get_width(void);
    244 unsigned int caca_get_height(void);
    245 void caca_set_size(unsigned int width, unsigned int height);
    246 void caca_set_width(unsigned int width);
    247 void caca_set_height(unsigned int height);
    248 int caca_set_window_title(char const *);
    249 unsigned int caca_get_window_width(void);
    250 unsigned int caca_get_window_height(void);
    251 void caca_refresh(void);
    252 void caca_end(void);
    253 /*  @} */
    254 
    255 /** \defgroup event Event handling
    256  *
    257  *  These functions handle user events such as keyboard input and mouse
    258  *  clicks.
    259  *
    260  *  @{ */
    261 unsigned int caca_get_event(unsigned int);
    262 unsigned int caca_wait_event(unsigned int);
    263 unsigned int caca_get_mouse_x(void);
    264 unsigned int caca_get_mouse_y(void);
     105cucul_t * cucul_init(void);
     106void cucul_set_size(cucul_t *, unsigned int, unsigned int);
     107unsigned int cucul_get_width(cucul_t *);
     108unsigned int cucul_get_height(cucul_t *);
     109enum cucul_feature cucul_get_feature(cucul_t *, enum cucul_feature);
     110void cucul_set_feature(cucul_t *, enum cucul_feature);
     111char const *cucul_get_feature_name(enum cucul_feature);
     112void cucul_end(cucul_t *);
    265113/*  @} */
    266114
     
    270118 *
    271119 *  @{ */
    272 void caca_set_color(enum caca_color, enum caca_color);
    273 enum caca_color caca_get_fg_color(void);
    274 enum caca_color caca_get_bg_color(void);
    275 char const *caca_get_color_name(enum caca_color);
    276 void caca_putchar(int, int, char);
    277 void caca_putstr(int, int, char const *);
    278 void caca_printf(int, int, char const *, ...);
    279 void caca_get_screen(char *);
    280 void caca_clear(void);
     120void cucul_set_color(cucul_t *, enum cucul_color, enum cucul_color);
     121enum cucul_color cucul_get_fg_color(cucul_t *);
     122enum cucul_color cucul_get_bg_color(cucul_t *);
     123char const *cucul_get_color_name(enum cucul_color);
     124void cucul_putchar(cucul_t *, int, int, char);
     125void cucul_putstr(cucul_t *, int, int, char const *);
     126void cucul_printf(cucul_t *, int, int, char const *, ...);
     127void cucul_get_screen(cucul_t *, char *);
     128void cucul_clear(cucul_t *);
    281129/*  @} */
    282130
     
    287135 *
    288136 *  @{ */
    289 void caca_draw_line(int, int, int, int, char);
    290 void caca_draw_polyline(int const x[], int const y[], int, char);
    291 void caca_draw_thin_line(int, int, int, int);
    292 void caca_draw_thin_polyline(int const x[], int const y[], int);
    293 
    294 void caca_draw_circle(int, int, int, char);
    295 void caca_draw_ellipse(int, int, int, int, char);
    296 void caca_draw_thin_ellipse(int, int, int, int);
    297 void caca_fill_ellipse(int, int, int, int, char);
    298 
    299 void caca_draw_box(int, int, int, int, char);
    300 void caca_draw_thin_box(int, int, int, int);
    301 void caca_fill_box(int, int, int, int, char);
    302 
    303 void caca_draw_triangle(int, int, int, int, int, int, char);
    304 void caca_draw_thin_triangle(int, int, int, int, int, int);
    305 void caca_fill_triangle(int, int, int, int, int, int, char);
     137void cucul_draw_line(cucul_t *, int, int, int, int, char);
     138void cucul_draw_polyline(cucul_t *, int const x[], int const y[], int, char);
     139void cucul_draw_thin_line(cucul_t *, int, int, int, int);
     140void cucul_draw_thin_polyline(cucul_t *, int const x[], int const y[], int);
     141
     142void cucul_draw_circle(cucul_t *, int, int, int, char);
     143void cucul_draw_ellipse(cucul_t *, int, int, int, int, char);
     144void cucul_draw_thin_ellipse(cucul_t *, int, int, int, int);
     145void cucul_fill_ellipse(cucul_t *, int, int, int, int, char);
     146
     147void cucul_draw_box(cucul_t *, int, int, int, int, char);
     148void cucul_draw_thin_box(cucul_t *, int, int, int, int);
     149void cucul_fill_box(cucul_t *, int, int, int, int, char);
     150
     151void cucul_draw_triangle(cucul_t *, int, int, int, int, int, int, char);
     152void cucul_draw_thin_triangle(cucul_t *, int, int, int, int, int, int);
     153void cucul_fill_triangle(cucul_t *, int, int, int, int, int, int, char);
    306154/*  @} */
    307155
     
    311159 *
    312160 *  @{ */
    313 int caca_rand(int, int);
    314 unsigned int caca_sqrt(unsigned int);
    315 float caca_powf(float x, float y);
     161int cucul_rand(int, int);
     162unsigned int cucul_sqrt(unsigned int);
     163float cucul_powf(float x, float y);
    316164/*  @} */
    317165
     
    322170 *
    323171 *  @{ */
    324 struct caca_sprite;
    325 struct caca_sprite * caca_load_sprite(char const *);
    326 int caca_get_sprite_frames(struct caca_sprite const *);
    327 int caca_get_sprite_width(struct caca_sprite const *, int);
    328 int caca_get_sprite_height(struct caca_sprite const *, int);
    329 int caca_get_sprite_dx(struct caca_sprite const *, int);
    330 int caca_get_sprite_dy(struct caca_sprite const *, int);
    331 void caca_draw_sprite(int, int, struct caca_sprite const *, int);
    332 void caca_free_sprite(struct caca_sprite *);
     172struct cucul_sprite;
     173struct cucul_sprite * cucul_load_sprite(cucul_t *, char const *);
     174int cucul_get_sprite_frames(cucul_t *, struct cucul_sprite const *);
     175int cucul_get_sprite_width(cucul_t *, struct cucul_sprite const *, int);
     176int cucul_get_sprite_height(cucul_t *, struct cucul_sprite const *, int);
     177int cucul_get_sprite_dx(cucul_t *, struct cucul_sprite const *, int);
     178int cucul_get_sprite_dy(cucul_t *, struct cucul_sprite const *, int);
     179void cucul_draw_sprite(cucul_t *, int, int, struct cucul_sprite const *, int);void cucul_free_sprite(cucul_t *, struct cucul_sprite *);
    333180/*  @} */
    334181
     
    339186 *
    340187 *  @{ */
    341 struct caca_bitmap;
    342 struct caca_bitmap *caca_create_bitmap(unsigned int, unsigned int,
     188struct cucul_bitmap;
     189struct cucul_bitmap *cucul_create_bitmap(cucul_t *, unsigned int, unsigned int,
    343190                                       unsigned int, unsigned int,
    344191                                       unsigned int, unsigned int,
    345192                                       unsigned int, unsigned int);
    346 void caca_set_bitmap_palette(struct caca_bitmap *,
     193void cucul_set_bitmap_palette(cucul_t *, struct cucul_bitmap *,
    347194                             unsigned int r[], unsigned int g[],
    348195                             unsigned int b[], unsigned int a[]);
    349 void caca_set_bitmap_gamma(struct caca_bitmap *, float);
    350 void caca_draw_bitmap(int, int, int, int, struct caca_bitmap const *, void *);
    351 void caca_free_bitmap(struct caca_bitmap *);
     196void cucul_set_bitmap_gamma(cucul_t *, struct cucul_bitmap *, float);
     197void cucul_draw_bitmap(cucul_t *, int, int, int, int, struct cucul_bitmap const *, void *);
     198void cucul_free_bitmap(cucul_t *, struct cucul_bitmap *);
    352199/*  @} */
    353200
     
    357204 *
    358205 *  @{ */
    359 char* caca_get_html(void);
    360 char* caca_get_html3(void);
    361 char* caca_get_irc(void);
    362 char* caca_get_ansi(int trailing);
     206char* cucul_get_html(cucul_t *);
     207char* cucul_get_html3(cucul_t *);
     208char* cucul_get_irc(cucul_t *);
     209char* cucul_get_ansi(cucul_t *, int trailing);
    363210/*  @} */
    364211
     
    367214#endif
    368215
    369 #endif /* __CACA_H__ */
     216#endif /* __CUCUL_H__ */
  • libcaca/trunk/src/event.c

    r522 r524  
    1919
    2020#include "config.h"
     21
     22#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
     23#   include <inttypes.h>
     24#else
     25typedef unsigned char uint8_t;
     26#endif
    2127
    2228#if defined(USE_SLANG)
     
    6066extern unsigned int gl_mouse_button, gl_mouse_state;
    6167#endif
     68#include "cucul.h"
     69#include "cucul_internals.h"
    6270#include "caca.h"
    6371#include "caca_internals.h"
    6472
    65 static unsigned int _get_next_event(void);
    66 static unsigned int _lowlevel_event(void);
     73static unsigned int _get_next_event(caca_t *kk);
     74static unsigned int _lowlevel_event(caca_t *kk);
    6775#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO)
    6876static void _push_event(unsigned int);
     
    101109 * \return The next matching event in the queue, or 0 if no event is pending.
    102110 */
    103 unsigned int caca_get_event(unsigned int event_mask)
     111unsigned int caca_get_event(caca_t *kk, unsigned int event_mask)
    104112{
    105113    if(!event_mask)
     
    108116    for( ; ; )
    109117    {
    110         unsigned int event = _get_next_event();
     118        unsigned int event = _get_next_event(kk);
    111119
    112120        if(!event || event & event_mask)
     
    125133 *  \return The next event in the queue.
    126134 */
    127 unsigned int caca_wait_event(unsigned int event_mask)
     135unsigned int caca_wait_event(caca_t *kk, unsigned int event_mask)
    128136{
    129137    if(!event_mask)
     
    132140    for( ; ; )
    133141    {
    134         unsigned int event = _get_next_event();
     142        unsigned int event = _get_next_event(kk);
    135143
    136144        if(event & event_mask)
     
    150158 *  \return The X mouse coordinate.
    151159 */
    152 unsigned int caca_get_mouse_x(void)
     160unsigned int caca_get_mouse_x(caca_t *kk)
    153161{
    154     if(mouse_x >= _caca_width)
    155         mouse_x = _caca_width - 1;
     162    if(mouse_x >= kk->qq->width)
     163        mouse_x = kk->qq->width - 1;
    156164
    157165    return mouse_x;
     
    167175 *  \return The Y mouse coordinate.
    168176 */
    169 unsigned int caca_get_mouse_y(void)
     177unsigned int caca_get_mouse_y(caca_t *kk)
    170178{
    171     if(mouse_y >= _caca_height)
    172         mouse_y = _caca_height - 1;
     179    if(mouse_y >= kk->qq->height)
     180        mouse_y = kk->qq->height - 1;
    173181
    174182    return mouse_y;
     
    179187 */
    180188
    181 static unsigned int _get_next_event(void)
     189static unsigned int _get_next_event(caca_t *kk)
    182190{
    183191#if defined(USE_SLANG) || defined(USE_NCURSES)
     
    189197#endif
    190198    unsigned int event;
    191 #if defined(USE_NULL)
    192     if(_caca_driver == CACA_DRIVER_NULL)
    193         return CACA_EVENT_NONE;
    194 #endif
    195 
    196     event = _lowlevel_event();
     199
     200    event = _lowlevel_event(kk);
    197201
    198202#if defined(USE_SLANG)
    199     if(_caca_driver != CACA_DRIVER_SLANG)
     203    if(kk->driver != CACA_DRIVER_SLANG)
    200204#endif
    201205#if defined(USE_NCURSES)
    202     if(_caca_driver != CACA_DRIVER_NCURSES)
     206    if(kk->driver != CACA_DRIVER_NCURSES)
    203207#endif
    204208    return event;
     
    225229    {
    226230        last_key_ticks = 0;
    227         return _get_next_event();
     231        return _get_next_event(kk);
    228232    }
    229233
     
    251255}
    252256
    253 static unsigned int _lowlevel_event(void)
     257static unsigned int _lowlevel_event(caca_t *kk)
    254258{
    255259    unsigned int event;
     
    264268#if defined(USE_X11)
    265269    /* The X11 event check routine */
    266     if(_caca_driver == CACA_DRIVER_X11)
     270    if(kk->driver == CACA_DRIVER_X11)
    267271    {
    268272        XEvent xevent;
    269273        char key;
    270274
    271         while(XCheckWindowEvent(x11_dpy, x11_window, x11_event_mask, &xevent)
     275        while(XCheckWindowEvent(kk->x11.dpy, kk->x11.window, kk->x11.event_mask, &xevent)
    272276               == True)
    273277        {
     
    277281            if(xevent.type == Expose)
    278282            {
    279                 XCopyArea(x11_dpy, x11_pixmap, x11_window, x11_gc, 0, 0,
    280                           _caca_width * x11_font_width,
    281                           _caca_height * x11_font_height, 0, 0);
     283                XCopyArea(kk->x11.dpy, kk->x11.pixmap, kk->x11.window, kk->x11.gc, 0, 0,
     284                          kk->qq->width * kk->x11.font_width,
     285                          kk->qq->height * kk->x11.font_height, 0, 0);
    282286                continue;
    283287            }
     
    288292                unsigned int w, h;
    289293
    290                 w = (xevent.xconfigure.width + x11_font_width / 3)
    291                       / x11_font_width;
    292                 h = (xevent.xconfigure.height + x11_font_height / 3)
    293                       / x11_font_height;
    294 
    295                 if(!w || !h || (w == _caca_width && h == _caca_height))
     294                w = (xevent.xconfigure.width + kk->x11.font_width / 3)
     295                      / kk->x11.font_width;
     296                h = (xevent.xconfigure.height + kk->x11.font_height / 3)
     297                      / kk->x11.font_height;
     298
     299                if(!w || !h || (w == kk->qq->width && h == kk->qq->height))
    296300                    continue;
    297301
    298                 x11_new_width = w;
    299                 x11_new_height = h;
    300 
    301                 if(_caca_resize)
     302                kk->x11.new_width = w;
     303                kk->x11.new_height = h;
     304
     305                if(kk->resize)
    302306                    continue;
    303307
    304                 _caca_resize = 1;
     308                kk->resize = 1;
    305309
    306310                return CACA_EVENT_RESIZE;
     
    310314            if(xevent.type == MotionNotify)
    311315            {
    312                 unsigned int newx = xevent.xmotion.x / x11_font_width;
    313                 unsigned int newy = xevent.xmotion.y / x11_font_height;
    314 
    315                 if(newx >= _caca_width)
    316                     newx = _caca_width - 1;
    317                 if(newy >= _caca_height)
    318                     newy = _caca_height - 1;
     316                unsigned int newx = xevent.xmotion.x / kk->x11.font_width;
     317                unsigned int newy = xevent.xmotion.y / kk->x11.font_height;
     318
     319                if(newx >= kk->qq->width)
     320                    newx = kk->qq->width - 1;
     321                if(newy >= kk->qq->height)
     322                    newy = kk->qq->height - 1;
    319323
    320324                if(mouse_x == newx && mouse_y == newy)
     
    347351                return event | key;
    348352
    349             keysym = XKeycodeToKeysym(x11_dpy, xevent.xkey.keycode, 0);
     353            keysym = XKeycodeToKeysym(kk->x11.dpy, xevent.xkey.keycode, 0);
    350354            switch(keysym)
    351355            {
     
    378382#endif
    379383#if defined(USE_NCURSES)
    380     if(_caca_driver == CACA_DRIVER_NCURSES)
     384    if(kk->driver == CACA_DRIVER_NCURSES)
    381385    {
    382386        int intkey;
    383387
    384         if(_caca_resize_event)
    385         {
    386             _caca_resize_event = 0;
    387             _caca_resize = 1;
     388        if(kk->resize_event)
     389        {
     390            kk->resize_event = 0;
     391            kk->resize = 1;
    388392            return CACA_EVENT_RESIZE;
    389393        }
     
    562566#endif
    563567#if defined(USE_SLANG)
    564     if(_caca_driver == CACA_DRIVER_SLANG)
     568    if(kk->driver == CACA_DRIVER_SLANG)
    565569    {
    566570        int intkey;
    567571
    568         if(_caca_resize_event)
    569         {
    570             _caca_resize_event = 0;
    571             _caca_resize = 1;
     572        if(kk->resize_event)
     573        {
     574            kk->resize_event = 0;
     575            kk->resize = 1;
    572576            return CACA_EVENT_RESIZE;
    573577        }
     
    645649#endif
    646650#if defined(USE_CONIO)
    647     if(_caca_driver == CACA_DRIVER_CONIO)
     651    if(kk->driver == CACA_DRIVER_CONIO)
    648652    {
    649653        if(!_conio_kbhit())
     
    657661#endif
    658662#if defined(USE_WIN32)
    659     if(_caca_driver == CACA_DRIVER_WIN32)
     663    if(kk->driver == CACA_DRIVER_WIN32)
    660664    {
    661665        INPUT_RECORD rec;
     
    731735#endif
    732736#if defined(USE_GL)
    733     if(_caca_driver == CACA_DRIVER_GL)
     737    if(kk->driver == CACA_DRIVER_GL)
    734738    {
    735739        glutMainLoopEvent();
    736740
    737         if(gl_resized && !_caca_resize)
    738         {
    739             _caca_resize = 1;
     741        if(gl_resized && !kk->resize)
     742        {
     743            kk->resize = 1;
    740744            gl_resized = 0;
    741745            return CACA_EVENT_RESIZE;
  • libcaca/trunk/src/graphics.c

    r522 r524  
    7777#include "caca.h"
    7878#include "caca_internals.h"
     79#include "cucul.h"
     80#include "cucul_internals.h"
    7981
    8082/*
    8183 * Global variables
    8284 */
    83 #if !defined(_DOXYGEN_SKIP_ME)
    84 unsigned int _caca_width = 0;
    85 unsigned int _caca_height = 0;
    86 int _caca_resize = 0;
    87 int _caca_resize_event = 0;
    88 #endif
    89 
    90 /*
    91  * Local variables
    92  */
    93 #if !defined(_DOXYGEN_SKIP_ME)
    94 static uint8_t *cache_char, *cache_attr;
    95 #endif
    96 
    97 #if defined(USE_NCURSES)
    98 static int ncurses_attr[16*16];
    99 #endif
    10085
    10186#if defined(USE_SLANG)
     
    163148#endif
    164149
    165 #if defined(USE_X11) && !defined(_DOXYGEN_SKIP_ME)
    166 Display *x11_dpy;
    167 Window x11_window;
    168 Pixmap x11_pixmap;
    169 GC x11_gc;
    170 long int x11_event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
    171             | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask
    172             | ExposureMask;
    173 int x11_font_width, x11_font_height;
    174 unsigned int x11_new_width, x11_new_height;
    175 static int x11_colors[16];
    176 static Font x11_font;
    177 static XFontStruct *x11_font_struct;
    178 static int x11_font_offset;
    179 #if defined(HAVE_X11_XKBLIB_H)
    180 static Bool x11_detect_autorepeat;
    181 #endif
    182 #endif
    183 
    184150#if defined(USE_WIN32)
    185151HANDLE win32_hin, win32_hout;
     
    271237#endif
    272238
    273 static char *_caca_empty_line;
    274 static char *_caca_scratch_line;
    275 
    276 static unsigned int _caca_delay;
    277 static unsigned int _caca_rendertime;
    278 
    279 #if defined(OPTIMISE_SLANG_PALETTE)
    280 static int _caca_fgisbg = 0;
    281 #endif
    282 static enum caca_color _caca_fgcolor = CACA_COLOR_LIGHTGRAY;
    283 static enum caca_color _caca_bgcolor = CACA_COLOR_BLACK;
     239#if defined(USE_NCURSES)
     240static int ncurses_attr[16*16];
     241#endif
    284242
    285243/*
    286244 * Local functions
    287245 */
    288 static void caca_handle_resize(void);
     246static void caca_handle_resize(caca_t *kk);
    289247
    290248#if defined(USE_SLANG)
     
    293251
    294252#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG))
     253static caca_t *sigwinch_kk;
    295254static RETSIGTYPE sigwinch_handler(int);
    296255#endif
     
    308267#endif
    309268
    310 /** \brief Set the default colour pair.
    311  *
    312  *  This function sets the default colour pair. String functions such as
    313  *  caca_printf() and graphical primitive functions such as caca_draw_line()
    314  *  will use these colour pairs.
    315  *
    316  *  \param fgcolor The requested foreground colour.
    317  *  \param bgcolor The requested background colour.
    318  */
    319 void caca_set_color(enum caca_color fgcolor, enum caca_color bgcolor)
    320 {
    321     if(fgcolor < 0 || fgcolor > 15 || bgcolor < 0 || bgcolor > 15)
    322         return;
    323 
    324     _caca_fgcolor = fgcolor;
    325     _caca_bgcolor = bgcolor;
    326 
    327     switch(_caca_driver)
    328     {
     269#if !defined(_DOXYGEN_SKIP_ME)
     270int _caca_init_graphics(caca_t *kk)
     271{
     272#if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG))
     273    sigwinch_kk = kk;
     274    signal(SIGWINCH, sigwinch_handler);
     275#endif
     276
    329277#if defined(USE_SLANG)
    330     case CACA_DRIVER_SLANG:
    331 
    332 #if defined(OPTIMISE_SLANG_PALETTE)
    333         /* If foreground == background, discard this colour pair. Functions
    334          * such as caca_putchar will print spaces instead of characters */
    335         if(fgcolor != bgcolor)
    336             _caca_fgisbg = 0;
    337         else
    338         {
    339             _caca_fgisbg = 1;
    340             if(fgcolor == CACA_COLOR_BLACK)
    341                 fgcolor = CACA_COLOR_WHITE;
    342             else if(fgcolor == CACA_COLOR_WHITE
    343                      || fgcolor <= CACA_COLOR_LIGHTGRAY)
    344                 fgcolor = CACA_COLOR_BLACK;
    345             else
    346                 fgcolor = CACA_COLOR_WHITE;
    347         }
    348 #endif
    349 
    350 #if defined(OPTIMISE_SLANG_PALETTE)
    351         SLsmg_set_color(slang_assoc[fgcolor + 16 * bgcolor]);
    352 #else
    353         SLsmg_set_color(fgcolor + 16 * bgcolor);
    354 #endif
    355         break;
    356 #endif
    357 #if defined(USE_NCURSES)
    358     case CACA_DRIVER_NCURSES:
    359         attrset(ncurses_attr[fgcolor + 16 * bgcolor]);
    360         break;
    361 #endif
    362 #if defined(USE_CONIO)
    363     case CACA_DRIVER_CONIO:
    364         textbackground(bgcolor);
    365         textcolor(fgcolor);
    366         break;
    367 #endif
    368 #if defined(USE_X11)
    369     case CACA_DRIVER_X11:
    370         /* Nothing to do */
    371         break;
    372 #endif
    373 #if defined(USE_WIN32)
    374     case CACA_DRIVER_WIN32:
    375         /* Nothing to do */
    376         break;
    377 #endif
    378 #if defined(USE_GL)
    379     case CACA_DRIVER_GL:
    380         /* Nothing to do */
    381         break;
    382 #endif
    383 #if defined(USE_NULL)
    384     case CACA_DRIVER_NULL:
    385         /* Nothing to do */
    386         break;
    387 #endif
    388     default:
    389         break;
    390     }
    391 }
    392 
    393 /** \brief Get the current foreground colour.
    394  *
    395  *  This function returns the current foreground colour that was set with
    396  *  caca_set_color().
    397  *
    398  *  \return The current foreground colour.
    399  */
    400 enum caca_color caca_get_fg_color(void)
    401 {
    402     return _caca_fgcolor;
    403 }
    404 
    405 /** \brief Get the current background colour.
    406  *
    407  *  This function returns the current background colour that was set with
    408  *  caca_set_color().
    409  *
    410  *  \return The current background colour.
    411  */
    412 enum caca_color caca_get_bg_color(void)
    413 {
    414     return _caca_bgcolor;
    415 }
    416 
    417 /** \brief Print a character.
    418  *
    419  *  This function prints a character at the given coordinates, using the
    420  *  default foreground and background values. If the coordinates are outside
    421  *  the screen boundaries, nothing is printed.
    422  *
    423  *  \param x X coordinate.
    424  *  \param y Y coordinate.
    425  *  \param c The character to print.
    426  */
    427 void caca_putchar(int x, int y, char c)
    428 {
    429 #if defined(USE_CONIO)
    430     char *data;
    431 #endif
    432     if(x < 0 || x >= (int)_caca_width ||
    433        y < 0 || y >= (int)_caca_height)
    434         return;
    435 
    436     cache_char[x + y * _caca_width] = c;
    437     cache_attr[x + y * _caca_width] = (_caca_bgcolor << 4) | _caca_fgcolor;
    438 
    439     switch(_caca_driver)
    440     {
    441 #if defined(USE_SLANG)
    442     case CACA_DRIVER_SLANG:
    443         SLsmg_gotorc(y, x);
    444 #if defined(OPTIMISE_SLANG_PALETTE)
    445         if(_caca_fgisbg)
    446             SLsmg_write_char(' ');
    447         else
    448 #endif
    449             SLsmg_write_char(c);
    450         break;
    451 #endif
    452 #if defined(USE_NCURSES)
    453     case CACA_DRIVER_NCURSES:
    454         move(y, x);
    455         addch(c);
    456         break;
    457 #endif
    458 #if defined(USE_CONIO)
    459     case CACA_DRIVER_CONIO:
    460         data = conio_screen + 2 * (x + y * _caca_width);
    461         data[0] = c;
    462         data[1] = (_caca_bgcolor << 4) | _caca_fgcolor;
    463         break;
    464 #endif
    465 #if defined(USE_X11)
    466     case CACA_DRIVER_X11:
    467         break;
    468 #endif
    469 #if defined(USE_WIN32)
    470     case CACA_DRIVER_WIN32:
    471         break;
    472 #endif
    473 #if defined(USE_GL)
    474     case CACA_DRIVER_GL:
    475         break;
    476 #endif
    477 #if defined(USE_NULL)
    478     case CACA_DRIVER_NULL:
    479         break;
    480 #endif
    481     default:
    482         break;
    483     }
    484 }
    485 
    486 /** \brief Print a string.
    487  *
    488  *  This function prints a string at the given coordinates, using the
    489  *  default foreground and background values. The coordinates may be outside
    490  *  the screen boundaries (eg. a negative Y coordinate) and the string will
    491  *  be cropped accordingly if it is too long.
    492  *
    493  *  \param x X coordinate.
    494  *  \param y Y coordinate.
    495  *  \param s The string to print.
    496  */
    497 void caca_putstr(int x, int y, char const *s)
    498 {
    499     unsigned char *charbuf;
    500     unsigned char *attrbuf;
    501     char const *t;
    502     unsigned int len;
    503 
    504     if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width)
    505         return;
    506 
    507     len = strlen(s);
    508 
    509     if(x < 0)
    510     {
    511         if(len < (unsigned int)-x)
    512             return;
    513         len -= -x;
    514         s += -x;
    515         x = 0;
    516     }
    517 
    518     if(x + len >= _caca_width)
    519     {
    520         len = _caca_width - x;
    521         memcpy(_caca_scratch_line, s, len);
    522         _caca_scratch_line[len] = '\0';
    523         s = _caca_scratch_line;
    524     }
    525 
    526     charbuf = cache_char + x + y * _caca_width;
    527     attrbuf = cache_attr + x + y * _caca_width;
    528     t = s;
    529     while(*t)
    530     {
    531         *charbuf++ = *t++;
    532         *attrbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;
    533     }
    534 
    535     switch(_caca_driver)
    536     {
    537 #if defined(USE_SLANG)
    538     case CACA_DRIVER_SLANG:
    539         SLsmg_gotorc(y, x);
    540 #if defined(OPTIMISE_SLANG_PALETTE)
    541         if(_caca_fgisbg)
    542             SLsmg_write_string(_caca_empty_line + _caca_width - len);
    543         else
    544 #endif
    545         {
    546             union { char *ch; const char *constch; } u;
    547             u.constch = s;
    548             SLsmg_write_string(u.ch);
    549         }
    550         break;
    551 #endif
    552 #if defined(USE_NCURSES)
    553     case CACA_DRIVER_NCURSES:
    554         move(y, x);
    555         addstr(s);
    556         break;
    557 #endif
    558 #if defined(USE_CONIO)
    559     case CACA_DRIVER_CONIO:
    560         charbuf = conio_screen + 2 * (x + y * _caca_width);
    561         while(*s)
    562         {
    563             *charbuf++ = *s++;
    564             *charbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;
    565         }
    566         break;
    567 #endif
    568 #if defined(USE_X11)
    569     case CACA_DRIVER_X11:
    570         break;
    571 #endif
    572 #if defined(USE_WIN32)
    573     case CACA_DRIVER_WIN32:
    574         break;
    575 #endif
    576 #if defined(USE_GL)
    577     case CACA_DRIVER_GL:
    578         break;
    579 #endif
    580 #if defined(USE_NULL)
    581     case CACA_DRIVER_NULL:
    582         break;
    583 #endif
    584     default:
    585         break;
    586     }
    587 }
    588 
    589 /** \brief Format a string.
    590  *
    591  *  This function formats a string at the given coordinates, using the
    592  *  default foreground and background values. The coordinates may be outside
    593  *  the screen boundaries (eg. a negative Y coordinate) and the string will
    594  *  be cropped accordingly if it is too long. The syntax of the format
    595  *  string is the same as for the C printf() function.
    596  *
    597  *  \param x X coordinate.
    598  *  \param y Y coordinate.
    599  *  \param format The format string to print.
    600  *  \param ... Arguments to the format string.
    601  */
    602 void caca_printf(int x, int y, char const *format, ...)
    603 {
    604     char tmp[BUFSIZ];
    605     char *buf = tmp;
    606     va_list args;
    607 
    608     if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width)
    609         return;
    610 
    611     if(_caca_width - x + 1 > BUFSIZ)
    612         buf = malloc(_caca_width - x + 1);
    613 
    614     va_start(args, format);
    615 #if defined(HAVE_VSNPRINTF)
    616     vsnprintf(buf, _caca_width - x + 1, format, args);
    617 #else
    618     vsprintf(buf, format, args);
    619 #endif
    620     buf[_caca_width - x] = '\0';
    621     va_end(args);
    622 
    623     caca_putstr(x, y, buf);
    624 
    625     if(buf != tmp)
    626         free(buf);
    627 }
    628 
    629 /** \brief Get the screen.
    630  *
    631  *  This function fills a byte array with the character values.
    632  */
    633 void caca_get_screen(char *buffer)
    634 {
    635     unsigned int x, y;
    636 
    637     for(y = 0; y < _caca_height; y++)
    638     {
    639         for(x = 0; x < _caca_width; x++)
    640         {
    641             *buffer++ = cache_attr[x + y * _caca_width];
    642             *buffer++ = cache_char[x + y * _caca_width];
    643         }
    644     }
    645 }
    646 
    647 /** \brief Clear the screen.
    648  *
    649  *  This function clears the screen using a black background.
    650  */
    651 void caca_clear(void)
    652 {
    653     enum caca_color oldfg = caca_get_fg_color();
    654     enum caca_color oldbg = caca_get_bg_color();
    655     int y = _caca_height;
    656 
    657     caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
    658 
    659     /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
    660     while(y--)
    661         caca_putstr(0, y, _caca_empty_line);
    662 
    663     caca_set_color(oldfg, oldbg);
    664 }
    665 
    666 #if !defined(_DOXYGEN_SKIP_ME)
    667 int _caca_init_graphics(void)
    668 {
    669 
    670 
    671 #if defined(HAVE_SIGNAL) && (defined(USE_NCURSES) || defined(USE_SLANG))
    672     signal(SIGWINCH, sigwinch_handler);
    673 #endif
    674 
    675 #if defined(USE_SLANG)
    676     if(_caca_driver == CACA_DRIVER_SLANG)
     278    if(kk->driver == CACA_DRIVER_SLANG)
    677279    {
    678280        slang_init_palette();
     
    682284        SLtt_Has_Alt_Charset = 0;
    683285
    684         _caca_width = SLtt_Screen_Cols;
    685         _caca_height = SLtt_Screen_Rows;
     286        if(!kk->qq->size_set)
     287            cucul_set_size(kk->qq, SLtt_Screen_Cols, SLtt_Screen_Rows);
    686288    }
    687289    else
    688290#endif
    689291#if defined(USE_NCURSES)
    690     if(_caca_driver == CACA_DRIVER_NCURSES)
     292    if(kk->driver == CACA_DRIVER_NCURSES)
    691293    {
    692294        static int curses_colors[] =
     
    729331            {
    730332                /* Use ((max + 7 - fg) % max) instead of fg so that colour 0
    731                  * is light gray on black, since some terminals don't like
    732                  * this colour pair to be redefined. */
     333                 * is light gray on black. Some terminals don't like this
     334                 * colour pair to be redefined. */
    733335                int col = ((max + 7 - fg) % max) + max * bg;
    734336                init_pair(col, curses_colors[fg], curses_colors[bg]);
     
    748350            }
    749351
    750         _caca_width = COLS;
    751         _caca_height = LINES;
     352        if(!kk->qq->size_set)
     353            cucul_set_size(kk->qq, COLS, LINES);
    752354    }
    753355    else
    754356#endif
    755357#if defined(USE_CONIO)
    756     if(_caca_driver == CACA_DRIVER_CONIO)
     358    if(kk->driver == CACA_DRIVER_CONIO)
    757359    {
    758360        gettextinfo(&conio_ti);
     
    766368        /* FIXME */
    767369#   endif
    768         _caca_width = conio_ti.screenwidth;
    769         _caca_height = conio_ti.screenheight;
     370        if(!kk->qq->size_set)
     371            cucul_set_size(kk->qq, conio_ti.screenwidth, conio_ti.screenheight);
    770372    }
    771373    else
    772374#endif
    773375#if defined(USE_X11)
    774     if(_caca_driver == CACA_DRIVER_X11)
     376    if(kk->driver == CACA_DRIVER_X11)
    775377    {
    776378        static int x11_palette[] =
     
    802404        int i;
    803405
    804         if(!_caca_width && !_caca_height)
    805         if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY")))
    806             sscanf(getenv("CACA_GEOMETRY"),
    807                    "%ux%u", &_caca_width, &_caca_height);
    808 
    809         if(!_caca_width)
    810             _caca_width = 80;
    811         if(!_caca_height)
    812             _caca_height = 32;
    813 
    814         x11_dpy = XOpenDisplay(NULL);
    815         if(x11_dpy == NULL)
     406        if(!kk->qq->size_set)
     407        {
     408            unsigned int width = 0, height = 0;
     409
     410            if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY")))
     411                sscanf(getenv("CACA_GEOMETRY"), "%ux%u", &width, &height);
     412
     413            if(width && height)
     414                cucul_set_size(kk->qq, width, height);
     415        }
     416
     417        kk->x11.dpy = XOpenDisplay(NULL);
     418        if(kk->x11.dpy == NULL)
    816419            return -1;
    817420
     
    822425        old_error_handler = XSetErrorHandler(x11_error_handler);
    823426
    824         x11_font = XLoadFont(x11_dpy, font_name);
    825         if(!x11_font)
    826         {
    827             XCloseDisplay(x11_dpy);
     427        kk->x11.font = XLoadFont(kk->x11.dpy, font_name);
     428        if(!kk->x11.font)
     429        {
     430            XCloseDisplay(kk->x11.dpy);
    828431            return -1;
    829432        }
    830433
    831         x11_font_struct = XQueryFont(x11_dpy, x11_font);
    832         if(!x11_font_struct)
    833         {
    834             XUnloadFont(x11_dpy, x11_font);
    835             XCloseDisplay(x11_dpy);
     434        kk->x11.font_struct = XQueryFont(kk->x11.dpy, kk->x11.font);
     435        if(!kk->x11.font_struct)
     436        {
     437            XUnloadFont(kk->x11.dpy, kk->x11.font);
     438            XCloseDisplay(kk->x11.dpy);
    836439            return -1;
    837440        }
     
    840443        XSetErrorHandler(old_error_handler);
    841444
    842         x11_font_width = x11_font_struct->max_bounds.width;
    843         x11_font_height = x11_font_struct->max_bounds.ascent
    844                              + x11_font_struct->max_bounds.descent;
    845         x11_font_offset = x11_font_struct->max_bounds.descent;
    846 
    847         colormap = DefaultColormap(x11_dpy, DefaultScreen(x11_dpy));
     445        kk->x11.font_width = kk->x11.font_struct->max_bounds.width;
     446        kk->x11.font_height = kk->x11.font_struct->max_bounds.ascent
     447                             + kk->x11.font_struct->max_bounds.descent;
     448        kk->x11.font_offset = kk->x11.font_struct->max_bounds.descent;
     449
     450        colormap = DefaultColormap(kk->x11.dpy, DefaultScreen(kk->x11.dpy));
    848451        for(i = 0; i < 16; i++)
    849452        {
     
    852455            color.green = x11_palette[i * 3 + 1];
    853456            color.blue = x11_palette[i * 3 + 2];
    854             XAllocColor(x11_dpy, colormap, &color);
    855             x11_colors[i] = color.pixel;
     457            XAllocColor(kk->x11.dpy, colormap, &color);
     458            kk->x11.colors[i] = color.pixel;
    856459        }
    857460
    858461        x11_winattr.backing_store = Always;
    859         x11_winattr.background_pixel = x11_colors[0];
     462        x11_winattr.background_pixel = kk->x11.colors[0];
    860463        x11_winattr.event_mask = ExposureMask | StructureNotifyMask;
    861464
    862         x11_window = XCreateWindow(x11_dpy, DefaultRootWindow(x11_dpy), 0, 0,
    863                                    _caca_width * x11_font_width,
    864                                    _caca_height * x11_font_height,
     465        kk->x11.window = XCreateWindow(kk->x11.dpy, DefaultRootWindow(kk->x11.dpy), 0, 0,
     466                                   kk->qq->width * kk->x11.font_width,
     467                                   kk->qq->height * kk->x11.font_height,
    865468                                   0, 0, InputOutput, 0,
    866469                                   CWBackingStore | CWBackPixel | CWEventMask,
    867470                                   &x11_winattr);
    868471
    869         XStoreName(x11_dpy, x11_window, "caca for X");
    870 
    871         XSelectInput(x11_dpy, x11_window, StructureNotifyMask);
    872         XMapWindow(x11_dpy, x11_window);
    873 
    874         x11_gc = XCreateGC(x11_dpy, x11_window, 0, NULL);
    875         XSetForeground(x11_dpy, x11_gc, x11_colors[15]);
    876         XSetFont(x11_dpy, x11_gc, x11_font);
     472        XStoreName(kk->x11.dpy, kk->x11.window, "caca for X");
     473
     474        XSelectInput(kk->x11.dpy, kk->x11.window, StructureNotifyMask);
     475        XMapWindow(kk->x11.dpy, kk->x11.window);
     476
     477        kk->x11.gc = XCreateGC(kk->x11.dpy, kk->x11.window, 0, NULL);
     478        XSetForeground(kk->x11.dpy, kk->x11.gc, kk->x11.colors[15]);
     479        XSetFont(kk->x11.dpy, kk->x11.gc, kk->x11.font);
    877480
    878481        for(;;)
    879482        {
    880483            XEvent event;
    881             XNextEvent(x11_dpy, &event);
     484            XNextEvent(kk->x11.dpy, &event);
    882485            if (event.type == MapNotify)
    883486                break;
     
    886489        /* Disable autorepeat */
    887490#if defined(HAVE_X11_XKBLIB_H)
    888         XkbSetDetectableAutoRepeat(x11_dpy, True, &x11_detect_autorepeat);
    889         if(!x11_detect_autorepeat)
    890             XAutoRepeatOff(x11_dpy);
    891 #endif
    892 
    893         XSelectInput(x11_dpy, x11_window, x11_event_mask);
    894 
    895         XSync(x11_dpy, False);
    896 
    897         x11_pixmap = XCreatePixmap(x11_dpy, x11_window,
    898                                    _caca_width * x11_font_width,
    899                                    _caca_height * x11_font_height,
    900                                    DefaultDepth(x11_dpy,
    901                                                 DefaultScreen(x11_dpy)));
    902 
    903         x11_new_width = x11_new_height = 0;
     491        XkbSetDetectableAutoRepeat(kk->x11.dpy, True, &kk->x11.detect_autorepeat);
     492        if(!kk->x11.detect_autorepeat)
     493            XAutoRepeatOff(kk->x11.dpy);
     494#endif
     495
     496        XSelectInput(kk->x11.dpy, kk->x11.window, kk->x11.event_mask);
     497
     498        XSync(kk->x11.dpy, False);
     499
     500        kk->x11.pixmap = XCreatePixmap(kk->x11.dpy, kk->x11.window,
     501                                   kk->qq->width * kk->x11.font_width,
     502                                   kk->qq->height * kk->x11.font_height,
     503                                   DefaultDepth(kk->x11.dpy,
     504                                                DefaultScreen(kk->x11.dpy)));
     505
     506        kk->x11.new_width = kk->x11.new_height = 0;
    904507    }
    905508    else
    906509#endif
    907510#if defined(USE_WIN32)
    908     if(_caca_driver == CACA_DRIVER_WIN32)
     511    if(kk->driver == CACA_DRIVER_WIN32)
    909512    {
    910513        CONSOLE_CURSOR_INFO cci;
     
    929532        /* Sample code to get the biggest possible window */
    930533        //size = GetLargestConsoleWindowSize(win32_hout);
    931         if(!_caca_width && !_caca_height)
    932           {
    933             _caca_width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
    934             _caca_height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
    935           }
    936         size.X = _caca_width;
    937         size.Y = _caca_height;
     534        if(!kk->qq->size_set)
     535        {
     536            cucul_set_size(kk->qq,
     537                           csbi.srWindow.Right - csbi.srWindow.Left + 1,
     538                           csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
     539        }
     540        size.X = kk->qq->width;
     541        size.Y = kk->qq->height;
    938542        SetConsoleScreenBufferSize(win32_front, size);
    939543        SetConsoleScreenBufferSize(win32_back, size);
     
    950554        SetConsoleActiveScreenBuffer(win32_front);
    951555
    952         win32_buffer = malloc(_caca_width * _caca_height * sizeof(CHAR_INFO));
     556        win32_buffer = malloc(kk->qq->width * kk->qq->height * sizeof(CHAR_INFO));
    953557        if(win32_buffer == NULL)
    954558            return -1;
     
    957561#endif
    958562#if defined(USE_GL)
    959     if(_caca_driver == CACA_DRIVER_GL)
     563    if(kk->driver == CACA_DRIVER_GL)
    960564    {
    961565        int argc;
     
    964568        char *empty;
    965569       
    966         if(!_caca_width && !_caca_height)
    967           if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY")))
    968             sscanf(getenv("CACA_GEOMETRY"),
    969                    "%ux%u", &_caca_width, &_caca_height);
    970 
    971         if(!_caca_width)
    972             _caca_width = 80;
    973         if(!_caca_height)
    974             _caca_height = 32;
     570        if(!kk->qq->size_set)
     571        {
     572            unsigned int width = 0, height = 0;
     573
     574            if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY")))
     575                sscanf(getenv("CACA_GEOMETRY"), "%ux%u", &width, &height);
     576
     577            if(width && height)
     578                cucul_set_size(kk->qq, width, height);
     579        }
    975580
    976581        gl_font_width = 9;
    977582        gl_font_height = 15;
    978583
    979         gl_width = _caca_width * gl_font_width;
    980         gl_height = _caca_height * gl_font_height;
     584        gl_width = kk->qq->width * gl_font_width;
     585        gl_height = kk->qq->height * gl_font_height;
    981586
    982587        argc = 1;
     
    1050655    else
    1051656#endif
    1052 #if defined(USE_NULL)
    1053     if(_caca_driver == CACA_DRIVER_NULL)
    1054     {
    1055       if(!_caca_width && !_caca_height)
    1056         if(getenv("CACA_GEOMETRY") && *(getenv("CACA_GEOMETRY")))
    1057           sscanf(getenv("CACA_GEOMETRY"),
    1058                  "%ux%u", &_caca_width, &_caca_height);
    1059       if(!_caca_width)
    1060         _caca_width = 80;
    1061       if(!_caca_height)
    1062         _caca_height = 32;
    1063     }
    1064     else
    1065 #endif
    1066657    {
    1067658        /* Dummy */
    1068659    }
    1069660
    1070     cache_char = malloc(_caca_width * _caca_height * sizeof(uint8_t));
    1071     if(cache_char == NULL)
    1072         return -1;
    1073 
    1074     cache_attr = malloc(_caca_width * _caca_height * sizeof(uint8_t));
    1075     if(cache_attr == NULL)
    1076     {
    1077         free(cache_char);
    1078         return -1;
    1079     }
    1080 
    1081     memset(cache_char, 0, _caca_width * _caca_height * sizeof(uint8_t));
    1082     memset(cache_attr, 0, _caca_width * _caca_height * sizeof(uint8_t));
    1083 
    1084     _caca_empty_line = malloc(_caca_width + 1);
    1085     memset(_caca_empty_line, ' ', _caca_width);
    1086     _caca_empty_line[_caca_width] = '\0';
    1087 
    1088     _caca_scratch_line = malloc(_caca_width + 1);
    1089 
    1090     _caca_delay = 0;
    1091     _caca_rendertime = 0;
     661    kk->delay = 0;
     662    kk->rendertime = 0;
    1092663
    1093664    return 0;
    1094665}
    1095666
    1096 int _caca_end_graphics(void)
    1097 {
    1098     free(cache_char);
    1099     free(cache_attr);
    1100 
     667int _caca_end_graphics(caca_t *kk)
     668{
    1101669#if defined(USE_SLANG)
    1102670    /* Nothing to do */
     
    1106674#endif
    1107675#if defined(USE_CONIO)
    1108     if(_caca_driver == CACA_DRIVER_CONIO)
     676    if(kk->driver == CACA_DRIVER_CONIO)
    1109677    {
    1110678        free(conio_screen);
     
    1113681#endif
    1114682#if defined(USE_X11)
    1115     if(_caca_driver == CACA_DRIVER_X11)
    1116     {
    1117         XSync(x11_dpy, False);
     683    if(kk->driver == CACA_DRIVER_X11)
     684    {
     685        XSync(kk->x11.dpy, False);
    1118686#if defined(HAVE_X11_XKBLIB_H)
    1119         if(!x11_detect_autorepeat)
    1120             XAutoRepeatOn(x11_dpy);
    1121 #endif
    1122         XFreePixmap(x11_dpy, x11_pixmap);
    1123         XFreeFont(x11_dpy, x11_font_struct);
    1124         XFreeGC(x11_dpy, x11_gc);
    1125         XUnmapWindow(x11_dpy, x11_window);
    1126         XDestroyWindow(x11_dpy, x11_window);
    1127         XCloseDisplay(x11_dpy);
     687        if(!kk->x11.detect_autorepeat)
     688            XAutoRepeatOn(kk->x11.dpy);
     689#endif
     690        XFreePixmap(kk->x11.dpy, kk->x11.pixmap);
     691        XFreeFont(kk->x11.dpy, kk->x11.font_struct);
     692        XFreeGC(kk->x11.dpy, kk->x11.gc);
     693        XUnmapWindow(kk->x11.dpy, kk->x11.window);
     694        XDestroyWindow(kk->x11.dpy, kk->x11.window);
     695        XCloseDisplay(kk->x11.dpy);
    1128696    }
    1129697    else
    1130698#endif
    1131699#if defined(USE_WIN32)
    1132     if(_caca_driver == CACA_DRIVER_WIN32)
     700    if(kk->driver == CACA_DRIVER_WIN32)
    1133701    {
    1134702        SetConsoleActiveScreenBuffer(win32_hout);
     
    1139707#endif
    1140708#if defined(USE_GL)
    1141     if(_caca_driver == CACA_DRIVER_GL)
     709    if(kk->driver == CACA_DRIVER_GL)
    1142710    {
    1143711        glutDestroyWindow(gl_window);
     
    1145713    else
    1146714#endif
    1147 #if defined(USE_NULL)
    1148     if(_caca_driver == CACA_DRIVER_NULL)
    1149     {
    1150         /* Nothing to do here. */
    1151     }
    1152     else
    1153 #endif
    1154715    {
    1155716        /* Dummy */
    1156717    }
    1157 
    1158     free(_caca_empty_line);
    1159718
    1160719    return 0;
     
    1170729 *  \return 0 upon success, a non-zero value if an error occurs.
    1171730 */
    1172 int caca_set_window_title(char const *title)
     731int caca_set_window_title(caca_t *kk, char const *title)
    1173732{
    1174733#if defined(USE_X11)
    1175     if(_caca_driver == CACA_DRIVER_X11)
    1176     {
    1177         XStoreName(x11_dpy, x11_window, title);
     734    if(kk->driver == CACA_DRIVER_X11)
     735    {
     736        XStoreName(kk->x11.dpy, kk->x11.window, title);
    1178737    }
    1179738    else
    1180739#endif
    1181740#if defined(USE_WIN32)
    1182     if(_caca_driver == CACA_DRIVER_WIN32)
     741    if(kk->driver == CACA_DRIVER_WIN32)
    1183742    {
    1184743        SetConsoleTitle(title);
     
    1187746#endif
    1188747#if defined(USE_GL)
    1189     if(_caca_driver == CACA_DRIVER_GL)
     748    if(kk->driver == CACA_DRIVER_GL)
    1190749    {
    1191750        glutSetWindowTitle(title);
     
    1210769 *  \return The window width.
    1211770 */
    1212 unsigned int caca_get_window_width(void)
     771unsigned int caca_get_window_width(caca_t *kk)
    1213772{
    1214773#if defined(USE_X11)
    1215     if(_caca_driver == CACA_DRIVER_X11)
    1216     {
    1217         return _caca_width * x11_font_width;
     774    if(kk->driver == CACA_DRIVER_X11)
     775    {
     776        return kk->qq->width * kk->x11.font_width;
    1218777    }
    1219778    else
    1220779#endif
    1221780#if defined(USE_WIN32)
    1222     if(_caca_driver == CACA_DRIVER_WIN32)
     781    if(kk->driver == CACA_DRIVER_WIN32)
    1223782    {
    1224783        /* FIXME */
     
    1227786#endif
    1228787#if defined(USE_GL)
    1229     if(_caca_driver == CACA_DRIVER_GL)
     788    if(kk->driver == CACA_DRIVER_GL)
    1230789    {
    1231790        return gl_width;
     
    1238797
    1239798    /* Fallback to a 6x10 font */
    1240     return _caca_width * 6;
     799    return kk->qq->width * 6;
    1241800}
    1242801
     
    1250809 *  \return The window height.
    1251810 */
    1252 unsigned int caca_get_window_height(void)
     811unsigned int caca_get_window_height(caca_t *kk)
    1253812{
    1254813#if defined(USE_X11)
    1255     if(_caca_driver == CACA_DRIVER_X11)
    1256     {
    1257         return _caca_height * x11_font_height;
     814    if(kk->driver == CACA_DRIVER_X11)
     815    {
     816        return kk->qq->height * kk->x11.font_height;
    1258817    }
    1259818    else
    1260819#endif
    1261820#if defined(USE_WIN32)
    1262     if(_caca_driver == CACA_DRIVER_WIN32)
     821    if(kk->driver == CACA_DRIVER_WIN32)
    1263822    {
    1264823        /* FIXME */
     
    1267826#endif
    1268827#if defined(USE_GL)
    1269     if(_caca_driver == CACA_DRIVER_GL)
     828    if(kk->driver == CACA_DRIVER_GL)
    1270829    {
    1271830        return gl_height;
     
    1278837
    1279838    /* Fallback to a 6x10 font */
    1280     return _caca_height * 10;
     839    return kk->qq->height * 10;
    1281840}
    1282841
     
    1290849 *  \param heigth The height of the window, in CHARACTERS.
    1291850 */
    1292 void caca_set_size(unsigned int width, unsigned int height)
    1293 {
    1294   _caca_width = width;
    1295   _caca_height = height;
     851void caca_set_size(caca_t *kk, unsigned int width, unsigned int height)
     852{
     853  kk->qq->width = width;
     854  kk->qq->height = height;
    1296855}
    1297856
     
    1303862 *  \param width The width of the window, in CHARACTERS.
    1304863 */
    1305 void caca_set_width(unsigned int width)
    1306 {
    1307    _caca_width = width;
     864void caca_set_width(caca_t *kk, unsigned int width)
     865{
     866   kk->qq->width = width;
    1308867}
    1309868/** \brief Set the height of the window, in characters, if device permits it.
     
    1312871 *  \param width The width of the window, in CHARACTERS.
    1313872 */
    1314 void caca_set_height(unsigned int height)
    1315 {
    1316    _caca_height = height;
     873void caca_set_height(caca_t *kk, unsigned int height)
     874{
     875   kk->qq->height = height;
    1317876}
    1318877
     
    1330889 *  \param usec The refresh delay in microseconds.
    1331890 */
    1332 void caca_set_delay(unsigned int usec)
    1333 {
    1334     _caca_delay = usec;
     891void caca_set_delay(caca_t *kk, unsigned int usec)
     892{
     893    kk->delay = usec;
    1335894}
    1336895
     
    1345904 *  \return The render time in microseconds.
    1346905 */
    1347 unsigned int caca_get_rendertime(void)
    1348 {
    1349     return _caca_rendertime;
     906unsigned int caca_get_rendertime(caca_t *kk)
     907{
     908    return kk->rendertime;
    1350909}
    1351910
     
    1362921 *  performing the screen refresh.
    1363922 */
    1364 void caca_refresh(void)
     923void caca_refresh(caca_t *kk)
    1365924{
    1366925#if !defined(_DOXYGEN_SKIP_ME)
     
    1372931
    1373932#if defined(USE_SLANG)
    1374     if(_caca_driver == CACA_DRIVER_SLANG)
     933    if(kk->driver == CACA_DRIVER_SLANG)
    1375934    {
    1376935        SLsmg_refresh();
     
    1379938#endif
    1380939#if defined(USE_NCURSES)
    1381     if(_caca_driver == CACA_DRIVER_NCURSES)
     940    if(kk->driver == CACA_DRIVER_NCURSES)
    1382941    {
    1383942        refresh();
     
    1386945#endif
    1387946#if defined(USE_CONIO)
    1388     if(_caca_driver == CACA_DRIVER_CONIO)
     947    if(kk->driver == CACA_DRIVER_CONIO)
    1389948    {
    1390949#   if defined(SCREENUPDATE_IN_PC_H)
     
    1397956#endif
    1398957#if defined(USE_X11)
    1399     if(_caca_driver == CACA_DRIVER_X11)
     958    if(kk->driver == CACA_DRIVER_X11)
    1400959    {
    1401960        unsigned int x, y, len;
     
    1403962        /* First draw the background colours. Splitting the process in two
    1404963         * loops like this is actually slightly faster. */
    1405         for(y = 0; y < _caca_height; y++)
    1406         {
    1407             for(x = 0; x < _caca_width; x += len)
     964        for(y = 0; y < kk->qq->height; y++)
     965        {
     966            for(x = 0; x < kk->qq->width; x += len)
    1408967            {
    1409                 uint8_t *attr = cache_attr + x + y * _caca_width;
     968                uint8_t *attr = kk->qq->attr + x + y * kk->qq->width;
    1410969
    1411970                len = 1;
    1412                 while(x + len < _caca_width
     971                while(x + len < kk->qq->width
    1413972                       && (attr[len] >> 4) == (attr[0] >> 4))
    1414973                    len++;
    1415974
    1416                 XSetForeground(x11_dpy, x11_gc, x11_colors[attr[0] >> 4]);
    1417                 XFillRectangle(x11_dpy, x11_pixmap, x11_gc,
    1418                                x * x11_font_width, y * x11_font_height,
    1419                                len * x11_font_width, x11_font_height);
     975                XSetForeground(kk->x11.dpy, kk->x11.gc, kk->x11.colors[attr[0] >> 4]);
     976                XFillRectangle(kk->x11.dpy, kk->x11.pixmap, kk->x11.gc,
     977                               x * kk->x11.font_width, y * kk->x11.font_height,
     978                               len * kk->x11.font_width, kk->x11.font_height);
    1420979            }
    1421980        }
    1422981
    1423982        /* Then print the foreground characters */
    1424         for(y = 0; y < _caca_height; y++)
    1425         {
    1426             for(x = 0; x < _caca_width; x += len)
     983        for(y = 0; y < kk->qq->height; y++)
     984        {
     985            for(x = 0; x < kk->qq->width; x += len)
    1427986            {
    1428                 uint8_t *attr = cache_attr + x + y * _caca_width;
     987                uint8_t *attr = kk->qq->attr + x + y * kk->qq->width;
    1429988
    1430989                len = 1;
    1431990
    1432991                /* Skip spaces */
    1433                 if(cache_char[x + y * _caca_width] == ' ')
     992                if(kk->qq->chars[x + y * kk->qq->width] == ' ')
    1434993                    continue;
    1435994
    1436                 while(x + len < _caca_width
     995                while(x + len < kk->qq->width
    1437996                       && (attr[len] & 0xf) == (attr[0] & 0xf))
    1438997                    len++;
    1439998
    1440                 XSetForeground(x11_dpy, x11_gc, x11_colors[attr[0] & 0xf]);
    1441                 XDrawString(x11_dpy, x11_pixmap, x11_gc, x * x11_font_width,
    1442                             (y + 1) * x11_font_height - x11_font_offset,
    1443                             (char*)(cache_char + x + y * _caca_width), len);
     999                XSetForeground(kk->x11.dpy, kk->x11.gc, kk->x11.colors[attr[0] & 0xf]);
     1000                XDrawString(kk->x11.dpy, kk->x11.pixmap, kk->x11.gc, x * kk->x11.font_width,
     1001                            (y + 1) * kk->x11.font_height - kk->x11.font_offset,
     1002                            (char*)(kk->qq->chars + x + y * kk->qq->width), len);
    14441003            }
    14451004        }
    14461005
    1447         XCopyArea(x11_dpy, x11_pixmap, x11_window, x11_gc, 0, 0,
    1448                   _caca_width * x11_font_width, _caca_height * x11_font_height,
     1006        XCopyArea(kk->x11.dpy, kk->x11.pixmap, kk->x11.window, kk->x11.gc, 0, 0,
     1007                  kk->qq->width * kk->x11.font_width, kk->qq->height * kk->x11.font_height,
    14491008                  0, 0);
    1450         XFlush(x11_dpy);
     1009        XFlush(kk->x11.dpy);
    14511010    }
    14521011    else
    14531012#endif
    14541013#if defined(USE_WIN32)
    1455     if(_caca_driver == CACA_DRIVER_WIN32)
     1014    if(kk->driver == CACA_DRIVER_WIN32)
    14561015    {
    14571016        COORD size, pos;
     
    14601019
    14611020        /* Render everything to our back buffer */
    1462         for(i = 0; i < _caca_width * _caca_height; i++)
    1463         {
    1464             win32_buffer[i].Char.AsciiChar = cache_char[i];
    1465             win32_buffer[i].Attributes = win32_fg_palette[cache_attr[i] & 0xf]
    1466                                        | win32_bg_palette[cache_attr[i] >> 4];
     1021        for(i = 0; i < kk->qq->width * kk->qq->height; i++)
     1022        {
     1023            win32_buffer[i].Char.AsciiChar = kk->qq->chars[i];
     1024            win32_buffer[i].Attributes = win32_fg_palette[kk->qq->attr[i] & 0xf]
     1025                                       | win32_bg_palette[kk->qq->attr[i] >> 4];
    14671026        }
    14681027
    14691028        /* Blit the back buffer to the front buffer */
    1470         size.X = _caca_width;
    1471         size.Y = _caca_height;
     1029        size.X = kk->qq->width;
     1030        size.Y = kk->qq->height;
    14721031        pos.X = pos.Y = 0;
    14731032        rect.Left = rect.Top = 0;
    1474         rect.Right = _caca_width - 1;
    1475         rect.Bottom = _caca_height - 1;
     1033        rect.Right = kk->qq->width - 1;
     1034        rect.Bottom = kk->qq->height - 1;
    14761035        WriteConsoleOutput(win32_front, win32_buffer, size, pos, &rect);
    14771036    }
     
    14791038#endif
    14801039#if defined(USE_GL)
    1481     if(_caca_driver == CACA_DRIVER_GL)
     1040    if(kk->driver == CACA_DRIVER_GL)
    14821041    {
    14831042        unsigned int x, y, offsetx, offsety;
     
    14911050            for(x = 0; x < gl_width; x += gl_font_width)
    14921051            {
    1493                 uint8_t *attr = cache_attr + offsetx + offsety * _caca_width;
     1052                uint8_t *attr = kk->qq->attr + offsetx + offsety * kk->qq->width;
    14941053                int offset;
    14951054                float br, bg, bb;
     
    15261085            for(x = 0; x < gl_width; x += gl_font_width)
    15271086            {
    1528                 uint8_t *attr = cache_attr + offsetx + offsety * _caca_width;
    1529                 unsigned char *chr = cache_char + offsetx + offsety * _caca_width;
     1087                uint8_t *attr = kk->qq->attr + offsetx + offsety * kk->qq->width;
     1088                unsigned char *chr = kk->qq->chars + offsetx + offsety * kk->qq->width;
    15301089                float fr, fg, fb;
    15311090
     
    15631122    else
    15641123#endif
    1565 #if defined(USE_NULL)
    1566     if(_caca_driver == CACA_DRIVER_NULL)
    1567     {
    1568         /* Nothing to do here. */
    1569     }
    1570     else
    1571 #endif
    15721124    {
    15731125        /* Dummy */
    15741126    }
    15751127
    1576     if(_caca_resize)
    1577     {
    1578         _caca_resize = 0;
    1579         caca_handle_resize();
    1580     }
    1581 
    1582     /* Wait until _caca_delay + time of last call */
     1128    if(kk->resize)
     1129    {
     1130        kk->resize = 0;
     1131        caca_handle_resize(kk);
     1132    }
     1133
     1134    /* Wait until kk->delay + time of last call */
    15831135    ticks += _caca_getticks(&timer);
    15841136    for(ticks += _caca_getticks(&timer);
    1585         ticks + IDLE_USEC < (int)_caca_delay;
     1137        ticks + IDLE_USEC < (int)kk->delay;
    15861138        ticks += _caca_getticks(&timer))
    15871139    {
     
    15901142
    15911143    /* Update the sliding mean of the render time */
    1592     _caca_rendertime = (7 * _caca_rendertime + ticks) / 8;
    1593 
    1594     lastticks = ticks - _caca_delay;
     1144    kk->rendertime = (7 * kk->rendertime + ticks) / 8;
     1145
     1146    lastticks = ticks - kk->delay;
    15951147
    15961148    /* If we drifted too much, it's bad, bad, bad. */
    1597     if(lastticks > (int)_caca_delay)
     1149    if(lastticks > (int)kk->delay)
    15981150        lastticks = 0;
    15991151}
     
    16021154 * XXX: following functions are local
    16031155 */
    1604 static void caca_handle_resize(void)
    1605 {
    1606     unsigned int old_width = _caca_width;
    1607     unsigned int old_height = _caca_height;
     1156
     1157static void caca_handle_resize(caca_t *kk)
     1158{
     1159    unsigned int old_width = kk->qq->width;
     1160    unsigned int old_height = kk->qq->height;
    16081161
    16091162#if defined(USE_SLANG)
    1610     if(_caca_driver == CACA_DRIVER_SLANG)
     1163    if(kk->driver == CACA_DRIVER_SLANG)
    16111164    {
    16121165        SLtt_get_screen_size();
    1613         _caca_width = SLtt_Screen_Cols;
    1614         _caca_height = SLtt_Screen_Rows;
    1615 
    1616         if(_caca_width != old_width || _caca_height != old_height)
     1166        kk->qq->width = SLtt_Screen_Cols;
     1167        kk->qq->height = SLtt_Screen_Rows;
     1168
     1169        if(kk->qq->width != old_width || kk->qq->height != old_height)
    16171170            SLsmg_reinit_smg();
    16181171    }
     
    16201173#endif
    16211174#if defined(USE_NCURSES)
    1622     if(_caca_driver == CACA_DRIVER_NCURSES)
     1175    if(kk->driver == CACA_DRIVER_NCURSES)
    16231176    {
    16241177        struct winsize size;
     
    16261179        if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0)
    16271180        {
    1628             _caca_width = size.ws_col;
    1629             _caca_height = size.ws_row;
     1181            kk->qq->width = size.ws_col;
     1182            kk->qq->height = size.ws_row;
    16301183#if defined(HAVE_RESIZE_TERM)
    1631             resize_term(_caca_height, _caca_width);
     1184            resize_term(kk->qq->height, kk->qq->width);
    16321185#else
    1633             resizeterm(_caca_height, _caca_width);
     1186            resizeterm(kk->qq->height, kk->qq->width);
    16341187#endif
    16351188            wrefresh(curscr);
     
    16391192#endif
    16401193#if defined(USE_CONIO)
    1641     if(_caca_driver == CACA_DRIVER_CONIO)
     1194    if(kk->driver == CACA_DRIVER_CONIO)
    16421195    {
    16431196        /* Nothing to do here. */
     
    16461199#endif
    16471200#if defined(USE_X11)
    1648     if(_caca_driver == CACA_DRIVER_X11)
     1201    if(kk->driver == CACA_DRIVER_X11)
    16491202    {
    16501203        Pixmap new_pixmap;
    16511204
    1652         _caca_width = x11_new_width;
    1653         _caca_height = x11_new_height;
    1654 
    1655         new_pixmap = XCreatePixmap(x11_dpy, x11_window,
    1656                                    _caca_width * x11_font_width,
    1657                                    _caca_height * x11_font_height,
    1658                                    DefaultDepth(x11_dpy,
    1659                                                 DefaultScreen(x11_dpy)));
    1660         XCopyArea(x11_dpy, x11_pixmap, new_pixmap, x11_gc, 0, 0,
    1661                   old_width * x11_font_width, old_height * x11_font_height,
     1205        kk->qq->width = kk->x11.new_width;
     1206        kk->qq->height = kk->x11.new_height;
     1207
     1208        new_pixmap = XCreatePixmap(kk->x11.dpy, kk->x11.window,
     1209                                   kk->qq->width * kk->x11.font_width,
     1210                                   kk->qq->height * kk->x11.font_height,
     1211                                   DefaultDepth(kk->x11.dpy,
     1212                                                DefaultScreen(kk->x11.dpy)));
     1213        XCopyArea(kk->x11.dpy, kk->x11.pixmap, new_pixmap, kk->x11.gc, 0, 0,
     1214                  old_width * kk->x11.font_width, old_height * kk->x11.font_height,
    16621215                  0, 0);
    1663         XFreePixmap(x11_dpy, x11_pixmap);
    1664         x11_pixmap = new_pixmap;
     1216        XFreePixmap(kk->x11.dpy, kk->x11.pixmap);
     1217        kk->x11.pixmap = new_pixmap;
    16651218    }
    16661219    else
    16671220#endif
    16681221#if defined(USE_WIN32)
    1669     if(_caca_driver == CACA_DRIVER_WIN32)
     1222    if(kk->driver == CACA_DRIVER_WIN32)
    16701223    {
    16711224        /* Nothing to do here. */
     
    16741227#endif
    16751228#if defined(USE_GL)
    1676     if(_caca_driver == CACA_DRIVER_GL)
     1229    if(kk->driver == CACA_DRIVER_GL)
    16771230    {
    16781231      gl_width = gl_new_width;
    16791232      gl_height = gl_new_height;
    16801233
    1681       _caca_width = gl_width/gl_font_width;
    1682       _caca_height = (gl_height/gl_font_height)+1;
     1234      kk->qq->width = gl_width/gl_font_width;
     1235      kk->qq->height = (gl_height/gl_font_height)+1;
    16831236
    16841237      glMatrixMode(GL_PROJECTION);
     
    16931246    else
    16941247#endif
    1695 #if defined(USE_NULL)
    1696     if(_caca_driver == CACA_DRIVER_NULL)
    1697     {
    1698         /* \_o< pOaK
    1699          * By the way, we should never reach this,
    1700          * as events are not handled */
    1701     }
    1702     else
    1703 #endif
    17041248    {
    17051249        /* Dummy */
    17061250    }
    17071251
    1708     if(_caca_width != old_width || _caca_height != old_height)
    1709     {
    1710         free(cache_char);
    1711         free(cache_attr);
    1712 
    1713         cache_char = malloc(_caca_width * _caca_height * sizeof(uint8_t));
    1714         memset(cache_char, 0, _caca_width * _caca_height * sizeof(uint8_t));
    1715         cache_attr = malloc(_caca_width * _caca_height * sizeof(uint8_t));
    1716         memset(cache_attr, 0, _caca_width * _caca_height * sizeof(uint8_t));
    1717     }
    1718 
    1719     if(_caca_width != old_width)
    1720     {
    1721         free(_caca_empty_line);
    1722         _caca_empty_line = malloc(_caca_width + 1);
    1723         memset(_caca_empty_line, ' ', _caca_width);
    1724         _caca_empty_line[_caca_width] = '\0';
    1725 
    1726         free(_caca_scratch_line);
    1727         _caca_scratch_line = malloc(_caca_width + 1);
     1252    if(kk->qq->width != old_width || kk->qq->height != old_height)
     1253    {
     1254        free(kk->qq->chars);
     1255        free(kk->qq->attr);
     1256
     1257        kk->qq->chars = malloc(kk->qq->width * kk->qq->height * sizeof(uint8_t));
     1258        memset(kk->qq->chars, 0, kk->qq->width * kk->qq->height * sizeof(uint8_t));
     1259        kk->qq->attr = malloc(kk->qq->width * kk->qq->height * sizeof(uint8_t));
     1260        memset(kk->qq->attr, 0, kk->qq->width * kk->qq->height * sizeof(uint8_t));
     1261    }
     1262
     1263    if(kk->qq->width != old_width)
     1264    {
     1265        free(kk->qq->empty_line);
     1266        kk->qq->empty_line = malloc(kk->qq->width + 1);
     1267        memset(kk->qq->empty_line, ' ', kk->qq->width);
     1268        kk->qq->empty_line[kk->qq->width] = '\0';
     1269
     1270        free(kk->qq->scratch_line);
     1271        kk->qq->scratch_line = malloc(kk->qq->width + 1);
    17281272    }
    17291273}
     
    17851329static RETSIGTYPE sigwinch_handler(int sig)
    17861330{
    1787     _caca_resize_event = 1;
     1331    sigwinch_kk->resize_event = 1;
    17881332
    17891333    signal(SIGWINCH, sigwinch_handler);;
     
    18331377#endif
    18341378
    1835 /* Exporters */
    1836 
    1837 /* HTML */
    1838 
    1839 /** \brief Generate HTML representation of current image.
    1840  *
    1841  *  This function generates and returns the HTML representation of
    1842  *  the current image.
    1843  */
    1844 char* caca_get_html(void)
    1845 {
    1846     static int const palette[] =
    1847     {
    1848         0x000, 0x008, 0x080, 0x088, 0x800, 0x808, 0x880, 0x888,
    1849         0x444, 0x44f, 0x4f4, 0x4ff, 0xf44, 0xf4f, 0xff4, 0xfff,
    1850     };
    1851     char *buffer, *cur;
    1852     unsigned int x, y, len;
    1853 
    1854     /* 13000 -> css palette
    1855      * 40 -> max size used for a pixel (plus 10, never know)*/
    1856     /* FIXME: Check this value */
    1857     buffer = malloc((13000 + ((_caca_width*_caca_height) * 40)) * sizeof(char));
    1858     cur = buffer;
    1859 
    1860     /* HTML header */
    1861     cur += sprintf(cur, "<html>\n<head>\n<title>Generated by libcaca %s</title>\n", VERSION);
    1862 
    1863     /* CSS */
    1864     cur += sprintf(cur, "<style>\n");
    1865     cur += sprintf(cur, ".caca { font-family: monospace, fixed; font-weight: bold; }");
    1866     for(x = 0; x < 0x100; x++)
    1867     {
    1868         cur += sprintf(cur, ".b%02x { color:#%03x; background-color:#%03x; }\n",
    1869                        x, palette[x & 0xf ], palette[x >> 4]);
    1870     }
    1871     cur += sprintf(cur, "</style>\n</head>\n<body>\n");
    1872 
    1873     cur += sprintf(cur, "<div cellpadding='0' cellspacing='0' style='%s'>\n",
    1874                         "font-family: monospace, fixed; font-weight: bold;");
    1875 
    1876     for(y = 0; y < _caca_height; y++)
    1877     {
    1878         uint8_t *lineattr = cache_attr + y * _caca_width;
    1879         uint8_t *linechar = cache_char + y * _caca_width;
    1880 
    1881         for(x = 0; x < _caca_width; x += len)
    1882         {
    1883             cur += sprintf(cur, "<span class='b%02x'>", lineattr[x]);
    1884 
    1885             for(len = 0;
    1886                 x + len < _caca_width && lineattr[x + len] == lineattr[x];
    1887                 len++)
    1888             {
    1889                 if(linechar[x + len] == ' ')
    1890                     cur += sprintf(cur, "&nbsp;");
    1891                 else
    1892                     cur += sprintf(cur, "%c", linechar[x + len]);
    1893             }
    1894             cur += sprintf(cur, "</span>");
    1895         }
    1896         /* New line */
    1897         cur += sprintf(cur, "<br />\n");
    1898     }
    1899 
    1900     cur += sprintf(cur, "</div></body></html>\n");
    1901 
    1902     /* Crop to really used size */
    1903     buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
    1904 
    1905     return buffer;
    1906 }
    1907 
    1908 /** \brief Generate HTML3 representation of current image.
    1909  *
    1910  *  This function generates and returns the HTML3 representation of
    1911  *  the current image. It is way bigger than caca_get_html(), but
    1912  *  permits viewing in old browsers (or limited ones such as links)
    1913  *  Won't work under gecko (mozilla rendering engine) unless you set
    1914  *  a correct header.
    1915  */
    1916 char* caca_get_html3(void)
    1917 {
    1918     static int const palette[] =
    1919     {
    1920         0x000000, 0x000088, 0x008800, 0x008888,
    1921         0x880000, 0x880088, 0x888800, 0x888888,
    1922         0x444444, 0x4444ff, 0x44ff44, 0x44ffff,
    1923         0xff4444, 0xff44ff, 0xffff44, 0xffffff,
    1924     };
    1925     char *buffer, *cur;
    1926     unsigned int x, y, len;
    1927 
    1928     /* 13000 -> css palette
    1929      * 40 -> max size used for a pixel (plus 10, never know) */
    1930     buffer = malloc((13000 + ((_caca_width*_caca_height)*40))*sizeof(char));
    1931     cur = buffer;
    1932 
    1933     /* Table */
    1934     cur += sprintf(cur, "<table cols='%d' cellpadding='0' cellspacing='0'>\n",
    1935                         _caca_height);
    1936 
    1937     for(y = 0; y < _caca_height; y++)
    1938     {
    1939         uint8_t *lineattr = cache_attr + y * _caca_width;
    1940         uint8_t *linechar = cache_char + y * _caca_width;
    1941 
    1942         cur += sprintf(cur, "<tr>");
    1943 
    1944         for(x = 0; x < _caca_width; x += len)
    1945         {
    1946             unsigned int i;
    1947 
    1948             /* Use colspan option to factorize cells with same attributes
    1949              * (see below) */
    1950             len = 1;
    1951             while(x + len < _caca_width && lineattr[x + len] == lineattr[x])
    1952                 len++;
    1953 
    1954             cur += sprintf(cur, "<td bgcolor=#%06x", palette[lineattr[x] >> 4]);
    1955 
    1956             if(len > 1)
    1957                 cur += sprintf(cur, " colspan=%d", len);
    1958 
    1959             cur += sprintf(cur, "><font color=#%06x>",
    1960                                 palette[lineattr[x] & 0x0f]);
    1961 
    1962             for(i = 0; i < len; i++)
    1963             {
    1964                 if(linechar[x + i] == ' ')
    1965                     cur += sprintf(cur, "&nbsp;");
    1966                 else
    1967                     cur += sprintf(cur, "%c", linechar[x + i]);
    1968             }
    1969 
    1970             cur += sprintf(cur, "</font></td>");
    1971         }
    1972         cur += sprintf(cur, "</tr>\n");
    1973     }
    1974 
    1975     /* Footer */
    1976     cur += sprintf(cur, "</table>\n");
    1977 
    1978     /* Crop to really used size */
    1979     buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
    1980 
    1981     return buffer;
    1982 }
    1983 
    1984 /** \brief Generate IRC representation of current image.
    1985  *
    1986  *  This function generates and returns an IRC representation of
    1987  *  the current image.
    1988  */
    1989 char* caca_get_irc(void)
    1990 {
    1991     static int const palette[] =
    1992     {
    1993         1, 2, 3, 10, 5, 6, 7, 15, /* Dark */
    1994         14, 12, 9, 11, 4, 13, 8, 0, /* Light */
    1995     };
    1996 
    1997     char *buffer, *cur;
    1998     unsigned int x, y;
    1999 
    2000     /* 11 bytes assumed for max length per pixel. Worst case scenario:
    2001      * ^Cxx,yy   6 bytes
    2002      * ^B^B      2 bytes
    2003      * c         1 byte
    2004      * \r\n      2 bytes
    2005      * In real life, the average bytes per pixel value will be around 5.
    2006      */
    2007     buffer = malloc((2 + (_caca_width * _caca_height * 11)) * sizeof(char));
    2008     cur = buffer;
    2009 
    2010     *cur++ = '\x0f';
    2011 
    2012     for(y = 0; y < _caca_height; y++)
    2013     {
    2014         uint8_t *lineattr = cache_attr + y * _caca_width;
    2015         uint8_t *linechar = cache_char + y * _caca_width;
    2016 
    2017         uint8_t prevfg = -1;
    2018         uint8_t prevbg = -1;
    2019 
    2020         for(x = 0; x < _caca_width; x++)
    2021         {
    2022             uint8_t fg = palette[lineattr[x] & 0x0f];
    2023             uint8_t bg = palette[lineattr[x] >> 4];
    2024             uint8_t c = linechar[x];
    2025 
    2026             if(bg == prevbg)
    2027             {
    2028                 if(fg == prevfg)
    2029                     ; /* Same fg/bg, do nothing */
    2030                 else if(c == ' ')
    2031                     fg = prevfg; /* Hackety hack */
    2032                 else
    2033                 {
    2034                     cur += sprintf(cur, "\x03%d", fg);
    2035                     if(c >= '0' && c <= '9')
    2036                         cur += sprintf(cur, "\x02\x02");
    2037                 }
    2038             }
    2039             else
    2040             {
    2041                 if(fg == prevfg)
    2042                     cur += sprintf(cur, "\x03,%d", bg);
    2043                 else
    2044                     cur += sprintf(cur, "\x03%d,%d", fg, bg);
    2045 
    2046                 if(c >= '0' && c <= '9')
    2047                     cur += sprintf(cur, "\x02\x02");
    2048             }
    2049             *cur++ = c;
    2050             prevfg = fg;
    2051             prevbg = bg;
    2052         }
    2053         *cur++ = '\r';
    2054         *cur++ = '\n';
    2055     }
    2056 
    2057     *cur++ = '\x0f';
    2058 
    2059     /* Crop to really used size */
    2060     buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
    2061 
    2062     return buffer;
    2063 }
    2064 
    2065 /** \brief Generate ANSI representation of current image.
    2066  *
    2067  *  This function generates and returns an ANSI representation of
    2068  *  the current image.
    2069  *  \param trailing if 0, raw ANSI will be generated. Otherwise, you'll be
    2070  *                  able to cut/paste the result to a function like printf
    2071  *  \return buffer containing generated ANSI codes as a big string
    2072  */
    2073 char * caca_get_ansi(int trailing)
    2074 {
    2075     static int const palette[] =
    2076     {
    2077         30, 34, 32, 36, 31, 35, 33, 37, /* Both lines (light and dark) are the same, */
    2078         30, 34, 32, 36, 31, 35, 33, 37, /* light colors handling is done later */
    2079     };
    2080 
    2081     char *buffer, *cur;
    2082     unsigned int x, y;
    2083 
    2084     /* 20 bytes assumed for max length per pixel.
    2085      * Add height*9 to that (zeroes color at the end and jump to next line) */
    2086     buffer = malloc(((_caca_height*9) + (_caca_width * _caca_height * 20)) * sizeof(char));
    2087     cur = buffer;
    2088 
    2089     // *cur++ = '';
    2090 
    2091     for(y = 0; y < _caca_height; y++)
    2092     {
    2093         uint8_t *lineattr = cache_attr + y * _caca_width;
    2094         uint8_t *linechar = cache_char + y * _caca_width;
    2095 
    2096         uint8_t prevfg = -1;
    2097         uint8_t prevbg = -1;
    2098 
    2099         for(x = 0; x < _caca_width; x++)
    2100         {
    2101             uint8_t fg = palette[lineattr[x] & 0x0f];
    2102             uint8_t bg = (palette[lineattr[x] >> 4])+10;
    2103             uint8_t c = linechar[x];
    2104 
    2105             if(!trailing)
    2106                 cur += sprintf(cur, "\033[");
    2107             else
    2108                 cur += sprintf(cur, "\\033[");
    2109 
    2110             if(fg > 7)
    2111                 cur += sprintf(cur, "1;%d;%dm",fg,bg);
    2112             else
    2113                 cur += sprintf(cur, "0;%d;%dm",fg,bg);
    2114             *cur++ = c;
    2115             if((c == '%') && trailing)
    2116                 *cur++ = c;
    2117             prevfg = fg;
    2118             prevbg = bg;
    2119         }
    2120         if(!trailing)
    2121             cur += sprintf(cur, "\033[0m\n\r");
    2122         else
    2123             cur += sprintf(cur, "\\033[0m\\n\n");
    2124     }
    2125 
    2126     /* Crop to really used size */
    2127     buffer = realloc(buffer, (strlen(buffer) + 1) * sizeof(char));
    2128 
    2129     return buffer;
    2130 }
    2131 
  • libcaca/trunk/src/line.c

    r522 r524  
    2929#include <stdlib.h>
    3030
    31 #include "caca.h"
    32 #include "caca_internals.h"
     31#include "cucul.h"
     32#include "cucul_internals.h"
    3333
    3434#if !defined(_DOXYGEN_SKIP_ME)
     
    3838    int x2, y2;
    3939    char c;
    40     void (*draw) (struct line*);
     40    void (*draw) (cucul_t *, struct line*);
    4141};
    4242#endif
    4343
    44 static void clip_line(struct line*);
    45 static uint8_t clip_bits(int, int);
    46 static void draw_solid_line(struct line*);
    47 static void draw_thin_line(struct line*);
     44static void clip_line(cucul_t*, struct line*);
     45static uint8_t clip_bits(cucul_t*, int, int);
     46static void draw_solid_line(cucul_t*, struct line*);
     47static void draw_thin_line(cucul_t*, struct line*);
    4848
    4949/**
     
    5757 * \return void
    5858 */
    59 void caca_draw_line(int x1, int y1, int x2, int y2, char c)
     59void cucul_draw_line(cucul_t *qq, int x1, int y1, int x2, int y2, char c)
    6060{
    6161    struct line s;
     
    6666    s.c = c;
    6767    s.draw = draw_solid_line;
    68     clip_line(&s);
     68    clip_line(qq, &s);
    6969}
    7070
     
    8181 * \return void
    8282 */
    83 void caca_draw_polyline(int const x[], int const y[], int n, char c)
     83void cucul_draw_polyline(cucul_t *qq, int const x[], int const y[], int n, char c)
    8484{
    8585    int i;
     
    9494        s.x2 = x[i+1];
    9595        s.y2 = y[i+1];
    96         clip_line(&s);
     96        clip_line(qq, &s);
    9797    }
    9898}
     
    107107 * \return void
    108108 */
    109 void caca_draw_thin_line(int x1, int y1, int x2, int y2)
     109void cucul_draw_thin_line(cucul_t *qq, int x1, int y1, int x2, int y2)
    110110{
    111111    struct line s;
     
    115115    s.y2 = y2;
    116116    s.draw = draw_thin_line;
    117     clip_line(&s);
     117    clip_line(qq, &s);
    118118}
    119119
     
    129129 * \return void
    130130 */
    131 void caca_draw_thin_polyline(int const x[], int const y[], int n)
     131void cucul_draw_thin_polyline(cucul_t *qq, int const x[], int const y[], int n)
    132132{
    133133    int i;
     
    141141        s.x2 = x[i+1];
    142142        s.y2 = y[i+1];
    143         clip_line(&s);
     143        clip_line(qq, &s);
    144144    }
    145145}
     
    155155 * \return void
    156156 */
    157 static void clip_line(struct line* s)
     157static void clip_line(cucul_t *qq, struct line* s)
    158158{
    159159    uint8_t bits1, bits2;
    160160
    161     bits1 = clip_bits(s->x1, s->y1);
    162     bits2 = clip_bits(s->x2, s->y2);
     161    bits1 = clip_bits(qq, s->x1, s->y1);
     162    bits2 = clip_bits(qq, s->x2, s->y2);
    163163
    164164    if(bits1 & bits2)
     
    168168    {
    169169        if(bits2 == 0)
    170             s->draw(s);
     170            s->draw(qq, s);
    171171        else
    172172        {
     
    174174            tmp = s->x1; s->x1 = s->x2; s->x2 = tmp;
    175175            tmp = s->y1; s->y1 = s->y2; s->y2 = tmp;
    176             clip_line(s);
     176            clip_line(qq, s);
    177177        }
    178178
     
    187187    else if(bits1 & (1<<1))
    188188    {
    189         int xmax = _caca_width - 1;
     189        int xmax = qq->width - 1;
    190190        s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1);
    191191        s->x1 = xmax;
     
    198198    else if(bits1 & (1<<3))
    199199    {
    200         int ymax = _caca_height - 1;
     200        int ymax = qq->height - 1;
    201201        s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1);
    202202        s->y1 = ymax;
    203203    }
    204204
    205     clip_line(s);
     205    clip_line(qq, s);
    206206}
    207207
     
    213213 * \return The clipping bits for the given point.
    214214 */
    215 static uint8_t clip_bits(int x, int y)
     215static uint8_t clip_bits(cucul_t *qq, int x, int y)
    216216{
    217217    uint8_t b = 0;
     
    219219    if(x < 0)
    220220        b |= (1<<0);
    221     else if(x >= (int)_caca_width)
     221    else if(x >= (int)qq->width)
    222222        b |= (1<<1);
    223223
    224224    if(y < 0)
    225225        b |= (1<<2);
    226     else if(y >= (int)_caca_height)
     226    else if(y >= (int)qq->height)
    227227        b |= (1<<3);
    228228
     
    237237 * \return void
    238238 */
    239 static void draw_solid_line(struct line* s)
     239static void draw_solid_line(cucul_t *qq, struct line* s)
    240240{
    241241    int x1, y1, x2, y2;
     
    259259        for(; dx>=0; dx--)
    260260        {
    261             caca_putchar(x1, y1, s->c);
     261            cucul_putchar(qq, x1, y1, s->c);
    262262            if(delta > 0)
    263263            {
     
    281281        for(; dy >= 0; dy--)
    282282        {
    283             caca_putchar(x1, y1, s->c);
     283            cucul_putchar(qq, x1, y1, s->c);
    284284            if(delta > 0)
    285285            {
     
    304304 * \return void
    305305 */
    306 static void draw_thin_line(struct line* s)
     306static void draw_thin_line(cucul_t *qq, struct line* s)
    307307{
    308308    char *charmapx, *charmapy;
     
    353353            if(delta > 0)
    354354            {
    355                 caca_putchar(x1, y1, charmapy[1]);
     355                cucul_putchar(qq, x1, y1, charmapy[1]);
    356356                x1++;
    357357                y1 += yinc;
     
    362362            {
    363363                if(prev)
    364                     caca_putchar(x1, y1, charmapy[0]);
     364                    cucul_putchar(qq, x1, y1, charmapy[0]);
    365365                else
    366                     caca_putchar(x1, y1, '-');
     366                    cucul_putchar(qq, x1, y1, '-');
    367367                x1++;
    368368                delta += dpr;
     
    381381            if(delta > 0)
    382382            {
    383                 caca_putchar(x1, y1, charmapx[0]);
    384                 caca_putchar(x1 + 1, y1, charmapx[1]);
     383                cucul_putchar(qq, x1, y1, charmapx[0]);
     384                cucul_putchar(qq, x1 + 1, y1, charmapx[1]);
    385385                x1++;
    386386                y1 += yinc;
     
    389389            else
    390390            {
    391                 caca_putchar(x1, y1, '|');
     391                cucul_putchar(qq, x1, y1, '|');
    392392                y1 += yinc;
    393393                delta += dpr;
  • libcaca/trunk/src/math.c

    r522 r524  
    2020#include "config.h"
    2121
     22#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
     23#   include <inttypes.h>
     24#else
     25typedef unsigned char uint8_t;
     26#endif
     27
    2228#include <stdlib.h>
    2329
    24 #include "caca.h"
    25 #include "caca_internals.h"
     30#include "cucul.h"
     31#include "cucul_internals.h"
    2632
    2733/**
     
    3238 * \return A random integer comprised between \p min and \p max, inclusive.
    3339 */
    34 int caca_rand(int min, int max)
     40int cucul_rand(int min, int max)
    3541{
    3642    return min + (int)((1.0*(max-min+1)) * rand() / (RAND_MAX+1.0));
     
    4450 * \return The approximate square root of \p a.
    4551 */
    46 unsigned int caca_sqrt(unsigned int a)
     52unsigned int cucul_sqrt(unsigned int a)
    4753{
    4854    if(a == 0)
     
    6672    }
    6773
    68     return 2 * caca_sqrt(a / 4);
     74    return 2 * cucul_sqrt(a / 4);
    6975}
    7076
     
    7783 */
    7884
    79 float caca_powf(float x, float y)
     85float cucul_powf(float x, float y)
    8086{
    8187    int i=((int)y);
  • libcaca/trunk/src/sprite.c

    r522 r524  
    2020#include "config.h"
    2121
     22#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
     23#   include <inttypes.h>
     24#else
     25typedef unsigned char uint8_t;
     26#endif
     27
    2228#include <stdio.h>
    2329#include <stdlib.h>
    2430#include <string.h>
    2531
    26 #include "caca.h"
    27 #include "caca_internals.h"
     32#include "cucul.h"
     33#include "cucul_internals.h"
    2834
    2935#if !defined(_DOXYGEN_SKIP_ME)
    30 struct caca_frame
     36struct cucul_frame
    3137{
    3238    int w, h;
     
    3642};
    3743
    38 struct caca_sprite
     44struct cucul_sprite
    3945{
    4046    int nf;
    41     struct caca_frame *frames;
     47    struct cucul_frame *frames;
    4248};
    4349#endif
     
    4955 * \return The sprite, or NULL if an error occured.
    5056 */
    51 struct caca_sprite *caca_load_sprite(char const *file)
     57struct cucul_sprite *cucul_load_sprite(cucul_t *qq, char const *file)
    5258{
    5359    char buf[BUFSIZ];
    54     struct caca_sprite *sprite;
     60    struct cucul_sprite *sprite;
    5561    FILE *fd;
    5662
     
    5965        return NULL;
    6066
    61     sprite = malloc(sizeof(struct caca_sprite));
     67    sprite = malloc(sizeof(struct cucul_sprite));
    6268    if(sprite == NULL)
    6369        goto sprite_alloc_failed;
     
    7076        int x, y;
    7177        int w = 0, h = 0, dx = 0, dy = 0;
    72         struct caca_frame *frame;
     78        struct cucul_frame *frame;
    7379
    7480        /* Get width and height */
     
    8389        {
    8490            void *tmp = realloc(sprite->frames,
    85                                 (sprite->nf + 1) * sizeof(struct caca_frame));
     91                                (sprite->nf + 1) * sizeof(struct cucul_frame));
    8692            if(tmp == NULL)
    8793                goto frame_failed;
     
    9197        else
    9298        {
    93             sprite->frames = malloc((sprite->nf + 1) * sizeof(struct caca_frame));
     99            sprite->frames = malloc((sprite->nf + 1) * sizeof(struct cucul_frame));
    94100            if(sprite->frames == NULL)
    95101                goto sprite_failed;
     
    170176 * \return The number of frames.
    171177 */
    172 int caca_get_sprite_frames(struct caca_sprite const *sprite)
     178int cucul_get_sprite_frames(cucul_t *qq, struct cucul_sprite const *sprite)
    173179{
    174180    if(sprite == NULL)
     
    185191 * \return The width of the given frame of the sprite.
    186192 */
    187 int caca_get_sprite_width(struct caca_sprite const *sprite, int f)
     193int cucul_get_sprite_width(cucul_t *qq, struct cucul_sprite const *sprite, int f)
    188194{
    189195    if(sprite == NULL)
     
    203209 * \return The height of the given frame of the sprite.
    204210 */
    205 int caca_get_sprite_height(struct caca_sprite const *sprite, int f)
     211int cucul_get_sprite_height(cucul_t *qq, struct cucul_sprite const *sprite, int f)
    206212{
    207213    if(sprite == NULL)
     
    221227 * \return The X coordinate of the given frame's handle.
    222228 */
    223 int caca_get_sprite_dx(struct caca_sprite const *sprite, int f)
     229int cucul_get_sprite_dx(cucul_t *qq, struct cucul_sprite const *sprite, int f)
    224230{
    225231    if(sprite == NULL)
     
    239245 * \return The Y coordinate of the given frame's handle.
    240246 */
    241 int caca_get_sprite_dy(struct caca_sprite const *sprite, int f)
     247int cucul_get_sprite_dy(cucul_t *qq, struct cucul_sprite const *sprite, int f)
    242248{
    243249    if(sprite == NULL)
     
    260266 * \return void
    261267 */
    262 void caca_draw_sprite(int x, int y, struct caca_sprite const *sprite, int f)
     268void cucul_draw_sprite(cucul_t *qq, int x, int y, struct cucul_sprite const *sprite, int f)
    263269{
    264270    int i, j;
    265     enum caca_color oldfg, oldbg;
    266     struct caca_frame *frame;
     271    enum cucul_color oldfg, oldbg;
     272    struct cucul_frame *frame;
    267273
    268274    if(sprite == NULL)
     
    274280    frame = &sprite->frames[f];
    275281
    276     oldfg = caca_get_fg_color();
    277     oldbg = caca_get_bg_color();
     282    oldfg = cucul_get_fg_color(qq);
     283    oldbg = cucul_get_bg_color(qq);
    278284
    279285    for(j = 0; j < frame->h; j++)
     
    284290            if(col >= 0)
    285291            {
    286                 caca_set_color(col, CACA_COLOR_BLACK);
    287                 caca_putchar(x + i - frame->dx, y + j - frame->dy,
    288                            frame->chars[frame->w * j + i]);
     292                cucul_set_color(qq, col, CUCUL_COLOR_BLACK);
     293                cucul_putchar(qq, x + i - frame->dx, y + j - frame->dy,
     294                              frame->chars[frame->w * j + i]);
    289295            }
    290296        }
    291297    }
    292298
    293     caca_set_color(oldfg, oldbg);
     299    cucul_set_color(qq, oldfg, oldbg);
    294300}
    295301
     
    300306 * \return void
    301307 */
    302 void caca_free_sprite(struct caca_sprite *sprite)
     308void cucul_free_sprite(cucul_t *qq, struct cucul_sprite *sprite)
    303309{
    304310    int i;
     
    309315    for(i = sprite->nf; i--;)
    310316    {
    311         struct caca_frame *frame = &sprite->frames[i];
     317        struct cucul_frame *frame = &sprite->frames[i];
    312318        free(frame->chars);
    313319        free(frame->color);
  • libcaca/trunk/src/triangle.c

    r522 r524  
    2020#include "config.h"
    2121
     22#if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
     23#   include <inttypes.h>
     24#else
     25typedef unsigned char uint8_t;
     26#endif
     27
    2228#include <stdlib.h>
    2329
    24 #include "caca.h"
    25 #include "caca_internals.h"
     30#include "cucul.h"
     31#include "cucul_internals.h"
    2632
    2733/**
     
    3743 * \return void
    3844 */
    39 void caca_draw_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
     45void cucul_draw_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, int x3, int y3, char c)
    4046{
    41     caca_draw_line(x1, y1, x2, y2, c);
    42     caca_draw_line(x2, y2, x3, y3, c);
    43     caca_draw_line(x3, y3, x1, y1, c);
     47    cucul_draw_line(qq, x1, y1, x2, y2, c);
     48    cucul_draw_line(qq, x2, y2, x3, y3, c);
     49    cucul_draw_line(qq, x3, y3, x1, y1, c);
    4450}
    4551
     
    5561 * \return void
    5662 */
    57 void caca_draw_thin_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
     63void cucul_draw_thin_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, int x3, int y3)
    5864{
    59     caca_draw_thin_line(x1, y1, x2, y2);
    60     caca_draw_thin_line(x2, y2, x3, y3);
    61     caca_draw_thin_line(x3, y3, x1, y1);
     65    cucul_draw_thin_line(qq, x1, y1, x2, y2);
     66    cucul_draw_thin_line(qq, x2, y2, x3, y3);
     67    cucul_draw_thin_line(qq, x3, y3, x1, y1);
    6268}
    6369
     
    7480 * \return void
    7581 */
    76 void caca_fill_triangle(int x1, int y1, int x2, int y2, int x3, int y3, char c)
     82void cucul_fill_triangle(cucul_t *qq, int x1, int y1, int x2, int y2, int x3, int y3, char c)
    7783{
    7884    int x, y, xa, xb, xmax, ymax;
     
    8187    if(y1 > y2)
    8288    {
    83         caca_fill_triangle(x2, y2, x1, y1, x3, y3, c);
     89        cucul_fill_triangle(qq, x2, y2, x1, y1, x3, y3, c);
    8490        return;
    8591    }
     
    8793    if(y2 > y3)
    8894    {
    89         caca_fill_triangle(x1, y1, x3, y3, x2, y2, c);
     95        cucul_fill_triangle(qq, x1, y1, x3, y3, x2, y2, c);
    9096        return;
    9197    }
     
    96102    x3 *= 4;
    97103
    98     xmax = _caca_width - 1;
    99     ymax = _caca_height - 1;
     104    xmax = qq->width - 1;
     105    ymax = qq->height - 1;
    100106
    101107    /* Rasterize our triangle */
     
    129135
    130136        for(x = xa; x <= xb; x++)
    131             caca_putchar(x, y, c);
     137            cucul_putchar(qq, x, y, c);
    132138    }
    133139}
  • libcaca/trunk/test

    • Property svn:ignore
      •  

        old new  
        55colors.exe
        66colors
         7demo.exe
         8demo
        79dithering.exe
        810dithering
  • libcaca/trunk/test/Makefile.am

    r475 r524  
    11# $Id$
    22
    3 noinst_PROGRAMS = colors dithering event hsv optipal spritedit
     3noinst_PROGRAMS = colors demo dithering event hsv optipal spritedit
    44
    55colors_SOURCES = colors.c
    66colors_LDADD = ../src/libcaca.la @CACA_LIBS@
    77colors_CPPFLAGS = -I$(top_srcdir)/src
     8
     9demo_SOURCES = demo.c
     10demo_LDADD = ../src/libcaca.la @CACA_LIBS@ @MATH_LIBS@
     11demo_CPPFLAGS = -I$(top_srcdir)/src -DDATADIR=\"$(pkgdatadir)\"
    812
    913dithering_SOURCES = dithering.c
     
    2024
    2125optipal_SOURCES = optipal.c
    22 optipal_LDADD = ../src/libcaca.la @CACA_LIBS@
     26optipal_LDADD = ../src/libcucul.la @CUCUL_LIBS@
    2327optipal_CPPFLAGS = -I$(top_srcdir)/src
    2428
  • libcaca/trunk/test/colors.c

    r522 r524  
    1616#include <stdio.h>
    1717
     18#include "cucul.h"
    1819#include "caca.h"
    1920
    2021int main(int argc, char **argv)
    2122{
     23    cucul_t *qq;
     24    caca_t *kk;
    2225    int i, j;
    2326
    24     if(caca_init())
     27    qq = cucul_init();
     28    if(!qq)
    2529        return 1;
    2630
    27     caca_clear();
     31    kk = caca_attach(qq);
     32    if(!kk)
     33        return 1;
     34
     35    cucul_clear(qq);
    2836    for(i = 0; i < 16; i++)
    2937    {
    30         caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
    31         caca_printf(4, i + (i >= 8 ? 4 : 3), "'%c': %i (%s)",
    32                     'a' + i, i, caca_get_color_name(i));
     38        cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
     39        cucul_printf(qq, 4, i + (i >= 8 ? 4 : 3), "'%c': %i (%s)",
     40                     'a' + i, i, cucul_get_color_name(i));
    3341        for(j = 0; j < 16; j++)
    3442        {
    35             caca_set_color(i, j);
    36             caca_putstr((j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3), "# ");
     43            cucul_set_color(qq, i, j);
     44            cucul_putstr(qq, (j >= 8 ? 41 : 40) + j * 2, i + (i >= 8 ? 4 : 3),
     45                         "# ");
    3746        }
    3847    }
    3948
    40     caca_refresh();
    41     caca_wait_event(CACA_EVENT_KEY_PRESS);
    42     caca_end();
     49    caca_refresh(kk);
     50    caca_wait_event(kk, CACA_EVENT_KEY_PRESS);
     51
     52    caca_detach(kk);
     53    cucul_end(qq);
    4354
    4455    return 0;
  • libcaca/trunk/test/demo.c

    r522 r524  
    3636int outline = 0;
    3737int dithering = 0;
    38 struct caca_sprite *sprite = NULL;
     38struct cucul_sprite *sprite = NULL;
     39
     40cucul_t *qq;
     41caca_t *kk;
    3942
    4043int main(int argc, char **argv)
     
    4346    int quit = 0;
    4447
    45     if(caca_init())
     48    qq = cucul_init();
     49    if(!qq)
    4650        return 1;
    47 
    48     caca_set_delay(40000);
     51    kk = caca_attach(qq);
     52    if(!kk)
     53        return 1;
     54
     55    caca_set_delay(kk, 40000);
    4956
    5057    /* Initialize data */
    51     sprite = caca_load_sprite(DATADIR "/caca.txt");
     58    sprite = cucul_load_sprite(qq, DATADIR "/caca.txt");
    5259    if(!sprite)
    53         sprite = caca_load_sprite("caca.txt");
     60        sprite = cucul_load_sprite(qq, "caca.txt");
    5461    if(!sprite)
    55         sprite = caca_load_sprite("examples/caca.txt");
     62        sprite = cucul_load_sprite(qq, "examples/caca.txt");
    5663
    5764    /* Main menu */
    5865    display_menu();
    59     caca_refresh();
     66    caca_refresh(kk);
    6067
    6168    /* Go ! */
     
    6572        int event;
    6673
    67         while((event = caca_get_event(CACA_EVENT_ANY)))
     74        while((event = caca_get_event(kk, CACA_EVENT_ANY)))
    6875        {
    6976            if(demo && (event & CACA_EVENT_KEY_PRESS))
     
    94101                case 'D':
    95102                    dithering = (dithering + 1) % 5;
    96                     caca_set_dithering(dithering);
     103                    cucul_set_feature(qq, dithering);
    97104                    display_menu();
    98105                    break;
     
    131138
    132139                if(demo)
    133                     caca_clear();
     140                    cucul_clear(qq);
    134141            }
    135142            else if(event & CACA_EVENT_MOUSE_MOTION)
     
    146153            if(mouse && !demo)
    147154            {
    148                 caca_set_color(CACA_COLOR_RED, CACA_COLOR_BLACK);
    149                 caca_putstr(xmouse, ymouse, "|\\");
     155                cucul_set_color(qq, CUCUL_COLOR_RED, CUCUL_COLOR_BLACK);
     156                cucul_putstr(qq, xmouse, ymouse, "|\\");
    150157            }
    151             caca_refresh();
     158            caca_refresh(kk);
    152159            mouse = menu = 0;
    153160        }
     
    157164            demo();
    158165
    159             caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
    160             caca_draw_thin_box(1, 1, caca_get_width() - 2, caca_get_height() - 2);
    161             caca_printf(4, 1, "[%i.%i fps]----",
    162                             1000000 / caca_get_rendertime(),
    163                             (10000000 / caca_get_rendertime()) % 10);
    164             caca_refresh();
     166            cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
     167            cucul_draw_thin_box(qq, 1, 1, cucul_get_width(qq) - 2, cucul_get_height(qq) - 2);
     168            cucul_printf(qq, 4, 1, "[%i.%i fps]----",
     169                         1000000 / caca_get_rendertime(kk),
     170                         (10000000 / caca_get_rendertime(kk)) % 10);
     171            caca_refresh(kk);
    165172        }
    166173    }
    167174
    168175    /* Clean up */
    169     caca_free_sprite(sprite);
    170     caca_end();
     176    cucul_free_sprite(qq, sprite);
     177    caca_detach(kk);
     178    cucul_end(qq);
    171179
    172180    return 0;
     
    175183static void display_menu(void)
    176184{
    177     int xo = caca_get_width() - 2;
    178     int yo = caca_get_height() - 2;
    179 
    180     caca_clear();
    181     caca_set_color(CACA_COLOR_LIGHTGRAY, CACA_COLOR_BLACK);
    182     caca_draw_thin_box(1, 1, xo, yo);
    183 
    184     caca_putstr((xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
    185     caca_putstr((xo - strlen("==============")) / 2, 4, "==============");
    186 
    187     caca_putstr(4, 6, "demos:");
    188     caca_putstr(4, 7, "'f': full");
    189     caca_putstr(4, 8, "'1': dots");
    190     caca_putstr(4, 9, "'2': lines");
    191     caca_putstr(4, 10, "'3': boxes");
    192     caca_putstr(4, 11, "'4': triangles");
    193     caca_putstr(4, 12, "'5': ellipses");
    194     caca_putstr(4, 13, "'c': colour");
    195     caca_putstr(4, 14, "'r': render");
     185    int xo = cucul_get_width(qq) - 2;
     186    int yo = cucul_get_height(qq) - 2;
     187
     188    cucul_clear(qq);
     189    cucul_set_color(qq, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
     190