1 #include <curses.h>
2 #include "mucurses.h"
3 #include "cursor.h"
4
5 /** @file
6 *
7 * MuCurses edging functions
8 *
9 */
10
11 /**
12 * Draw borders from single-byte characters and renditions around a
13 * window
14 *
15 * @v *win window to be bordered
16 * @v verch vertical chtype
17 * @v horch horizontal chtype
18 * @ret rc return status code
19 */
box(WINDOW * win,chtype verch,chtype horch)20 int box ( WINDOW *win, chtype verch, chtype horch ) {
21 chtype corner = '+' | win->attrs; /* default corner character */
22 return wborder( win, verch, verch, horch, horch,
23 corner, corner, corner, corner );
24 }
25
26 /**
27 * Draw borders from single-byte characters and renditions around a
28 * window
29 *
30 * @v *win window to be bordered
31 * @v ls left side
32 * @v rs right side
33 * @v ts top
34 * @v bs bottom
35 * @v tl top left corner
36 * @v tr top right corner
37 * @v bl bottom left corner
38 * @v br bottom right corner
39 * @ret rc return status code
40 */
wborder(WINDOW * win,chtype ls,chtype rs,chtype ts,chtype bs,chtype tl,chtype tr,chtype bl,chtype br)41 int wborder ( WINDOW *win, chtype ls, chtype rs,
42 chtype ts, chtype bs, chtype tl,
43 chtype tr, chtype bl, chtype br ) {
44 struct cursor_pos pos;
45
46 _store_curs_pos( win, &pos );
47 wmove(win,0,0);
48
49 _wputch(win,tl,WRAP);
50 while ( ( win->width - 1 ) - win->curs_x ) {
51 _wputch(win,ts,WRAP);
52 }
53 _wputch(win,tr,WRAP);
54
55 while ( ( win->height - 1 ) - win->curs_y ) {
56 _wputch(win,ls,WRAP);
57 wmove(win,win->curs_y,(win->width)-1);
58 _wputch(win,rs,WRAP);
59 }
60
61 _wputch(win,bl,WRAP);
62 while ( ( win->width -1 ) - win->curs_x ) {
63 _wputch(win,bs,WRAP);
64 }
65 _wputch(win,br,NOWRAP); /* do not wrap last char to leave
66 cursor in last position */
67 _restore_curs_pos( win, &pos );
68
69 return OK;
70 }
71
72 /**
73 * Create a horizontal line in a window
74 *
75 * @v *win subject window
76 * @v ch rendition and character
77 * @v n max number of chars (wide) to render
78 * @ret rc return status code
79 */
whline(WINDOW * win,chtype ch,int n)80 int whline ( WINDOW *win, chtype ch, int n ) {
81 struct cursor_pos pos;
82
83 _store_curs_pos ( win, &pos );
84 while ( ( win->curs_x - win->width ) && n-- ) {
85 _wputch ( win, ch, NOWRAP );
86 }
87 _restore_curs_pos ( win, &pos );
88
89 return OK;
90 }
91
92 /**
93 * Create a vertical line in a window
94 *
95 * @v *win subject window
96 * @v ch rendition and character
97 * @v n max number of chars (high) to render
98 * @ret rc return status code
99 */
wvline(WINDOW * win,chtype ch,int n)100 int wvline ( WINDOW *win, chtype ch, int n ) {
101 struct cursor_pos pos;
102
103 _store_curs_pos ( win, &pos );
104 while ( ( win->curs_y - win->height ) && n-- ) {
105 _wputch ( win, ch, NOWRAP );
106 wmove( win, ++(win->curs_y), pos.x);
107 }
108 _restore_curs_pos ( win, &pos );
109
110 return OK;
111 }
112