Changeset 1342 for libcaca


Ignore:
Timestamp:
Nov 11, 2006, 3:24:35 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Add cursor and handle support to canvases. Unused yet.
Location:
libcaca/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/TODO

    r1341 r1342  
    77  - allow to change the canvas size in a per-frame basis.
    88  - export attribute parsing functions such as attr_to_ansi4fg etc.
    9   - add cursor support in the canvas, so that we can load ANSI files
    10     in stream mode.
    119
    1210  \subsection indep API-independent stuff
  • libcaca/trunk/cucul/canvas.c

    r1341 r1342  
    4242#include "cucul_internals.h"
    4343
     44/** \brief Set cursor position.
     45 *
     46 *  Put the cursor at the given coordinates. Functions making use of the
     47 *  cursor will use the new values. Setting the cursor position outside the
     48 *  canvas is legal but the cursor will not be shown.
     49 *
     50 *  This function never fails.
     51 *
     52 *  \param cv A handle to the libcucul canvas.
     53 *  \param x X cursor coordinate.
     54 *  \param y Y cursor coordinate.
     55 *  \return This function always returns 0.
     56 */
     57int cucul_gotoxy(cucul_canvas_t *cv, int x, int y)
     58{
     59    cv->frames[cv->frame].x = x;
     60    cv->frames[cv->frame].y = y;
     61
     62    return 0;
     63}
     64
     65/** \brief Get X cursor position.
     66 *
     67 *  Retrieve the X coordinate of the cursor's position.
     68 *
     69 *  This function never fails.
     70 *
     71 *  \param cv A handle to the libcucul canvas.
     72 *  \return The cursor's X coordinate.
     73 */
     74int cucul_get_cursor_x(cucul_canvas_t *cv)
     75{
     76    return cv->frames[cv->frame].x;
     77}
     78
     79/** \brief Get Y cursor position.
     80 *
     81 *  Retrieve the Y coordinate of the cursor's position.
     82 *
     83 *  This function never fails.
     84 *
     85 *  \param cv A handle to the libcucul canvas.
     86 *  \return The cursor's Y coordinate.
     87 */
     88int cucul_get_cursor_y(cucul_canvas_t *cv)
     89{
     90    return cv->frames[cv->frame].y;
     91}
     92
    4493/** \brief Print an ASCII or Unicode character.
    4594 *
     
    263312
    264313    return 0;
     314}
     315
     316/** \brief Set cursor handle.
     317 *
     318 *  Set the canvas' handle. Blitting functions will use the handle value
     319 *  to put the canvas at the proper coordinates.
     320 *
     321 *  This function never fails.
     322 *
     323 *  \param cv A handle to the libcucul canvas.
     324 *  \param x X handle coordinate.
     325 *  \param y Y handle coordinate.
     326 *  \return This function always returns 0.
     327 */
     328int cucul_set_canvas_handle(cucul_canvas_t *cv, int x, int y)
     329{
     330    cv->frames[cv->frame].handlex = x;
     331    cv->frames[cv->frame].handley = y;
     332
     333    return 0;
     334}
     335
     336/** \brief Get X handle position.
     337 *
     338 *  Retrieve the X coordinate of the canvas' handle.
     339 *
     340 *  This function never fails.
     341 *
     342 *  \param cv A handle to the libcucul canvas.
     343 *  \return The canvas' handle's X coordinate.
     344 */
     345int cucul_get_canvas_handle_x(cucul_canvas_t *cv)
     346{
     347    return cv->frames[cv->frame].handlex;
     348}
     349
     350/** \brief Get Y handle position.
     351 *
     352 *  Retrieve the Y coordinate of the canvas' handle.
     353 *
     354 *  This function never fails.
     355 *
     356 *  \param cv A handle to the libcucul canvas.
     357 *  \return The canvas' handle's Y coordinate.
     358 */
     359int cucul_get_canvas_handle_y(cucul_canvas_t *cv)
     360{
     361    return cv->frames[cv->frame].handley;
    265362}
    266363
  • libcaca/trunk/cucul/cucul.c

    r1338 r1342  
    4444 *  should be called at the end of the program to free all allocated resources.
    4545 *
     46 *  Both the cursor and the canvas' handle are initialised at the top-left
     47 *  corner.
     48 *
    4649 *  If an error occurs, NULL is returned and \b errno is set accordingly:
    4750 *  - \c ENOMEM Not enough memory for the requested canvas size.
     
    7982    cv->frames[0].chars = NULL;
    8083    cv->frames[0].attrs = NULL;
     84    cv->frames[0].x = cv->frames[0].y = 0;
     85    cv->frames[0].handlex = cv->frames[0].handley = 0;
    8186    cv->frames[0].curattr = cv->curattr;
    8287
  • libcaca/trunk/cucul/cucul.h

    r1333 r1342  
    9090 *  @{ */
    9191#define CUCUL_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */
     92int cucul_gotoxy(cucul_canvas_t *, int, int);
     93int cucul_get_cursor_x(cucul_canvas_t *);
     94int cucul_get_cursor_y(cucul_canvas_t *);
    9295unsigned long int cucul_get_attr(cucul_canvas_t *, int, int);
    9396int cucul_set_attr(cucul_canvas_t *, unsigned long int);
     
    100103int cucul_printf(cucul_canvas_t *, int, int, char const *, ...);
    101104int cucul_clear_canvas(cucul_canvas_t *);
     105int cucul_set_canvas_handle(cucul_canvas_t *, int, int);
     106int cucul_get_canvas_handle_x(cucul_canvas_t *);
     107int cucul_get_canvas_handle_y(cucul_canvas_t *);
    102108int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *,
    103109               cucul_canvas_t const *);
  • libcaca/trunk/cucul/cucul_internals.h

    r1338 r1342  
    2929
    3030    /* Painting context */
     31    int x, y;
     32    int handlex, handley;
    3133    uint32_t curattr;
    3234};
  • libcaca/trunk/cucul/export.c

    r1332 r1342  
    172172     *  - 24 bytes for the frame info
    173173     * 8 bytes for each character cell */
    174     *bytes = 44 + 8 * cv->width * cv->height;
     174    *bytes = 52 + 8 * cv->width * cv->height;
    175175    cur = data = malloc(*bytes);
    176176
     
    179179
    180180    /* canvas_header */
    181     cur += sprintu32(cur, 16 + 24);
     181    cur += sprintu32(cur, 16 + 32 * 1);
    182182    cur += sprintu32(cur, cv->width * cv->height * 8);
    183183    cur += sprintu16(cur, 0x0001);
     
    190190    cur += sprintu32(cur, 0);
    191191    cur += sprintu32(cur, cv->curattr);
    192     cur += sprintu32(cur, 0);
    193     cur += sprintu32(cur, 0);
     192    cur += sprintu32(cur, cv->frames[0].x);
     193    cur += sprintu32(cur, cv->frames[0].y);
     194    cur += sprintu32(cur, cv->frames[0].handlex);
     195    cur += sprintu32(cur, cv->frames[0].handley);
    194196
    195197    /* canvas_data */
     
    237239 *                               // not specify a duration
    238240 *       uint32_t attr;          // Graphics context attribute
     241 *       int32_t cursor_x;       // Cursor X coordinate
     242 *       int32_t cursor_y;       // Cursor Y coordinate
    239243 *       int32_t handle_x;       // Handle X coordinate
    240244 *       int32_t handle_y;       // Handle Y coordinate
  • libcaca/trunk/cucul/frame.c

    r1341 r1342  
    115115        cv->frames[f] = cv->frames[f - 1];
    116116
     117    if(cv->frame >= id)
     118        cv->frame++;
     119
    117120    cv->frames[id].width = cv->width;
    118121    cv->frames[id].height = cv->height;
     
    123126    cv->frames[id].curattr = cv->curattr;
    124127
    125     if(cv->frame >= id)
    126         cv->frame++;
     128    cv->frames[id].x = cv->frames[cv->frame].x;
     129    cv->frames[id].y = cv->frames[cv->frame].y;
     130    cv->frames[id].handlex = cv->frames[cv->frame].handlex;
     131    cv->frames[id].handley = cv->frames[cv->frame].handley;
    127132
    128133    return 0;
  • libcaca/trunk/cucul/import.c

    r1314 r1342  
    248248        return 0;
    249249
    250     if(control_size < 16 + frames * 24)
     250    if(control_size < 16 + frames * 32)
    251251        goto invalid_caca;
    252252
     
    255255        unsigned int width, height, duration;
    256256        uint32_t attr;
    257         int x, y;
     257        int x, y, handlex, handley;
    258258
    259259        width = sscanu32(buf + 4 + 16 + f * 24);
     
    263263        x = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 16);
    264264        y = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 20);
     265        handlex = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 24);
     266        handley = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 28);
    265267
    266268        expected_size += width * height * 8;
     
    284286
    285287    cv->curattr = sscanu32(buf + 4 + 16 + 12);
     288    cv->frames[0].x = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 16);
     289    cv->frames[0].y = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 20);
     290    cv->frames[0].handlex = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 24);
     291    cv->frames[0].handley = (int32_t)sscanu32(buf + 4 + 16 + f * 24 + 28);
    286292
    287293    return 4 + control_size + data_size;
Note: See TracChangeset for help on using the changeset viewer.