* Started changing function prototypes so that they return an integer instead of void, just in case they might fail.tags/v0.99.beta14
@@ -65,7 +65,7 @@ dnl conditional builds | |||||
AC_ARG_ENABLE(doc, | AC_ARG_ENABLE(doc, | ||||
[ --enable-doc build documentation (needs doxygen and LaTeX)]) | [ --enable-doc build documentation (needs doxygen and LaTeX)]) | ||||
AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h) | AC_CHECK_HEADERS(stdio.h stdarg.h signal.h sys/ioctl.h sys/time.h inttypes.h endian.h unistd.h arpa/inet.h netinet/in.h winsock2.h errno.h) | ||||
AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) | AC_CHECK_FUNCS(signal ioctl vsnprintf getenv putenv strcasecmp htons) | ||||
AC_CHECK_FUNCS(usleep gettimeofday) | AC_CHECK_FUNCS(usleep gettimeofday) | ||||
@@ -26,6 +26,8 @@ | |||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
/** \brief Draw a box on the canvas using the given character. | /** \brief Draw a box on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the upper-left corner of the box. | * \param x1 X coordinate of the upper-left corner of the box. | ||||
@@ -33,27 +35,31 @@ | |||||
* \param x2 X coordinate of the lower-right corner of the box. | * \param x2 X coordinate of the lower-right corner of the box. | ||||
* \param y2 Y coordinate of the lower-right corner of the box. | * \param y2 Y coordinate of the lower-right corner of the box. | ||||
* \param str UTF-8 string containing the character to use to draw the box. | * \param str UTF-8 string containing the character to use to draw the box. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | int cucul_draw_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | ||||
char const *str) | char const *str) | ||||
{ | { | ||||
cucul_draw_line(cv, x1, y1, x1, y2, str); | cucul_draw_line(cv, x1, y1, x1, y2, str); | ||||
cucul_draw_line(cv, x1, y2, x2, y2, str); | cucul_draw_line(cv, x1, y2, x2, y2, str); | ||||
cucul_draw_line(cv, x2, y2, x2, y1, str); | cucul_draw_line(cv, x2, y2, x2, y1, str); | ||||
cucul_draw_line(cv, x2, y1, x1, y1, str); | cucul_draw_line(cv, x2, y1, x1, y1, str); | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw a thin box on the canvas. | /** \brief Draw a thin box on the canvas. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the upper-left corner of the box. | * \param x1 X coordinate of the upper-left corner of the box. | ||||
* \param y1 Y coordinate of the upper-left corner of the box. | * \param y1 Y coordinate of the upper-left corner of the box. | ||||
* \param x2 X coordinate of the lower-right corner of the box. | * \param x2 X coordinate of the lower-right corner of the box. | ||||
* \param y2 Y coordinate of the lower-right corner of the box. | * \param y2 Y coordinate of the lower-right corner of the box. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | int cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | ||||
{ | { | ||||
int x, y, xmax, ymax; | int x, y, xmax, ymax; | ||||
@@ -73,7 +79,7 @@ void cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | |||||
ymax = cv->height - 1; | ymax = cv->height - 1; | ||||
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | ||||
return; | return 0; | ||||
/* Draw edges */ | /* Draw edges */ | ||||
if(y1 >= 0) | if(y1 >= 0) | ||||
@@ -104,9 +110,13 @@ void cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | |||||
if(x2 <= xmax && y2 <= ymax) | if(x2 <= xmax && y2 <= ymax) | ||||
_cucul_putchar32(cv, x2, y2, (uint32_t)'\''); | _cucul_putchar32(cv, x2, y2, (uint32_t)'\''); | ||||
return 0; | |||||
} | } | ||||
/** \brief Fill a box on the canvas using the given character. | /** \brief Fill a box on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the upper-left corner of the box. | * \param x1 X coordinate of the upper-left corner of the box. | ||||
@@ -114,10 +124,10 @@ void cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | |||||
* \param x2 X coordinate of the lower-right corner of the box. | * \param x2 X coordinate of the lower-right corner of the box. | ||||
* \param y2 Y coordinate of the lower-right corner of the box. | * \param y2 Y coordinate of the lower-right corner of the box. | ||||
* \param str UTF-8 string containing the character to fill the box with. | * \param str UTF-8 string containing the character to fill the box with. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | int cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | ||||
char const *str) | char const *str) | ||||
{ | { | ||||
int x, y, xmax, ymax; | int x, y, xmax, ymax; | ||||
uint32_t ch; | uint32_t ch; | ||||
@@ -138,7 +148,7 @@ void cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | |||||
ymax = cv->height - 1; | ymax = cv->height - 1; | ||||
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax) | ||||
return; | return 0; | ||||
if(x1 < 0) x1 = 0; | if(x1 < 0) x1 = 0; | ||||
if(y1 < 0) y1 = 0; | if(y1 < 0) y1 = 0; | ||||
@@ -150,5 +160,7 @@ void cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | |||||
for(y = y1; y <= y2; y++) | for(y = y1; y <= y2; y++) | ||||
for(x = x1; x <= x2; x++) | for(x = x1; x <= x2; x++) | ||||
_cucul_putchar32(cv, x, y, ch); | _cucul_putchar32(cv, x, y, ch); | ||||
return 0; | |||||
} | } | ||||
@@ -32,6 +32,8 @@ | |||||
* This function returns the length (in bytes) of the memory area stored | * This function returns the length (in bytes) of the memory area stored | ||||
* in the given \e libcucul buffer. | * in the given \e libcucul buffer. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param buf A \e libcucul buffer | * \param buf A \e libcucul buffer | ||||
* \return The buffer data length. | * \return The buffer data length. | ||||
*/ | */ | ||||
@@ -45,6 +47,8 @@ unsigned long int cucul_get_buffer_size(cucul_buffer_t *buf) | |||||
* This function returns a pointer to the memory area stored in the given | * This function returns a pointer to the memory area stored in the given | ||||
* \e libcucul buffer. | * \e libcucul buffer. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param buf A \e libcucul buffer | * \param buf A \e libcucul buffer | ||||
* \return A pointer to the buffer memory area. | * \return A pointer to the buffer memory area. | ||||
*/ | */ | ||||
@@ -58,11 +62,16 @@ void * cucul_get_buffer_data(cucul_buffer_t *buf) | |||||
* This function frees the structures associated with the given | * This function frees the structures associated with the given | ||||
* \e libcucul buffer. | * \e libcucul buffer. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param buf A \e libcucul buffer | * \param buf A \e libcucul buffer | ||||
* \return This function always returns 0. | |||||
*/ | */ | ||||
void cucul_free_buffer(cucul_buffer_t *buf) | int cucul_free_buffer(cucul_buffer_t *buf) | ||||
{ | { | ||||
free(buf->data); | free(buf->data); | ||||
free(buf); | free(buf); | ||||
return 0; | |||||
} | } | ||||
@@ -24,6 +24,9 @@ | |||||
# include <string.h> | # include <string.h> | ||||
# include <stdlib.h> | # include <stdlib.h> | ||||
# include <stdarg.h> | # include <stdarg.h> | ||||
# if defined(HAVE_ERRNO_H) | |||||
# include <errno.h> | |||||
# endif | |||||
# if defined(HAVE_UNISTD_H) | # if defined(HAVE_UNISTD_H) | ||||
# include <unistd.h> | # include <unistd.h> | ||||
# endif | # endif | ||||
@@ -47,10 +50,13 @@ | |||||
* replaced with a space. To print a sequence of bytes forming an UTF-8 | * replaced with a space. To print a sequence of bytes forming an UTF-8 | ||||
* character, use cucul_putstr() instead. | * character, use cucul_putstr() instead. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param cv A handle to the libcucul canvas. | * \param cv A handle to the libcucul canvas. | ||||
* \param x X coordinate. | * \param x X coordinate. | ||||
* \param y Y coordinate. | * \param y Y coordinate. | ||||
* \param ch The character to print. | * \param ch The character to print. | ||||
* \return This function always returns 0. | |||||
*/ | */ | ||||
void cucul_putchar(cucul_canvas_t *cv, int x, int y, char ch) | void cucul_putchar(cucul_canvas_t *cv, int x, int y, char ch) | ||||
{ | { | ||||
@@ -72,10 +78,13 @@ void cucul_putchar(cucul_canvas_t *cv, int x, int y, char ch) | |||||
* the canvas boundaries (eg. a negative Y coordinate) and the string will | * the canvas boundaries (eg. a negative Y coordinate) and the string will | ||||
* be cropped accordingly if it is too long. | * be cropped accordingly if it is too long. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param cv A handle to the libcucul canvas. | * \param cv A handle to the libcucul canvas. | ||||
* \param x X coordinate. | * \param x X coordinate. | ||||
* \param y Y coordinate. | * \param y Y coordinate. | ||||
* \param s The string to print. | * \param s The string to print. | ||||
* \return This function always returns 0. | |||||
*/ | */ | ||||
void cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s) | void cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s) | ||||
{ | { | ||||
@@ -120,11 +129,14 @@ void cucul_putstr(cucul_canvas_t *cv, int x, int y, char const *s) | |||||
* be cropped accordingly if it is too long. The syntax of the format | * be cropped accordingly if it is too long. The syntax of the format | ||||
* string is the same as for the C printf() function. | * string is the same as for the C printf() function. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param cv A handle to the libcucul canvas. | * \param cv A handle to the libcucul canvas. | ||||
* \param x X coordinate. | * \param x X coordinate. | ||||
* \param y Y coordinate. | * \param y Y coordinate. | ||||
* \param format The format string to print. | * \param format The format string to print. | ||||
* \param ... Arguments to the format string. | * \param ... Arguments to the format string. | ||||
* \return This function always returns 0. | |||||
*/ | */ | ||||
void cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...) | void cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...) | ||||
{ | { | ||||
@@ -157,7 +169,10 @@ void cucul_printf(cucul_canvas_t *cv, int x, int y, char const *format, ...) | |||||
* | * | ||||
* This function clears the canvas using the current background colour. | * This function clears the canvas using the current background colour. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param cv The canvas to clear. | * \param cv The canvas to clear. | ||||
* \return This function always returns 0. | |||||
*/ | */ | ||||
void cucul_clear_canvas(cucul_canvas_t *cv) | void cucul_clear_canvas(cucul_canvas_t *cv) | ||||
{ | { | ||||
@@ -182,14 +197,20 @@ void cucul_clear_canvas(cucul_canvas_t *cv) | |||||
* \param y Y coordinate. | * \param y Y coordinate. | ||||
* \param src The source canvas. | * \param src The source canvas. | ||||
* \param mask The mask canvas. | * \param mask The mask canvas. | ||||
* \return 0 in case of success, -1 otherwise. | |||||
*/ | */ | ||||
void cucul_blit(cucul_canvas_t *dst, int x, int y, | int cucul_blit(cucul_canvas_t *dst, int x, int y, | ||||
cucul_canvas_t const *src, cucul_canvas_t const *mask) | cucul_canvas_t const *src, cucul_canvas_t const *mask) | ||||
{ | { | ||||
int i, j, starti, startj, endi, endj; | int i, j, starti, startj, endi, endj; | ||||
if(mask && (src->width != mask->width || src->height != mask->height)) | if(mask && (src->width != mask->width || src->height != mask->height)) | ||||
return; | { | ||||
#if defined(HAVE_ERRNO_H) | |||||
errno = EINVAL; | |||||
#endif | |||||
return -1; | |||||
} | |||||
starti = x < 0 ? -x : 0; | starti = x < 0 ? -x : 0; | ||||
startj = y < 0 ? -y : 0; | startj = y < 0 ? -y : 0; | ||||
@@ -197,7 +218,7 @@ void cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
endj = (y + src->height >= dst->height) ? dst->height - y : src->height; | endj = (y + src->height >= dst->height) ? dst->height - y : src->height; | ||||
if(starti >= endi || startj >= endj) | if(starti >= endi || startj >= endj) | ||||
return; | return 0; | ||||
for(j = startj; j < endj; j++) | for(j = startj; j < endj; j++) | ||||
{ | { | ||||
@@ -224,6 +245,8 @@ void cucul_blit(cucul_canvas_t *dst, int x, int y, | |||||
(endi - starti) * 4); | (endi - starti) * 4); | ||||
} | } | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
/* | /* | ||||
@@ -29,6 +29,8 @@ | |||||
static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t); | static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t); | ||||
/** \brief Draw a circle on the canvas using the given character. | /** \brief Draw a circle on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x Center X coordinate. | * \param x Center X coordinate. | ||||
@@ -36,9 +38,9 @@ static void ellipsepoints(cucul_canvas_t *, int, int, int, int, uint32_t); | |||||
* \param r Circle radius. | * \param r Circle radius. | ||||
* \param str UTF-8 string representing the character that should be used | * \param str UTF-8 string representing the character that should be used | ||||
* to draw the circle outline. | * to draw the circle outline. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, char const *str) | int cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, char const *str) | ||||
{ | { | ||||
int test, dx, dy; | int test, dx, dy; | ||||
uint32_t ch = _cucul_utf8_to_utf32(str); | uint32_t ch = _cucul_utf8_to_utf32(str); | ||||
@@ -51,9 +53,13 @@ void cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, char const *str) | |||||
test += test > 0 ? dx - dy-- : dx; | test += test > 0 ? dx - dy-- : dx; | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
/** \brief Fill an ellipse on the canvas using the given character. | /** \brief Fill an ellipse on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param xo Center X coordinate. | * \param xo Center X coordinate. | ||||
@@ -62,10 +68,10 @@ void cucul_draw_circle(cucul_canvas_t *cv, int x, int y, int r, char const *str) | |||||
* \param b Ellipse Y radius. | * \param b Ellipse Y radius. | ||||
* \param str UTF-8 string representing the character that should be used | * \param str UTF-8 string representing the character that should be used | ||||
* to fill the ellipse. | * to fill the ellipse. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | int cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | ||||
char const *str) | char const *str) | ||||
{ | { | ||||
int d2; | int d2; | ||||
int x = 0; | int x = 0; | ||||
@@ -108,9 +114,13 @@ void cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | |||||
cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, str); | cucul_draw_line(cv, xo - x, yo - y, xo + x, yo - y, str); | ||||
cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, str); | cucul_draw_line(cv, xo - x, yo + y, xo + x, yo + y, str); | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw an ellipse on the canvas using the given character. | /** \brief Draw an ellipse on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param xo Center X coordinate. | * \param xo Center X coordinate. | ||||
@@ -119,10 +129,10 @@ void cucul_fill_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | |||||
* \param b Ellipse Y radius. | * \param b Ellipse Y radius. | ||||
* \param str UTF-8 string representing the character that should be used | * \param str UTF-8 string representing the character that should be used | ||||
* to draw the ellipse outline. | * to draw the ellipse outline. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | int cucul_draw_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | ||||
char const *str) | char const *str) | ||||
{ | { | ||||
int d2; | int d2; | ||||
int x = 0; | int x = 0; | ||||
@@ -163,18 +173,22 @@ void cucul_draw_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b, | |||||
y--; | y--; | ||||
ellipsepoints(cv, xo, yo, x, y, ch); | ellipsepoints(cv, xo, yo, x, y, ch); | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw a thin ellipse on the canvas. | /** \brief Draw a thin ellipse on the canvas. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param xo Center X coordinate. | * \param xo Center X coordinate. | ||||
* \param yo Center Y coordinate. | * \param yo Center Y coordinate. | ||||
* \param a Ellipse X radius. | * \param a Ellipse X radius. | ||||
* \param b Ellipse Y radius. | * \param b Ellipse Y radius. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_thin_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b) | int cucul_draw_thin_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b) | ||||
{ | { | ||||
/* FIXME: this is not correct */ | /* FIXME: this is not correct */ | ||||
int d2; | int d2; | ||||
@@ -215,6 +229,8 @@ void cucul_draw_thin_ellipse(cucul_canvas_t *cv, int xo, int yo, int a, int b) | |||||
y--; | y--; | ||||
ellipsepoints(cv, xo, yo, x, y, '|'); | ellipsepoints(cv, xo, yo, x, y, '|'); | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y, | static void ellipsepoints(cucul_canvas_t *cv, int xo, int yo, int x, int y, | ||||
@@ -86,7 +86,7 @@ int cucul_rand(int, int); | |||||
* @{ */ | * @{ */ | ||||
unsigned long int cucul_get_buffer_size(cucul_buffer_t *); | unsigned long int cucul_get_buffer_size(cucul_buffer_t *); | ||||
void * cucul_get_buffer_data(cucul_buffer_t *); | void * cucul_get_buffer_data(cucul_buffer_t *); | ||||
void cucul_free_buffer(cucul_buffer_t *); | int cucul_free_buffer(cucul_buffer_t *); | ||||
/* @} */ | /* @} */ | ||||
/** \defgroup canvas libcucul canvas drawing | /** \defgroup canvas libcucul canvas drawing | ||||
@@ -102,7 +102,7 @@ void cucul_putchar(cucul_canvas_t *, int, int, char); | |||||
void cucul_putstr(cucul_canvas_t *, int, int, char const *); | void cucul_putstr(cucul_canvas_t *, int, int, char const *); | ||||
void cucul_printf(cucul_canvas_t *, int, int, char const *, ...); | void cucul_printf(cucul_canvas_t *, int, int, char const *, ...); | ||||
void cucul_clear_canvas(cucul_canvas_t *); | void cucul_clear_canvas(cucul_canvas_t *); | ||||
void cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *, cucul_canvas_t const *); | int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *, cucul_canvas_t const *); | ||||
/* @} */ | /* @} */ | ||||
/** \defgroup transform libcucul canvas transformation | /** \defgroup transform libcucul canvas transformation | ||||
@@ -122,23 +122,23 @@ void cucul_rotate(cucul_canvas_t *); | |||||
* boxes, triangles and ellipses. | * boxes, triangles and ellipses. | ||||
* | * | ||||
* @{ */ | * @{ */ | ||||
void cucul_draw_line(cucul_canvas_t *, int, int, int, int, char const *); | int cucul_draw_line(cucul_canvas_t *, int, int, int, int, char const *); | ||||
void cucul_draw_polyline(cucul_canvas_t *, int const x[], int const y[], int, char const *); | int cucul_draw_polyline(cucul_canvas_t *, int const x[], int const y[], int, char const *); | ||||
void cucul_draw_thin_line(cucul_canvas_t *, int, int, int, int); | int cucul_draw_thin_line(cucul_canvas_t *, int, int, int, int); | ||||
void cucul_draw_thin_polyline(cucul_canvas_t *, int const x[], int const y[], int); | int cucul_draw_thin_polyline(cucul_canvas_t *, int const x[], int const y[], int); | ||||
int cucul_draw_circle(cucul_canvas_t *, int, int, int, char const *); | |||||
void cucul_draw_circle(cucul_canvas_t *, int, int, int, char const *); | int cucul_draw_ellipse(cucul_canvas_t *, int, int, int, int, char const *); | ||||
void cucul_draw_ellipse(cucul_canvas_t *, int, int, int, int, char const *); | int cucul_draw_thin_ellipse(cucul_canvas_t *, int, int, int, int); | ||||
void cucul_draw_thin_ellipse(cucul_canvas_t *, int, int, int, int); | int cucul_fill_ellipse(cucul_canvas_t *, int, int, int, int, char const *); | ||||
void cucul_fill_ellipse(cucul_canvas_t *, int, int, int, int, char const *); | int cucul_draw_box(cucul_canvas_t *, int, int, int, int, char const *); | ||||
int cucul_draw_thin_box(cucul_canvas_t *, int, int, int, int); | |||||
void cucul_draw_box(cucul_canvas_t *, int, int, int, int, char const *); | int cucul_fill_box(cucul_canvas_t *, int, int, int, int, char const *); | ||||
void cucul_draw_thin_box(cucul_canvas_t *, int, int, int, int); | int cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *); | ||||
void cucul_fill_box(cucul_canvas_t *, int, int, int, int, char const *); | int cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int, int, int); | ||||
int cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *); | |||||
void cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *); | |||||
void cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int, int, int); | |||||
void cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *); | |||||
/* @} */ | /* @} */ | ||||
/** \defgroup frame libcucul canvas frame handling | /** \defgroup frame libcucul canvas frame handling | ||||
@@ -42,6 +42,8 @@ static void draw_solid_line(cucul_canvas_t*, struct line*); | |||||
static void draw_thin_line(cucul_canvas_t*, struct line*); | static void draw_thin_line(cucul_canvas_t*, struct line*); | ||||
/** \brief Draw a line on the canvas using the given character. | /** \brief Draw a line on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the first point. | * \param x1 X coordinate of the first point. | ||||
@@ -49,10 +51,10 @@ static void draw_thin_line(cucul_canvas_t*, struct line*); | |||||
* \param x2 X coordinate of the second point. | * \param x2 X coordinate of the second point. | ||||
* \param y2 Y coordinate of the second point. | * \param y2 Y coordinate of the second point. | ||||
* \param str UTF-8 string containing the character to use to draw the line. | * \param str UTF-8 string containing the character to use to draw the line. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | int cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | ||||
char const *str) | char const *str) | ||||
{ | { | ||||
struct line s; | struct line s; | ||||
s.x1 = x1; | s.x1 = x1; | ||||
@@ -62,6 +64,8 @@ void cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | |||||
s.ch = _cucul_utf8_to_utf32(str); | s.ch = _cucul_utf8_to_utf32(str); | ||||
s.draw = draw_solid_line; | s.draw = draw_solid_line; | ||||
clip_line(cv, &s); | clip_line(cv, &s); | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw a polyline. | /** \brief Draw a polyline. | ||||
@@ -71,15 +75,17 @@ void cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | |||||
* draw a polygon you need to specify the starting point at the end of the | * draw a polygon you need to specify the starting point at the end of the | ||||
* list as well. | * list as well. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x Array of X coordinates. Must have \p n + 1 elements. | * \param x Array of X coordinates. Must have \p n + 1 elements. | ||||
* \param y Array of Y coordinates. Must have \p n + 1 elements. | * \param y Array of Y coordinates. Must have \p n + 1 elements. | ||||
* \param n Number of lines to draw. | * \param n Number of lines to draw. | ||||
* \param str UTF-8 string containing the character to use to draw the lines. | * \param str UTF-8 string containing the character to use to draw the lines. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[], | int cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[], | ||||
int n, char const *str) | int n, char const *str) | ||||
{ | { | ||||
int i; | int i; | ||||
struct line s; | struct line s; | ||||
@@ -94,18 +100,22 @@ void cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[], | |||||
s.y2 = y[i+1]; | s.y2 = y[i+1]; | ||||
clip_line(cv, &s); | clip_line(cv, &s); | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw a thin line on the canvas, using ASCII art. | /** \brief Draw a thin line on the canvas, using ASCII art. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the first point. | * \param x1 X coordinate of the first point. | ||||
* \param y1 Y coordinate of the first point. | * \param y1 Y coordinate of the first point. | ||||
* \param x2 X coordinate of the second point. | * \param x2 X coordinate of the second point. | ||||
* \param y2 Y coordinate of the second point. | * \param y2 Y coordinate of the second point. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | int cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | ||||
{ | { | ||||
struct line s; | struct line s; | ||||
s.x1 = x1; | s.x1 = x1; | ||||
@@ -114,6 +124,8 @@ void cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | |||||
s.y2 = y2; | s.y2 = y2; | ||||
s.draw = draw_thin_line; | s.draw = draw_thin_line; | ||||
clip_line(cv, &s); | clip_line(cv, &s); | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw an ASCII art thin polyline. | /** \brief Draw an ASCII art thin polyline. | ||||
@@ -123,14 +135,16 @@ void cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2) | |||||
* to draw a polygon you need to specify the starting point at the end of | * to draw a polygon you need to specify the starting point at the end of | ||||
* the list as well. | * the list as well. | ||||
* | * | ||||
* This function never fails. | |||||
* | |||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x Array of X coordinates. Must have \p n + 1 elements. | * \param x Array of X coordinates. Must have \p n + 1 elements. | ||||
* \param y Array of Y coordinates. Must have \p n + 1 elements. | * \param y Array of Y coordinates. Must have \p n + 1 elements. | ||||
* \param n Number of lines to draw. | * \param n Number of lines to draw. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[], | int cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[], | ||||
int n) | int n) | ||||
{ | { | ||||
int i; | int i; | ||||
struct line s; | struct line s; | ||||
@@ -144,6 +158,8 @@ void cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[], | |||||
s.y2 = y[i+1]; | s.y2 = y[i+1]; | ||||
clip_line(cv, &s); | clip_line(cv, &s); | ||||
} | } | ||||
return 0; | |||||
} | } | ||||
/* | /* | ||||
@@ -26,6 +26,8 @@ | |||||
#include "cucul_internals.h" | #include "cucul_internals.h" | ||||
/** \brief Draw a triangle on the canvas using the given character. | /** \brief Draw a triangle on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the first point. | * \param x1 X coordinate of the first point. | ||||
@@ -36,17 +38,21 @@ | |||||
* \param y3 Y coordinate of the third point. | * \param y3 Y coordinate of the third point. | ||||
* \param str UTF-8 string representing the character that should be used | * \param str UTF-8 string representing the character that should be used | ||||
* to draw the triangle outline. | * to draw the triangle outline. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | int cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | ||||
int x3, int y3, char const *str) | int x3, int y3, char const *str) | ||||
{ | { | ||||
cucul_draw_line(cv, x1, y1, x2, y2, str); | cucul_draw_line(cv, x1, y1, x2, y2, str); | ||||
cucul_draw_line(cv, x2, y2, x3, y3, str); | cucul_draw_line(cv, x2, y2, x3, y3, str); | ||||
cucul_draw_line(cv, x3, y3, x1, y1, str); | cucul_draw_line(cv, x3, y3, x1, y1, str); | ||||
return 0; | |||||
} | } | ||||
/** \brief Draw a thin triangle on the canvas. | /** \brief Draw a thin triangle on the canvas. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the first point. | * \param x1 X coordinate of the first point. | ||||
@@ -55,17 +61,21 @@ void cucul_draw_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | |||||
* \param y2 Y coordinate of the second point. | * \param y2 Y coordinate of the second point. | ||||
* \param x3 X coordinate of the third point. | * \param x3 X coordinate of the third point. | ||||
* \param y3 Y coordinate of the third point. | * \param y3 Y coordinate of the third point. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1, | int cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1, | ||||
int x2, int y2, int x3, int y3) | int x2, int y2, int x3, int y3) | ||||
{ | { | ||||
cucul_draw_thin_line(cv, x1, y1, x2, y2); | cucul_draw_thin_line(cv, x1, y1, x2, y2); | ||||
cucul_draw_thin_line(cv, x2, y2, x3, y3); | cucul_draw_thin_line(cv, x2, y2, x3, y3); | ||||
cucul_draw_thin_line(cv, x3, y3, x1, y1); | cucul_draw_thin_line(cv, x3, y3, x1, y1); | ||||
return 0; | |||||
} | } | ||||
/** \brief Fill a triangle on the canvas using the given character. | /** \brief Fill a triangle on the canvas using the given character. | ||||
* | |||||
* This function never fails. | |||||
* | * | ||||
* \param cv The handle to the libcucul canvas. | * \param cv The handle to the libcucul canvas. | ||||
* \param x1 X coordinate of the first point. | * \param x1 X coordinate of the first point. | ||||
@@ -76,26 +86,20 @@ void cucul_draw_thin_triangle(cucul_canvas_t *cv, int x1, int y1, | |||||
* \param y3 Y coordinate of the third point. | * \param y3 Y coordinate of the third point. | ||||
* \param str UTF-8 string representing the character that should be used | * \param str UTF-8 string representing the character that should be used | ||||
* to fill the triangle. | * to fill the triangle. | ||||
* \return void | * \return This function always returns 0. | ||||
*/ | */ | ||||
void cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | int cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | ||||
int x3, int y3, char const *str) | int x3, int y3, char const *str) | ||||
{ | { | ||||
int x, y, xa, xb, xmax, ymax; | int x, y, xa, xb, xmax, ymax; | ||||
uint32_t ch; | uint32_t ch; | ||||
/* Bubble-sort y1 <= y2 <= y3 */ | /* Bubble-sort y1 <= y2 <= y3 */ | ||||
if(y1 > y2) | if(y1 > y2) | ||||
{ | return cucul_fill_triangle(cv, x2, y2, x1, y1, x3, y3, str); | ||||
cucul_fill_triangle(cv, x2, y2, x1, y1, x3, y3, str); | |||||
return; | |||||
} | |||||
if(y2 > y3) | if(y2 > y3) | ||||
{ | return cucul_fill_triangle(cv, x1, y1, x3, y3, x2, y2, str); | ||||
cucul_fill_triangle(cv, x1, y1, x3, y3, x2, y2, str); | |||||
return; | |||||
} | |||||
/* Promote precision */ | /* Promote precision */ | ||||
x1 *= 4; | x1 *= 4; | ||||
@@ -139,5 +143,7 @@ void cucul_fill_triangle(cucul_canvas_t *cv, int x1, int y1, int x2, int y2, | |||||
for(x = xa; x <= xb; x++) | for(x = xa; x <= xb; x++) | ||||
_cucul_putchar32(cv, x, y, ch); | _cucul_putchar32(cv, x, y, ch); | ||||
} | } | ||||
return 0; | |||||
} | } | ||||