Migrating from libcaca 0.9 to the 1.0 API

This section will guide you through the migration of a libcaca 0.9 application to the latest API version.

Overview

The most important changes in the 1.0 API of libcaca are the libcaca / libcucul split and the object-oriented design. Where you used to do:

#include <caca.h>

int main(void)
{
    /* Initialise libcaca */
    caca_init();
    /* Set window title */
    caca_set_window_title("Hello!");
    /* Choose drawing colours */
    caca_set_color(CACA_COLOR_BLACK, CACA_COLOR_WHITE);
    /* Draw a string at coordinates (0, 0) */
    caca_putstr(0, 0, "This is a message");
    /* Refresh display */
    caca_refresh();
    /* Wait for a key press event */
    caca_wait_event(CACA_EVENT_KEY_PRESS);
    /* Clean up library */
    caca_end();

    return 0;
}

You now do:

#include <cucul.h>
#include <caca.h>

int main(void)
{
    /* Initialise libcaca */
    cucul_canvas_t *cv; caca_display_t *dp; caca_event_t ev;
    cv = cucul_create_canvas(0, 0);
    dp = caca_create_display(cv);
    /* Set window title */
    caca_set_display_title(dp, "Hello!");
    /* Choose drawing colours */
    cucul_set_color(cv, CUCUL_COLOR_BLACK, CUCUL_COLOR_WHITE);
    /* Draw a string at coordinates (0, 0) */
    cucul_putstr(cv, 0, 0, "This is a message");
    /* Refresh display */
    caca_refresh_display();
    /* Wait for a key press event */
    caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1);
    /* Clean up library */
    caca_free_display(dp);
    cucul_free_canvas(cv);

    return 0;
}

Note the following important things:

Function equivalence list

Basic functions

Event handling

Character printing

Primitives drawing

Mathematical functions

Sprite handling

The sprite handling functions are currently being reworked.

Bitmap handling

Compilation

The caca-config utility is deprecated in favour of the standard pkg-config interface:

gcc -c foobar.c -o foobar.o `pkg-config --cflags caca`
gcc foobar.o -o foobar `pkg-config --libs caca`

caca-config is still provided as a convenience tool but will be removed in the future.