Ignore:
Timestamp:
Nov 25, 2007, 6:13:08 PM (12 years ago)
Author:
Sam Hocevar
Message:
  • Allow caca_create_display()'s argument to be NULL. It will automatically create a canvas when so.
  • Add caca_get_canvas() to retrieve the cucul canvas.
Location:
libcaca/trunk/caca
Files:
3 edited

Legend:

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

    r2056 r2061  
    5555 *  then be displayed by the libcaca driver.
    5656 *
     57 *  If no cucul canvas is provided, a new one is created. Its handle can be
     58 *  retrieved using caca_get_canvas() and it is automatically destroyed when
     59 *  caca_free_display() is called.
     60 *
    5761 *  If an error occurs, NULL is returned and \b errno is set accordingly:
    5862 *  - \c ENOMEM Not enough memory.
     
    7276    }
    7377
     78    if((dp->autorelease = (cv == NULL)))
     79    {
     80        cv = cucul_create_canvas(0, 0);
     81    }
     82
     83    dp->cv = cv;
     84
    7485    if(cucul_manage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp))
    7586    {
     87        if(dp->autorelease)
     88            cucul_free_canvas(dp->cv);
    7689        free(dp);
    7790        seterrno(EBUSY);
     
    7992    }
    8093
    81     dp->cv = cv;
    8294#if defined(USE_PLUGINS)
    8395    dp->plugin = NULL;
     
    91103#endif
    92104        cucul_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp);
     105        if(dp->autorelease)
     106            cucul_free_canvas(dp->cv);
    93107        free(dp);
    94108        seterrno(ENODEV);
     
    103117#endif
    104118        cucul_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp);
     119        if(dp->autorelease)
     120            cucul_free_canvas(dp->cv);
    105121        free(dp);
    106122        seterrno(ENODEV);
     
    145161 *  attached to it afterwards.
    146162 *
     163 *  If the cucul canvas was automatically created by caca_create_display(),
     164 *  it is automatically destroyed and any handle to it becomes invalid.
     165 *
    147166 *  This function never fails.
    148167 *
     
    158177#endif
    159178    cucul_unmanage_canvas(dp->cv, (int (*)(void *))caca_can_resize, (void *)dp);
     179    if(dp->autorelease)
     180        cucul_free_canvas(dp->cv);
    160181    free(dp);
    161182
    162183    return 0;
     184}
     185
     186/** \brief Get the canvas attached to a caca graphical context.
     187 *
     188 *  Return a handle on the \e cucul_canvas_t object that was either attached
     189 *  or created by caca_create_display().
     190 *
     191 *  This function never fails.
     192 *
     193 *  \param dp The libcaca graphical context.
     194 *  \return The libcucul canvas.
     195 */
     196cucul_canvas_t * caca_get_canvas(caca_display_t *dp)
     197{
     198    return dp->cv;
    163199}
    164200
  • libcaca/trunk/caca/caca.h

    r2049 r2061  
    155155__extern caca_display_t * caca_create_display(cucul_canvas_t *);
    156156__extern int caca_free_display(caca_display_t *);
     157__extern cucul_canvas_t * caca_get_canvas(caca_display_t *);
    157158__extern int caca_refresh_display(caca_display_t *);
    158159__extern int caca_set_display_time(caca_display_t *, unsigned int);
  • libcaca/trunk/caca/caca_internals.h

    r2055 r2061  
    109109    /* A link to our cucul canvas */
    110110    cucul_canvas_t *cv;
     111    int autorelease;
    111112
    112113#if defined(USE_PLUGINS)
Note: See TracChangeset for help on using the changeset viewer.