Ignore:
Timestamp:
Apr 18, 2006, 5:11:25 PM (14 years ago)
Author:
Sam Hocevar
Message:
  • Renamed caca_t into caca_display_t.
  • Renamed canvas handle variables from "c" to "cv". Eh ouais mon gros.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/line.c

    r810 r811  
    4343/** \brief Draw a line on the canvas using the given character.
    4444 *
    45  *  \param c The handle to the libcucul canvas.
     45 *  \param cv The handle to the libcucul canvas.
    4646 *  \param x1 X coordinate of the first point.
    4747 *  \param y1 Y coordinate of the first point.
     
    5151 *  \return void
    5252 */
    53 void cucul_draw_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2,
     53void cucul_draw_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
    5454                     char const *str)
    5555{
     
    6161    s.ch = _cucul_utf8_to_utf32(str);
    6262    s.draw = draw_solid_line;
    63     clip_line(c, &s);
     63    clip_line(cv, &s);
    6464}
    6565
     
    7171 *  list as well.
    7272 *
    73  *  \param c The handle to the libcucul canvas.
     73 *  \param cv The handle to the libcucul canvas.
    7474 *  \param x Array of X coordinates. Must have \p n + 1 elements.
    7575 *  \param y Array of Y coordinates. Must have \p n + 1 elements.
     
    7878 *  \return void
    7979 */
    80 void cucul_draw_polyline(cucul_canvas_t *c, int const x[], int const y[], int n,
    81                          char const *str)
     80void cucul_draw_polyline(cucul_canvas_t *cv, int const x[], int const y[],
     81                         int n, char const *str)
    8282{
    8383    int i;
     
    9292        s.x2 = x[i+1];
    9393        s.y2 = y[i+1];
    94         clip_line(c, &s);
     94        clip_line(cv, &s);
    9595    }
    9696}
     
    9898/** \brief Draw a thin line on the canvas, using ASCII art.
    9999 *
    100  *  \param c The handle to the libcucul canvas.
     100 *  \param cv The handle to the libcucul canvas.
    101101 *  \param x1 X coordinate of the first point.
    102102 *  \param y1 Y coordinate of the first point.
     
    105105 *  \return void
    106106 */
    107 void cucul_draw_thin_line(cucul_canvas_t *c, int x1, int y1, int x2, int y2)
     107void cucul_draw_thin_line(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
    108108{
    109109    struct line s;
     
    113113    s.y2 = y2;
    114114    s.draw = draw_thin_line;
    115     clip_line(c, &s);
     115    clip_line(cv, &s);
    116116}
    117117
     
    123123 *  the list as well.
    124124 *
    125  *  \param c The handle to the libcucul canvas.
     125 *  \param cv The handle to the libcucul canvas.
    126126 *  \param x Array of X coordinates. Must have \p n + 1 elements.
    127127 *  \param y Array of Y coordinates. Must have \p n + 1 elements.
     
    129129 *  \return void
    130130 */
    131 void cucul_draw_thin_polyline(cucul_canvas_t *c, int const x[], int const y[], int n)
     131void cucul_draw_thin_polyline(cucul_canvas_t *cv, int const x[], int const y[],
     132                              int n)
    132133{
    133134    int i;
     
    141142        s.x2 = x[i+1];
    142143        s.y2 = y[i+1];
    143         clip_line(c, &s);
     144        clip_line(cv, &s);
    144145    }
    145146}
     
    150151
    151152/* Generic Cohen-Sutherland line clipping function. */
    152 static void clip_line(cucul_canvas_t *c, struct line* s)
     153static void clip_line(cucul_canvas_t *cv, struct line* s)
    153154{
    154155    uint8_t bits1, bits2;
    155156
    156     bits1 = clip_bits(c, s->x1, s->y1);
    157     bits2 = clip_bits(c, s->x2, s->y2);
     157    bits1 = clip_bits(cv, s->x1, s->y1);
     158    bits2 = clip_bits(cv, s->x2, s->y2);
    158159
    159160    if(bits1 & bits2)
     
    163164    {
    164165        if(bits2 == 0)
    165             s->draw(c, s);
     166            s->draw(cv, s);
    166167        else
    167168        {
     
    169170            tmp = s->x1; s->x1 = s->x2; s->x2 = tmp;
    170171            tmp = s->y1; s->y1 = s->y2; s->y2 = tmp;
    171             clip_line(c, s);
     172            clip_line(cv, s);
    172173        }
    173174
     
    182183    else if(bits1 & (1<<1))
    183184    {
    184         int xmax = c->width - 1;
     185        int xmax = cv->width - 1;
    185186        s->y1 = s->y2 - (s->x2 - xmax) * (s->y2 - s->y1) / (s->x2 - s->x1);
    186187        s->x1 = xmax;
     
    193194    else if(bits1 & (1<<3))
    194195    {
    195         int ymax = c->height - 1;
     196        int ymax = cv->height - 1;
    196197        s->x1 = s->x2 - (s->y2 - ymax) * (s->x2 - s->x1) / (s->y2 - s->y1);
    197198        s->y1 = ymax;
    198199    }
    199200
    200     clip_line(c, s);
     201    clip_line(cv, s);
    201202}
    202203
    203204/* Helper function for clip_line(). */
    204 static uint8_t clip_bits(cucul_canvas_t *c, int x, int y)
     205static uint8_t clip_bits(cucul_canvas_t *cv, int x, int y)
    205206{
    206207    uint8_t b = 0;
     
    208209    if(x < 0)
    209210        b |= (1<<0);
    210     else if(x >= (int)c->width)
     211    else if(x >= (int)cv->width)
    211212        b |= (1<<1);
    212213
    213214    if(y < 0)
    214215        b |= (1<<2);
    215     else if(y >= (int)c->height)
     216    else if(y >= (int)cv->height)
    216217        b |= (1<<3);
    217218
     
    221222/* Solid line drawing function, using Bresenham's mid-point line
    222223 * scan-conversion algorithm. */
    223 static void draw_solid_line(cucul_canvas_t *c, struct line* s)
     224static void draw_solid_line(cucul_canvas_t *cv, struct line* s)
    224225{
    225226    int x1, y1, x2, y2;
     
    243244        for(; dx>=0; dx--)
    244245        {
    245             _cucul_putchar32(c, x1, y1, s->ch);
     246            _cucul_putchar32(cv, x1, y1, s->ch);
    246247            if(delta > 0)
    247248            {
     
    265266        for(; dy >= 0; dy--)
    266267        {
    267             _cucul_putchar32(c, x1, y1, s->ch);
     268            _cucul_putchar32(cv, x1, y1, s->ch);
    268269            if(delta > 0)
    269270            {
     
    283284/* Thin line drawing function, using Bresenham's mid-point line
    284285 * scan-conversion algorithm and ASCII art graphics. */
    285 static void draw_thin_line(cucul_canvas_t *c, struct line* s)
     286static void draw_thin_line(cucul_canvas_t *cv, struct line* s)
    286287{
    287288    uint32_t charmapx[2], charmapy[2];
     
    330331            if(delta > 0)
    331332            {
    332                 _cucul_putchar32(c, x1, y1, charmapy[1]);
     333                _cucul_putchar32(cv, x1, y1, charmapy[1]);
    333334                x1++;
    334335                y1 += yinc;
     
    339340            {
    340341                if(prev)
    341                     _cucul_putchar32(c, x1, y1, charmapy[0]);
     342                    _cucul_putchar32(cv, x1, y1, charmapy[0]);
    342343                else
    343                     _cucul_putchar32(c, x1, y1, (uint32_t)'-');
     344                    _cucul_putchar32(cv, x1, y1, (uint32_t)'-');
    344345                x1++;
    345346                delta += dpr;
     
    358359            if(delta > 0)
    359360            {
    360                 _cucul_putchar32(c, x1, y1, charmapx[0]);
    361                 _cucul_putchar32(c, x1 + 1, y1, charmapx[1]);
     361                _cucul_putchar32(cv, x1, y1, charmapx[0]);
     362                _cucul_putchar32(cv, x1 + 1, y1, charmapx[1]);
    362363                x1++;
    363364                y1 += yinc;
     
    366367            else
    367368            {
    368                 _cucul_putchar32(c, x1, y1, (uint32_t)'|');
     369                _cucul_putchar32(cv, x1, y1, (uint32_t)'|');
    369370                y1 += yinc;
    370371                delta += dpr;
Note: See TracChangeset for help on using the changeset viewer.