1 /****************************************************************************
2 * Copyright (c) 1998,2000,2001 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 ****************************************************************************/
37 ** The routines overlay(), copywin(), and overwrite().
41 #include <curses.priv.h>
43 MODULE_ID("$Id: lib_overlay.c,v 1.20 2001/12/19 01:06:37 tom Exp $")
46 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.
80 overlay(const WINDOW *win1, WINDOW *win2)
82 T((T_CALLED("overlay(%p,%p)"), win1, win2));
83 returnCode(overlap(win1, win2, TRUE));
88 ** overwrite(win1, win2)
91 ** overwrite() writes the overlapping area of win1 behind win2
92 ** on win2 destructively.
97 overwrite(const WINDOW *win1, WINDOW *win2)
99 T((T_CALLED("overwrite(%p,%p)"), win1, win2));
100 returnCode(overlap(win1, win2, FALSE));
105 (const WINDOW *src, WINDOW *dst,
106 int sminrow, int smincol,
107 int dminrow, int dmincol, int dmaxrow, int dmaxcol,
112 attr_t bk = AttrOf(dst->_nc_bkgd);
113 attr_t mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0);
115 T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
116 src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
121 /* make sure rectangle exists in source */
122 if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) ||
123 (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) {
127 T(("rectangle exists in source"));
129 /* make sure rectangle fits in destination */
130 if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) {
134 T(("rectangle fits in destination"));
136 for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) {
138 for (dx = dmincol, sx = smincol; dx <= dmaxcol; sx++, dx++) {
140 if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
141 (!CharEq(dst->_line[dy].text[dx], src->_line[sy].text[sx]))) {
142 dst->_line[dy].text[dx] = src->_line[sy].text[sx];
143 SetAttr(dst->_line[dy].text[dx],
144 (AttrOf(src->_line[sy].text[sx]) & mask) | bk);
148 if (!CharEq(dst->_line[dy].text[dx], src->_line[sy].text[sx])) {
149 dst->_line[dy].text[dx] = src->_line[sy].text[sx];
155 touchline(dst, 0, getmaxy(dst));
158 T(("finished copywin"));