home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / cursesp.zip / ATTRIB.C next >
C/C++ Source or Header  |  1991-12-03  |  6KB  |  171 lines

  1. /****************************************************************/
  2. /* Character attribute routines of the PCcurses package         */
  3. /*                                                              */
  4. /****************************************************************/
  5. /* This version of curses is based on ncurses, a curses version */
  6. /* originally written by Pavel Curtis at Cornell University.    */
  7. /* I have made substantial changes to make it run on IBM PC's,  */
  8. /* and therefore consider myself free make it public domain.    */
  9. /*              Bjorn Larsson (...mcvax!enea!infovax!bl)        */
  10. /****************************************************************/
  11. /* 1.0: Release:                                        870515  */
  12. /* 1.2: Rcsid[] string for maintenance:                 881002  */
  13. /* 1.3: MSC -W3, Turbo'C' -w -w-pro checkes:            881005  */
  14. /****************************************************************/
  15.  
  16. #include <curses.h>
  17. #include <curspriv.h>
  18.  
  19. char _curses_attrib_rcsid[] = "@(#)attrib.c v1.3 - 881005";
  20.  
  21. /*  Translate the attributes code into EGA/VGA attributes */
  22.  
  23. void translate_attrs(int attrs, int *ega_attrs)
  24. {
  25.   int  tmp;
  26.   int  bg = ((attrs >> 11) & 0x07);
  27.   int  fg = ((attrs >> 8)  & 0x07);
  28.   int  md = ((attrs >> 14) & 0x03);
  29.  
  30.   switch(md)
  31.   {
  32.   case  (A_HIGH >> 14) & 0x03:
  33.     fg += 8;
  34.     md = 0;
  35.     break;
  36.   case  (A_REVERSE >> 14) & 0x03:
  37.         tmp = bg;
  38.     bg = fg;
  39.     fg = tmp;
  40.     md = 0;
  41.     break;
  42.   case  (A_BLINK >> 14) & 0x03:
  43.     md = 1;
  44.   }
  45.   *ega_attrs = ((md <<15)&0x8000) | (bg << 12) | (fg << 8);
  46. }
  47.  
  48. /****************************************************************/
  49. /* Wattrset() sets the attributes as specified in window 'win'. */
  50. /****************************************************************/
  51.  
  52. void wattrset(WINDOW *win, int attrs)
  53.   {
  54.   int   ega_attrs;
  55.  
  56.   if(attrs != A_NORMAL)
  57.       translate_attrs(attrs, &ega_attrs);
  58.   else
  59.       ega_attrs = (B_BLACK < 1) | F_GRAY;
  60.   win->_attrs = ega_attrs & ATR_MSK;
  61.   } /* wattrset */
  62.  
  63. /****************************************************************/
  64. /* Wattron() sets the specified attribute(s) in window 'win'.   */
  65. /****************************************************************/
  66.  
  67. void    wattron(WINDOW *win, int attrs)
  68.   {
  69.   int  tmp;
  70.   int  bg = ((attrs >> 11) & 0x07);
  71.   int  fg = ((attrs >> 8)  & 0x07);
  72.   int  md = ((attrs >> 14) & 0x03);
  73.                         
  74.   if(fg == 0)           //  Use old colours if new colours not requested
  75.         fg = (win->_attrs >> 8)  & 0x7;
  76.   if(bg == 0)
  77.         bg = (win->_attrs >> 12) & 0x7;
  78.  
  79.   switch(md)            // Change in characteristics ?
  80.   {
  81.   case  (A_HIGH >> 14) & 0x03:
  82.         fg |= 0x08;
  83.         break;
  84.   case  (A_REVERSE >> 14) & 0x03:
  85.         tmp = bg;
  86.         bg  = fg;
  87.         fg  = tmp;
  88.         md  = 0;
  89.         break;
  90.   case  (A_BLINK >> 14) & 0x03:
  91.         md = 1;
  92.   }
  93.   win->_attrs =  ((md<<15)&0x8000) | (bg<<12) | (fg<<8);
  94.   } /* wattron */
  95.  
  96. /****************************************************************/
  97. /* Wattroff() clears the specified attribute(s) in window       */
  98. /* 'win'.                                                       */
  99. /****************************************************************/
  100.  
  101. void    wattroff(WINDOW *win, int attrs)
  102.   {
  103.   int  ega_attrs;
  104.  
  105.   translate_attrs(attrs, &ega_attrs);
  106.   win->_attrs &= (~ega_attrs & ATR_MSK);
  107.   } /* wattroff */
  108.  
  109. /****************************************************************/
  110. /* Wstandout() starts standout mode in window 'win'.            */
  111. /****************************************************************/
  112.  
  113. void    wstandout(WINDOW *win)
  114.   {
  115.   wattron(win, A_STANDOUT);
  116.   } /* wstandout */
  117.  
  118. /****************************************************************/
  119. /* Wstandend() clears all special attributes in window 'win'.   */
  120. /****************************************************************/
  121.  
  122. void    wstandend(WINDOW *win)
  123.   {
  124.   wattroff(win, A_STANDOUT);
  125.   } /* wstandend */
  126.  
  127. /****************************************************************/
  128. /* Attrset() sets the attributes as specified in stdscr.        */
  129. /****************************************************************/
  130.  
  131. void    attrset(int attrs)
  132.   {
  133.   wattrset(stdscr, attrs);
  134.   } /* attrset */
  135.  
  136. /****************************************************************/
  137. /* Attron() sets the specified attribute(s) in stdscr.          */
  138. /****************************************************************/
  139.  
  140. void    attron(int attrs)
  141.   {
  142.   wattron(stdscr, attrs);
  143.   } /* attron */
  144.  
  145. /****************************************************************/
  146. /* Attroff() clears the specified attribute(s) in stdscr.       */
  147. /****************************************************************/
  148.  
  149. void    attroff(int attrs)
  150.   {
  151.   wattroff(stdscr, attrs);
  152.   } /* attroff */
  153.  
  154. /****************************************************************/
  155. /* Standout() starts standout mode in stdscr.                   */
  156. /****************************************************************/
  157.  
  158. void    standout()
  159.   {
  160.   wattron(stdscr, A_STANDOUT);
  161.   } /* standout */
  162.  
  163. /****************************************************************/
  164. /* Standend() clears all special attributes in stdscr.          */
  165. /****************************************************************/
  166.  
  167. void    standend(void)
  168.   {
  169.   wattroff(stdscr, A_STANDOUT);
  170.   } /* standend */
  171.