1 /* $NetBSD: line.c,v 1.4 2002/01/02 10:38:28 blymn Exp $ */ 2 3 /*- 4 * Copyright (c) 1998-1999 Brett Lymn 5 * (blymn@baea.com.au, brett_lymn@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 2002/01/02 10:38:28 blymn Exp $"); 35 #endif /* not lint */ 36 37 #include "curses.h" 38 #include "curses_private.h" 39 40 /* 41 * hline -- 42 * Draw a horizontal line of character c on stdscr. 43 */ 44 int 45 hline(chtype ch, int count) 46 { 47 return whline(stdscr, ch, count); 48 } 49 50 /* 51 * mvhline -- 52 * Move to location (y, x) and draw a horizontal line of character c 53 * on stdscr. 54 */ 55 int 56 mvhline(int y, int x, chtype ch, int count) 57 { 58 return mvwhline(stdscr, y, x, ch, count); 59 } 60 61 /* 62 * mvwhline -- 63 * Move to location (y, x) and draw a horizontal line of character c 64 * in the given window. 65 */ 66 int 67 mvwhline(WINDOW *win, int y, int x, chtype ch, int count) 68 { 69 if (wmove(win, y, x) == ERR) 70 return ERR; 71 72 return whline(win, ch, count); 73 } 74 75 /* 76 * whline -- 77 * Draw a horizontal line of character c in the given window moving 78 * towards the rightmost column. At most count characters are drawn 79 * or until the edge of the screen, whichever comes first. 80 */ 81 int 82 whline(WINDOW *win, chtype ch, int count) 83 { 84 int ocurx, n, i; 85 86 n = min(count, win->maxx - win->curx); 87 ocurx = win->curx; 88 89 if (!(ch & __CHARTEXT)) 90 ch |= ACS_HLINE; 91 for (i = 0; i < n; i++) 92 mvwaddch(win, win->cury, ocurx + i, ch); 93 94 wmove(win, win->cury, ocurx); 95 return OK; 96 } 97 98 /* 99 * vline -- 100 * Draw a vertical line of character ch on stdscr. 101 */ 102 int 103 vline(chtype ch, int count) 104 { 105 return wvline(stdscr, ch, count); 106 } 107 108 /* 109 * mvvline -- 110 * Move to the given location an draw a vertical line of character ch. 111 */ 112 int 113 mvvline(int y, int x, chtype ch, int count) 114 { 115 return mvwvline(stdscr, y, x, ch, count); 116 } 117 118 /* 119 * mvwvline -- 120 * Move to the given location and draw a vertical line of character ch 121 * on the given window. 122 */ 123 int 124 mvwvline(WINDOW *win, int y, int x, chtype ch, int count) 125 { 126 if (wmove(win, y, x) == ERR) 127 return ERR; 128 129 return wvline(win, ch, count); 130 } 131 132 /* 133 * wvline -- 134 * Draw a vertical line of character ch in the given window moving 135 * towards the bottom of the screen. At most count characters are drawn 136 * or until the edge of the screen, whichever comes first. 137 */ 138 int 139 wvline(WINDOW *win, chtype ch, int count) 140 { 141 int ocury, ocurx, n, i; 142 143 n = min(count, win->maxy - win->cury); 144 ocury = win->cury; 145 ocurx = win->curx; 146 147 if (!(ch & __CHARTEXT)) 148 ch |= ACS_VLINE; 149 for (i = 0; i < n; i++) 150 mvwaddch(win, ocury + i, ocurx, ch); 151 152 wmove(win, ocury, ocurx); 153 return OK; 154 } 155