예제 #1
0
NCURSES_SP_NAME(assume_default_colors) (NCURSES_SP_DCLx int fg, int bg)
{
    int code = ERR;

    T((T_CALLED("assume_default_colors(%p,%d,%d)"), (void *) SP_PARM, fg, bg));
#ifdef USE_TERM_DRIVER
    if (sp != 0)
	code = CallDriver_2(sp, defaultcolors, fg, bg);
#else
    if ((orig_pair || orig_colors) && !initialize_pair) {

	SP_PARM->_default_color = isDefaultColor(fg) || isDefaultColor(bg);
	SP_PARM->_has_sgr_39_49 = (tigetflag("AX") == TRUE);
	SP_PARM->_default_fg = isDefaultColor(fg) ? COLOR_DEFAULT : (fg & C_MASK);
	SP_PARM->_default_bg = isDefaultColor(bg) ? COLOR_DEFAULT : (bg & C_MASK);
	if (SP_PARM->_color_pairs != 0) {
	    bool save = SP_PARM->_default_color;
	    SP_PARM->_default_color = TRUE;
	    init_pair(0, (short) fg, (short) bg);
	    SP_PARM->_default_color = save;
	}
	code = OK;
    }
#endif
    returnCode(code);
}
예제 #2
0
static char *
color_of(int c)
{
    if (c != my_cached) {
	my_cached = c;
	my_select = !my_select;
	if (isDefaultColor(c))
	    _nc_STRCPY(my_buffer[my_select], "default",
		       COLOR_BUF_SIZE(my_select));
	else
	    _nc_SPRINTF(my_buffer[my_select],
			_nc_SLIMIT(COLOR_BUF_SIZE(my_select))
			"color%d", c);
    }
    return my_buffer[my_select];
}
예제 #3
0
NCURSES_SP_NAME(_nc_do_color) (NCURSES_SP_DCLx
			       int old_pair,
			       int pair,
			       int reverse,
			       NCURSES_SP_OUTC outc)
{
#ifdef USE_TERM_DRIVER
    CallDriver_4(SP_PARM, td_docolor, old_pair, pair, reverse, outc);
#else
    NCURSES_COLOR_T fg = COLOR_DEFAULT;
    NCURSES_COLOR_T bg = COLOR_DEFAULT;
    NCURSES_COLOR_T old_fg = -1;
    NCURSES_COLOR_T old_bg = -1;

    if (!ValidPair(pair)) {
	return;
    } else if (pair != 0) {
	if (set_color_pair) {
	    TPUTS_TRACE("set_color_pair");
	    NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx
				    TPARM_1(set_color_pair, pair),
				    1, outc);
	    return;
	} else if (SP_PARM != 0) {
	    if (pair_content((NCURSES_COLOR_T) pair, &fg, &bg) == ERR)
		return;
	}
    }

    if (old_pair >= 0
	&& SP_PARM != 0
	&& pair_content((NCURSES_COLOR_T) old_pair, &old_fg, &old_bg) != ERR) {
	if ((isDefaultColor(fg) && !isDefaultColor(old_fg))
	    || (isDefaultColor(bg) && !isDefaultColor(old_bg))) {
#if NCURSES_EXT_FUNCS
	    /*
	     * A minor optimization - but extension.  If "AX" is specified in
	     * the terminal description, treat it as screen's indicator of ECMA
	     * SGR 39 and SGR 49, and assume the two sequences are independent.
	     */
	    if (SP_PARM->_has_sgr_39_49
		&& isDefaultColor(old_bg)
		&& !isDefaultColor(old_fg)) {
		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[39m", 1, outc);
	    } else if (SP_PARM->_has_sgr_39_49
		       && isDefaultColor(old_fg)
		       && !isDefaultColor(old_bg)) {
		NCURSES_SP_NAME(tputs) (NCURSES_SP_ARGx "\033[49m", 1, outc);
	    } else
#endif
		reset_color_pair(NCURSES_SP_ARG);
	}
    } else {
	reset_color_pair(NCURSES_SP_ARG);
    }

#if NCURSES_EXT_FUNCS
    if (isDefaultColor(fg))
	fg = (NCURSES_COLOR_T) default_fg(NCURSES_SP_ARG);
    if (isDefaultColor(bg))
	bg = (NCURSES_COLOR_T) default_bg(NCURSES_SP_ARG);
#endif

    if (reverse) {
	NCURSES_COLOR_T xx = fg;
	fg = bg;
	bg = xx;
    }

    TR(TRACE_ATTRS, ("setting colors: pair = %d, fg = %d, bg = %d", pair,
		     fg, bg));

    if (!isDefaultColor(fg)) {
	set_foreground_color(NCURSES_SP_ARGx fg, outc);
    }
    if (!isDefaultColor(bg)) {
	set_background_color(NCURSES_SP_ARGx bg, outc);
    }
#endif
}
예제 #4
0
NCURSES_SP_NAME(init_pair) (NCURSES_SP_DCLx
			    NCURSES_PAIRS_T pair,
			    NCURSES_COLOR_T f,
			    NCURSES_COLOR_T b)
{
    colorpair_t result;
    colorpair_t previous;
    int maxcolors;

    T((T_CALLED("init_pair(%p,%d,%d,%d)"),
       (void *) SP_PARM,
       (int) pair,
       (int) f,
       (int) b));

    if (!ValidPair(pair))
	returnCode(ERR);

    maxcolors = MaxColors;

    previous = SP_PARM->_color_pairs[pair];
#if NCURSES_EXT_FUNCS
    if (SP_PARM->_default_color || SP_PARM->_assumed_color) {
	bool isDefault = FALSE;
	bool wasDefault = FALSE;
	int default_pairs = SP_PARM->_default_pairs;

	/*
	 * Map caller's color number, e.g., -1, 0, 1, .., 7, etc., into
	 * internal unsigned values which we will store in the _color_pairs[]
	 * table.
	 */
	if (isDefaultColor(f)) {
	    f = COLOR_DEFAULT;
	    isDefault = TRUE;
	} else if (!OkColorHi(f)) {
	    returnCode(ERR);
	}

	if (isDefaultColor(b)) {
	    b = COLOR_DEFAULT;
	    isDefault = TRUE;
	} else if (!OkColorHi(b)) {
	    returnCode(ERR);
	}

	/*
	 * Check if the table entry that we are going to init/update used
	 * default colors.
	 */
	if ((FORE_OF(previous) == COLOR_DEFAULT)
	    || (BACK_OF(previous) == COLOR_DEFAULT))
	    wasDefault = TRUE;

	/*
	 * Keep track of the number of entries in the color pair table which
	 * used a default color.
	 */
	if (isDefault && !wasDefault) {
	    ++default_pairs;
	} else if (wasDefault && !isDefault) {
	    --default_pairs;
	}

	/*
	 * As an extension, ncurses allows the pair number to exceed the
	 * terminal's color_pairs value for pairs using a default color.
	 *
	 * Note that updating a pair which used a default color with one
	 * that does not will decrement the count - and possibly interfere
	 * with sequentially adding new pairs.
	 */
	if (pair > (SP_PARM->_pair_count + default_pairs)) {
	    returnCode(ERR);
	}
	SP_PARM->_default_pairs = default_pairs;
    } else
#endif
    {
	if ((f < 0) || !OkColorHi(f)
	    || (b < 0) || !OkColorHi(b)
	    || (pair < 1)) {
	    returnCode(ERR);
	}
    }

    /*
     * When a pair's content is changed, replace its colors (if pair was
     * initialized before a screen update is performed replacing original
     * pair colors with the new ones).
     */
    result = PAIR_OF(f, b);
    if (previous != 0
	&& previous != result) {
	int y, x;

	for (y = 0; y <= CurScreen(SP_PARM)->_maxy; y++) {
	    struct ldat *ptr = &(CurScreen(SP_PARM)->_line[y]);
	    bool changed = FALSE;
	    for (x = 0; x <= CurScreen(SP_PARM)->_maxx; x++) {
		if (GetPair(ptr->text[x]) == pair) {
		    /* Set the old cell to zero to ensure it will be
		       updated on the next doupdate() */
		    SetChar(ptr->text[x], 0, 0);
		    CHANGED_CELL(ptr, x);
		    changed = TRUE;
		}
	    }
	    if (changed)
		NCURSES_SP_NAME(_nc_make_oldhash) (NCURSES_SP_ARGx y);
	}
    }

    SP_PARM->_color_pairs[pair] = result;
    if (GET_SCREEN_PAIR(SP_PARM) == pair)
	SET_SCREEN_PAIR(SP_PARM, (int) (~0));	/* force attribute update */

#ifdef USE_TERM_DRIVER
    CallDriver_3(SP_PARM, td_initpair, pair, f, b);
#else
    if (initialize_pair && InPalette(f) && InPalette(b)) {
	const color_t *tp = DefaultPalette;

	TR(TRACE_ATTRS,
	   ("initializing pair: pair = %d, fg=(%d,%d,%d), bg=(%d,%d,%d)",
	    (int) pair,
	    (int) tp[f].red, (int) tp[f].green, (int) tp[f].blue,
	    (int) tp[b].red, (int) tp[b].green, (int) tp[b].blue));

	NCURSES_PUTP2("initialize_pair",
		      TPARM_7(initialize_pair,
			      pair,
			      (int) tp[f].red,
			      (int) tp[f].green,
			      (int) tp[f].blue,
			      (int) tp[b].red,
			      (int) tp[b].green,
			      (int) tp[b].blue));
    }
#endif

    returnCode(OK);
}
예제 #5
0
void TerrainTest::Render()
{
	Image* scr = Screen::Instance();
	if (!grid)
		return;
	
	color c;
	tile* t;
	tile* tt;
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{
			t = GetTile(x, y);
			c.r = c.g = c.b = t->height * 25;
			
			scr->DrawRect( rect(x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE), c, true);

			if (m_bDisplayTypeMap)
			{
				//Mark tile types
				c = color();
				switch (GetTileType(x, y))
				{
					case TILE_SOUTHEDGE:
						c.r = 255; 
						break;
					case TILE_WESTEDGE:
						c.g = 255;
						break;
					case TILE_EASTEDGE:
						c.b = 255;
						break;
					case TILE_NORTHEDGE:
						c.r = c.g = 255;
						break;
					case TILE_SWEDGE:
						c.r = 128;
						break;
					case TILE_SEEDGE:
						c.g = 128;
						break;
					case TILE_NWEDGE:
						c.b = 128;
						break;
					case TILE_NEEDGE:
						c.r = c.g = 128;
						break;
					case TILE_SWBEND:
						c.g = c.b = 255;
						break;
					case TILE_SEBEND:
						c.g = c.b = 128;
						break;
					case TILE_NEBEND:
						c.r = c.b = 255;
						break;
					case TILE_NWBEND:
						c.r = c.b = 128;
						break;
					default: break;	
				}
			
				if (!isDefaultColor(c))
					scr->DrawRound( x*TILE_SIZE, y*TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE/2, c);	
			}
			
			//Render edge lines for all tiles that have too drastic a height difference between them
			tt = GetTile(x, y-1);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE+16, y*TILE_SIZE, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE+16, y*TILE_SIZE, color(0,255), 2);
			}
			
			tt = GetTile(x, y+1);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE+14, x*TILE_SIZE+16, y*TILE_SIZE+14, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE+14, x*TILE_SIZE+16, y*TILE_SIZE+14, color(0,255), 2);
			}
			
			tt = GetTile(x+1, y);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE+14, y*TILE_SIZE, x*TILE_SIZE+14, y*TILE_SIZE+14, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE+14, y*TILE_SIZE, x*TILE_SIZE+14, y*TILE_SIZE+14, color(0,255), 2);
			}
			
			tt = GetTile(x-1, y);
			if (tt)
			{
				if (tt->height > t->height+1)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE, y*TILE_SIZE+14, color(255), 2);
				else if (tt->height+1 < t->height)
					scr->DrawLine(x*TILE_SIZE, y*TILE_SIZE, x*TILE_SIZE, y*TILE_SIZE+14, color(0,255), 2);	
			}
			
			
		}
	}
	
	string msg = "m_bDisplayTypeMap: " + its(m_bDisplayTypeMap) + " (T) \\c900 m_iUpperHeight: " + its(m_iUpperHeight) + " (+Q -A). \\c090 m_iLowerHeight: " 
				+  its(m_iLowerHeight) + " (+W -S). \\c009 N to clear all";
	gui->mFont->Render(scr, 5, 5, msg, color(255,255,255));
	
	msg = "\\c090Green \\c999and \\c900red \\c999lines mark gradients too steep (Algorithm failure).";
	gui->mFont->Render(scr, 5, scr->Height() - 40, msg, color());
}