Ignore:
Timestamp:
Mar 7, 2006, 10:17:35 AM (14 years ago)
Author:
Sam Hocevar
Message:
  • Polished the driver split a bit (still no events, except resize events), properly credited authors and documented a few things.
File:
1 edited

Legend:

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

    r539 r540  
    2222#include "config.h"
    2323
    24 #if defined(HAVE_INTTYPES_H) || defined(_DOXYGEN_SKIP_ME)
    25 #   include <inttypes.h>
    26 #else
    27 typedef unsigned int uint32_t;
    28 typedef unsigned char uint8_t;
    29 #endif
    30 
    3124#include <stdlib.h>
    3225#include <string.h>
     
    3831
    3932static int caca_init_driver(caca_t *kk);
    40 static void caca_init_terminal(caca_t *kk);
    41 
     33static void caca_check_terminal(caca_t *kk);
     34
     35/** \brief Attach a caca graphical context to a cucul backend context.
     36 *
     37 *  Create a graphical context using device-dependent features (ncurses for
     38 *  terminals, an X11 window, a DOS command window...) that attaches to a
     39 *  libcucul canvas. Everything that gets drawn in the libcucul canvas can
     40 *  then be displayed by the libcaca driver.
     41 *
     42 *  \param qq The cucul backend context.
     43 *  \return The caca graphical context or NULL if an error occurred.
     44 */
    4245caca_t * caca_attach(cucul_t * qq)
    4346{
    44     int ret;
    4547    caca_t *kk = malloc(sizeof(caca_t));
    4648
    47     ret = caca_init_driver(kk);
    48 
    49     if(ret)
     49    kk->qq = qq;
     50
     51    if(caca_init_driver(kk))
    5052    {
    5153        free(kk);
     
    5355    }
    5456
    55     qq->refcount++;
    56     kk->qq = qq;
    57 
    58     /* Only for slang and ncurses */
    59     caca_init_terminal(kk);
    60 
    61     if(_caca_init_graphics(kk))
    62     {
    63         qq->refcount--;
     57    /* Only needed for slang and ncurses */
     58    caca_check_terminal(kk);
     59
     60    if(kk->driver.init_graphics(kk))
     61    {
    6462        free(kk);
    6563        return NULL;
    6664    }
    6765
    68     /* Initialise events stuff */
     66    /* Attached! */
     67    kk->qq->refcount++;
     68
     69    /* Graphics stuff */
     70    kk->delay = 0;
     71    kk->rendertime = 0;
     72
     73    /* Events stuff */
     74#if defined(USE_SLANG) || defined(USE_NCURSES)
    6975    kk->events.key_timer.last_sec = 0;
    7076    kk->events.key_timer.last_usec = 0;
     
    7278    kk->events.autorepeat_ticks = 0;
    7379    kk->events.last_key = 0;
     80#endif
    7481
    7582    kk->timer.last_sec = 0;
     
    8390}
    8491
     92/** \brief Detach a caca graphical context from a cucul backend context.
     93 *
     94 *  Detach a graphical context from its cucul backend and destroy it. The
     95 *  libcucul canvas continues to exist and other graphical contexts can be
     96 *  attached to it afterwards.
     97 *
     98 *  \param qq The caca graphical context.
     99 */
    85100void caca_detach(caca_t *kk)
    86101{
     
    176191}
    177192
    178 static void caca_init_terminal(caca_t *kk)
     193static void caca_check_terminal(caca_t *kk)
    179194{
    180195#if defined(HAVE_GETENV) && defined(HAVE_PUTENV) && \
Note: See TracChangeset for help on using the changeset viewer.