Browse Source

* Implemented cucul_draw_cp437_box().

tags/v0.99.beta14
Sam Hocevar sam 18 years ago
parent
commit
1b491f11a9
2 changed files with 61 additions and 8 deletions
  1. +60
    -8
      cucul/box.c
  2. +1
    -0
      cucul/cucul.h

+ 60
- 8
cucul/box.c View File

@@ -99,17 +99,69 @@ int cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
cucul_putchar(cv, x2, y, '|');

/* Draw corners */
if(x1 >= 0 && y1 >= 0)
cucul_putchar(cv, x1, y1, ',');
cucul_putchar(cv, x1, y1, ',');
cucul_putchar(cv, x1, y2, '`');
cucul_putchar(cv, x2, y1, '.');
cucul_putchar(cv, x2, y2, '\'');

if(x1 >= 0 && y2 <= ymax)
cucul_putchar(cv, x1, y2, '`');
return 0;
}

/** \brief Draw a box on the canvas using CP437 characters.
*
* This function never fails.
*
* \param cv The handle to the libcucul canvas.
* \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 x2 X coordinate of the lower-right corner of the box.
* \param y2 Y coordinate of the lower-right corner of the box.
* \return This function always returns 0.
*/
int cucul_draw_cp437_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
{
int x, y, xmax, ymax;

if(x1 > x2)
{
int tmp = x1;
x1 = x2; x2 = tmp;
}

if(y1 > y2)
{
int tmp = y1;
y1 = y2; y2 = tmp;
}

xmax = cv->width - 1;
ymax = cv->height - 1;

if(x2 <= xmax && y1 >= 0)
cucul_putchar(cv, x2, y1, '.');
if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
return 0;

if(x2 <= xmax && y2 <= ymax)
cucul_putchar(cv, x2, y2, '\'');
/* Draw edges */
if(y1 >= 0)
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
cucul_putchar(cv, x, y1, 0x2500); /* ─ */

if(y2 <= ymax)
for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
cucul_putchar(cv, x, y2, 0x2500); /* ─ */

if(x1 >= 0)
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
cucul_putchar(cv, x1, y, 0x2502); /* │ */

if(x2 <= xmax)
for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
cucul_putchar(cv, x2, y, 0x2502); /* │ */

/* Draw corners */
cucul_putchar(cv, x1, y1, 0x250c); /* ┌ */
cucul_putchar(cv, x1, y2, 0x2514); /* └ */
cucul_putchar(cv, x2, y1, 0x2510); /* ┐ */
cucul_putchar(cv, x2, y2, 0x2518); /* ┘ */

return 0;
}


+ 1
- 0
cucul/cucul.h View File

@@ -146,6 +146,7 @@ int 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);
int cucul_draw_cp437_box(cucul_canvas_t *, int, int, int, int);
int cucul_fill_box(cucul_canvas_t *, int, int, int, int, char const *);

int cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int, int, char const *);


Loading…
Cancel
Save