line.c revision 1.1 1 1.1 blymn /* $NetBSD: line.c,v 1.1 2000/04/24 14:09:44 blymn Exp $ */
2 1.1 blymn
3 1.1 blymn /*-
4 1.1 blymn * Copyright (c) 1998-1999 Brett Lymn
5 1.1 blymn * (blymn (at) baea.com.au, brett_lymn (at) yahoo.com.au)
6 1.1 blymn * All rights reserved.
7 1.1 blymn *
8 1.1 blymn * This code has been donated to The NetBSD Foundation by the Author.
9 1.1 blymn *
10 1.1 blymn * Redistribution and use in source and binary forms, with or without
11 1.1 blymn * modification, are permitted provided that the following conditions
12 1.1 blymn * are met:
13 1.1 blymn * 1. Redistributions of source code must retain the above copyright
14 1.1 blymn * notice, this list of conditions and the following disclaimer.
15 1.1 blymn * 2. The name of the author may not be used to endorse or promote products
16 1.1 blymn * derived from this software withough specific prior written permission
17 1.1 blymn *
18 1.1 blymn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 blymn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 blymn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 blymn * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 blymn * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 blymn * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 blymn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 blymn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 blymn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 blymn * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 blymn *
29 1.1 blymn *
30 1.1 blymn */
31 1.1 blymn
32 1.1 blymn #include <sys/cdefs.h>
33 1.1 blymn #ifndef lint
34 1.1 blymn __RCSID("$NetBSD: line.c,v 1.1 2000/04/24 14:09:44 blymn Exp $");
35 1.1 blymn #endif /* not lint */
36 1.1 blymn
37 1.1 blymn #include "curses.h"
38 1.1 blymn #include "curses_private.h"
39 1.1 blymn
40 1.1 blymn /*
41 1.1 blymn * hline --
42 1.1 blymn * Draw a horizontal line of character c on stdscr.
43 1.1 blymn */
44 1.1 blymn int
45 1.1 blymn hline(chtype ch, int count)
46 1.1 blymn {
47 1.1 blymn return whline(stdscr, ch, count);
48 1.1 blymn }
49 1.1 blymn
50 1.1 blymn /*
51 1.1 blymn * mvhline --
52 1.1 blymn * Move to location (y, x) and draw a horizontal line of character c
53 1.1 blymn * on stdscr.
54 1.1 blymn */
55 1.1 blymn int
56 1.1 blymn mvhline(int y, int x, chtype ch, int count)
57 1.1 blymn {
58 1.1 blymn return mvwhline(stdscr, y, x, ch, count);
59 1.1 blymn }
60 1.1 blymn
61 1.1 blymn /*
62 1.1 blymn * mvwhline --
63 1.1 blymn * Move to location (y, x) and draw a horizontal line of character c
64 1.1 blymn * in the given window.
65 1.1 blymn */
66 1.1 blymn int
67 1.1 blymn mvwhline(WINDOW *win, int y, int x, chtype ch, int count)
68 1.1 blymn {
69 1.1 blymn if (wmove(win, y, x) == ERR)
70 1.1 blymn return ERR;
71 1.1 blymn
72 1.1 blymn return whline(win, ch, count);
73 1.1 blymn }
74 1.1 blymn
75 1.1 blymn /*
76 1.1 blymn * whline --
77 1.1 blymn * Draw a horizontal line of character c in the given window moving
78 1.1 blymn * towards the rightmost column. At most count characters are drawn
79 1.1 blymn * or until the edge of the screen, whichever comes first.
80 1.1 blymn */
81 1.1 blymn int
82 1.1 blymn whline(WINDOW *win, chtype ch, int count)
83 1.1 blymn {
84 1.1 blymn int ocurx, n, i;
85 1.1 blymn
86 1.1 blymn n = min(count, win->maxx - win->curx);
87 1.1 blymn ocurx = win->curx;
88 1.1 blymn
89 1.1 blymn for (i = 0; i < n; i++)
90 1.1 blymn mvwaddch(win, win->cury, ocurx + i, ch);
91 1.1 blymn
92 1.1 blymn wmove(win, win->cury, ocurx);
93 1.1 blymn return OK;
94 1.1 blymn }
95 1.1 blymn
96 1.1 blymn /*
97 1.1 blymn * vline --
98 1.1 blymn * Draw a vertical line of character ch on stdscr.
99 1.1 blymn */
100 1.1 blymn int
101 1.1 blymn vline(chtype ch, int count)
102 1.1 blymn {
103 1.1 blymn return wvline(stdscr, ch, count);
104 1.1 blymn }
105 1.1 blymn
106 1.1 blymn /*
107 1.1 blymn * mvvline --
108 1.1 blymn * Move to the given location an draw a vertical line of character ch.
109 1.1 blymn */
110 1.1 blymn int
111 1.1 blymn mvvline(int y, int x, chtype ch, int count)
112 1.1 blymn {
113 1.1 blymn return mvwvline(stdscr, y, x, ch, count);
114 1.1 blymn }
115 1.1 blymn
116 1.1 blymn /*
117 1.1 blymn * mvwvline --
118 1.1 blymn * Move to the given location and draw a vertical line of character ch
119 1.1 blymn * on the given window.
120 1.1 blymn */
121 1.1 blymn int
122 1.1 blymn mvwvline(WINDOW *win, int y, int x, chtype ch, int count)
123 1.1 blymn {
124 1.1 blymn if (wmove(win, y, x) == ERR)
125 1.1 blymn return ERR;
126 1.1 blymn
127 1.1 blymn return wvline(win, ch, count);
128 1.1 blymn }
129 1.1 blymn
130 1.1 blymn /*
131 1.1 blymn * wvline --
132 1.1 blymn * Draw a vertical line of character ch in the given window moving
133 1.1 blymn * towards the bottom of the screen. At most count characters are drawn
134 1.1 blymn * or until the edge of the screen, whichever comes first.
135 1.1 blymn */
136 1.1 blymn int
137 1.1 blymn wvline(WINDOW *win, chtype ch, int count)
138 1.1 blymn {
139 1.1 blymn int ocury, ocurx, n, i;
140 1.1 blymn
141 1.1 blymn n = min(count, win->maxy - win->cury);
142 1.1 blymn ocury = win->cury;
143 1.1 blymn ocurx = win->curx;
144 1.1 blymn
145 1.1 blymn for (i = 0; i < n; i++)
146 1.1 blymn mvwaddch(win, ocury + i, ocurx, ch);
147 1.1 blymn
148 1.1 blymn wmove(win, ocury, ocurx);
149 1.1 blymn return OK;
150 1.1 blymn }
151