COLOUR in PC curses (ANSI-C and BorlandC++ compatible) This version of PC curses supports EGA/VGA colours. The old curses on UNIX only supports a few attributes such as STANDOUT, REVERSE VIDEO ... The PC curses 1.3 only support a few momochrome attributes. For this version I have worked out a scheme for colour support. This scheme may not be totally compatible with the ideas behind the curses for UNIX, but it will be comfortable to use. Firstly it strikes me that the attributes of UNIX curses are independent of one another. This means you can turn many on at the same time, one at a time and turn off them in a similar fashion. When I see how EGA/VGA handles text colour, the game is very different. This is my colour scheme for this copy of pc curses There are two classes of attributes defined. + Characteristics : NORMAL, HIGH, REVERSE and STANDOUT. These are used to control the way the screen look. + Foreground and Background colour attributes for text. The main routine to set attributes is wattrset(WINDOW *win, int attrs) This routine set the attributes which are supplied as a bit-OR of many flags. For example, to get the blue background, white characters and high intensity video you can use (F_GRAY | B_BLUE | A_HIGH) which form a 16 bit unsigned integer. How the colours work -------------------- Here is the section for users who do not want to know details about technical implementation. The routines for controlling colours and other video characteristics are. These routines are in scrutiny until I am sastisfied that they are useful and according to common sense. - wattrset(WINDOW *win, int attrs) - wattron (WINDOW *win, int attrs) - wattroff(WINDOW *win, int attrs) The most useful function is wattrset(). It set the combination of attributes you desire. Most of the time you will use it without worrying about the other routines. wattron() is implemented to common sense unlike the UNIX version of curses. It does more than a simple OR to turn bits on. Here is what it does - Turn an attribute(s) on by all means. Examples: wattron(F_RED) turn RED colour on wattron(B_GRAY | F_RED) turn RED colour on GRAY background wattron(A_BLINK) turn BLINK mode on - It keeps the old attributes intact if there is no conflict. This means only conflict in colours results in an overriding of the old colour. The rest is kept intact. Technical notes =============== Here is the set of all attributes. It is an extract from the header file curses.h // We will have 2 leftmost bits for attributes. These attributes are // not colour attributes. They are to be used with wattron(), wattroff() // and wattrset() (do bit OR with colour attributes). #define A_NORMAL 0x0000 // Binary 00 #define A_HIGH 0x4000 // 01 Do not go with BLINK #define A_BLINK 0x8000 // 10 Do not go with HIGH #define A_REVERSE 0xC000 // 11 Overide all others #define A_STANDOUT A_REVERSE // 11 Same as REVERSE // And we have the 3 bits for background colours + 3 bits for foreground // colours. Altogether 8 bits for EGA/VGA colours. These are colour // attributes (not characteristics). They cannot be used with wattron() // until the previous colour attributes have been turned off by wattroff(). // However, wattrset() will always work. #define F_BLACK 0x0000 #define F_BLUE 0x0100 #define F_GREEN 0x0200 #define F_CYAN 0x0300 #define F_RED 0x0400 #define F_MAGENTA 0x0500 #define F_BROWN 0x0600 #define F_GRAY 0x0700 #define B_BLACK 0x0000 #define B_BLUE 0x0800 #define B_GREEN 0x1000 #define B_CYAN 0x1800 #define B_RED 0x2000 #define B_MAGENTA 0x2800 #define B_BROWN 0x3000 #define B_GRAY 0x3800 Colour implementation --------------------- The implementation of colours is not straigh forward. We have to look at how EGA/VGA mode work. For every character there is an attribute byte of 8 bits Bits : 7 654 3210 BBB FFFF ^ ^ ^ | | | The four bits for foreground colours (16) | | The three bits for background colours (7) | The blinking bit. It is obvious that all attributes for curses must make use of the colours to implement them appropriately. However I also see that the attributes like REVERSE VIDEO or HIGH INTENSITY should exist all the time regardless what colours are being used. I had to struggle to make the best use of the 8 bits. I have devised a scheme of 2 bits for characteristics and 3 bits for each of the foreground and background colours. Bits : 76 543 210 BBB FFF ^ ^ ^ | | | The three bits for foreground colours (16) | | The three bits for background colours (7) | The characteristics 2 bits. In this scheme the two characteristics bits give 4 combinations which are allocated for A_NORMAL, A_HIGH, A_BLINK and A_REVERSE. I define A_STANDOUT the same as A_REVERSE. The attributes A_HIGH and A_REVERSE are not compatible. A_REVERSE is binary 11 and A_HIGH is 01. This means when you use A_REVERSE, A_HIGH is not available. The A_HIGH bit when used will shift the 8 foreground colours into the next 8 colours in the EGA/VGA colour table. This is how I implement the colours for this version of curses to get 16 colours. // End of colours.txt