]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_overlay.c
e63b367272a402e924cdbfe773e74927965946cc
[ncurses.git] / ncurses / lib_overlay.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
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.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22
23 /*
24 **      lib_overlay.c
25 **
26 **      The routines overlay(), copywin(), and overwrite().
27 **
28 */
29
30 #include <curses.priv.h>
31
32 MODULE_ID("$Id: lib_overlay.c,v 1.8 1997/04/24 10:34:38 tom Exp $")
33
34 static int overlap(const WINDOW *const s, WINDOW *const d, int const flag)
35 {
36 int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol;
37
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;
47
48         return(copywin(s, d,
49                        sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol,
50                        flag));
51 }
52
53 /*
54 **
55 **      overlay(win1, win2)
56 **
57 **
58 **      overlay() writes the overlapping area of win1 behind win2
59 **      on win2 non-destructively.
60 **
61 **/
62
63 int overlay(const WINDOW *win1, WINDOW *win2)
64 {
65         T((T_CALLED("overlay(%p,%p)"), win1, win2));
66         returnCode(overlap(win1, win2, TRUE));
67 }
68
69 /*
70 **
71 **      overwrite(win1, win2)
72 **
73 **
74 **      overwrite() writes the overlapping area of win1 behind win2
75 **      on win2 destructively.
76 **
77 **/
78
79 int overwrite(const WINDOW *win1, WINDOW *win2)
80 {
81         T((T_CALLED("overwrite(%p,%p)"), win1, win2));
82         returnCode(overlap(win1, win2, FALSE));
83 }
84
85 int copywin(const WINDOW *src, WINDOW *dst,
86         int sminrow, int smincol,
87         int dminrow, int dmincol, int dmaxrow, int dmaxcol,
88         int over)
89 {
90 int sx, sy, dx, dy;
91 bool touched;
92
93         T((T_CALLED("copywin(%p, %p, %d, %d, %d, %d, %d, %d, %d)"),
94                 src, dst, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, over));
95
96         /* make sure rectangle exists in source */
97         if ((sminrow + dmaxrow - dminrow) > (src->_maxy + 1) ||
98             (smincol + dmaxcol - dmincol) > (src->_maxx + 1)) {
99                 returnCode(ERR);
100         }
101
102         T(("rectangle exists in source"));
103
104         /* make sure rectangle fits in destination */
105         if (dmaxrow > dst->_maxy || dmaxcol > dst->_maxx) {
106                 returnCode(ERR);
107         }
108
109         T(("rectangle fits in destination"));
110
111         for (dy = dminrow, sy = sminrow; dy <= dmaxrow; sy++, dy++) {
112            touched = FALSE;
113            for(dx=dmincol, sx=smincol; dx <= dmaxcol; sx++, dx++)
114            {
115                 if (over)
116                 {
117                    if ((TextOf(src->_line[sy].text[sx]) != ' ') &&
118                        (dst->_line[dy].text[dx]!=src->_line[sy].text[sx]))
119                    {
120                         dst->_line[dy].text[dx] = src->_line[sy].text[sx];
121                         touched = TRUE;
122                    }
123                 }
124                 else {
125                    if (dst->_line[dy].text[dx] != src->_line[sy].text[sx])
126                    {
127                         dst->_line[dy].text[dx] = src->_line[sy].text[sx];
128                         touched = TRUE;
129                    }
130                 }
131            }
132            if (touched)
133            {
134               touchline(dst,0,getmaxy(dst));
135            }
136         }
137         T(("finished copywin"));
138         returnCode(OK);
139 }