Logo Search packages:      
Sourcecode: libcaca version File versions  Download package

void caca_putstr ( int  x,
int  y,
char const *  s 
)

Print a string.

This function prints a string at the given coordinates, using the default foreground and background values. The coordinates may be outside the screen boundaries (eg. a negative Y coordinate) and the string will be cropped accordingly if it is too long.

Parameters:
x X coordinate.
y Y coordinate.
s The string to print.

Definition at line 433 of file graphics.c.

Referenced by caca_clear(), and caca_printf().

{
#if defined(USE_CONIO) | defined(USE_X11) | defined(USE_WIN32)
    char *charbuf;
#endif
#if defined(USE_X11) | defined(USE_WIN32)
    char *attrbuf;
#endif
    unsigned int len;

    if(y < 0 || y >= (int)_caca_height || x >= (int)_caca_width)
        return;

    len = strlen(s);

    if(x < 0)
    {
        if(len < (unsigned int)-x)
            return;
        len -= -x;
        s += -x;
        x = 0;
    }

    if(x + len >= _caca_width)
    {
        len = _caca_width - x;
        memcpy(_caca_scratch_line, s, len);
        _caca_scratch_line[len] = '\0';
        s = _caca_scratch_line;
    }

    switch(_caca_driver)
    {
#if defined(USE_SLANG)
    case CACA_DRIVER_SLANG:
        SLsmg_gotorc(y, x);
#if defined(OPTIMISE_SLANG_PALETTE)
        if(_caca_fgisbg)
            SLsmg_write_string(_caca_empty_line + _caca_width - len);
        else
#endif
            SLsmg_write_string((char *)(intptr_t)s);
        break;
#endif
#if defined(USE_NCURSES)
    case CACA_DRIVER_NCURSES:
        move(y, x);
        addstr(s);
        break;
#endif
#if defined(USE_CONIO)
    case CACA_DRIVER_CONIO:
        charbuf = conio_screen + 2 * (x + y * _caca_width);
        while(*s)
        {
            *charbuf++ = *s++;
            *charbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;
        }
        break;
#endif
#if defined(USE_X11)
    case CACA_DRIVER_X11:
        charbuf = x11_char + x + y * _caca_width;
        attrbuf = x11_attr + x + y * _caca_width;
        while(*s)
        {
            *charbuf++ = *s++;
            *attrbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;
        }
        break;
#endif
#if defined(USE_WIN32)
    case CACA_DRIVER_WIN32:
        charbuf = win32_char + x + y * _caca_width;
        attrbuf = win32_attr + x + y * _caca_width;
        while(*s)
        {
            *charbuf++ = *s++;
            *attrbuf++ = (_caca_bgcolor << 4) | _caca_fgcolor;
        }
        break;
#endif
    default:
        break;
    }
}


Generated by  Doxygen 1.6.0   Back to index