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

int caca_init ( void   ) 

Initialise libcaca.

This function initialises internal libcaca structures and the backend that will be used for subsequent graphical operations. It must be the first libcaca function to be called in a function. caca_end() should be called at the end of the program to free all allocated resources.

Returns:
0 upon success, a non-zero value if an error occurs.

Definition at line 90 of file caca.c.

{
#if defined(USE_NCURSES)
    mmask_t newmask;
#endif

    caca_init_driver();

    if(_caca_driver == CACA_DRIVER_NONE)
        return -1;

    caca_init_features();
    caca_init_terminal();

#if defined(USE_SLANG)
    if(_caca_driver == CACA_DRIVER_SLANG)
    {
        /* Initialise slang library */
        SLsig_block_signals();
        SLtt_get_terminfo();

        if(SLkp_init() == -1)
        {
            SLsig_unblock_signals();
            return -1;
        }

        SLang_init_tty(-1, 0, 1);

        if(SLsmg_init_smg() == -1)
        {
            SLsig_unblock_signals();
            return -1;
        }

        SLsig_unblock_signals();

        SLsmg_cls();
        SLtt_set_cursor_visibility(0);
        SLkp_define_keysym("\e[M", 1001);
        SLtt_set_mouse_mode(1, 0);
        SLsmg_refresh();

        /* Disable scrolling so that hashmap scrolling optimization code
         * does not cause ugly refreshes due to slow terminals */
        SLtt_Term_Cannot_Scroll = 1;
    }
    else
#endif
#if defined(USE_NCURSES)
    if(_caca_driver == CACA_DRIVER_NCURSES)
    {
        initscr();
        keypad(stdscr, TRUE);
        nonl();
        raw();
        noecho();
        nodelay(stdscr, TRUE);
        curs_set(0);

        /* Activate mouse */
        newmask = REPORT_MOUSE_POSITION | ALL_MOUSE_EVENTS;
        mousemask(newmask, &oldmask);
        mouseinterval(-1); /* No click emulation */

        /* Set the escape delay to a ridiculously low value */
        ESCDELAY = 10;
    }
    else
#endif
#if defined(USE_CONIO)
    if(_caca_driver == CACA_DRIVER_CONIO)
    {
        _wscroll = 0;
        _setcursortype(_NOCURSOR);
        clrscr();
    }
    else
#endif
#if defined(USE_X11)
    if(_caca_driver == CACA_DRIVER_X11)
    {
        /* Nothing to do */
    }
    else
#endif
#if defined(USE_WIN32)
    if(_caca_driver == CACA_DRIVER_WIN32)
    {
        /* This call is allowed to fail in cas we already have a console */
        AllocConsole();

        win32_hin = GetStdHandle(STD_INPUT_HANDLE);
        win32_hout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
                                FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
                                OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

        if(win32_hout == INVALID_HANDLE_VALUE)
            return -1;

        GetConsoleCursorInfo(win32_hout, &cci);
        cci.bVisible = FALSE;
        SetConsoleCursorInfo(win32_hout, &cci);

        SetConsoleMode(win32_hout, ENABLE_MOUSE_INPUT);
    }
    else
#endif
    {
        /* Dummy */
    }

    if(_caca_init_graphics())
        return -1;

    if(_caca_init_bitmap())
        return -1;

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index