xref: /original-bsd/lib/libcurses/overlay.c (revision f4a18198)
1 /*
2  * Copyright (c) 1981, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)overlay.c	8.2 (Berkeley) 05/04/94";
10 #endif	/* not lint */
11 
12 #include <ctype.h>
13 
14 #include "curses.h"
15 
16 /*
17  * overlay --
18  *	Writes win1 on win2 non-destructively.
19  */
20 int
21 overlay(win1, win2)
22 	register WINDOW *win1, *win2;
23 {
24 
25 	register int x, y, y1, y2, endy, endx, starty, startx;
26 	register __LDATA *sp, *end;
27 
28 #ifdef DEBUG
29 	__CTRACE("overlay: (%0.2o, %0.2o);\n", win1, win2);
30 #endif
31 	starty = max(win1->begy, win2->begy);
32 	startx = max(win1->begx, win2->begx);
33 	endy = min(win1->maxy + win1->begy, win2->maxy + win2->begx);
34 	endx = min(win1->maxx + win1->begx, win2->maxx + win2->begx);
35 #ifdef DEBUG
36 	__CTRACE("overlay: from (%d,%d) to (%d,%d)\n",
37 	    starty, startx, endy, endx);
38 #endif
39 	if (starty >= endy || startx >= endx)
40 		return (OK);
41 	y1 = starty - win1->begy;
42 	y2 = starty - win2->begy;
43 	for (y = starty; y < endy; y++, y1++, y2++) {
44 		end = &win1->lines[y1]->line[endx - win1->begx];
45 		x = startx - win2->begx;
46 		for (sp = &win1->lines[y1]->line[startx - win1->begx];
47 		     sp < end; sp++) {
48 			if (!isspace(sp->ch)) {
49 				wmove(win2, y2, x);
50 				__waddch(win2, sp);
51 			}
52 			x++;
53 		}
54 	}
55 	return (OK);
56 }
57