Changeset 1390


Ignore:
Timestamp:
Nov 14, 2006, 12:16:35 AM (14 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.
Location:
libcaca/trunk
Files:
9 edited

Legend:

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

    r1362 r1390  
    473473    new = cucul_create_canvas(w, h);
    474474
    475     framecount = cucul_get_canvas_frame_count(cv);
     475    framecount = cucul_get_frame_count(cv);
    476476    saved_f = cv->frame;
    477477
     
    479479    {
    480480        if(f)
    481             cucul_create_canvas_frame(new, framecount);
    482 
    483         cucul_set_canvas_frame(cv, f);
    484         cucul_set_canvas_frame(new, f);
     481            cucul_create_frame(new, framecount);
     482
     483        cucul_set_frame(cv, f);
     484        cucul_set_frame(new, f);
    485485        cucul_blit(new, -x, -y, cv, NULL);
    486486
     
    493493    free(new);
    494494
    495     cucul_set_canvas_frame(cv, saved_f);
    496 
    497     return 0;
    498 }
    499 
     495    cucul_set_frame(cv, saved_f);
     496
     497    return 0;
     498}
     499
  • libcaca/trunk/cucul/cucul.c

    r1381 r1390  
    5959
    6060    cv->refcount = 0;
     61    cv->autoinc = 0;
    6162
    6263    cv->frame = 0;
     
    7576    cv->frames[0].handlex = cv->frames[0].handley = 0;
    7677    cv->frames[0].curattr = 0;
     78    cv->frames[0].name = strdup("frame#00000000");
    7779
    7880    _cucul_load_frame_info(cv);
     
    8284    {
    8385        int saved_errno = geterrno();
     86        free(cv->frames[0].name);
    8487        free(cv->frames);
    8588        free(cv);
     
    186189        free(cv->frames[f].chars);
    187190        free(cv->frames[f].attrs);
     191        free(cv->frames[f].name);
    188192    }
    189193
  • libcaca/trunk/cucul/cucul.h

    r1366 r1390  
    181181 *
    182182 *  @{ */
    183 unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *);
    184 int cucul_set_canvas_frame(cucul_canvas_t *, unsigned int);
    185 int cucul_create_canvas_frame(cucul_canvas_t *, unsigned int);
    186 int cucul_free_canvas_frame(cucul_canvas_t *, unsigned int);
     183unsigned int cucul_get_frame_count(cucul_canvas_t *);
     184int cucul_set_frame(cucul_canvas_t *, unsigned int);
     185char const *cucul_get_frame_name(cucul_canvas_t *);
     186int cucul_set_frame_name(cucul_canvas_t *, char const *);
     187int cucul_create_frame(cucul_canvas_t *, unsigned int);
     188int cucul_free_frame(cucul_canvas_t *, unsigned int);
    187189/*  @} */
    188190
     
    265267    int cucul_set_truecolor(cucul_canvas_t *, unsigned int,
    266268                            unsigned int) CUCUL_DEPRECATED;
     269    unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *)
     270                                              CUCUL_DEPRECATED;
     271    int cucul_set_canvas_frame(cucul_canvas_t *,
     272                               unsigned int) CUCUL_DEPRECATED;
     273    int cucul_create_canvas_frame(cucul_canvas_t *,
     274                                  unsigned int) CUCUL_DEPRECATED;
     275    int cucul_free_canvas_frame(cucul_canvas_t *,
     276                                unsigned int) CUCUL_DEPRECATED;
    267277    cucul_buffer_t *cucul_load_memory(void *,
    268278                                      unsigned long int) CUCUL_DEPRECATED;
  • libcaca/trunk/cucul/cucul_internals.h

    r1381 r1390  
    3232    int handlex, handley;
    3333    uint32_t curattr;
     34
     35    /* Frame name */
     36    char *name;
    3437};
    3538
     
    4144
    4245    unsigned int refcount;
     46    unsigned int autoinc;
    4347
    4448    /* Shortcut to the active frame information */
  • 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++)
  • libcaca/trunk/cucul/legacy.c

    r1366 r1390  
    108108
    109109/*
     110 * Functions from frame.c
     111 */
     112
     113unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *cv)
     114{
     115    return cucul_get_frame_count(cv);
     116}
     117
     118int cucul_set_canvas_frame(cucul_canvas_t *cv, unsigned int id)
     119{
     120    return cucul_set_frame(cv, id);
     121}
     122
     123int cucul_create_canvas_frame(cucul_canvas_t *cv, unsigned int id)
     124{
     125    return cucul_create_frame(cv, id);
     126}
     127
     128int cucul_free_canvas_frame(cucul_canvas_t *cv, unsigned int id)
     129{
     130    return cucul_free_frame(cv, id);
     131}
     132
     133/*
    110134 * Functions from buffer.c
    111135 */
  • libcaca/trunk/cxx/cucul++.cpp

    r1388 r1390  
    254254unsigned int Cucul::getFrameCount()
    255255{
    256     return cucul_get_canvas_frame_count(cv);
     256    return cucul_get_frame_count(cv);
    257257}
    258258int Cucul::setFrame(unsigned int f)
    259259{
    260     return cucul_set_canvas_frame(cv, f);
     260    return cucul_set_frame(cv, f);
    261261}
    262262int Cucul::createFrame(unsigned int f)
    263263{
    264     return cucul_create_canvas_frame(cv, f);
     264    return cucul_create_frame(cv, f);
    265265}
    266266int Cucul::freeFrame(unsigned int f)
    267267{
    268     return cucul_create_canvas_frame(cv, f);
     268    return cucul_create_frame(cv, f);
    269269}
    270270
  • libcaca/trunk/test/all.c

    r1389 r1390  
    1717#if !defined(__KERNEL__)
    1818#   include <stdio.h>
     19#   include <string.h>
    1920#endif
    2021
     
    2223#include "caca.h"
    2324
    24 #define ITER 1000
     25#define ITER 128
    2526
    2627int main(int argc, char *argv[])
    2728{
    2829    cucul_canvas_t *cv;
    29     unsigned int i, w, h;
     30    unsigned int i, j, w, h;
    3031
    31     /* cucul_create_canvas */
    3232    fprintf(stderr, "testing cucul_create_canvas()\n");
    3333    for(i = 0; i < ITER; i++)
     
    4242    }
    4343
     44    fprintf(stderr, "testing cucul_set_frame_name()\n");
     45    cv = cucul_create_canvas(1, 1);
     46    for(i = 0; i < ITER; i++)
     47    {
     48        cucul_create_frame(cv, 0);
     49        for(j = 0; j < ITER; j++)
     50        {
     51            char buf[BUFSIZ];
     52            w = cucul_rand(1, 1000);
     53            memset(buf, 'x', w);
     54            buf[w] = '\0';
     55            cucul_set_frame_name(cv, buf);
     56        }
     57    }
     58    cucul_free_canvas(cv);
     59
    4460    fprintf(stderr, "all tests passed\n");
    4561    return 0;
  • libcaca/trunk/test/frames.c

    r1347 r1390  
    3434    cv = cucul_create_canvas(0, 0);
    3535    for(frame = 1; frame < 200; frame++)
    36         cucul_create_canvas_frame(cv, frame);
     36        cucul_create_frame(cv, frame);
    3737
    3838    fprintf(stderr, "canvas created, size is %ix%i\n",
     
    4848    for(frame = 0; frame < 16; frame++)
    4949    {
    50         cucul_set_canvas_frame(cv, frame);
     50        cucul_set_frame(cv, frame);
    5151        cucul_set_color_ansi(cv, CUCUL_WHITE, frame);
    5252        cucul_fill_box(cv, 0, 0, 40, 15, ':');
     
    7171    while(!caca_get_event(dp, CACA_EVENT_KEY_PRESS, NULL, 0))
    7272    {
    73         cucul_set_canvas_frame(cv, n % 16);
     73        cucul_set_frame(cv, n % 16);
    7474        caca_refresh_display(dp);
    7575        n++;
Note: See TracChangeset for help on using the changeset viewer.