iPXE
edging.c
Go to the documentation of this file.
1#include <curses.h>
2#include "mucurses.h"
3#include "cursor.h"
4
5/** @file
6 *
7 * MuCurses edging functions
8 *
9 */
10
11FILE_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 */
22int 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 */
43int 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 */
82int 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 */
102int 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}
MuCurses header file.
uint32_t chtype
Definition curses.h:30
#define OK
Definition curses.h:25
struct _curses_window WINDOW
Curses Window struct.
MuCurses cursor implementation specific header file.
static void _store_curs_pos(WINDOW *win, struct cursor_pos *pos)
Store cursor position for later restoration.
Definition cursor.h:33
static void _restore_curs_pos(WINDOW *win, struct cursor_pos *pos)
Restore cursor position from encoded backup variable.
Definition cursor.h:23
int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
Draw borders from single-byte characters and renditions around a window.
Definition edging.c:43
int wvline(WINDOW *win, chtype ch, int n)
Create a vertical line in a window.
Definition edging.c:102
int whline(WINDOW *win, chtype ch, int n)
Create a horizontal line in a window.
Definition edging.c:82
int box(WINDOW *win, chtype verch, chtype horch)
Draw borders from single-byte characters and renditions around a window.
Definition edging.c:22
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
int wmove(WINDOW *win, int y, int x) __nonnull
Move a window's cursor to the specified position.
Definition mucurses.c:136
void _wputch(WINDOW *win, chtype ch, int wrap) __nonnull
Write a single character rendition to a window.
Definition mucurses.c:51
MuCurses core implementation specific header file.
#define WRAP
Definition mucurses.h:13
#define NOWRAP
Definition mucurses.h:14
uint8_t bl
Definition registers.h:0
uint8_t ch
Definition registers.h:1
unsigned int curs_x
window cursor position
Definition curses.h:98
unsigned int width
window dimensions
Definition curses.h:100
unsigned int height
Definition curses.h:100
unsigned int curs_y
Definition curses.h:98
attr_t attrs
window attributes
Definition curses.h:94
unsigned int x
Definition cursor.h:14