xref: /original-bsd/lib/libcurses/toucholap.c (revision 860e07fc)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)toucholap.c	5.6 (Berkeley) 08/23/92";
10 #endif /* not lint */
11 
12 #include <curses.h>
13 
14 /*
15  * touchoverlap --
16  *	Touch, on win2, the part that overlaps with win1.
17  */
18 int
19 touchoverlap(win1, win2)
20 	register WINDOW *win1, *win2;
21 {
22 	register int y, endy, endx, starty, startx;
23 
24 #ifdef DEBUG
25 	__TRACE("touchoverlap: (%0.2o, %0.2o);\n", win1, win2);
26 #endif
27 	starty = max(win1->_begy, win2->_begy);
28 	startx = max(win1->_begx, win2->_begx);
29 	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
30 	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
31 #ifdef DEBUG
32 	__TRACE("touchoverlap: from (%d,%d) to (%d,%d)\n",
33 	    starty, startx, endy, endx);
34 	__TRACE("touchoverlap: win1 (%d,%d) to (%d,%d)\n",
35 	    win1->_begy, win1->_begx, win1->_begy + win1->_maxy,
36 	    win1->_begx + win1->_maxx);
37 	__TRACE("touchoverlap: win2 (%d,%d) to (%d,%d)\n",
38 	    win2->_begy, win2->_begx, win2->_begy + win2->_maxy,
39 	    win2->_begx + win2->_maxx);
40 #endif
41 	if (starty >= endy || startx >= endx)
42 		return (OK);
43 	starty -= win2->_begy;
44 	startx -= win2->_begx;
45 	endy -= win2->_begy;
46 	endx -= win2->_begx;
47 	for (--endx, y = starty; y < endy; y++)
48 		touchline(win2, y, startx, endx);
49 	return (OK);
50 }
51