Ignore:
Timestamp:
Nov 14, 2006, 12:16:35 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • Implemented cucul_get_frame_name() and cucul_set_frame_name().
  • Renamed cucul_*_canvas_frame() to cucul_*_frame() because we bloody well know that a frame belongs to a canvas.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/frame.c

    r1381 r1390  
    3737 *  \return The frame count
    3838 */
    39 unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
     39unsigned int cucul_get_frame_count(cucul_canvas_t *cv)
    4040{
    4141    return cv->framecount;
     
    5454 *
    5555 *  \param cv A libcucul canvas
    56  *  \param frame The canvas frame to activate
    57  *  \return 0 in case of success, -1 if an error occurred.
    58  */
    59 int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int frame)
    60 {
    61     if(frame >= cv->framecount)
     56 *  \param id The canvas frame to activate
     57 *  \return 0 in case of success, -1 if an error occurred.
     58 */
     59int cucul_set_frame(cucul_canvas_t *cv, unsigned int id)
     60{
     61    if(id >= cv->framecount)
    6262    {
    6363        seterrno(EINVAL);
     
    6666
    6767    _cucul_save_frame_info(cv);
    68     cv->frame = frame;
     68    cv->frame = id;
    6969    _cucul_load_frame_info(cv);
     70
     71    return 0;
     72}
     73
     74/** \brief Get the current frame's name.
     75 *
     76 *  Return the current frame's name. The returned string is valid until
     77 *  the frame is deleted or cucul_set_frame_name() is called to change
     78 *  the frame name again.
     79 *
     80 *  This function never fails.
     81 *
     82 *  \param cv A libcucul canvas.
     83 *  \return The current frame's name.
     84 */
     85char const *cucul_get_frame_name(cucul_canvas_t *cv)
     86{
     87    return cv->frames[cv->frame].name;
     88}
     89
     90/** \brief Set the current frame's name.
     91 *
     92 *  Set the current frame's name. Upon creation, a frame has a default name
     93 *  of \rc "frame#xxxxxxxx" where \c xxxxxxxx is a self-incrementing
     94 *  hexadecimal number.
     95 *
     96 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     97 *  - \c ENOMEM Not enough memory to allocate new frame.
     98 *
     99 *  \param cv A libcucul canvas.
     100 *  \return 0 in case of success, -1 if an error occurred.
     101 */
     102int cucul_set_frame_name(cucul_canvas_t *cv, char const *name)
     103{
     104    char *newname = strdup(name);
     105
     106    if(!newname)
     107    {
     108        seterrno(ENOMEM);
     109        return -1;
     110    }
     111
     112    free(cv->frames[cv->frame].name);
     113    cv->frames[cv->frame].name = newname;
    70114
    71115    return 0;
     
    92136 *  \return 0 in case of success, -1 if an error occurred.
    93137 */
    94 int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
     138int cucul_create_frame(cucul_canvas_t *cv, unsigned int id)
    95139{
    96140    unsigned int size = cv->width * cv->height;
     
    123167    cv->frames[id].handley = cv->frames[cv->frame].handley;
    124168
     169    cv->frames[id].name = strdup("frame#--------");
     170    sprintf(cv->frames[id].name + 6, "%.08x", cv->autoinc++);
     171
    125172    return 0;
    126173}
     
    147194 *  \return 0 in case of success, -1 if an error occurred.
    148195 */
    149 int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
     196int cucul_free_frame(cucul_canvas_t *cv, unsigned int id)
    150197{
    151198    unsigned int f;
     
    165212    free(cv->frames[id].chars);
    166213    free(cv->frames[id].attrs);
     214    free(cv->frames[id].name);
    167215
    168216    for(f = id + 1; f < cv->framecount; f++)
Note: See TracChangeset for help on using the changeset viewer.