Changeset 1079


Ignore:
Timestamp:
Sep 22, 2006, 2:20:06 AM (17 years ago)
Author:
Sam Hocevar
Message:
  • Implement cucul_set_canvas_boundaries() for cropping and expanding.
Location:
libcaca/trunk/cucul
Files:
2 edited

Legend:

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

    r1066 r1079  
    290290}
    291291
     292/** \brief Set a canvas' new boundaries.
     293 *
     294 *  This function sets new boundaries for a canvas. It can be used to crop a
     295 *  canvas, to expand it or for combinations of both actions.
     296 *
     297 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     298 *  - \c EBUSY The canvas is in use by a display driver and cannot be resized.
     299 *  - \c ENOMEM Not enough memory for the requested canvas size. If this
     300 *    happens, the canvas handle becomes invalid and should not be used.
     301 *
     302 *  \param cv The canvas to crop.
     303 *  \param x X coordinate of the top-left corner.
     304 *  \param y Y coordinate of the top-left corner.
     305 *  \param w The width of the cropped area.
     306 *  \param h The height of the cropped area.
     307 *  \return 0 in case of success, -1 if an error occurred.
     308 */
     309int cucul_set_canvas_boundaries(cucul_canvas_t *cv, int x, int y,
     310                                unsigned int w, unsigned int h)
     311{
     312    cucul_canvas_t *new;
     313    unsigned int f, saved_f, framecount;
     314
     315    if(cv->refcount)
     316    {
     317#if defined(HAVE_ERRNO_H)
     318        errno = EBUSY;
     319#endif
     320        return -1;
     321    }
     322
     323    new = cucul_create_canvas(w, h);
     324
     325    framecount = cucul_get_canvas_frame_count(cv);
     326    saved_f = cv->frame;
     327
     328    for(f = 0; f < framecount; f++)
     329    {
     330        if(f)
     331            cucul_create_canvas_frame(new, framecount);
     332
     333        cucul_set_canvas_frame(cv, f);
     334        cucul_set_canvas_frame(new, f);
     335        cucul_blit(new, -x, -y, cv, NULL);
     336
     337        free(cv->allchars[f]);
     338        free(cv->allattr[f]);
     339    }
     340
     341    memcpy(cv, new, sizeof(cucul_canvas_t));
     342    free(new);
     343
     344    cucul_set_canvas_frame(cv, saved_f);
     345
     346    return 0;
     347}
     348
  • libcaca/trunk/cucul/cucul.h

    r1066 r1079  
    106106int cucul_printf(cucul_canvas_t *, int, int, char const *, ...);
    107107int cucul_clear_canvas(cucul_canvas_t *);
    108 int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *, cucul_canvas_t const *);
     108int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *,
     109               cucul_canvas_t const *);
     110int cucul_set_canvas_boundaries(cucul_canvas_t *, int, int,
     111                                unsigned int, unsigned int);
    109112/*  @} */
    110113
Note: See TracChangeset for help on using the changeset viewer.