xref: /original-bsd/lib/libcurses/toucholap.c (revision 2c7ae287)
1 /*
2  * Copyright (c) 1981 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)toucholap.c	5.2 (Berkeley) 06/08/88";
15 #endif /* not lint */
16 
17 # include	"curses.ext"
18 
19 # define	min(a,b)	(a < b ? a : b)
20 # define	max(a,b)	(a > b ? a : b)
21 
22 /*
23  *	Touch, on win2, the part that overlaps with win1.
24  *
25  */
26 touchoverlap(win1, win2)
27 reg WINDOW	*win1, *win2; {
28 
29 	reg int		x, y, endy, endx, starty, startx;
30 
31 # ifdef DEBUG
32 	fprintf(outf, "TOUCHOVERLAP(%0.2o, %0.2o);\n", win1, win2);
33 # endif
34 	starty = max(win1->_begy, win2->_begy);
35 	startx = max(win1->_begx, win2->_begx);
36 	endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begx);
37 	endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
38 # ifdef DEBUG
39 	fprintf(outf, "TOUCHOVERLAP:from (%d,%d) to (%d,%d)\n", starty, startx, endy, endx);
40 	fprintf(outf, "TOUCHOVERLAP:win1 (%d,%d) to (%d,%d)\n", win1->_begy, win1->_begx, win1->_begy + win1->_maxy, win1->_begx + win1->_maxx);
41 	fprintf(outf, "TOUCHOVERLAP:win2 (%d,%d) to (%d,%d)\n", win2->_begy, win2->_begx, win2->_begy + win2->_maxy, win2->_begx + win2->_maxx);
42 # endif
43 	if (starty >= endy || startx >= endx)
44 		return;
45 	starty -= win2->_begy;
46 	startx -= win2->_begx;
47 	endy -= win2->_begy;
48 	endx -= win2->_begx;
49 	endx--;
50 	for (y = starty; y < endy; y++)
51 		touchline(win2, y, startx, endx);
52 }
53