home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / cursesp.zip / OVERLAY.C < prev    next >
C/C++ Source or Header  |  1991-12-03  |  5KB  |  155 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 (bl@infovox.se)    */
  10. /****************************************************************/
  11. /* 1.4:  Overlaying window will not line up with over-        */
  12. /*     layed window's origin, but at it's 'own' origin    */
  13. /*     relative to the overlayed's origin. Use of int    */
  14. /*     wherever possible. Portability improvements:    900114    */
  15. /* 1.3:     MSC -W3, Turbo'C' -w -w-pro checks:        881005    */
  16. /* 1.2:     Max limits off by 1. Fixed thanks to S. Creps:    881002    */
  17. /* 1.0:     Release:                    870515    */
  18. /****************************************************************/
  19.  
  20. #include <curses.h>
  21. #include <curspriv.h>
  22.  
  23. char _curses_overlay_rcsid[] = "@(#)overlay.c    v.1.4  - 900114";
  24.  
  25. /****************************************************************/
  26. /* Overlay() overwrites 'win1' upon 'win2', with 'win1' appea-    */
  27. /* ring in 'win2' at it own origin relative to 'win2's origin.    */
  28. /* This is a departure, but a desirable one, from the initial    */
  29. /* definition of this function. Overlay is transparent; blanks    */
  30. /* from 'win1' are not copied to 'win2'.            */
  31. /****************************************************************/
  32.  
  33. void overlay(WINDOW *win1, WINDOW *win2)
  34.   {
  35.   register  int        *minchng;
  36.   register  int        *maxchng;
  37.   register  int        *w1ptr;
  38.   register  int        *w2ptr;
  39.   int         attrs;
  40.   int         col;
  41.   int         line;
  42.   int         last_line;
  43.   int         last_col;
  44.  
  45.   last_col = min(win1->_maxx + win1->_begx, win2->_maxx) - 1;
  46.   last_line = min(win1->_maxy + win1->_begy, win2->_maxy) - 1;
  47.   attrs = win2->_attrs & ATR_MSK;
  48.   minchng = win2->_minchng + win1->_begy;
  49.   maxchng = win2->_maxchng + win1->_begy;
  50.  
  51.   for(line = win1->_begy;  line <= last_line;  line++)
  52.     {
  53.     register int   fc, lc;
  54.  
  55.     w1ptr = win1->_line[line - win1->_begy];
  56.     w2ptr = win2->_line[line] + win1->_begx;
  57.     fc = _NO_CHANGE;
  58.  
  59.     for(col = win1->_begx;  col <= last_col;  col++)
  60.       {
  61.       if ((*w1ptr & CHR_MSK) != ' ')
  62.     {
  63.     *w2ptr = (*w1ptr & CHR_MSK) | attrs;
  64.     if (fc == _NO_CHANGE)
  65.       fc = col;
  66.     lc = col;
  67.     } /* if */
  68.       w1ptr++;
  69.       w2ptr++;
  70.       } /* for */
  71.  
  72.     if (*minchng == _NO_CHANGE)
  73.       {
  74.       *minchng = fc;
  75.       *maxchng = lc;
  76.       } /* if */
  77.     else
  78.       if (fc != _NO_CHANGE)
  79.     {
  80.     if (fc < *minchng)
  81.       *minchng = fc;
  82.     if (lc > *maxchng)
  83.       *maxchng = lc;
  84.     } /* else if */
  85.     minchng++;
  86.     maxchng++;
  87.     } /* for */
  88.   } /* overlay */
  89.  
  90. /****************************************************************/
  91. /* Overwrite() overwrites 'win1' upon 'win2', with 'win1' ap-    */
  92. /* pearing in 'win2' at it own origin relative to 'win2's ori-    */
  93. /* gin. This is a departure, but a desirable one, from the    */
  94. /* initial definition of this function. Overwrite is non-trans-    */
  95. /* parent; blanks from 'win1' are copied to 'win2'.        */
  96. /****************************************************************/
  97.  
  98. void    overwrite(win1, win2)
  99.   WINDOW    *win1, *win2;
  100.   {
  101.   register  int        *minchng;
  102.   register  int        *maxchng;
  103.   register  int        *w1ptr;
  104.   register  int        *w2ptr;
  105.   int         attrs;
  106.   int         col;
  107.   int         line;
  108.   int         last_line;
  109.   int         last_col;
  110.  
  111.   last_col = min(win1->_maxx + win1->_begx, win2->_maxx) - 1;
  112.   last_line = min(win1->_maxy + win1->_begy, win2->_maxy) - 1;
  113.   attrs = win2->_attrs & ATR_MSK;
  114.   minchng = win2->_minchng + win1->_begy;
  115.   maxchng = win2->_maxchng + win1->_begy;
  116.  
  117.   for(line = win1->_begy;  line <= last_line;  line++)
  118.     {
  119.     register int   fc, lc;
  120.  
  121.     w1ptr = win1->_line[line - win1->_begy];
  122.     w2ptr = win2->_line[line] + win1->_begx;
  123.     fc = _NO_CHANGE;
  124.  
  125.     for(col = win1->_begx;  col <= last_col;  col++)
  126.       {
  127.       if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK))
  128.     {
  129.     *w2ptr = (*w1ptr & CHR_MSK) | attrs;
  130.     if (fc == _NO_CHANGE)
  131.       fc = col;
  132.     lc = col;
  133.     } /* if */
  134.       w1ptr++;
  135.       w2ptr++;
  136.       } /* for */
  137.  
  138.     if (*minchng == _NO_CHANGE)
  139.       {
  140.       *minchng = fc;
  141.       *maxchng = lc;
  142.       } /* if */
  143.     else
  144.       if (fc != _NO_CHANGE)
  145.     {
  146.     if (fc < *minchng)
  147.       *minchng = fc;
  148.     if (lc > *maxchng)
  149.       *maxchng = lc;
  150.     } /* else if */
  151.     minchng++;
  152.     maxchng++;
  153.     } /* for */
  154.   } /* overwrite */
  155.