ncurses 4.1
[ncurses.git] / ncurses / lib_box.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 /*
25 **      lib_box.c
26 **
27 **      line drawing routines:
28 **      wborder()
29 **      whline()
30 **      wvline()
31 **
32 */
33
34 #include <curses.priv.h>
35
36 MODULE_ID("$Id: lib_box.c,v 1.7 1997/04/12 17:51:49 tom Exp $")
37
38 int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts,
39         chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
40 {
41 short i;
42 short endx, endy;
43
44     T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
45         win,
46         _tracechtype2(1,ls),
47         _tracechtype2(2,rs),
48         _tracechtype2(3,ts),
49         _tracechtype2(4,bs),
50         _tracechtype2(5,tl),
51         _tracechtype2(6,tr),
52         _tracechtype2(7,bl),
53         _tracechtype2(8,br)));
54
55         if (ls == 0) ls = ACS_VLINE;
56         if (rs == 0) rs = ACS_VLINE;
57         if (ts == 0) ts = ACS_HLINE;
58         if (bs == 0) bs = ACS_HLINE;
59         if (tl == 0) tl = ACS_ULCORNER;
60         if (tr == 0) tr = ACS_URCORNER;
61         if (bl == 0) bl = ACS_LLCORNER;
62         if (br == 0) br = ACS_LRCORNER;
63
64         ls = _nc_render(win, ls);
65         rs = _nc_render(win, rs);
66         ts = _nc_render(win, ts);
67         bs = _nc_render(win, bs);
68         tl = _nc_render(win, tl);
69         tr = _nc_render(win, tr);
70         bl = _nc_render(win, bl);
71         br = _nc_render(win, br);
72
73         T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx", ls, rs, ts, bs, tl, tr, bl, br));
74
75         endx = win->_maxx;
76         endy = win->_maxy;
77
78         for (i = 0; i <= endx; i++) {
79                 win->_line[0].text[i] = ts;
80                 win->_line[endy].text[i] = bs;
81         }
82         win->_line[endy].firstchar = win->_line[0].firstchar = 0;
83         win->_line[endy].lastchar = win->_line[0].lastchar = endx;
84
85         for (i = 0; i <= endy; i++) {
86                 win->_line[i].text[0] =  ls;
87                 win->_line[i].text[endx] =  rs;
88                 win->_line[i].firstchar = 0;
89                 win->_line[i].lastchar = endx;
90         }
91         win->_line[0].text[0] = tl;
92         win->_line[0].text[endx] = tr;
93         win->_line[endy].text[0] = bl;
94         win->_line[endy].text[endx] = br;
95
96         _nc_synchook(win);
97         returnCode(OK);
98 }
99
100 int whline(WINDOW *win, chtype ch, int n)
101 {
102 short line;
103 short start;
104 short end;
105
106         T((T_CALLED("whline(%p,%s,%d)"), win, _tracechtype(ch), n));
107
108         line = win->_cury;
109         start = win->_curx;
110         end = start + n - 1;
111         if (end > win->_maxx)
112                 end = win->_maxx;
113
114         if (win->_line[line].firstchar == _NOCHANGE || win->_line[line].firstchar > start)
115                 win->_line[line].firstchar = start;
116         if (win->_line[line].lastchar == _NOCHANGE || win->_line[line].lastchar < start)
117                 win->_line[line].lastchar = end;
118
119         if (ch == 0)
120                 ch = ACS_HLINE;
121         ch = _nc_render(win, ch);
122
123         while ( end >= start) {
124                 win->_line[line].text[end] = ch;
125                 end--;
126         }
127
128         returnCode(OK);
129 }
130
131 int wvline(WINDOW *win, chtype ch, int n)
132 {
133 short row, col;
134 short end;
135
136         T((T_CALLED("wvline(%p,%s,%d)"), win, _tracechtype(ch), n));
137
138         row = win->_cury;
139         col = win->_curx;
140         end = row + n - 1;
141         if (end > win->_maxy)
142                 end = win->_maxy;
143
144         if (ch == 0)
145                 ch = ACS_VLINE;
146         ch = _nc_render(win, ch);
147
148         while(end >= row) {
149                 win->_line[end].text[col] = ch;
150                 if (win->_line[end].firstchar == _NOCHANGE || win->_line[end].firstchar > col)
151                         win->_line[end].firstchar = col;
152                 if (win->_line[end].lastchar == _NOCHANGE || win->_line[end].lastchar < col)
153                         win->_line[end].lastchar = col;
154                 end--;
155         }
156
157         _nc_synchook(win);
158         returnCode(OK);
159 }
160