xref: /illumos-gate/usr/src/ucblib/libcurses/overlay.c (revision 0250c53ad267726f2438e3c6556199a0bbf588a2)
1 /*
2  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved.  The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 /*LINTLIBRARY*/
16 
17 #ifndef lint
18 static char
19 sccsid[] = "@(#)overlay.c 1.9 89/07/13 SMI"; /* from UCB 5.2 86/02/12 */
20 #endif /* not lint */
21 
22 #include	"curses.ext"
23 #include	<ctype.h>
24 
25 #define	min(a, b)	((a) < (b) ? (a) : (b))
26 #define	max(a, b)	((a) > (b) ? (a) : (b))
27 
28 /*
29  *	This routine writes win1 on win2 non-destructively.
30  */
31 
32 int
33 overlay(WINDOW *win1, WINDOW *win2)
34 {
35 	char	*sp, *end;
36 	int	x, y, endy, endx, starty, startx;
37 	int 	y1, y2;
38 
39 #ifdef DEBUG
40 	fprintf(outf, "OVERLAY(%0.2o, %0.2o);\n", win1, win2);
41 #endif
42 	starty = max(win1->_begy, win2->_begy);
43 	startx = max(win1->_begx, win2->_begx);
44 	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy);
45 	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
46 #ifdef DEBUG
47 	fprintf(outf, "OVERLAY:from (%d,%d) to (%d,%d)\n",
48 	    starty, startx, endy, endx);
49 #endif
50 	if (starty >= endy || startx >= endx)
51 		return (OK);
52 	y1 = starty - win1->_begy;
53 	y2 = starty - win2->_begy;
54 	for (y = starty; y < endy; y++, y1++, y2++) {
55 		end = &win1->_y[y1][endx - win1->_begx];
56 		x = startx - win2->_begx;
57 		for (sp = &win1->_y[y1][startx - win1->_begx]; sp < end; sp++) {
58 			if (!isspace(*sp))
59 				(void) mvwaddch(win2, y2, x, *sp);
60 			x++;
61 		}
62 	}
63 	return (OK);
64 }
65