1 /* $NetBSD: line.c,v 1.6 2010/02/23 19:48:26 drochner Exp $ */
4 * Copyright (c) 1998-1999 Brett Lymn
5 * (blymn@baea.com.au, brett_lymn@yahoo.com.au)
8 * This code has been donated to The NetBSD Foundation by the Author.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: line.c,v 1.6 2010/02/23 19:48:26 drochner Exp $");
40 #include "curses_private.h"
44 * Draw a horizontal line of character c on stdscr.
47 hline(chtype ch
, int count
)
49 return whline(stdscr
, ch
, count
);
54 * Move to location (y, x) and draw a horizontal line of character c
58 mvhline(int y
, int x
, chtype ch
, int count
)
60 return mvwhline(stdscr
, y
, x
, ch
, count
);
65 * Move to location (y, x) and draw a horizontal line of character c
66 * in the given window.
69 mvwhline(WINDOW
*win
, int y
, int x
, chtype ch
, int count
)
71 if (wmove(win
, y
, x
) == ERR
)
74 return whline(win
, ch
, count
);
79 * Draw a horizontal line of character c in the given window moving
80 * towards the rightmost column. At most count characters are drawn
81 * or until the edge of the screen, whichever comes first.
84 whline(WINDOW
*win
, chtype ch
, int count
)
89 n
= min(count
, win
->maxx
- win
->curx
);
92 if (!(ch
& __CHARTEXT
))
94 for (i
= 0; i
< n
; i
++)
95 mvwaddch(win
, win
->cury
, ocurx
+ i
, ch
);
97 wmove(win
, win
->cury
, ocurx
);
102 if (ch
& __CHARTEXT
) {
103 __cursesi_chtype_to_cchar(ch
, &cch
);
108 return whline_set(win
, cchp
, count
);
114 * Draw a vertical line of character ch on stdscr.
117 vline(chtype ch
, int count
)
119 return wvline(stdscr
, ch
, count
);
124 * Move to the given location an draw a vertical line of character ch.
127 mvvline(int y
, int x
, chtype ch
, int count
)
129 return mvwvline(stdscr
, y
, x
, ch
, count
);
134 * Move to the given location and draw a vertical line of character ch
135 * on the given window.
138 mvwvline(WINDOW
*win
, int y
, int x
, chtype ch
, int count
)
140 if (wmove(win
, y
, x
) == ERR
)
143 return wvline(win
, ch
, count
);
148 * Draw a vertical line of character ch in the given window moving
149 * towards the bottom of the screen. At most count characters are drawn
150 * or until the edge of the screen, whichever comes first.
153 wvline(WINDOW
*win
, chtype ch
, int count
)
156 int ocury
, ocurx
, n
, i
;
158 n
= min(count
, win
->maxy
- win
->cury
);
162 if (!(ch
& __CHARTEXT
))
164 for (i
= 0; i
< n
; i
++)
165 mvwaddch(win
, ocury
+ i
, ocurx
, ch
);
167 wmove(win
, ocury
, ocurx
);
172 if (ch
& __CHARTEXT
) {
173 __cursesi_chtype_to_cchar(ch
, &cch
);
178 return wvline_set(win
, cchp
, count
);
182 int hline_set(const cchar_t
*wch
, int n
)
187 return whline_set( stdscr
, wch
, n
);
188 #endif /* HAVE_WCHAR */
191 int mvhline_set(int y
, int x
, const cchar_t
*wch
, int n
)
196 return mvwhline_set( stdscr
, y
, x
, wch
, n
);
197 #endif /* HAVE_WCHAR */
200 int mvwhline_set(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
, int n
)
205 if ( wmove( win
, y
, x
) == ERR
)
208 return whline_set( win
, wch
, n
);
209 #endif /* HAVE_WCHAR */
212 int whline_set(WINDOW
*win
, const cchar_t
*wch
, int n
)
217 int ocurx
, wcn
, i
, cw
;
220 cw
= wcwidth( wch
->vals
[ 0 ]);
223 if ( ( win
->maxx
- win
->curx
) < cw
)
225 wcn
= min( n
, ( win
->maxx
- win
->curx
) / cw
);
227 __CTRACE(__CTRACE_LINE
, "whline_set: line of %d\n", wcn
);
231 memcpy( &cc
, wch
, sizeof( cchar_t
));
232 if (!(wch
->vals
[ 0 ]))
233 cc
.vals
[ 0 ] |= WACS_HLINE
->vals
[0];
234 for (i
= 0; i
< wcn
; i
++ ) {
236 __CTRACE(__CTRACE_LINE
, "whline_set: (%d,%d)\n",
237 win
->cury
, ocurx
+ i
* cw
);
239 mvwadd_wch(win
, win
->cury
, ocurx
+ i
* cw
, &cc
);
242 wmove(win
, win
->cury
, ocurx
);
244 #endif /* HAVE_WCHAR */
247 int vline_set(const cchar_t
*wch
, int n
)
252 return wvline_set( stdscr
, wch
, n
);
253 #endif /* HAVE_WCHAR */
256 int mvvline_set(int y
, int x
, const cchar_t
*wch
, int n
)
261 return mvwvline_set( stdscr
, y
, x
, wch
, n
);
262 #endif /* HAVE_WCHAR */
265 int mvwvline_set(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
, int n
)
270 if ( wmove( win
, y
, x
) == ERR
)
273 return wvline_set( win
, wch
, n
);
274 #endif /* HAVE_WCHAR */
277 int wvline_set(WINDOW
*win
, const cchar_t
*wch
, int n
)
282 int ocury
, ocurx
, wcn
, i
;
285 wcn
= min( n
, win
->maxy
- win
->cury
);
287 __CTRACE(__CTRACE_LINE
, "wvline_set: line of %d\n", wcn
);
292 memcpy( &cc
, wch
, sizeof( cchar_t
));
293 if (!(wch
->vals
[ 0 ]))
294 cc
.vals
[ 0 ] |= WACS_VLINE
->vals
[0];
295 for (i
= 0; i
< wcn
; i
++) {
296 mvwadd_wch(win
, ocury
+ i
, ocurx
, &cc
);
298 __CTRACE(__CTRACE_LINE
, "wvline_set: (%d,%d)\n",
302 wmove(win
, ocury
, ocurx
);
304 #endif /* HAVE_WCHAR */