Changeset 1338 for libcaca/trunk/cucul/sprite.c
- Timestamp:
- Nov 11, 2006, 1:57:03 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/cucul/sprite.c
r1257 r1338 31 31 #include "cucul_internals.h" 32 32 33 static void save_frame_info(cucul_canvas_t *); 34 static void load_frame_info(cucul_canvas_t *); 35 33 36 /** \brief Get the number of frames in a canvas. 34 37 * … … 70 73 } 71 74 75 save_frame_info(cv); 72 76 cv->frame = frame; 73 74 cv->chars = cv->allchars[cv->frame]; 75 cv->attrs = cv->allattrs[cv->frame]; 77 load_frame_info(cv); 76 78 77 79 return 0; … … 85 87 * The frame index indicates where the frame should be inserted. Valid 86 88 * values range from 0 to the current canvas frame count. If the frame 87 * index is greater th eor equals the current canvas frame count, the new89 * index is greater than or equals the current canvas frame count, the new 88 90 * frame is appended at the end of the canvas. 89 91 * … … 107 109 108 110 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); 111 113 112 114 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; 122 124 123 125 if(cv->frame >= frame) 124 126 cv->frame++; 125 126 cv->chars = cv->allchars[cv->frame];127 cv->attrs = cv->allattrs[cv->frame];128 127 129 128 return 0; … … 171 170 } 172 171 173 free(cv-> allchars[frame]);174 free(cv-> allattrs[frame]);172 free(cv->frames[frame].chars); 173 free(cv->frames[frame].attrs); 175 174 176 175 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]; 181 177 182 178 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); 185 181 186 182 if(cv->frame > frame) 187 183 cv->frame--; 188 184 else if(cv->frame == frame) 185 { 189 186 cv->frame = 0; 190 191 cv->chars = cv->allchars[cv->frame]; 192 cv->attrs = cv->allattrs[cv->frame]; 187 load_frame_info(cv); 188 } 193 189 194 190 return 0; 195 191 } 196 192 193 /* 194 * XXX: the following functions are local. 195 */ 196 197 static 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 205 static 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.