1 /* $NetBSD: line.c,v 1.4.20.2 2007/01/21 17:43:35 jdc 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.4.20.2 2007/01/21 17:43:35 jdc 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
)
88 n
= min(count
, win
->maxx
- win
->curx
);
91 if (!(ch
& __CHARTEXT
))
93 for (i
= 0; i
< n
; i
++)
94 mvwaddch(win
, win
->cury
, ocurx
+ i
, ch
);
96 wmove(win
, win
->cury
, ocurx
);
102 * Draw a vertical line of character ch on stdscr.
105 vline(chtype ch
, int count
)
107 return wvline(stdscr
, ch
, count
);
112 * Move to the given location an draw a vertical line of character ch.
115 mvvline(int y
, int x
, chtype ch
, int count
)
117 return mvwvline(stdscr
, y
, x
, ch
, count
);
122 * Move to the given location and draw a vertical line of character ch
123 * on the given window.
126 mvwvline(WINDOW
*win
, int y
, int x
, chtype ch
, int count
)
128 if (wmove(win
, y
, x
) == ERR
)
131 return wvline(win
, ch
, count
);
136 * Draw a vertical line of character ch in the given window moving
137 * towards the bottom of the screen. At most count characters are drawn
138 * or until the edge of the screen, whichever comes first.
141 wvline(WINDOW
*win
, chtype ch
, int count
)
143 int ocury
, ocurx
, n
, i
;
145 n
= min(count
, win
->maxy
- win
->cury
);
149 if (!(ch
& __CHARTEXT
))
151 for (i
= 0; i
< n
; i
++)
152 mvwaddch(win
, ocury
+ i
, ocurx
, ch
);
154 wmove(win
, ocury
, ocurx
);
158 int hline_set(const cchar_t
*wch
, int n
)
163 return whline_set( stdscr
, wch
, n
);
164 #endif /* HAVE_WCHAR */
167 int mvhline_set(int y
, int x
, const cchar_t
*wch
, int n
)
172 return mvwhline_set( stdscr
, y
, x
, wch
, n
);
173 #endif /* HAVE_WCHAR */
176 int mvwhline_set(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
, int n
)
181 if ( wmove( win
, y
, x
) == ERR
)
184 return whline_set( win
, wch
, n
);
185 #endif /* HAVE_WCHAR */
188 int whline_set(WINDOW
*win
, const cchar_t
*wch
, int n
)
193 int ocurx
, wcn
, i
, cw
;
196 cw
= wcwidth( wch
->vals
[ 0 ]);
197 if ( ( win
->maxx
- win
->curx
) < cw
)
199 wcn
= min( n
, ( win
->maxx
- win
->curx
) / cw
);
201 __CTRACE(__CTRACE_LINE
, "whline_set: line of %d\n", wcn
);
205 memcpy( &cc
, wch
, sizeof( cchar_t
));
206 if (!(wch
->vals
[ 0 ]))
207 cc
.vals
[ 0 ] |= WACS_HLINE
;
208 for (i
= 0; i
< wcn
; i
++ ) {
210 __CTRACE(__CTRACE_LINE
, "whline_set: (%d,%d)\n",
211 win
->cury
, ocurx
+ i
* cw
);
213 mvwadd_wch(win
, win
->cury
, ocurx
+ i
* cw
, &cc
);
216 wmove(win
, win
->cury
, ocurx
);
218 #endif /* HAVE_WCHAR */
221 int vline_set(const cchar_t
*wch
, int n
)
226 return wvline_set( stdscr
, wch
, n
);
227 #endif /* HAVE_WCHAR */
230 int mvvline_set(int y
, int x
, const cchar_t
*wch
, int n
)
235 return mvwvline_set( stdscr
, y
, x
, wch
, n
);
236 #endif /* HAVE_WCHAR */
239 int mvwvline_set(WINDOW
*win
, int y
, int x
, const cchar_t
*wch
, int n
)
244 if ( wmove( win
, y
, x
) == ERR
)
247 return wvline_set( win
, wch
, n
);
248 #endif /* HAVE_WCHAR */
251 int wvline_set(WINDOW
*win
, const cchar_t
*wch
, int n
)
256 int ocury
, ocurx
, wcn
, i
;
259 wcn
= min( n
, win
->maxy
- win
->cury
);
261 __CTRACE(__CTRACE_LINE
, "wvline_set: line of %d\n", wcn
);
266 memcpy( &cc
, wch
, sizeof( cchar_t
));
267 if (!(wch
->vals
[ 0 ]))
268 cc
.vals
[ 0 ] |= WACS_VLINE
;
269 for (i
= 0; i
< wcn
; i
++) {
270 mvwadd_wch(win
, ocury
+ i
, ocurx
, &cc
);
272 __CTRACE(__CTRACE_LINE
, "wvline_set: (%d,%d)\n",
276 wmove(win
, ocury
, ocurx
);
278 #endif /* HAVE_WCHAR */