非常感谢您之前的回答,但我还有一个问题。
如果我不知道使用的颜色是什么,我如何获取颜色文本和角色的颜色背景。 以你为例,你知道什么是颜色;然后你可以比较;但如果你不知道颜色是什么;我怎样才能比你得到颜色。
这是您发送给我的代码。
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();
最佳答案
要获取 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);
关于c - 如何使用 mvinch 获取文本的颜色编号和颜色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27715993/