非常感谢您之前的回答,但我有另一个问题。
如果我不知道使用的颜色是什么,我怎么能得到角色的颜色文字和颜色。 我的例子,你知道什么是颜色;然后你可以比较;但如果你不知道颜色是什么;我怎么能得到比你更好的颜色。
这是您发送给我的代码。
init_pair(1, COLOR_BLUE, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_WHITE, COLOR_BLACK);
attron(COLOR_PAIR(1));
mvprintw(1, 1, "Sky");
attron(COLOR_PAIR(2));
mvprintw(2, 1, "Grass");
const int color_one = mvinch(1, 1) & A_COLOR;
const int color_two = mvinch(2, 1) & A_COLOR;
attron(COLOR_PAIR(3));
if ( color_one == COLOR_PAIR(1) ) {
mvprintw(4, 1, "Sky is blue");
}
else if ( color_one == COLOR_PAIR(2) ) {
mvprintw(4, 1, "Sky is green");
}
else if ( color_one == COLOR_PAIR(3) ) {
mvprintw(4, 1, "Sky is white");
}
if ( color_two == COLOR_PAIR(1) ) {
mvprintw(5, 1, "Grass is blue");
}
else if ( color_two == COLOR_PAIR(2) ) {
mvprintw(5, 1, "Grass is green");
}
else if ( color_two == COLOR_PAIR(3) ) {
mvprintw(5, 1, "Grass is white");
}
refresh();
getch();
endwin();
答案 0 :(得分:0)
要使用COLOR_PAIR号码:
int color_pair = PAIR_NUMBER(mvinch(1,1));
将返回颜色对(本例中为1)
然后将此号码传递给:
int foreground , background;
pair_content(color_pair, &foreground, &background);
获得颜色。
如果你想让rgb用于颜色:
int r, g, b;
color_content(foreground, &r, &g, &b);