home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / cursesp.zip / COLOURS.TXT < prev    next >
Text File  |  1991-12-03  |  6KB  |  150 lines

  1.  
  2. COLOUR in PC curses (ANSI-C and BorlandC++ compatible)
  3.  
  4. This version of PC curses supports EGA/VGA colours. The old 
  5. curses on UNIX only supports a few attributes such as STANDOUT, 
  6. REVERSE VIDEO ...
  7.  
  8. The PC curses 1.3 only support a few momochrome attributes. 
  9. For this version I have worked out a scheme for colour support. 
  10. This scheme may not be totally compatible with the ideas behind 
  11. the curses for UNIX, but it will be comfortable to use. Firstly
  12. it strikes me that the attributes of UNIX curses are independent
  13. of one another. This means you can turn many on at the same time,
  14. one at a time and turn off them in a similar fashion. When I 
  15. see how EGA/VGA handles text colour, the game is very different.
  16.  
  17. This is my colour scheme for this copy of pc curses
  18.  
  19. There are two classes of attributes defined.
  20.  
  21.   + Characteristics : NORMAL, HIGH, REVERSE and
  22.     STANDOUT. These are used to control the way
  23.     the screen look.
  24.   + Foreground and Background colour attributes for text.
  25.  
  26. The main routine to set attributes is 
  27.     
  28.     wattrset(WINDOW *win, int attrs)
  29.  
  30. This routine set the attributes which are supplied as a bit-OR 
  31. of many flags. For example, to get the blue background, white 
  32. characters and high intensity video you can use
  33.  
  34.         (F_GRAY | B_BLUE | A_HIGH)
  35.  
  36.     which form a 16 bit unsigned integer.
  37.  
  38. How the colours work
  39. --------------------
  40.   Here is the section for users who do not want to know details
  41. about technical implementation. The routines for controlling colours
  42. and other video characteristics are. These routines are in scrutiny
  43. until I am sastisfied that they are useful and according to common 
  44. sense.
  45.  
  46.   - wattrset(WINDOW *win, int attrs)
  47.   - wattron (WINDOW *win, int attrs)
  48.   - wattroff(WINDOW *win, int attrs)
  49.  
  50.   The most useful function is wattrset(). It set the combination of 
  51. attributes you desire. Most of the time you will use it without
  52. worrying about the other routines.
  53.  
  54.   wattron() is implemented to common sense unlike the UNIX version
  55. of curses. It does more than a simple OR to turn bits on. Here is
  56. what it does
  57.  
  58.   - Turn an attribute(s) on by all means. 
  59.  
  60.     Examples:
  61.         wattron(F_RED)              turn RED colour on
  62.         wattron(B_GRAY | F_RED)     turn RED colour on GRAY background
  63.         wattron(A_BLINK)            turn BLINK mode on
  64.  
  65.   - It keeps the old attributes intact if there is no conflict. This
  66.     means only conflict in colours results in an overriding of the
  67.     old colour. The rest is kept intact.
  68.  
  69. Technical notes
  70. ===============
  71.  
  72. Here is the set of all attributes. It is an extract from the header 
  73. file curses.h
  74.  
  75. // We will have 2 leftmost bits for attributes. These attributes are
  76. // not colour attributes. They are to be used with wattron(), wattroff()
  77. // and wattrset() (do bit OR with colour attributes). 
  78.  
  79. #define A_NORMAL    0x0000      //  Binary  00
  80. #define A_HIGH      0x4000      //          01  Do not go with BLINK
  81. #define A_BLINK     0x8000      //          10  Do not go with HIGH
  82. #define A_REVERSE   0xC000      //          11  Overide all others
  83. #define A_STANDOUT  A_REVERSE   //          11  Same as REVERSE
  84.  
  85. // And we have the 3 bits for background colours + 3 bits for foreground
  86. // colours. Altogether 8 bits for EGA/VGA colours. These are colour
  87. // attributes (not characteristics). They cannot be used with wattron()
  88. // until the previous colour attributes have been turned off by wattroff().
  89. // However, wattrset() will always work. 
  90.  
  91. #define F_BLACK         0x0000
  92. #define F_BLUE          0x0100
  93. #define F_GREEN         0x0200
  94. #define F_CYAN          0x0300
  95. #define F_RED           0x0400
  96. #define F_MAGENTA       0x0500
  97. #define F_BROWN         0x0600
  98. #define F_GRAY          0x0700
  99.  
  100. #define B_BLACK         0x0000
  101. #define B_BLUE          0x0800
  102. #define B_GREEN         0x1000
  103. #define B_CYAN          0x1800
  104. #define B_RED           0x2000
  105. #define B_MAGENTA       0x2800
  106. #define B_BROWN         0x3000
  107. #define B_GRAY          0x3800
  108.  
  109. Colour implementation
  110. ---------------------
  111.   The implementation of colours is not straigh forward. We have to 
  112. look at how EGA/VGA mode work. For every character there is an
  113. attribute byte of 8 bits
  114.  
  115.         Bits :    7  654  3210
  116.                      BBB  FFFF
  117.                   ^   ^    ^
  118.                   |   |    | The four bits for foreground colours (16)
  119.                   |   | The three bits for background colours (7)
  120.                   | The blinking bit.
  121.  
  122.   It is obvious that all attributes for curses must make use of the
  123. colours to implement them appropriately. However I also see that 
  124. the attributes like REVERSE VIDEO or HIGH INTENSITY should exist
  125. all the time regardless what colours are being used. 
  126.  
  127.    I had to struggle to make the best use of the 8 bits. I have 
  128. devised a scheme of 2 bits for characteristics and 3 bits for each
  129. of the foreground and background colours.
  130.  
  131.         Bits :    76 543 210
  132.                      BBB FFF
  133.                   ^   ^   ^
  134.                   |   |   | The three bits for foreground colours (16)
  135.                   |   | The three bits for background colours (7)
  136.                   | The characteristics 2 bits.
  137.  
  138. In this scheme the two characteristics bits give 4 combinations
  139. which are allocated for A_NORMAL, A_HIGH, A_BLINK and A_REVERSE. I 
  140. define A_STANDOUT the same as A_REVERSE. The attributes A_HIGH and 
  141. A_REVERSE are not compatible. A_REVERSE is binary  11  and A_HIGH is  
  142. 01. This means when you use A_REVERSE, A_HIGH is not available.
  143.  
  144. The A_HIGH bit when used will shift the 8 foreground colours into
  145. the next 8 colours in the EGA/VGA colour table. This is how I 
  146. implement the colours for this version of curses to get 16 colours. 
  147.  
  148. // End of colours.txt
  149.  
  150.