From 6d526ea629ca1959f16a2d4e192dc10b998f6102 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 18 Dec 2009 21:36:15 +0000 Subject: [PATCH] Implement caca_unset_attr() and caca_toggle_attr(). Fixes #7. --- caca/attr.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ caca/caca.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/caca/attr.c b/caca/attr.c index 8ec0068..174320f 100644 --- a/caca/attr.c +++ b/caca/attr.c @@ -106,6 +106,60 @@ int caca_set_attr(caca_canvas_t *cv, uint32_t attr) return 0; } +/** \brief Unset flags in the default character attribute. + * + * Unset flags in the default character attribute for drawing. Attributes + * define foreground and background colour, transparency, bold, italics and + * underline styles, as well as blink. String functions such as + * caca_printf() and graphical primitive functions such as caca_draw_line() + * will use this attribute. + * + * The value of \e attr is a combination (bitwise OR) of style values + * (\e CACA_UNDERLINE, \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS). + * Unsetting these attributes does not modify the current colour information. + * + * To retrieve the current attribute value, use caca_get_attr(-1,-1). + * + * This function never fails. + * + * \param cv A handle to the libcaca canvas. + * \param attr The requested attribute values to unset. + * \return This function always returns 0. + */ +int caca_unset_attr(caca_canvas_t *cv, uint32_t attr) +{ + cv->curattr &= ~(attr & 0x0000000f); + + return 0; +} + +/** \brief Toggle flags in the default character attribute. + * + * Toggle flags in the default character attribute for drawing. Attributes + * define foreground and background colour, transparency, bold, italics and + * underline styles, as well as blink. String functions such as + * caca_printf() and graphical primitive functions such as caca_draw_line() + * will use this attribute. + * + * The value of \e attr is a combination (bitwise OR) of style values + * (\e CACA_UNDERLINE, \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS). + * Toggling these attributes does not modify the current colour information. + * + * To retrieve the current attribute value, use caca_get_attr(-1,-1). + * + * This function never fails. + * + * \param cv A handle to the libcaca canvas. + * \param attr The requested attribute values to toggle. + * \return This function always returns 0. + */ +int caca_toggle_attr(caca_canvas_t *cv, uint32_t attr) +{ + cv->curattr ^= attr & 0x0000000f; + + return 0; +} + /** \brief Set the character attribute at the given coordinates. * * Set the character attribute, without changing the character's value. If diff --git a/caca/caca.h b/caca/caca.h index d52b27a..6f48334 100644 --- a/caca/caca.h +++ b/caca/caca.h @@ -285,6 +285,8 @@ __extern int caca_stretch_right(caca_canvas_t *); * @{ */ __extern uint32_t caca_get_attr(caca_canvas_t const *, int, int); __extern int caca_set_attr(caca_canvas_t *, uint32_t); +__extern int caca_unset_attr(caca_canvas_t *, uint32_t); +__extern int caca_toggle_attr(caca_canvas_t *, uint32_t); __extern int caca_put_attr(caca_canvas_t *, int, int, uint32_t); __extern int caca_set_color_ansi(caca_canvas_t *, uint8_t, uint8_t); __extern int caca_set_color_argb(caca_canvas_t *, uint16_t, uint16_t);