xref: /original-bsd/lib/libcurses/toucholap.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[] = "@(#)toucholap.c	8.2 (Berkeley) 05/04/94";
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 	__CTRACE("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 	__CTRACE("touchoverlap: from (%d,%d) to (%d,%d)\n",
33 	    starty, startx, endy, endx);
34 	__CTRACE("touchoverlap: win1 (%d,%d) to (%d,%d)\n",
35 	    win1->begy, win1->begx, win1->begy + win1->maxy,
36 	    win1->begx + win1->maxx);
37 	__CTRACE("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, 0);
49 	return (OK);
50 }
51 
52