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

void caca_refresh ( void   ) 

Flush pending changes and redraw the screen.

This function flushes all graphical operations and prints them to the screen. Nothing will show on the screen until caca_refresh() is called.

If caca_set_delay() was called with a non-zero value, caca_refresh() will use that value to achieve constant framerate: if two consecutive calls to caca_refresh() are within a time range shorter than the value set with caca_set_delay(), the second call will wait a bit before performing the screen refresh.

Definition at line 1120 of file graphics.c.

{
#if !defined(_DOXYGEN_SKIP_ME)
#define IDLE_USEC 10000
#endif
    static struct caca_timer timer = CACA_TIMER_INITIALIZER;
    static int lastticks = 0;
    int ticks = lastticks + _caca_getticks(&timer);

#if defined(USE_SLANG)
    if(_caca_driver == CACA_DRIVER_SLANG)
    {
        SLsmg_refresh();
    }
    else
#endif
#if defined(USE_NCURSES)
    if(_caca_driver == CACA_DRIVER_NCURSES)
    {
        refresh();
    }
    else
#endif
#if defined(USE_CONIO)
    if(_caca_driver == CACA_DRIVER_CONIO)
    {
#   if defined(SCREENUPDATE_IN_PC_H)
        ScreenUpdate(conio_screen);
#   else
        /* FIXME */
#   endif
    }
    else
#endif
#if defined(USE_X11)
    if(_caca_driver == CACA_DRIVER_X11)
    {
        unsigned int x, y, len;

        /* First draw the background colours. Splitting the process in two
         * loops like this is actually slightly faster. */
        for(y = 0; y < _caca_height; y++)
        {
            for(x = 0; x < _caca_width; x += len)
            {
                unsigned char *attr = x11_attr + x + y * _caca_width;

                len = 1;
                while(x + len < _caca_width
                       && (attr[len] >> 4) == (attr[0] >> 4))
                    len++;

                XSetForeground(x11_dpy, x11_gc, x11_colors[attr[0] >> 4]);
                XFillRectangle(x11_dpy, x11_pixmap, x11_gc,
                               x * x11_font_width, y * x11_font_height,
                               len * x11_font_width, x11_font_height);
            }
        }

        /* Then print the foreground characters */
        for(y = 0; y < _caca_height; y++)
        {
            for(x = 0; x < _caca_width; x += len)
            {
                unsigned char *attr = x11_attr + x + y * _caca_width;

                len = 1;

                /* Skip spaces */
                if(x11_char[x + y * _caca_width] == ' ')
                    continue;

                while(x + len < _caca_width
                       && (attr[len] & 0xf) == (attr[0] & 0xf))
                    len++;

                XSetForeground(x11_dpy, x11_gc, x11_colors[attr[0] & 0xf]);
                XDrawString(x11_dpy, x11_pixmap, x11_gc, x * x11_font_width,
                            (y + 1) * x11_font_height - x11_font_offset,
                            x11_char + x + y * _caca_width, len);
            }
        }

        XCopyArea(x11_dpy, x11_pixmap, x11_window, x11_gc, 0, 0,
                  _caca_width * x11_font_width, _caca_height * x11_font_height,
                  0, 0);
        XFlush(x11_dpy);
    }
    else
#endif
#if defined(USE_WIN32)
    if(_caca_driver == CACA_DRIVER_WIN32)
    {
        COORD size, pos;
        SMALL_RECT rect;
        DWORD dummy;
        unsigned int x, y, len;

        /* Render everything to our back buffer */
        for(y = 0; y < _caca_height; y++)
        {
            pos.X = 0;
            pos.Y = y;
            SetConsoleCursorPosition(win32_back, pos);

            for(x = 0; x < _caca_width; x += len)
            {
                unsigned char *attr = win32_attr + x + y * _caca_width;

                len = 1;
                while(x + len < _caca_width && attr[len] == attr[0])
                    len++;

                SetConsoleTextAttribute(win32_back,
                                        win32_fg_palette[attr[0] & 0xf]
                                         | win32_bg_palette[attr[0] >> 4]);

                WriteConsole(win32_back, win32_char + x + y * _caca_width,
                             len, &dummy, NULL);
            }
        }

        /* Blit the back buffer to the front buffer */
        size.X = _caca_width;
        size.Y = _caca_height;
        pos.X = pos.Y = 0;
        rect.Left = rect.Top = 0;
        rect.Right = _caca_width - 1;
        rect.Bottom = _caca_height - 1;
        ReadConsoleOutput(win32_back, win32_buffer, size, pos, &rect);
        WriteConsoleOutput(win32_front, win32_buffer, size, pos, &rect);
    }
    else
#endif
    {
        /* Dummy */
    }

    if(_caca_resize)
    {
        _caca_resize = 0;
        caca_handle_resize();
    }

    /* Wait until _caca_delay + time of last call */
    ticks += _caca_getticks(&timer);
    for(ticks += _caca_getticks(&timer);
        ticks + IDLE_USEC < (int)_caca_delay;
        ticks += _caca_getticks(&timer))
    {
        _caca_sleep(IDLE_USEC);
    }

    /* Update the sliding mean of the render time */
    _caca_rendertime = (7 * _caca_rendertime + ticks) / 8;

    lastticks = ticks - _caca_delay;

    /* If we drifted too much, it's bad, bad, bad. */
    if(lastticks > (int)_caca_delay)
        lastticks = 0;
}


Generated by  Doxygen 1.6.0   Back to index