1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
38 ** The routines overlay(), copywin(), and overwrite().
42 #include <curses.priv.h>
44 MODULE_ID("$Id: lib_overlay.c,v 1.12 1998/02/11 12:13:59 tom Exp $")
46 static int overlap(const WINDOW *const s, WINDOW *const d, int const flag)
48 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
50 T(("overlap : sby %d, sbx %d, smy %d, smx %d, dby %d, dbx %d, dmy %d, dmx %d",
51 s->_begy, s->_begx, s->_maxy, s->_maxx,
52 d->_begy, d->_begx, d->_maxy, d->_maxx));
57 sminrow = max(s->_begy, d->_begy) - s->_begy;
58 smincol = max(s->_begx, d->_begx) - s->_begx;
59 dminrow = max(s->_begy, d->_begy) - d->_begy;
60 dmincol = max(s->_begx, d->_begx) - d->_begx;
61 dmaxrow = min(s->_maxy+s->_begy, d->_maxy+d->_begy) - d->_begy;
62 dmaxcol = min(s->_maxx+s->_begx, d->_maxx+d->_begx) - d->_begx;
65 sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol,
71 ** overlay(win1, win2)
74 ** overlay() writes the overlapping area of win1 behind win2
75 ** on win2 non-destructively.
79 int overlay(const WINDOW *win1, WINDOW *win2)
81 T((T_CALLED("overlay(%p,%p)"), win1, win2));
82 returnCode(overlap(win1, win2, TRUE));
87 ** overwrite(win1, win2)
90 ** overwrite() writes the overlapping area of win1 behind win2
91 ** on win2 destructively.
95 int overwrite(const WINDOW *win1, WINDOW *win2)
97 T((T_CALLED("overwrite(%p,%p)"), win1, win2));
98 returnCode(overlap(win1, win2, FALSE));
101 int copywin(const WINDOW *src, WINDOW *dst,
102 int sminrow, int smincol,
103 int dminrow, int dmincol, int dmaxrow, int dmaxcol,
108 chtype bk = AttrOf(dst->_bkgd);
109 chtype mask = ~(chtype)((bk&A_COLOR) ? A_COLOR : 0);
111 T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
112 src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
117 /* make sure rectangle exists in source */
118 if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) ||
119 (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) {
123 T(("rectangle exists in source"));
125 /* make sure rectangle fits in destination */
126 if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) {
130 T(("rectangle fits in destination"));
132 for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) {
134 for(dx=dmincol, sx=smincol; dx <= dmaxcol; sx++, dx++)
138 if ((TextOf(src->_line[sy].text[sx]) != ' ') &&
139 (dst->_line[dy].text[dx]!=src->_line[sy].text[sx]))
141 dst->_line[dy].text[dx] =
142 (src->_line[sy].text[sx] & mask) | bk;
147 if (dst->_line[dy].text[dx] != src->_line[sy].text[sx])
149 dst->_line[dy].text[dx] = src->_line[sy].text[sx];
156 touchline(dst,0,getmaxy(dst));
159 T(("finished copywin"));