Beispiel #1
0
int assume_default_colors(int f, int b)
{
    PDC_LOG(("assume_default_colors() - called: f %d b %d\n", f, b));

    if (f < -1 || f >= COLORS || b < -1 || b >= COLORS)
        return ERR;

    if (pdc_color_started)
    {
        short fg, bg, oldfg, oldbg;

        fg = f;
        bg = b;

        _normalize(&fg, &bg);

        PDC_pair_content(0, &oldfg, &oldbg);

        if (oldfg != fg || oldbg != bg)
            curscr->_clear = TRUE;

        PDC_init_pair(0, fg, bg);
    }

    return OK;
}
Beispiel #2
0
int init_pair(short pair, short fg, short bg)
{
    PDC_LOG(("init_pair() - called: pair %d fg %d bg %d\n", pair, fg, bg));

    if (!pdc_color_started || pair < 1 || pair >= COLOR_PAIRS ||
        fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS)
        return ERR;

    _normalize(&fg, &bg);

    /* To allow the PDC_PRESERVE_SCREEN option to work, we only reset 
       curscr if this call to init_pair() alters a color pair created by 
       the user. */

    if (pair_set[pair])
    {
        short oldfg, oldbg;

        PDC_pair_content(pair, &oldfg, &oldbg);

        if (oldfg != fg || oldbg != bg)
            curscr->_clear = TRUE;
    }

    PDC_init_pair(pair, fg, bg);

    pair_set[pair] = TRUE;

    return OK;
}
Beispiel #3
0
//------------------------------------------------------------------------------
__QOR_INTERFACE( QURSES_QOR ) int assume_default_colors( int f, int b )
{
    __QCS_FCONTEXT( "assume_default_colors" );

    if( f < -1 || f >= COLORS || b < -1 || b >= COLORS )
	{
        return ERR;
	}

    if( pdc_color_started )
    {
        short fg, bg, oldfg, oldbg;

        fg = (short)f;
        bg = (short)b;

        _normalize( &fg, &bg );

        PDC_pair_content( 0, &oldfg, &oldbg );

        if( oldfg != fg || oldbg != bg )
		{
            curscr->_clear = TRUE;
		}

        PDC_init_pair( 0, fg, bg );
    }

    return 0;
}
Beispiel #4
0
//------------------------------------------------------------------------------
__QOR_INTERFACE( QURSES_QOR ) int init_pair( short pair, short fg, short bg )
{
    __QCS_FCONTEXT( "init_pair" );

    if( !pdc_color_started || pair < 1 || pair >= COLOR_PAIRS || fg < first_col || fg >= COLORS || bg < first_col || bg >= COLORS )
	{
        return ERR;
	}

    _normalize( &fg, &bg );

    // To allow the PDC_PRESERVE_SCREEN option to work, we only reset curscr if this call to init_pair() alters a color pair created by the user.

    if( pair_set[ pair ] )
    {
        short oldfg, oldbg;

        PDC_pair_content( pair, &oldfg, &oldbg );

        if( oldfg != fg || oldbg != bg )
		{
            curscr->_clear = TRUE;
		}
    }

    PDC_init_pair( pair, fg, bg );

    pair_set[ pair ] = TRUE;

    return 0;
}
Beispiel #5
0
int pair_content(short pair, short *fg, short *bg)
{
    PDC_LOG(("pair_content() - called\n"));

    if (pair < 0 || pair >= COLOR_PAIRS || !fg || !bg)
        return ERR;

    return PDC_pair_content(pair, fg, bg);
}
Beispiel #6
0
//------------------------------------------------------------------------------
__QOR_INTERFACE( QURSES_QOR ) int pair_content( short pair, short* fg, short* bg )
{ 
    __QCS_FCONTEXT( "pair_content" );

    if( pair < 0 || pair >= COLOR_PAIRS || !fg || !bg )
	{
        return ERR;
	}

    return PDC_pair_content( pair, fg, bg );
}
Beispiel #7
0
static void _set_attr(chtype ch)
{
    ch &= (A_COLOR|A_BOLD|A_BLINK|A_REVERSE);

    if (oldch != ch)
    {
        short newfg, newbg;

        if (SP->mono)
            return;

        PDC_pair_content(PAIR_NUMBER(ch), &newfg, &newbg);

        newfg |= (ch & A_BOLD) ? 8 : 0;
        newbg |= (ch & A_BLINK) ? 8 : 0;

        if (ch & A_REVERSE)
        {
            short tmp = newfg;
            newfg = newbg;
            newbg = tmp;
        }

        if (newfg != foregr)
        {
            SDL_SetPalette(pdc_font, SDL_LOGPAL,
                           pdc_color + newfg, pdc_flastc, 1);
            foregr = newfg;
        }

        if (newbg != backgr)
        {
            if (newbg == -1)
                SDL_SetColorKey(pdc_font, SDL_SRCCOLORKEY, 0);
            else
            {
                if (backgr == -1)
                    SDL_SetColorKey(pdc_font, 0, 0);

                SDL_SetPalette(pdc_font, SDL_LOGPAL,
                               pdc_color + newbg, 0, 1);
            }

            backgr = newbg;
        }

        oldch = ch;
    }
}
Beispiel #8
0
void _new_packet(attr_t attr, int lineno, int x, int len, const chtype *srcp)
{
    int j;
    short fore, back;
    bool blink, ansi;

    if (pdc_conemu && pdc_ansi &&
        (lineno == (SP->lines - 1)) && ((x + len) == SP->cols))
    {
        len--;
        if (len)
            _new_packet(attr, lineno, x, len, srcp);
        pdc_ansi = FALSE;
        _new_packet(attr, lineno, x + len, 1, srcp + len);
        pdc_ansi = TRUE;
        return;
    }

    PDC_pair_content(PAIR_NUMBER(attr), &fore, &back);
    ansi = pdc_ansi || (fore >= 16 || back >= 16);
    blink = (SP->termattrs & A_BLINK) && (attr & A_BLINK);

    if (blink)
    {
        attr &= ~A_BLINK;
        if (blinked_off)
            attr &= ~(A_UNDERLINE | A_RIGHT | A_LEFT);
    }

    if (attr & A_BOLD)
        fore |= 8;
    if (attr & A_BLINK)
        back |= 8;

    if (ansi)
    {
#ifdef PDC_WIDE
        WCHAR buffer[512];
#else
        char buffer[512];
#endif
        for (j = 0; j < len; j++)
        {
            chtype ch = srcp[j];

            if (ch & A_ALTCHARSET && !(ch & 0xff80))
                ch = acs_map[ch & 0x7f];

            if (blink && blinked_off)
                ch = ' ';

            buffer[j] = ch & A_CHARTEXT;
        }

        PDC_gotoyx(lineno, x);
        _set_ansi_color(fore, back, attr);
#ifdef PDC_WIDE
        WriteConsoleW(pdc_con_out, buffer, len, NULL, NULL);
#else
        WriteConsoleA(pdc_con_out, buffer, len, NULL, NULL);
#endif
    }
    else
    {
        CHAR_INFO buffer[512];
        COORD bufSize, bufPos;
        SMALL_RECT sr;
        WORD mapped_attr;

        fore = pdc_curstoreal[fore];
        back = pdc_curstoreal[back];

        if (attr & A_REVERSE)
            mapped_attr = back | (fore << 4);
        else
            mapped_attr = fore | (back << 4);

        if (attr & A_UNDERLINE)
            mapped_attr |= 0x8000; /* COMMON_LVB_UNDERSCORE */
        if (attr & A_LEFT)
            mapped_attr |= 0x0800; /* COMMON_LVB_GRID_LVERTICAL */
        if (attr & A_RIGHT)
            mapped_attr |= 0x1000; /* COMMON_LVB_GRID_RVERTICAL */

        for (j = 0; j < len; j++)
        {
            chtype ch = srcp[j];

            if (ch & A_ALTCHARSET && !(ch & 0xff80))
                ch = acs_map[ch & 0x7f];

            if (blink && blinked_off)
                ch = ' ';

            buffer[j].Attributes = mapped_attr;
            buffer[j].Char.UnicodeChar = ch & A_CHARTEXT;
        }

        bufPos.X = bufPos.Y = 0;
        bufSize.X = len;
        bufSize.Y = 1;

        sr.Top = sr.Bottom = lineno;
        sr.Left = x;
        sr.Right = x + len - 1;

        WriteConsoleOutput(pdc_con_out, buffer, bufSize, bufPos, &sr);
    }
}