1 /* $NetBSD: line.c,v 1.1 2000/04/24 14:09:44 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 withough 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.1 2000/04/24 14:09:44 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 for (i = 0; i < n; i++) 90 mvwaddch(win, win->cury, ocurx + i, ch); 91 92 wmove(win, win->cury, ocurx); 93 return OK; 94 } 95 96 /* 97 * vline -- 98 * Draw a vertical line of character ch on stdscr. 99 */ 100 int 101 vline(chtype ch, int count) 102 { 103 return wvline(stdscr, ch, count); 104 } 105 106 /* 107 * mvvline -- 108 * Move to the given location an draw a vertical line of character ch. 109 */ 110 int 111 mvvline(int y, int x, chtype ch, int count) 112 { 113 return mvwvline(stdscr, y, x, ch, count); 114 } 115 116 /* 117 * mvwvline -- 118 * Move to the given location and draw a vertical line of character ch 119 * on the given window. 120 */ 121 int 122 mvwvline(WINDOW *win, int y, int x, chtype ch, int count) 123 { 124 if (wmove(win, y, x) == ERR) 125 return ERR; 126 127 return wvline(win, ch, count); 128 } 129 130 /* 131 * wvline -- 132 * Draw a vertical line of character ch in the given window moving 133 * towards the bottom of the screen. At most count characters are drawn 134 * or until the edge of the screen, whichever comes first. 135 */ 136 int 137 wvline(WINDOW *win, chtype ch, int count) 138 { 139 int ocury, ocurx, n, i; 140 141 n = min(count, win->maxy - win->cury); 142 ocury = win->cury; 143 ocurx = win->curx; 144 145 for (i = 0; i < n; i++) 146 mvwaddch(win, ocury + i, ocurx, ch); 147 148 wmove(win, ocury, ocurx); 149 return OK; 150 } 151