Changeset 1324 for libcaca


Ignore:
Timestamp:
Nov 10, 2006, 11:29:54 AM (16 years ago)
Author:
Sam Hocevar
Message:
  • Implemented cucul_putattr(), cucul_putchar()'s attribute equivalent.
Location:
libcaca/trunk/cucul
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/Makefile.am

    r1302 r1324  
    1919        transform.c \
    2020        charset.c \
    21         colour.c \
     21        attr.c \
    2222        line.c \
    2323        box.c \
  • libcaca/trunk/cucul/attr.c

    r1312 r1324  
    1313
    1414/*
    15  *  This file contains functions for converting colour values between
    16  *  various colourspaces.
     15 *  This file contains functions for attribute management and colourspace
     16 *  conversions.
    1717 */
    1818
     
    102102}
    103103
     104/** \brief Set the character attribute at the given coordinates.
     105 *
     106 *  Set the character attribute, without changing the character's value. If
     107 *  the character at the given coordinates is a fullwidth character, both
     108 *  cells' attributes are replaced.
     109 *
     110 *  The value of \e attr is either:
     111 *  - a 32-bit integer as returned by cucul_get_attr(), in which case it
     112 *    also contains colour information,
     113 *  - a combination (bitwise OR) of style values (\e CUCUL_UNDERLINE,
     114 *    \e CUCUL_BLINK, \e CUCUL_BOLD and \e CUCUL_ITALICS), in which case
     115 *    setting the attribute does not modify the current colour information.
     116 *
     117 *  If an error occurs, -1 is returned and \b errno is set accordingly:
     118 *  - \c EINVAL The attribute value is out of the 32-bit range.
     119 *
     120 *  \param cv A handle to the libcucul canvas.
     121 *  \param x X coordinate.
     122 *  \param y Y coordinate.
     123 *  \param attr The requested attribute value.
     124 *  \return 0 in case of success, -1 if an error occurred.
     125 */
     126int cucul_putattr(cucul_canvas_t *cv, int x, int y, unsigned long int attr)
     127{
     128    uint32_t *curattr, *curchar;
     129
     130    if(sizeof(unsigned long int) > sizeof(uint32_t) && attr > 0xffffffff)
     131    {
     132#if defined(HAVE_ERRNO_H)
     133        errno = EINVAL;
     134#endif
     135        return -1;
     136    }
     137
     138    if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height)
     139        return 0;
     140
     141    curchar = cv->chars + x + y * cv->width;
     142    curattr = cv->attrs + x + y * cv->width;
     143
     144    if(curattr[0] < 0x00000010)
     145        curattr[0] = (cv->curattr & 0xfffffff0) | curattr[0];
     146
     147    if(x && curchar[0] == CUCUL_MAGIC_FULLWIDTH)
     148        curattr[-1] = curattr[0];
     149    else if(x + 1 < (int)cv->width && curchar[1] == CUCUL_MAGIC_FULLWIDTH)
     150        curattr[1] = curattr[0];
     151
     152    return 0;
     153}
     154
    104155/** \brief Set the default colour pair for text (ANSI version).
    105156 *
  • libcaca/trunk/cucul/cucul.h

    r1307 r1324  
    9292unsigned long int cucul_get_attr(cucul_canvas_t *, int, int);
    9393int cucul_set_attr(cucul_canvas_t *, unsigned long int);
     94int cucul_putattr(cucul_canvas_t *, int, int, unsigned long int);
    9495int cucul_set_color_ansi(cucul_canvas_t *, unsigned char, unsigned char);
    9596int cucul_set_color_argb(cucul_canvas_t *, unsigned int, unsigned int);
Note: See TracChangeset for help on using the changeset viewer.