2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
26 ** The routines overlay(), copywin(), and overwrite().
30 #include <curses.priv.h>
32 MODULE_ID("$Id: lib_overlay.c,v 1.8 1997/04/24 10:34:38 tom Exp $")
34 static int overlap(const WINDOW *const s, WINDOW *const d, int const flag)
36 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
38 T(("overlap : sby %d, sbx %d, smy %d, smx %d, dby %d, dbx %d, dmy %d, dmx %d",
39 s->_begy, s->_begx, s->_maxy, s->_maxx,
40 d->_begy, d->_begx, d->_maxy, d->_maxx));
41 sminrow = max(s->_begy, d->_begy) - s->_begy;
42 smincol = max(s->_begx, d->_begx) - s->_begx;
43 dminrow = max(s->_begy, d->_begy) - d->_begy;
44 dmincol = max(s->_begx, d->_begx) - d->_begx;
45 dmaxrow = min(s->_maxy+s->_begy, d->_maxy+d->_begy) - d->_begy;
46 dmaxcol = min(s->_maxx+s->_begx, d->_maxx+d->_begx) - d->_begx;
49 sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol,
55 ** overlay(win1, win2)
58 ** overlay() writes the overlapping area of win1 behind win2
59 ** on win2 non-destructively.
63 int overlay(const WINDOW *win1, WINDOW *win2)
65 T((T_CALLED("overlay(%p,%p)"), win1, win2));
66 returnCode(overlap(win1, win2, TRUE));
71 ** overwrite(win1, win2)
74 ** overwrite() writes the overlapping area of win1 behind win2
75 ** on win2 destructively.
79 int overwrite(const WINDOW *win1, WINDOW *win2)
81 T((T_CALLED("overwrite(%p,%p)"), win1, win2));
82 returnCode(overlap(win1, win2, FALSE));
85 int copywin(const WINDOW *src, WINDOW *dst,
86 int sminrow, int smincol,
87 int dminrow, int dmincol, int dmaxrow, int dmaxcol,
93 T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
94 src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
96 /* make sure rectangle exists in source */
97 if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) ||
98 (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) {
102 T(("rectangle exists in source"));
104 /* make sure rectangle fits in destination */
105 if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) {
109 T(("rectangle fits in destination"));
111 for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) {
113 for(dx=dmincol, sx=smincol; dx <= dmaxcol; sx++, dx++)
117 if ((TextOf(src->_line[sy].text[sx]) != ' ') &&
118 (dst->_line[dy].text[dx]!=src->_line[sy].text[sx]))
120 dst->_line[dy].text[dx] = src->_line[sy].text[sx];
125 if (dst->_line[dy].text[dx] != src->_line[sy].text[sx])
127 dst->_line[dy].text[dx] = src->_line[sy].text[sx];
134 touchline(dst,0,getmaxy(dst));
137 T(("finished copywin"));