home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CURS13_2.ZIP / OVERLAY.C < prev    next >
Text File  |  1989-12-08  |  4KB  |  148 lines

  1. /****************************************************************/
  2. /* Overlay() and overwrite() functions 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 to make it public domain.    */
  9. /*        Bjorn Larsson (...mcvax!enea!infovax!bl)    */
  10. /****************************************************************/
  11. /* 1.0:    Release:                    870515    */
  12. /* 1.2:    Max limits off by 1. Fixed thanks to S. Creps:    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_overlay_rcsid[] = "@(#)overlay.c v1.3 - 881005";
  20.  
  21. /****************************************************************/
  22. /* Overlay() overwrites 'win1' upon 'win2', with origins alig-    */
  23. /* ned. Overlay is transparent; blanks from 'win1' are not    */
  24. /* copied to 'win2'.                        */
  25. /****************************************************************/
  26.  
  27. void overlay(win1, win2)
  28.   WINDOW    *win1, *win2;
  29.   {
  30.   int        *minchng;
  31.   int        *maxchng;
  32.   int        *w1ptr;
  33.   int        *w2ptr;
  34.   int         attrs;
  35.   int         col;
  36.   int         line;
  37.   int         last_line;
  38.   int         last_col;
  39.  
  40.   last_col = min(win1->_maxx, win2->_maxx) - 1;
  41.   last_line = min(win1->_maxy, win2->_maxy) - 1;
  42.   attrs = win2->_attrs & ATR_MSK;
  43.   minchng = win2->_minchng;
  44.   maxchng = win2->_maxchng;
  45.  
  46.   for(line = 0;  line <= last_line;  line++)
  47.     {
  48.     register short   fc, lc;
  49.     w1ptr = win1->_line[line];
  50.     w2ptr = win2->_line[line];
  51.     fc = _NO_CHANGE;
  52.     for(col = 0;  col <= last_col;  col++)
  53.       {
  54.       if ((*w1ptr & CHR_MSK) != ' ')
  55.     {
  56.     *w2ptr = (*w1ptr & CHR_MSK) | attrs;
  57.     if (fc == _NO_CHANGE)
  58.       fc = col;
  59.     lc = col;
  60.     } /* if */
  61.       w1ptr++;
  62.       w2ptr++;
  63.       } /* for */
  64.  
  65.     if (*minchng == _NO_CHANGE)
  66.       {
  67.       *minchng = fc;
  68.       *maxchng = lc;
  69.       } /* if */
  70.     else
  71.       if (fc != _NO_CHANGE)
  72.     {
  73.     if (fc < *minchng)
  74.       *minchng = fc;
  75.     if (lc > *maxchng)
  76.       *maxchng = lc;
  77.     } /* else if */
  78.     minchng++;
  79.     maxchng++;
  80.     } /* for */
  81.   } /* overlay */
  82.  
  83. /****************************************************************/
  84. /* Overwrite() overwrites 'win1' upon 'win2', with origins    */
  85. /* aligned. Overwrite is non-transparent; blanks from 'win1'    */
  86. /* are copied to 'win2'.                    */
  87. /****************************************************************/
  88.  
  89. void    overwrite(win1, win2)
  90.   WINDOW    *win1, *win2;
  91.   {
  92.   int        *minchng;
  93.   int        *maxchng;
  94.   int        *w1ptr;
  95.   int        *w2ptr;
  96.   int         attrs;
  97.   int         col;
  98.   int         line;
  99.   int         last_line;
  100.   int         last_col;
  101.  
  102.   last_col = min(win1->_maxx, win2->_maxx) - 1;
  103.   last_line = min(win1->_maxy, win2->_maxy) - 1;
  104.   attrs = win2->_attrs & ATR_MSK;
  105.   minchng = win2->_minchng;
  106.   maxchng = win2->_maxchng;
  107.  
  108.   for(line = 0;  line <= last_line;  line++)
  109.     {
  110.     register short   fc, lc;
  111.  
  112.     w1ptr = win1->_line[line];
  113.     w2ptr = win2->_line[line];
  114.     fc = _NO_CHANGE;
  115.  
  116.     for(col = 0;  col <= last_col;  col++)
  117.       {
  118.       if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK))
  119.     {
  120.     *w2ptr = (*w1ptr & CHR_MSK) | attrs;
  121.  
  122.     if (fc == _NO_CHANGE)
  123.       fc = col;
  124.     lc = col;
  125.     } /* if */
  126.  
  127.       w1ptr++;
  128.       w2ptr++;
  129.       } /* for */
  130.  
  131.     if (*minchng == _NO_CHANGE)
  132.       {
  133.       *minchng = fc;
  134.       *maxchng = lc;
  135.       } /* if */
  136.     else
  137.       if (fc != _NO_CHANGE)
  138.     {
  139.     if (fc < *minchng)
  140.       *minchng = fc;
  141.     if (lc > *maxchng)
  142.       *maxchng = lc;
  143.     } /* else if */
  144.     minchng++;
  145.     maxchng++;
  146.     } /* for */
  147.   } /* overwrite */
  148.