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