Пример #1
0
/*
typedef struct _POINT_INFO {

	int origin_x;
	int origin_y;
	int x_from_origin;
	int y_from_origin;

} POINT_INFO;

typedef void (*PRINT_HEADER_FUNC) (WINDOW*, int);
typedef void (*PRINT_DATA_FUNC) (WINDOW*, gpointer, int);

typedef struct _BOARD_WIDGET {
	WINDOW* mainWnd;
	WINDOW* headerWnd;

	GPtrArray* wndTable;
	GPtrArray* dataTable;
	PRINT_HEADER_FUNC printHeader;
	PRINT_DATA_FUNC printData;
	int firstrow_index;
	int lastrow_index;

	int row;
	int col;
	int row_width;
	int col_width;

	POINT_INFO* point_info;
	POINT_INFO* origin_point_info;

	chtype base_color;
	chtype selected_color;
	guint selected_index;

	bool wndFlag;
	bool dataFlag;	
} BOARD_WIDGET;

*/
void init_scr()
{
	initscr();
	start_color(); 
	curs_set(0);
	noecho();
	nodelay (stdscr, TRUE); 
	keypad(stdscr, TRUE);
	use_default_colors (); 
	short r, g, b;
	r=81, g=243, b=22;
	color_content (COLOR_GREEN, &r, &g, &b);
	r=8, g=35, b=77;
	color_content (COLOR_BLUE, &r, &g, &b);
/*	r=249, g=249, b=41;
	color_content (COLOR_YELLOW, &r, &g, &b); */
	init_pair (1, COLOR_YELLOW, COLOR_GREEN);
	init_pair (2, COLOR_YELLOW, COLOR_BLUE);
	init_pair (3, COLOR_YELLOW, COLOR_RED);
	init_pair (4, COLOR_WHITE, COLOR_GREEN);
	init_pair (5, COLOR_WHITE, COLOR_RED);
	init_pair (6, COLOR_WHITE, COLOR_BLUE);
	init_pair (7, COLOR_WHITE, COLOR_MAGENTA);

	refresh ();
}
Пример #2
0
void Program::init_curses() {

  setlocale(LC_ALL, "");
  //window = subwin(initscr(), 200, 200, 0, 0);
  window= initscr();
  start_color();

  timeout(0);
  noecho();

  /*if (!has_colors() || ! can_change_color()) {
    //TODO: Add descriptive error message, clean up
    exit(EXIT_FAILURE);
  }*/

  color_content(COLOR_WHITE, &white.r, &white.g, &white.b);
  color_content(COLOR_BLACK, &black.r, &black.g, &black.b);
  color_content(COLOR_RED, &red.r, &red.g, &red.b);
  color_content(COLOR_GREEN, &green.r, &green.g, &green.b);
  color_content(COLOR_YELLOW, &yellow.r, &yellow.g, &yellow.b);

  init_pair(1, COLOR_BLACK, COLOR_BLACK);
  init_pair(2, COLOR_BLACK, COLOR_RED);
  init_pair(3, COLOR_BLACK, COLOR_GREEN);
  init_pair(4, COLOR_BLACK, COLOR_YELLOW);

  init_pair(5, COLOR_RED, COLOR_BLACK);
  init_pair(6, COLOR_RED, COLOR_RED);
  init_pair(7, COLOR_RED, COLOR_GREEN);
  init_pair(8, COLOR_RED, COLOR_YELLOW);

  init_pair(9, COLOR_GREEN, COLOR_BLACK);
  init_pair(10, COLOR_GREEN, COLOR_RED);
  init_pair(11, COLOR_GREEN, COLOR_GREEN);
  init_pair(12, COLOR_GREEN, COLOR_YELLOW);

  init_pair(13, COLOR_YELLOW, COLOR_BLACK);
  init_pair(14, COLOR_YELLOW, COLOR_RED);
  init_pair(15, COLOR_YELLOW, COLOR_GREEN);
  init_pair(16, COLOR_YELLOW, COLOR_YELLOW);

  init_color(COLOR_WHITE, 0, 0, 0);
  init_color(COLOR_BLACK, 0, 0, 0);
  init_color(COLOR_RED, 333, 333, 333);
  init_color(COLOR_GREEN, 667, 667, 667);
  init_color(COLOR_YELLOW, 1000, 1000, 1000);

  erase();
}
Пример #3
0
static void term_refresh() {
	// to set up a 256-color terminal, see:
	// http://push.cx/2008/256-color-xterms-in-ubuntu
	if (0 && can_change_color()) {
		int i;
		for (i = 0; i < 16; i++) {
			short r = palette[i].r * 1000;
			short g = palette[i].g * 1000;
			short b = palette[i].b * 1000;
			if (r < 0) r = 0;
			if (g < 0) g = 0;
			if (b < 0) b = 0;
			init_color(i + 1, r, g, b);
		}
	}
	if (0) {
		int i;
		short r, g, b;
		for (i = 0; i < 8; i++) {
			color_content(i, &r, &g, &b);
			palette[i].r = r * .001;
			palette[i].g = g * .001;
			palette[i].b = b * .001;
		}
	}


	if (colormode == coerce_256) {
		buffer_render_256();
	}

	refresh();
}
Пример #4
0
static void
backup_colors(void)
{
	short i;
	for (i = 0; i < GNT_TOTAL_COLORS; i++)
	{
		color_content(i, &colors[i].r,
				&colors[i].g, &colors[i].b);
	}
}
Пример #5
0
/* Return a list of three elements containing the RGB of COLOR */
SCM
gucu_color_content (SCM s_color)
{
  int ret;
  short c_red, c_green, c_blue;

  ret = color_content (scm_to_short (s_color), &c_red, &c_green, &c_blue);
  if (ret == OK)
    {
      return scm_list_3 (scm_from_short (c_red),
			 scm_from_short (c_green), scm_from_short (c_blue));
    }
  else
    return SCM_BOOL_F;
}
Пример #6
0
int main(void)
{
	short x,r,b,g;

	initscr();
	start_color();

	for(x=0;x<COLORS;x++)
	{
		color_content(x,&r,&g,&b);
		printw("Color %d = Red: %4d\tGreen: %4d\tBlue: %4d\n",
				x,r,g,b);
	}
	refresh();
	getch();

	endwin();
	return 0;
}
Пример #7
0
// color_content() seems to give you the default ncurses value (one of 0, 680
// or 1000), *not* the actual value being used by the terminal... :/ This
// function is not likely useful until we can get the latter (we don't want
// generally to restore the (hideous) ncurses defaults).
int preserve_colors(void){
	int ret = OK,q;

	if(colorpairs_allowed >= 0 || colors_allowed >= 0){
		return ERR;
	}
	colors_allowed = COLORS;
	colorpairs_allowed = COLOR_PAIRS;
	if(colors_allowed > COLOR_CEILING || colorpairs_allowed > COLORPAIR_CEILING){
		return ERR;
	}
	for(q = 0 ; q < colorpairs_allowed ; ++q){
		ret |= pair_content(q,ofg + q,obg + q);
	}
	for(q = 0 ; q < colors_allowed ; ++q){
		ret |= color_content(q,oor + q,oog + q,oob + q);
	}
	return ret;
}
Пример #8
0
static void console_savecolors(struct NcConsole *self) {
	short int i;
	short int r,g,b;
	short int fg, bg;
	struct color_reader cr;
	int use_cr;
	use_cr = self->flags & NC_SUPPORTSCOLORREADER && !color_reader_init(&cr);
	int maxc = MIN(self->maxcolors, CONSOLE_MAXSAVECOLORS);
	for (i = MIN_COLOR; i < maxc; i++) {
		if(use_cr) color_reader_get_color(&cr, i, &self->org_colors[i]);
		else {
			color_content(i, &r, &g, &b);
			self->org_colors[i] = RGB(console_fromthousand(r), console_fromthousand(g), console_fromthousand(b));
		}
	}
	if(use_cr) color_reader_close(&cr);
	for (i = MIN_PAIR; i < maxc+MIN_PAIR; i++) {
		pair_content(i, &fg, &bg);
		self->org_fgcolors[i-MIN_PAIR] = fg;
		self->org_bgcolors[i-MIN_PAIR] = bg;
	}
}
Пример #9
0
void colorTest(WINDOW *win)
{
    static const short colors[] =
    {
        COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
        COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
    };

    static const char *colornames[] =
    {
        "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE",
        "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE"
    };

    chtype fill = ACS_BLOCK;

    int i, j, tmarg, col1, col2, col3, col4, ch;

    if (!has_colors())
        return;

    do
    {
        tmarg = (LINES - 19) / 2;
        col1 = (COLS - 60) / 2;
        col2 = col1 + 15;
        col3 = col2 + 15;
        col4 = col3 + 15;

        attrset(A_BOLD);
        mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros");
        attrset(A_NORMAL);

        mvaddstr(tmarg + 3, col2 + 2, "A_NORMAL");
        mvaddstr(tmarg + 3, col3 + 3, "A_BOLD");
        mvaddstr(tmarg + 3, col4 + 3, "A_BLINK");

        for (i = 0; i < 8; i++)
        {
            init_pair((short)(i + 4), colors[i], background_index);
            mvaddstr(tmarg + i + 5, col1, colornames[i]);

            for (j = 0; j < 12; j++)
            {
                mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4));
                mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD);
                mvaddch(tmarg + i + 5, col4 + j, fill | COLOR_PAIR(i + 4) | A_BLINK);
            }
            attrset( COLOR_PAIR( i + 4) | A_BLINK);
            mvaddstr( tmarg + i + 5, col4 + 5, "Text");
            attrset( COLOR_PAIR( i + 4) | A_BOLD);
            mvaddstr( tmarg + i + 5, col3 + 5, "Text");
            attroff( A_BOLD);
            mvaddstr( tmarg + i + 5, col2 + 5, "Text");
            attrset( A_NORMAL);
        }

        mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS);
        mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS);

#ifdef CHTYPE_LONG
#if( CHTYPE_LONG >= 2)       /* "non-standard" 64-bit chtypes     */
        attrset(A_ITALIC);
        mvprintw( tmarg + 15, col3, "Italic");
        attrset(A_ITALIC | A_BLINK);
        mvprintw( tmarg + 15, col4, "Italic Blink");
        attrset(A_BOLD | A_ITALIC);
        mvprintw( tmarg + 17, col4, "Italic Bold");
        attrset(A_BOLD | A_ITALIC | A_BLINK);
        mvprintw( tmarg + 18, col4, "Italic Blink Bold");
#endif
#endif
        attrset(A_BOLD);
        mvprintw( tmarg + 16, col3, "Bold");
        attrset(A_BLINK);
        mvprintw( tmarg + 17, col3, "Blink");

        attrset(A_BLINK | A_BOLD);
        mvprintw( tmarg + 16, col4, "Blink Bold");
/* end BJG addenda */
        attrset(A_NORMAL);

        mvaddstr(tmarg + 19, 3, "Press any key to continue");
        ch = getch();
# ifdef PDCURSES
        if( ch == KEY_RESIZE)
        {
            erase();
            resize_term(0, 0);
        }
# endif
    }  while( ch == KEY_RESIZE);

    if (can_change_color())
    {
        struct
        {
            short red, green, blue;
        } orgcolors[16];

        int MAXCOL = (COLORS >= 16) ? 16 : 8;

        if (MAXCOL < 8)
            return;

        for (i = 0; i < MAXCOL; i++)
            color_content((short)i, &(orgcolors[i].red),
                                    &(orgcolors[i].green),
                                    &(orgcolors[i].blue));

        attrset(A_BOLD);
        mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example ");
        attrset(A_NORMAL);

        refresh();

        for (i = 0; i < 8; i++)
        {
            init_color(colors[i], (short)(i * 125), 0, (short)(i * 125));

            if (MAXCOL == 16)
                init_color((short)(colors[i] + 8), 0, (short)(i * 125), 0);
        }

        mvaddstr(tmarg + 19, 3, "Press any key to continue");
        getch();
        for (i = 0; i < MAXCOL; i++)
            init_color((short)i, orgcolors[i].red,
                                 orgcolors[i].green,
                                 orgcolors[i].blue);
    }
/* BJG additions: */
    if( COLORS == 256 && LINES >= 18) do  /* show off all 256 colors */
    {
       tmarg = LINES / 2 - 8;
       erase( );
       for( i = 0; i < 256; i++)
           {
           char tbuff[4];
           const int col = COLS / 2 - 24;

           if( i >= 16)
              init_pair((short)i, (short)i, COLOR_BLACK);
           attrset( COLOR_PAIR( i) | A_REVERSE);
           sprintf( tbuff, "%02x ", i);
           mvaddstr( tmarg + i / 16, col + (i % 16) * 3, tbuff);
           }
#ifdef A_LEFTLINE
       attrset( A_LEFTLINE);
       mvaddstr( tmarg + 17, col1, "A_LEFTLINE");
#endif
#ifdef A_UNDERLINE
       attrset( A_UNDERLINE);
       mvaddstr( tmarg + 18, col1, "A_UNDERLINE");
#endif
#ifdef A_RIGHTLINE
       attrset( A_RIGHTLINE);
       mvaddstr( tmarg + 19, col1, "A_RIGHTLINE");
#endif
# if(CHTYPE_LONG >= 2)        /* following types don't exist otherwise: */
       attrset( A_OVERLINE);
       mvaddstr( tmarg + 17, col2, "A_OVERLINE");
       attrset( A_STRIKEOUT);
       mvaddstr( tmarg + 18, col2, "A_STRIKEOUT");
       attrset( A_OVERLINE | A_UNDERLINE);
       mvaddstr( tmarg + 19, col2, "Over/underlined");
#endif
       attrset(A_NORMAL);
       refresh( );
       ch = getch( );
# ifdef PDCURSES
        if( ch == KEY_RESIZE)
            resize_term(0, 0);
# endif
    } while( ch == KEY_RESIZE);
}
Пример #10
0
void curses_init_nhcolors()
{
#ifdef TEXTCOLOR
    if (has_colors())
    {
        use_default_colors();
        init_pair(1, COLOR_BLACK, -1);
        init_pair(2, COLOR_RED, -1);
        init_pair(3, COLOR_GREEN, -1);
        init_pair(4, COLOR_YELLOW, -1);
        init_pair(5, COLOR_BLUE, -1);
        init_pair(6, COLOR_MAGENTA, -1);
        init_pair(7, COLOR_CYAN, -1);
        init_pair(8, -1, -1);

        if (COLORS >= 16)
        {
            init_pair(9, COLOR_WHITE, -1);
            init_pair(10, COLOR_RED + 8, -1);
            init_pair(11, COLOR_GREEN + 8, -1);
            init_pair(12, COLOR_YELLOW + 8, -1);
            init_pair(13, COLOR_BLUE + 8, -1);
            init_pair(14, COLOR_MAGENTA + 8, -1);
            init_pair(15, COLOR_CYAN + 8, -1);
            init_pair(16, COLOR_WHITE + 8, -1);
        }

        if (can_change_color())
        {
            /* Preserve initial terminal colors */
            color_content(COLOR_YELLOW, &orig_yellow.r, &orig_yellow.g,
             &orig_yellow.b);
            color_content(COLOR_WHITE, &orig_white.r, &orig_white.g,
             &orig_white.b);
            
            /* Set colors to appear as NetHack expects */
            init_color(COLOR_YELLOW, 500, 300, 0);
            init_color(COLOR_WHITE, 600, 600, 600);
            if (COLORS >= 16)
            {
                /* Preserve initial terminal colors */
                color_content(COLOR_RED + 8, &orig_hired.r,
                 &orig_hired.g, &orig_hired.b);
                color_content(COLOR_GREEN + 8, &orig_higreen.r,
                 &orig_higreen.g, &orig_higreen.b);
                color_content(COLOR_YELLOW + 8, &orig_hiyellow.r,
                 &orig_hiyellow.g, &orig_hiyellow.b);
                color_content(COLOR_BLUE + 8, &orig_hiblue.r,
                 &orig_hiblue.g, &orig_hiblue.b);
                color_content(COLOR_MAGENTA + 8, &orig_himagenta.r,
                 &orig_himagenta.g, &orig_himagenta.b);
                color_content(COLOR_CYAN + 8, &orig_hicyan.r,
                 &orig_hicyan.g, &orig_hicyan.b);
                color_content(COLOR_WHITE + 8, &orig_hiwhite.r,
                 &orig_hiwhite.g, &orig_hiwhite.b);
            
                /* Set colors to appear as NetHack expects */
                init_color(COLOR_RED + 8, 1000, 500, 0);
                init_color(COLOR_GREEN + 8, 0, 1000, 0);
                init_color(COLOR_YELLOW + 8, 1000, 1000, 0);
                init_color(COLOR_BLUE + 8, 0, 0, 1000);
                init_color(COLOR_MAGENTA + 8, 1000, 0, 1000);
                init_color(COLOR_CYAN + 8, 0, 1000, 1000);
                init_color(COLOR_WHITE + 8, 1000, 1000, 1000);
#ifdef USE_DARKGRAY
                if (COLORS > 16)
                {
                    init_color(CURSES_DARK_GRAY, 300, 300, 300);
                }
#endif
            }
            else
            {
                /* Set flag to use bold for bright colors */
            }
        }
    }
#endif
}
Пример #11
0
void colorTest(WINDOW *win)
{
    static const short colors[] =
    {
        COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
        COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
    };

    static const char *colornames[] =
    {
        "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE",
        "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE"
    };

    chtype fill = ACS_BLOCK;

    int i, j, tmarg, col1, col2, col3;

    if (!has_colors())
        return;

    tmarg = (LINES - 19) / 2;
    col1 = (COLS - 60) / 2;
    col2 = col1 + 20;
    col3 = col2 + 20;

    attrset(A_BOLD);
    mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros");
    attrset(A_NORMAL);

    mvaddstr(tmarg + 3, col2 + 4, "A_NORMAL");
    mvaddstr(tmarg + 3, col3 + 5, "A_BOLD");

    for (i = 0; i < 8; i++)
    {
        init_pair(i + 4, colors[i], COLOR_BLACK);

        mvaddstr(tmarg + i + 5, col1, colornames[i]);

        for (j = 0; j < 16; j++)
        {
            mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4));
            mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD);
        }
    }

    mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS);
    mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS);

    mvaddstr(tmarg + 19, 3, "Press any key to continue");
    getch();

    if (can_change_color())
    {
        struct
        {
            short red, green, blue;
        } orgcolors[16];

        int MAXCOL = (COLORS >= 16) ? 16 : 8;

        if (MAXCOL < 8)
            return;

        for (i = 0; i < MAXCOL; i++)
            color_content(i, &(orgcolors[i].red),
                          &(orgcolors[i].green),
                          &(orgcolors[i].blue));

        attrset(A_BOLD);
        mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example ");
        attrset(A_NORMAL);

        refresh();

        for (i = 0; i < 8; i++)
        {
            init_color(colors[i], i * 125, 0, i * 125);

            if (MAXCOL == 16)
                init_color(colors[i] + 8, 0, i * 125, 0);
        }

        mvaddstr(tmarg + 19, 3, "Press any key to continue");
        getch();

        for (i = 0; i < MAXCOL; i++)
            init_color(i, orgcolors[i].red,
                       orgcolors[i].green,
                       orgcolors[i].blue);
    }
}
Пример #12
0
// FIXME dark evil hackery aieeeee
int setup_extended_colors(void){
	int ret = OK,q;

	if(can_change_color() != TRUE){
		return ERR;
	}
	// rgb of 0->0, 85->333, 128->500, 170->666, 192->750, 255->999
	// Gnome-terminal palette:
	// #2E3436:#CC0000:#4E9A06:#C4A000:
	// #3465A4:#75507B:#06989A:#D3D7CF:
	// #555753:#EF2929:#8AE234:#FCE94F:
	// #729FCF:#AD7FA8:#34E2E2:#EEEEEC
	ret |= init_color(COLOR_BLACK,156,203,211);
	ret |= init_color(COLOR_RED,CURSES_RGB(RRED),CURSES_RGB(GRED),CURSES_RGB(BRED));
	ret |= init_color(COLOR_GREEN,CURSES_RGB(RGREEN),CURSES_RGB(GGREEN),CURSES_RGB(BGREEN));
	ret |= init_color(COLOR_YELLOW,CURSES_RGB(RYELLOW),CURSES_RGB(GYELLOW),CURSES_RGB(BYELLOW));
	ret |= init_color(COLOR_BLUE,CURSES_RGB(RBLUE),CURSES_RGB(GBLUE),CURSES_RGB(BBLUE));
	ret |= init_color(COLOR_MAGENTA,CURSES_RGB(RMAGENTA),CURSES_RGB(GMAGENTA),CURSES_RGB(BMAGENTA));
	ret |= init_color(COLOR_CYAN,CURSES_RGB(RCYAN),CURSES_RGB(GCYAN),CURSES_RGB(BCYAN));
	ret |= init_color(COLOR_WHITE,CURSES_RGB(RWHITE),CURSES_RGB(GWHITE),CURSES_RGB(BWHITE));
	ret |= init_color(8,332,340,324);
	ret |= init_color(9,933,160,160);
	ret |= init_color(COLOR_BRGREEN,539,882,203); // ncurses def
	ret |= init_color(11,983,909,308);
	ret |= init_color(COLOR_LIGHTBLUE,445,620,808); // ncurses def
	ret |= init_color(13,675,496,656);
	ret |= init_color(14,203,882,882);
	ret |= init_color(COLOR_BRIGHTWHITE,CURSES_RGB(RBRWHITE),CURSES_RGB(GBRWHITE),CURSES_RGB(BBRWHITE));
	ret |= init_color(COLOR_CYAN_75,CURSES75_RGB(RCYAN),CURSES75_RGB(GCYAN),CURSES75_RGB(BCYAN));
	ret |= init_color(COLOR_BLUE_75,CURSES75_RGB(RBLUE),CURSES75_RGB(GBLUE),CURSES75_RGB(BBLUE));
	ret |= init_color(COLOR_CYAN_50,CURSES50_RGB(RCYAN),CURSES50_RGB(GCYAN),CURSES50_RGB(BCYAN));
	ret |= init_color(COLOR_BLUE_50,CURSES50_RGB(RBLUE),CURSES50_RGB(GBLUE),CURSES50_RGB(BBLUE));
	ret |= init_color(COLOR_BONE,CURSES_RGB(_BONE_R),CURSES_RGB(_BONE_G),CURSES_RGB(_BONE_B));
	ret |= init_color(COLOR_VIOLET,CURSES_RGB(RVIOLET),CURSES_RGB(GVIOLET),CURSES_RGB(BVIOLET));
	ret |= init_color(COLOR_ORANGE,CURSES_RGB(RORANGE),CURSES_RGB(GORANGE),CURSES_RGB(BORANGE));
	ret |= init_color(COLOR_BONE_75,CURSES75_RGB(_BONE_R),CURSES75_RGB(_BONE_G),CURSES75_RGB(_BONE_B));
	ret |= init_color(COLOR_VIOLET_75,CURSES75_RGB(RVIOLET),CURSES75_RGB(GVIOLET),CURSES75_RGB(BVIOLET));
	ret |= init_color(COLOR_GREEN_75,CURSES75_RGB(RGREEN),CURSES75_RGB(GGREEN),CURSES75_RGB(BGREEN));
	ret |= init_color(COLOR_ORANGE_75,CURSES75_RGB(RORANGE),CURSES75_RGB(GORANGE),CURSES75_RGB(BORANGE));
	ret |= init_color(COLOR_MAGENTA_75,CURSES75_RGB(RMAGENTA),CURSES75_RGB(GMAGENTA),CURSES75_RGB(BMAGENTA));
	ret |= init_color(COLOR_BONE_50,CURSES50_RGB(_BONE_R),CURSES50_RGB(_BONE_G),CURSES50_RGB(_BONE_B));
	ret |= init_color(COLOR_VIOLET_50,CURSES50_RGB(RVIOLET),CURSES50_RGB(GVIOLET),CURSES50_RGB(BVIOLET));
	ret |= init_color(COLOR_GREEN_50,CURSES50_RGB(RGREEN),CURSES50_RGB(GGREEN),CURSES50_RGB(BGREEN));
	ret |= init_color(COLOR_MAGENTA_50,CURSES50_RGB(RMAGENTA),CURSES50_RGB(GMAGENTA),CURSES50_RGB(BMAGENTA));
	ret |= init_color(COLOR_PALEMAGENTA,CURSES5_RGB(RMAGENTA),CURSES5_RGB(GMAGENTA),CURSES5_RGB(BMAGENTA));
	ret |= init_color(COLOR_PALEORANGE,CURSES5_RGB(RORANGE),CURSES5_RGB(GORANGE),CURSES5_RGB(BORANGE));
	ret |= init_color(COLOR_PALEBLUE,CURSES5_RGB(RBLUE),CURSES5_RGB(GBLUE),CURSES5_RGB(BBLUE));
	ret |= init_color(COLOR_PALECYAN,CURSES5_RGB(RCYAN),CURSES5_RGB(GCYAN),CURSES5_RGB(BCYAN));
	ret |= init_color(COLOR_PALEVIOLET,CURSES5_RGB(RVIOLET),CURSES5_RGB(GVIOLET),CURSES5_RGB(BVIOLET));
	ret |= init_color(COLOR_PALEYELLOW,CURSES5_RGB(RYELLOW),CURSES5_RGB(GYELLOW),CURSES5_RGB(BYELLOW));
	ret |= init_color(COLOR_SKYBLUE,CURSES_RGB(RSKYBLUE),CURSES_RGB(GSKYBLUE),CURSES_RGB(BSKYBLUE));
	ret |= init_color(COLOR_SKYBLUE_75,CURSES75_RGB(RSKYBLUE),CURSES75_RGB(GSKYBLUE),CURSES75_RGB(BSKYBLUE));
	ret |= init_color(COLOR_SKYBLUE_50,CURSES50_RGB(RSKYBLUE),CURSES50_RGB(GSKYBLUE),CURSES50_RGB(BSKYBLUE));
	ret |= init_color(COLOR_CHAMELEON,CURSES_RGB(RCHAMELEON),CURSES_RGB(GCHAMELEON),CURSES_RGB(BCHAMELEON));
	ret |= init_color(COLOR_CHAMELEON_75,CURSES_RGB(RCHAMELEON2),CURSES_RGB(GCHAMELEON2),CURSES_RGB(BCHAMELEON2));
	ret |= init_color(COLOR_CHAMELEON_50,CURSES50_RGB(RCHAMELEON),CURSES50_RGB(GCHAMELEON),CURSES50_RGB(BCHAMELEON));
	ret |= init_color(COLOR_ALUMINIUM,CURSES_RGB(RALUMINIUM),CURSES_RGB(GALUMINIUM),CURSES_RGB(BALUMINIUM));
	ret |= init_color(COLOR_ALUMINIUM_75,CURSES75_RGB(RALUMINIUM),CURSES75_RGB(GALUMINIUM),CURSES75_RGB(BALUMINIUM));
	ret |= init_color(COLOR_ALUMINIUM_50,CURSES50_RGB(RALUMINIUM),CURSES50_RGB(GALUMINIUM),CURSES50_RGB(BALUMINIUM));
	ret |= init_color(COLOR_PALEALUMINIUM,CURSES5_RGB(RALUMINIUM),CURSES5_RGB(GALUMINIUM),CURSES5_RGB(BALUMINIUM));
	ret |= wrefresh(curscr);
	if(ret == OK){
		modified_colors = 1;
	}
	for(q = 0 ; q < colors_allowed ; ++q){
		ret |= color_content(q,or + q,og + q,ob + q);
	}
	return ret;
}
Пример #13
0
bool Screen::init(float updatefreq, void (* charprocfunc) (int))
{
#ifdef DEBUG
	char	tmpbuf[256];
#endif
	
	if (_inited)
		return false;

	// Assign character processing callback
	_charprocfunc = (void *) charprocfunc;

	// Figure out update frequency dependent stuff
	if (updatefreq < 0)
		return false;
	
	_updatefreq = updatefreq;
	_updateperiod.tv_sec = (int) floor(1/updatefreq);
	_updateperiod.tv_nsec = (int) (1000000000.0 *
			(1/updatefreq - floor(1/updatefreq)));
	
	// OK, set up the terminal for operation
	_stdscr = initscr();
	if (!_stdscr)
		return false;
	if (nonl() == ERR) // turn off newline translation
		return false;
	if (cbreak() == ERR) // turn off line buffering erase/kill 
		return false;
	if (noecho() == ERR) // Disable auto echo by input functions
		return false;
	if (leaveok(_stdscr, true) == ERR)  // Leave cursor in place after update
		return false;
	timeout(0); // Because nodelay() doesn't work
	curs_set(0); // Make the cursor invisible

	// Initialize terminal info
	getmaxyx (_stdscr, _maxy, _maxx);

#ifdef DEBUG
	move (0,0);

	sprintf (tmpbuf,"Update Freq: %f\tPeriod: %d sec %d nsec\n",
		_updatefreq, 
		(int) _updateperiod.tv_sec, 
		(int) _updateperiod.tv_nsec);
	addstr (tmpbuf);

	sprintf (tmpbuf,"Maxy: %d\tMaxx: %d\n",_maxy, _maxx);
	addstr (tmpbuf);
#endif
	// Initialize attributes
	_colors = has_colors();
	if (_colors)
	{
		// OK, start the color subsystem
		start_color();
		/*
		 * FIXME: Add some sort of color tuning capability here
		 *
		if (can_change_color())
		{
			short r,g,b;
			addstr ("Can alter colors\n");
			// Pump up the volume on all the colors
			for (short i = 1; i < 8; i++)
			{
				color_content (i,&r,&g,&b);
				//r += 0x101;
				//g += 0x101;
				//b += 0x101;
				init_color(i, r, g, b);
			}
		}
		*/
#ifdef DEBUG
		sprintf (tmpbuf, "Colors: %d Color Pairs: %d\n",
				COLORS, COLOR_PAIRS);
		addstr (tmpbuf);
#endif
		// Define and set color attributes
		for (short i = 1; i < 8; i++)
		{
			// Initialize pairs one through eight to match
			// it's color on a black background
			init_pair(i,i,0);
			
			// Put the new color attribute in the color table
			_colortbl[i] = COLOR_PAIR(i);
			
#ifdef DEBUG
			short fg,bg;
			short r,g,b;
			color_content (i,&r,&g,&b);
			pair_content (i, &fg, &bg);

			attrset(COLOR_PAIR(i));
			sprintf (tmpbuf, "Color %d = (0x%03x:0x%03x:0x%03x), Pair %d = 0x%03x (%d:%d)\n", 
					i,r,g,b,i,COLOR_PAIR(i),fg,bg);
			addstr (tmpbuf);
			attron(A_BOLD);
			sprintf (tmpbuf, "+Bold = (0x%03lx)",COLOR_PAIR(i)|A_BOLD);
			addstr (tmpbuf);
			attroff(A_BOLD);
			attron(A_REVERSE);
			sprintf (tmpbuf, ", +Rvrs = (0x%03lx)",COLOR_PAIR(i)|A_REVERSE);
			addstr (tmpbuf);
			attroff(A_REVERSE);
			attron(A_REVERSE|A_BOLD);
			sprintf (tmpbuf, ", +Rvrs+Bold = (0x%03lx)\n",COLOR_PAIR(i)|A_REVERSE|A_BOLD);
			addstr (tmpbuf);
			attroff(A_REVERSE|A_BOLD);
#endif
		}

	} else
	{
		return false;
	}
	
#ifdef DEBUG
	refresh();
#endif
	_inited = true;
	return true;
}
Пример #14
0
static void color_edit(void)
/* display the color test pattern, without trying to edit colors */
{
    int	i, c, value = 0, current = 0, field = 0, usebase = 0;

    refresh();

    for (i = 0; i < COLORS; i++)
	init_pair(i, COLOR_WHITE, i);

    do {
	short	red, green, blue;

	attron(A_BOLD);
	mvaddstr(0, 20, "Color RGB Value Editing");
	attroff(A_BOLD);

	for (i = 0; i < COLORS; i++)
        {
	    mvprintw(2 + i, 0, "%c %-8s:",
		     (i == current ? '>' : ' '),
		     (i < sizeof(colors)/sizeof(colors[0]) ? colors[i] : ""));
	    attrset(COLOR_PAIR(i));
	    addstr("        ");
	    attrset(A_NORMAL);

	    /*
	     * Note: this refresh should *not* be necessary!  It works around
	     * a bug in attribute handling that apparently causes the A_NORMAL
	     * attribute sets to interfere with the actual emission of the
	     * color setting somehow.  This needs to be fixed.
	     */
	    refresh();

	    color_content(i, &red, &green, &blue);
	    addstr("   R = ");
	    if (current == i && field == 0) attron(A_STANDOUT);
	    printw("%04d", red);
	    if (current == i && field == 0) attrset(A_NORMAL);
	    addstr(", G = ");
	    if (current == i && field == 1) attron(A_STANDOUT);
	    printw("%04d", green);
	    if (current == i && field == 1) attrset(A_NORMAL);
	    addstr(", B = ");
	    if (current == i && field == 2) attron(A_STANDOUT);
	    printw("%04d", blue);
	    if (current == i && field == 2) attrset(A_NORMAL);
	    attrset(A_NORMAL);
	    addstr(")");
	}

	mvaddstr(COLORS + 3, 0,
	    "Use up/down to select a color, left/right to change fields.");
	mvaddstr(COLORS + 4, 0,
	    "Modify field by typing nnn=, nnn-, or nnn+.  ? for help.");

	move(2 + current, 0);

	switch (c = getch())
	{
	case KEY_UP:
	    current = (current == 0 ? (COLORS - 1) : current - 1);
	    value = 0;
	    break;

	case KEY_DOWN:
	    current = (current == (COLORS - 1) ? 0 : current + 1);
	    value = 0;
	    break;

	case KEY_RIGHT:
	    field = (field == 2 ? 0 : field + 1);
	    value = 0;
	    break;

	case KEY_LEFT:
	    field = (field == 0 ? 2 : field - 1);
	    value = 0;
	    break;

	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	    do {
		value = value * 10 + (c - '0');
		c = getch();
	    } while
		(isdigit(c));
	    if (c != '+' && c != '-' && c != '=')
		beep();
	    else
		ungetch(c);
	    break;

	case '+':
	    usebase = 1;
	    goto changeit;

	case '-':
	    value = -value;
	    usebase = 1;
	    goto changeit;

	case '=':
	    usebase = 0;
	changeit:
	    color_content(current, &red, &green, &blue);
	    if (field == 0)
		red = red * usebase + value;
	    else if (field == 1)
		green = green * usebase + value;
	    else if (field == 2)
		blue = blue * usebase + value;
	    init_color(current, red, green, blue);
	    break;

	case '?':
	    erase();
    P("                      RGB Value Editing Help");
    P("");
    P("You are in the RGB value editor.  Use the arrow keys to select one of");
    P("the fields in one of the RGB triples of the current colors; the one");
    P("currently selected will be reverse-video highlighted.");
    P("");
    P("To change a field, enter the digits of the new value; they won't be");
    P("echoed.  Finish by typing `='; the change will take effect instantly.");
    P("To increment or decrement a value, use the same procedure, but finish");
    P("with a `+' or `-'.");
    P("");
    P("To quit, do `x' or 'q'");

	    move(LINES - 1, 0);
	    addstr("Press any key to continue... ");
	    (void) getch();
	    erase();
	    break;

	case 'x':
	case 'q':
	    break;

	default:
	    beep();
	    break;
	}
    } while
	(c != 'x' && c != 'q');

    erase();
    endwin();
}