1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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.27 2008/06/07 23:30:34 tom Exp $")
46 overlap(const WINDOW *const src, WINDOW *const dst, int const flag)
49 int sx1, sy1, sx2, sy2;
50 int dx1, dy1, dx2, dy2;
55 T((T_CALLED("overlap(%p,%p,%d)"), src, dst, flag));
57 if (src != 0 && dst != 0) {
58 _nc_lock_global(curses);
60 T(("src : begy %ld, begx %ld, maxy %ld, maxx %ld",
65 T(("dst : begy %ld, begx %ld, maxy %ld, maxx %ld",
73 sx2 = sx1 + src->_maxx;
74 sy2 = sy1 + src->_maxy;
78 dx2 = dx1 + dst->_maxx;
79 dy2 = dy1 + dst->_maxy;
81 if (dx2 >= sx1 && dx1 <= sx2 && dy2 >= sy1 && dy1 <= sy2) {
82 sminrow = max(sy1, dy1) - sy1;
83 smincol = max(sx1, dx1) - sx1;
84 dminrow = max(sy1, dy1) - dy1;
85 dmincol = max(sx1, dx1) - dx1;
86 dmaxrow = min(sy2, dy2) - dy1;
87 dmaxcol = min(sx2, dx2) - dx1;
89 rc = copywin(src, dst,
95 _nc_unlock_global(curses);
102 ** overlay(win1, win2)
105 ** overlay() writes the overlapping area of win1 behind win2
106 ** on win2 non-destructively.
111 overlay(const WINDOW *win1, WINDOW *win2)
113 T((T_CALLED("overlay(%p,%p)"), win1, win2));
114 returnCode(overlap(win1, win2, TRUE));
119 ** overwrite(win1, win2)
122 ** overwrite() writes the overlapping area of win1 behind win2
123 ** on win2 destructively.
128 overwrite(const WINDOW *win1, WINDOW *win2)
130 T((T_CALLED("overwrite(%p,%p)"), win1, win2));
131 returnCode(overlap(win1, win2, FALSE));
135 copywin(const WINDOW *src, WINDOW *dst,
136 int sminrow, int smincol,
137 int dminrow, int dmincol,
138 int dmaxrow, int dmaxcol,
147 T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
148 src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
151 _nc_lock_global(curses);
153 bk = AttrOf(dst->_nc_bkgd);
154 mask = ~(attr_t) ((bk & A_COLOR) ? A_COLOR : 0);
156 /* make sure rectangle exists in source */
157 if ((sminrow + dmaxrow - dminrow) <= (src->_maxy + 1) &&
158 (smincol + dmaxcol - dmincol) <= (src->_maxx + 1)) {
160 T(("rectangle exists in source"));
162 /* make sure rectangle fits in destination */
163 if (dmaxrow <= dst->_maxy && dmaxcol <= dst->_maxx) {
165 T(("rectangle fits in destination"));
167 for (dy = dminrow, sy = sminrow;
172 for (dx = dmincol, sx = smincol;
176 if ((CharOf(src->_line[sy].text[sx]) != L(' ')) &&
177 (!CharEq(dst->_line[dy].text[dx],
178 src->_line[sy].text[sx]))) {
179 dst->_line[dy].text[dx] =
180 src->_line[sy].text[sx];
181 SetAttr(dst->_line[dy].text[dx],
182 ((AttrOf(src->_line[sy].text[sx]) &
187 if (!CharEq(dst->_line[dy].text[dx],
188 src->_line[sy].text[sx])) {
189 dst->_line[dy].text[dx] =
190 src->_line[sy].text[sx];
196 touchline(dst, dminrow, (dmaxrow - dminrow + 1));
199 T(("finished copywin"));
203 _nc_unlock_global(curses);