Home | History | Annotate | Line # | Download | only in libcurses
line.c revision 1.4.20.1
      1 /*	$NetBSD: line.c,v 1.4.20.1 2007/01/21 11:38:59 blymn Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998-1999 Brett Lymn
      5  *						 (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
      6  * All rights reserved.
      7  *
      8  * This code has been donated to The NetBSD Foundation by the Author.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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
     17  *
     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.
     28  *
     29  *
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #ifndef lint
     34 __RCSID("$NetBSD: line.c,v 1.4.20.1 2007/01/21 11:38:59 blymn Exp $");
     35 #endif				/* not lint */
     36 
     37 #include <string.h>
     38 
     39 #include "curses.h"
     40 #include "curses_private.h"
     41 
     42 /*
     43  * hline --
     44  *	Draw a horizontal line of character c on stdscr.
     45  */
     46 int
     47 hline(chtype ch, int count)
     48 {
     49 	return whline(stdscr, ch, count);
     50 }
     51 
     52 /*
     53  * mvhline --
     54  *	Move to location (y, x) and draw a horizontal line of character c
     55  *	on stdscr.
     56  */
     57 int
     58 mvhline(int y, int x, chtype ch, int count)
     59 {
     60 	return mvwhline(stdscr, y, x, ch, count);
     61 }
     62 
     63 /*
     64  * mvwhline --
     65  *	Move to location (y, x) and draw a horizontal line of character c
     66  *	in the given window.
     67  */
     68 int
     69 mvwhline(WINDOW *win, int y, int x, chtype ch, int count)
     70 {
     71 	if (wmove(win, y, x) == ERR)
     72 		return ERR;
     73 
     74 	return whline(win, ch, count);
     75 }
     76 
     77 /*
     78  * whline --
     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.
     82  */
     83 int
     84 whline(WINDOW *win, chtype ch, int count)
     85 {
     86 	int ocurx, n, i;
     87 
     88 	n = min(count, win->maxx - win->curx);
     89 	ocurx = win->curx;
     90 
     91 	if (!(ch & __CHARTEXT))
     92 		ch |= ACS_HLINE;
     93 	for (i = 0; i < n; i++)
     94 		mvwaddch(win, win->cury, ocurx + i, ch);
     95 
     96 	wmove(win, win->cury, ocurx);
     97 	return OK;
     98 }
     99 
    100 /*
    101  * vline --
    102  *	Draw a vertical line of character ch on stdscr.
    103  */
    104 int
    105 vline(chtype ch, int count)
    106 {
    107 	return wvline(stdscr, ch, count);
    108 }
    109 
    110 /*
    111  * mvvline --
    112  *   Move to the given location an draw a vertical line of character ch.
    113  */
    114 int
    115 mvvline(int y, int x, chtype ch, int count)
    116 {
    117 	return mvwvline(stdscr, y, x, ch, count);
    118 }
    119 
    120 /*
    121  * mvwvline --
    122  *	Move to the given location and draw a vertical line of character ch
    123  *	on the given window.
    124  */
    125 int
    126 mvwvline(WINDOW *win, int y, int x, chtype ch, int count)
    127 {
    128 	if (wmove(win, y, x) == ERR)
    129 		return ERR;
    130 
    131 	return wvline(win, ch, count);
    132 }
    133 
    134 /*
    135  * wvline --
    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.
    139  */
    140 int
    141 wvline(WINDOW *win, chtype ch, int count)
    142 {
    143 	int ocury, ocurx, n, i;
    144 
    145 	n = min(count, win->maxy - win->cury);
    146 	ocury = win->cury;
    147 	ocurx = win->curx;
    148 
    149 	if (!(ch & __CHARTEXT))
    150 		ch |= ACS_VLINE;
    151 	for (i = 0; i < n; i++)
    152 		mvwaddch(win, ocury + i, ocurx, ch);
    153 
    154 	wmove(win, ocury, ocurx);
    155 	return OK;
    156 }
    157 
    158 int hline_set(const cchar_t *wch, int n)
    159 {
    160 #ifndef HAVE_WCHAR
    161 	return ERR;
    162 #else
    163 	return whline_set( stdscr, wch, n );
    164 #endif /* HAVE_WCHAR */
    165 }
    166 
    167 int mvhline_set(int y, int x, const cchar_t *wch, int n)
    168 {
    169 #ifndef HAVE_WCHAR
    170 	return ERR;
    171 #else
    172 	return mvwhline_set( stdscr, y, x, wch, n );
    173 #endif /* HAVE_WCHAR */
    174 }
    175 
    176 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
    177 {
    178 #ifndef HAVE_WCHAR
    179 	return ERR;
    180 #else
    181 	if ( wmove( win, y , x ) == ERR )
    182 		return ERR;
    183 
    184 	return whline_set( win, wch, n );
    185 #endif /* HAVE_WCHAR */
    186 }
    187 
    188 int whline_set(WINDOW *win, const cchar_t *wch, int n)
    189 {
    190 #ifndef HAVE_WCHAR
    191 	return ERR;
    192 #else
    193 	int ocurx, wcn, i, cw;
    194 	cchar_t cc;
    195 
    196 	cw = wcwidth( wch->vals[ 0 ]);
    197 	if ( ( win->maxx - win->curx ) < cw )
    198 		return ERR;
    199 	wcn = min( n, ( win->maxx - win->curx ) / cw );
    200 #ifdef DEBUG
    201 	__CTRACE("[whline_set]line of %d\n", wcn );
    202 #endif /* DEBUG */
    203 	ocurx = win->curx;
    204 
    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++ ) {
    209 #ifdef DEBUG
    210 		__CTRACE("[whline_set](%d,%d)\n", win->cury, ocurx + i * cw );
    211 #endif /* DEBUG */
    212 		mvwadd_wch(win, win->cury, ocurx + i * cw, &cc);
    213 	}
    214 
    215 	wmove(win, win->cury, ocurx);
    216 	return OK;
    217 #endif /* HAVE_WCHAR */
    218 }
    219 
    220 int vline_set(const cchar_t *wch, int n)
    221 {
    222 #ifndef HAVE_WCHAR
    223 	return ERR;
    224 #else
    225 	return wvline_set( stdscr, wch, n );
    226 #endif /* HAVE_WCHAR */
    227 }
    228 
    229 int mvvline_set(int y, int x, const cchar_t *wch, int n)
    230 {
    231 #ifndef HAVE_WCHAR
    232 	return ERR;
    233 #else
    234 	return mvwvline_set( stdscr, y, x, wch, n );
    235 #endif /* HAVE_WCHAR */
    236 }
    237 
    238 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
    239 {
    240 #ifndef HAVE_WCHAR
    241 	return ERR;
    242 #else
    243 	if ( wmove( win, y, x ) == ERR )
    244 		return ERR;
    245 
    246 	return wvline_set( win, wch, n );
    247 #endif /* HAVE_WCHAR */
    248 }
    249 
    250 int wvline_set(WINDOW *win, const cchar_t *wch, int n)
    251 {
    252 #ifndef HAVE_WCHAR
    253 	return ERR;
    254 #else
    255 	int ocury, ocurx, wcn, i;
    256 	cchar_t cc;
    257 
    258 	wcn = min( n, win->maxy - win->cury);
    259 #ifdef DEBUG
    260 	__CTRACE("[wvline_set]line of %d\n", wcn );
    261 #endif /* DEBUG */
    262 	ocury = win->cury;
    263 	ocurx = win->curx;
    264 
    265 	memcpy( &cc, wch, sizeof( cchar_t ));
    266 	if (!(wch->vals[ 0 ]))
    267 		cc.vals[ 0 ] |= WACS_VLINE;
    268 	for (i = 0; i < wcn; i++) {
    269 		mvwadd_wch(win, ocury + i, ocurx, &cc);
    270 #ifdef DEBUG
    271 		__CTRACE("[wvline_set](%d,%d)\n", ocury + i, ocurx);
    272 #endif /* DEBUG */
    273 	}
    274 	wmove(win, ocury, ocurx);
    275 	return OK;
    276 #endif /* HAVE_WCHAR */
    277 }
    278