Re: colors in [pd]curses - unix vs windows
- From: Joshua Day <josh.day@xxxxxxxxx>
- Date: Fri, 2 Oct 2009 16:19:36 +0000 (UTC)
Xecutor <konstantin.stupnik@xxxxxxxxx> wrote:
But I need numberic colors.
So I need array of constants to be mapped to numbers...
Since you set up your COLOR_PAIRs yourself, you can assign them in any
order you like. Personally, I use something like this (I'm just
letting my macros wrap, since they're just over my line length):
#define COLORING(fg,bg) (((fg) & 0x0f) | (((bg) & 0x07) << 4))
#define COLOR_INDEX(color) (1 + ((color)&0x07) + (((color) >> 1) &
0x38))
#define COLOR_ATTR(color) (COLOR_PAIR(COLOR_INDEX(color)) |
(((color)&0x08) ? A_BOLD : 0))
void preparecolor ( ) {
static int pairParts[8] = {
COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW,
COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE
};
int fg, bg;
for (bg=0; bg<8; bg++) {
for (fg=0; fg<8; fg++) {
init_pair(
COLOR_INDEX(COLORING(fg, bg)),
pairParts[fg], pairParts[bg]
);
}
}
}
Now the colors from 0 to 15 are mapped in a way that I like and I can
forget about the constants completely. This call will make text
show up yellow-on-red:
attrset(COLOR_ATTR(COLORING(11, 1)));
But when I'm storing the color of an entity in the world, I just store
the COLORING() part as an int instead of keeping the foreground and
background colors separate. I have a couple of macros to replace
just the foreground or just the background, but I've never really needed
them.
--
Joshua
.
- References:
- colors in [pd]curses - unix vs windows
- From: Konstantin Stupnik
- Re: colors in [pd]curses - unix vs windows
- From: Joshua
- Re: colors in [pd]curses - unix vs windows
- From: Konstantin Stupnik
- Re: colors in [pd]curses - unix vs windows
- From: Ido Yehieli
- Re: colors in [pd]curses - unix vs windows
- From: Xecutor
- colors in [pd]curses - unix vs windows
- Prev by Date: Re: colors in [pd]curses - unix vs windows
- Next by Date: Re: colors in [pd]curses - unix vs windows
- Previous by thread: Re: colors in [pd]curses - unix vs windows
- Next by thread: Re: colors in [pd]curses - unix vs windows
- Index(es):
Loading