Ignore:
Timestamp:
Nov 11, 2006, 1:57:03 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Prepare the way for per-frame width/height information.
File:
1 edited

Legend:

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

    r1257 r1338  
    3131#include "cucul_internals.h"
    3232
     33static void save_frame_info(cucul_canvas_t *);
     34static void load_frame_info(cucul_canvas_t *);
     35
    3336/** \brief Get the number of frames in a canvas.
    3437 *
     
    7073    }
    7174
     75    save_frame_info(cv);
    7276    cv->frame = frame;
    73 
    74     cv->chars = cv->allchars[cv->frame];
    75     cv->attrs = cv->allattrs[cv->frame];
     77    load_frame_info(cv);
    7678
    7779    return 0;
     
    8587 *  The frame index indicates where the frame should be inserted. Valid
    8688 *  values range from 0 to the current canvas frame count. If the frame
    87  *  index is greater the or equals the current canvas frame count, the new
     89 *  index is greater than or equals the current canvas frame count, the new
    8890 *  frame is appended at the end of the canvas.
    8991 *
     
    107109
    108110    cv->framecount++;
    109     cv->allchars = realloc(cv->allchars, sizeof(uint32_t *) * cv->framecount);
    110     cv->allattrs = realloc(cv->allattrs, sizeof(uint32_t *) * cv->framecount);
     111    cv->frames = realloc(cv->frames,
     112                         sizeof(struct cucul_frame) * cv->framecount);
    111113
    112114    for(f = cv->framecount - 1; f > frame; f--)
    113     {
    114         cv->allchars[f] = cv->allchars[f - 1];
    115         cv->allattrs[f] = cv->allattrs[f - 1];
    116     }
    117 
    118     cv->allchars[frame] = malloc(size);
    119     memcpy(cv->allchars[frame], cv->chars, size);
    120     cv->allattrs[frame] = malloc(size);
    121     memcpy(cv->allattrs[frame], cv->attrs, size);
     115        cv->frames[f] = cv->frames[f - 1];
     116
     117    cv->frames[frame].width = cv->width;
     118    cv->frames[frame].height = cv->height;
     119    cv->frames[frame].chars = malloc(size);
     120    memcpy(cv->frames[frame].chars, cv->chars, size);
     121    cv->frames[frame].attrs = malloc(size);
     122    memcpy(cv->frames[frame].attrs, cv->attrs, size);
     123    cv->frames[frame].curattr = cv->curattr;
    122124
    123125    if(cv->frame >= frame)
    124126        cv->frame++;
    125 
    126     cv->chars = cv->allchars[cv->frame];
    127     cv->attrs = cv->allattrs[cv->frame];
    128127
    129128    return 0;
     
    171170    }
    172171
    173     free(cv->allchars[frame]);
    174     free(cv->allattrs[frame]);
     172    free(cv->frames[frame].chars);
     173    free(cv->frames[frame].attrs);
    175174
    176175    for(f = frame + 1; f < cv->framecount; f++)
    177     {
    178         cv->allchars[f - 1] = cv->allchars[f];
    179         cv->allattrs[f - 1] = cv->allattrs[f];
    180     }
     176        cv->frames[f - 1] = cv->frames[f];
    181177
    182178    cv->framecount--;
    183     cv->allchars = realloc(cv->allchars, sizeof(uint32_t *) * cv->framecount);
    184     cv->allattrs = realloc(cv->allattrs, sizeof(uint32_t *) * cv->framecount);
     179    cv->frames = realloc(cv->frames,
     180                         sizeof(struct cucul_frame) * cv->framecount);
    185181
    186182    if(cv->frame > frame)
    187183        cv->frame--;
    188184    else if(cv->frame == frame)
     185    {
    189186        cv->frame = 0;
    190 
    191     cv->chars = cv->allchars[cv->frame];
    192     cv->attrs = cv->allattrs[cv->frame];
     187        load_frame_info(cv);
     188    }
    193189
    194190    return 0;
    195191}
    196192
     193/*
     194 * XXX: the following functions are local.
     195 */
     196
     197static void save_frame_info(cucul_canvas_t *cv)
     198{
     199    cv->frames[cv->frame].width = cv->width;
     200    cv->frames[cv->frame].height = cv->height;
     201
     202    cv->frames[cv->frame].curattr = cv->curattr;
     203}
     204
     205static void load_frame_info(cucul_canvas_t *cv)
     206{
     207    cv->width = cv->frames[cv->frame].width;
     208    cv->height = cv->frames[cv->frame].height;
     209
     210    cv->chars = cv->frames[cv->frame].chars;
     211    cv->attrs = cv->frames[cv->frame].attrs;
     212
     213    cv->curattr = cv->frames[cv->frame].curattr;
     214}
     215
Note: See TracChangeset for help on using the changeset viewer.