Ignore:
Timestamp:
Sep 27, 2008, 3:12:46 PM (11 years ago)
Author:
Sam Hocevar
Message:

Starting refactoring to get rid of libcucul. The initial reason for the
split is rendered moot by the plugin system: when enabled, binaries do
not link directly with libX11 or libGL. I hope this is a step towards
more consisteny and clarity.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/caca/canvas.c

    r2819 r2821  
    11/*
    2  *  libcucul      Canvas for ultrafast compositing of Unicode letters
     2 *  libcaca       Colour ASCII-Art library
    33 *  Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
     
    1414
    1515/*
    16  *  This file contains the main functions used by \e libcucul applications
     16 *  This file contains the main functions used by \e libcaca applications
    1717 *  to initialise a drawing context.
    1818 */
     
    3131#endif
    3232
    33 #include "cucul.h"
    34 #include "cucul_internals.h"
    35 
    36 static int cucul_resize(cucul_canvas_t *, int, int);
    37 
    38 /** \brief Initialise a \e libcucul canvas.
    39  *
    40  *  Initialise internal \e libcucul structures and the backend that will
     33#include "caca.h"
     34#include "caca_internals.h"
     35
     36static int caca_resize(caca_canvas_t *, int, int);
     37
     38/** \brief Initialise a \e libcaca canvas.
     39 *
     40 *  Initialise internal \e libcaca structures and the backend that will
    4141 *  be used for subsequent graphical operations. It must be the first
    42  *  \e libcucul function to be called in a function. cucul_free_canvas()
     42 *  \e libcaca function to be called in a function. caca_free_canvas()
    4343 *  should be called at the end of the program to free all allocated resources.
    4444 *
     
    5252 *  \param width The desired canvas width
    5353 *  \param height The desired canvas height
    54  *  \return A libcucul canvas handle upon success, NULL if an error occurred.
    55  */
    56 cucul_canvas_t * cucul_create_canvas(int width, int height)
    57 {
    58     cucul_canvas_t *cv;
     54 *  \return A libcaca canvas handle upon success, NULL if an error occurred.
     55 */
     56caca_canvas_t * caca_create_canvas(int width, int height)
     57{
     58    caca_canvas_t *cv;
    5959
    6060    if(width < 0 || height < 0)
     
    6464    }
    6565
    66     cv = malloc(sizeof(cucul_canvas_t));
     66    cv = malloc(sizeof(caca_canvas_t));
    6767
    6868    if(!cv)
     
    7676    cv->frame = 0;
    7777    cv->framecount = 1;
    78     cv->frames = malloc(sizeof(struct cucul_frame));
     78    cv->frames = malloc(sizeof(struct caca_frame));
    7979    if(!cv->frames)
    8080    {
     
    9191    cv->frames[0].name = strdup("frame#00000000");
    9292
    93     _cucul_load_frame_info(cv);
    94     cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
     93    _caca_load_frame_info(cv);
     94    caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
    9595
    9696    cv->ff = NULL;
    9797
    98     if(cucul_resize(cv, width, height) < 0)
     98    if(caca_resize(cv, width, height) < 0)
    9999    {
    100100        int saved_errno = geterrno();
     
    117117 *  Lock a canvas to prevent it from being resized. If non-NULL,
    118118 *  the \e callback function pointer will be called upon each
    119  *  \e cucul_set_canvas_size call and if the returned value is zero, the
     119 *  \e caca_set_canvas_size call and if the returned value is zero, the
    120120 *  canvas resize request will be denied.
    121121 *
     
    126126 *  - \c EBUSY The canvas is already being managed.
    127127 *
    128  *  \param cv A libcucul canvas.
     128 *  \param cv A libcaca canvas.
    129129 *  \param callback An optional callback function pointer.
    130130 *  \param p The argument to be passed to \e callback.
    131131 *  \return 0 in case of success, -1 if an error occurred.
    132132 */
    133 int cucul_manage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)
     133int caca_manage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
    134134{
    135135    if(cv->refcount)
     
    148148/** \brief Unmanage a canvas.
    149149 *
    150  *  Unlock a canvas previously locked by cucul_manage_canvas(). For safety
     150 *  Unlock a canvas previously locked by caca_manage_canvas(). For safety
    151151 *  reasons, the callback and callback data arguments must be the same as for
    152  *  the cucul_manage_canvas() call.
     152 *  the caca_manage_canvas() call.
    153153 *
    154154 *  This function is only useful for display drivers such as the \e libcaca
     
    159159 *              not match.
    160160 *
    161  *  \param cv A libcucul canvas.
     161 *  \param cv A libcaca canvas.
    162162 *  \param callback The \e callback argument previously passed to
    163                     cucul_manage_canvas().
    164  *  \param p The \e p argument previously passed to cucul_manage_canvas().
     163                    caca_manage_canvas().
     164 *  \param p The \e p argument previously passed to caca_manage_canvas().
    165165 *  \return 0 in case of success, -1 if an error occurred.
    166166 */
    167 int cucul_unmanage_canvas(cucul_canvas_t *cv, int (*callback)(void *), void *p)
     167int caca_unmanage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
    168168{
    169169    if(!cv->refcount
     
    205205 *    happens, the canvas handle becomes invalid and should not be used.
    206206 *
    207  *  \param cv A libcucul canvas.
     207 *  \param cv A libcaca canvas.
    208208 *  \param width The desired canvas width.
    209209 *  \param height The desired canvas height.
    210210 *  \return 0 in case of success, -1 if an error occurred.
    211211 */
    212 int cucul_set_canvas_size(cucul_canvas_t *cv, int width, int height)
     212int caca_set_canvas_size(caca_canvas_t *cv, int width, int height)
    213213{
    214214    if(width < 0 || height < 0)
     
    225225    }
    226226
    227     return cucul_resize(cv, width, height);
     227    return caca_resize(cv, width, height);
    228228}
    229229
     
    234234 *  This function never fails.
    235235 *
    236  *  \param cv A libcucul canvas.
     236 *  \param cv A libcaca canvas.
    237237 *  \return The canvas width.
    238238 */
    239 int cucul_get_canvas_width(cucul_canvas_t const *cv)
     239int caca_get_canvas_width(caca_canvas_t const *cv)
    240240{
    241241    return cv->width;
     
    248248 *  This function never fails.
    249249 *
    250  *  \param cv A libcucul canvas.
     250 *  \param cv A libcaca canvas.
    251251 *  \return The canvas height.
    252252 */
    253 int cucul_get_canvas_height(cucul_canvas_t const *cv)
     253int caca_get_canvas_height(caca_canvas_t const *cv)
    254254{
    255255    return cv->height;
     
    260260 *  Return the current canvas' internal character array. The array elements
    261261 *  consist in native endian 32-bit Unicode values as returned by
    262  *  cucul_get_char().
     262 *  caca_get_char().
    263263 *
    264264 *  This function is only useful for display drivers such as the \e libcaca
     
    267267 *  This function never fails.
    268268 *
    269  *  \param cv A libcucul canvas.
     269 *  \param cv A libcaca canvas.
    270270 *  \return The canvas character array.
    271271 */
    272 uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *cv)
     272uint8_t const * caca_get_canvas_chars(caca_canvas_t const *cv)
    273273{
    274274    return (uint8_t const *)cv->chars;
     
    279279 *  Returns the current canvas' internal attribute array. The array elements
    280280 *  consist in native endian 32-bit attribute values as returned by
    281  *  cucul_get_attr().
     281 *  caca_get_attr().
    282282 *
    283283 *  This function is only useful for display drivers such as the \e libcaca
     
    286286 *  This function never fails.
    287287 *
    288  *  \param cv A libcucul canvas.
     288 *  \param cv A libcaca canvas.
    289289 *  \return The canvas attribute array.
    290290 */
    291 uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *cv)
     291uint8_t const * caca_get_canvas_attrs(caca_canvas_t const *cv)
    292292{
    293293    return (uint8_t const *)cv->attrs;
    294294}
    295295
    296 /** \brief Uninitialise \e libcucul.
    297  *
    298  *  Free all resources allocated by cucul_create_canvas(). After
    299  *  this function has been called, no other \e libcucul functions may be
    300  *  used unless a new call to cucul_create_canvas() is done.
     296/** \brief Uninitialise \e libcaca.
     297 *
     298 *  Free all resources allocated by caca_create_canvas(). After
     299 *  this function has been called, no other \e libcaca functions may be
     300 *  used unless a new call to caca_create_canvas() is done.
    301301 *
    302302 *  If an error occurs, -1 is returned and \b errno is set accordingly:
    303303 *  - \c EBUSY The canvas is in use by a display driver and cannot be freed.
    304304 *
    305  *  \param cv A libcucul canvas.
     305 *  \param cv A libcaca canvas.
    306306 *  \return 0 in case of success, -1 if an error occurred.
    307307 */
    308 int cucul_free_canvas(cucul_canvas_t *cv)
     308int caca_free_canvas(caca_canvas_t *cv)
    309309{
    310310    int f;
     
    323323    }
    324324
    325     cucul_canvas_set_figfont(cv, NULL);
     325    caca_canvas_set_figfont(cv, NULL);
    326326
    327327    free(cv->frames);
     
    342342 *  (inclusive).
    343343 */
    344 int cucul_rand(int min, int max)
     344int caca_rand(int min, int max)
    345345{
    346346    static int need_init = 1;
     
    355355}
    356356
    357 /** \brief Return the \e libcucul version.
    358  *
    359  *  Return a read-only string with the \e libcucul version information.
    360  *
    361  *  This function never fails.
    362  *
    363  *  \return The \e libcucul version information.
    364  */
    365 char const * cucul_get_version(void)
    366 {
    367     return VERSION;
    368 }
    369357
    370358/*
     
    372360 */
    373361
    374 int cucul_resize(cucul_canvas_t *cv, int width, int height)
     362int caca_resize(caca_canvas_t *cv, int width, int height)
    375363{
    376364    int x, y, f, old_width, old_height, new_size, old_size;
     
    380368    old_size = old_width * old_height;
    381369
    382     _cucul_save_frame_info(cv);
     370    _caca_save_frame_info(cv);
    383371
    384372    cv->width = width;
     
    508496
    509497    /* Reset the current frame shortcuts */
    510     _cucul_load_frame_info(cv);
     498    _caca_load_frame_info(cv);
    511499
    512500    return 0;
Note: See TracChangeset for help on using the changeset viewer.