From f13f15d2f1742be7f0f69f999dc4be14ce8b0c35 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 19 Sep 2006 16:07:13 +0000 Subject: [PATCH] =?UTF-8?q?=20=20*=20Implemented=20cucul=5Fgetchar().=20Us?= =?UTF-8?q?eful=20because=20you=20don=E2=80=99t=20necessarily=20know=20=20?= =?UTF-8?q?=20=20=20what=20you=20are=20importing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cucul/canvas.c | 26 ++++++++++++++++++++++++++ cucul/cucul.h | 1 + 2 files changed, 27 insertions(+) diff --git a/cucul/canvas.c b/cucul/canvas.c index 05a4bdd..6964cd7 100644 --- a/cucul/canvas.c +++ b/cucul/canvas.c @@ -74,6 +74,32 @@ int cucul_putchar(cucul_canvas_t *cv, int x, int y, unsigned long int ch) return 0; } +/** \brief Get the Unicode character at the given coordinates. + * + * This function gets the ASCII or Unicode value of the character at + * the given coordinates. If the value is less or equal to 127 (0x7f), + * the character can be printed as ASCII. Otherise, it must be handled + * as a UTF-32 value. + * + * If the coordinates are outside the canvas boundaries, a space (0x20) + * 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 character value. + * \return The character always returns 0. + */ +unsigned long int cucul_getchar(cucul_canvas_t *cv, int x, int y) +{ + if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height) + return 0; + + return (unsigned long int)cv->chars[x + y * cv->width]; +} + /** \brief Print a string. * * This function prints an UTF-8 string at the given coordinates, using the diff --git a/cucul/cucul.h b/cucul/cucul.h index f9098c6..5630ce8 100644 --- a/cucul/cucul.h +++ b/cucul/cucul.h @@ -101,6 +101,7 @@ int cucul_set_color(cucul_canvas_t *, unsigned char, unsigned char); int cucul_set_truecolor(cucul_canvas_t *, unsigned int, unsigned 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); int cucul_putstr(cucul_canvas_t *, int, int, char const *); int cucul_printf(cucul_canvas_t *, int, int, char const *, ...); int cucul_clear_canvas(cucul_canvas_t *);