diff --git a/cucul/colour.c b/cucul/colour.c index 3f00d52..ea37a7b 100644 --- a/cucul/colour.c +++ b/cucul/colour.c @@ -108,6 +108,33 @@ int cucul_set_truecolor(cucul_canvas_t *cv, unsigned int fg, unsigned int bg) return 0; } +/** \brief Get the colour pair at the given coordinates. + * + * This function gets the internal \e libcucul colour pair value of the + * character at the given coordinates. The colour pair value has 32 + * significant bits: the lower 16 are for the foreground colour, the higher + * 16 are for the background. + * + * If the coordinates are outside the canvas boundaries, the current colour + * pair is returned. + * + * This function never fails. + * + * \param cv A handle to the libcucul canvas. + * \param x X coordinate. + * \param y Y coordinate. + * \param ch The requested colour pair value. + * \return The character always returns 0. + */ +unsigned long int cucul_get_color(cucul_canvas_t *cv, int x, int y) +{ + if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) + return ((uint32_t)cv->bgcolor << 16) | (uint32_t)cv->fgcolor; + + return (unsigned long int)cv->attr[x + y * cv->width]; +} + + /* * XXX: the following functions are local */ diff --git a/cucul/cucul.h b/cucul/cucul.h index 70f99dd..7a3ea8a 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -99,6 +99,7 @@ int cucul_free_buffer(cucul_buffer_t *); * @{ */ int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char); int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned int); +unsigned long int cucul_get_color(cucul_canvas_t *, int, int); char const *cucul_get_color_name(unsigned int); int cucul_putchar(cucul_canvas_t *, int, int, unsigned long int); unsigned long int cucul_getchar(cucul_canvas_t *, int, int);