iPXE
edging.c
Go to the documentation of this file.
00001 #include <curses.h>
00002 #include "mucurses.h"
00003 #include "cursor.h"
00004 
00005 /** @file
00006  *
00007  * MuCurses edging functions
00008  *
00009  */
00010 
00011 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00012 
00013 /**
00014  * Draw borders from single-byte characters and renditions around a
00015  * window
00016  *
00017  * @v *win      window to be bordered
00018  * @v verch     vertical chtype
00019  * @v horch     horizontal chtype
00020  * @ret rc      return status code
00021  */
00022 int box ( WINDOW *win, chtype verch, chtype horch ) {
00023         chtype corner = '+' | win->attrs; /* default corner character */
00024         return wborder( win, verch, verch, horch, horch,
00025                         corner, corner, corner, corner );
00026 }
00027 
00028 /**
00029  * Draw borders from single-byte characters and renditions around a
00030  * window
00031  *
00032  * @v *win      window to be bordered
00033  * @v ls        left side
00034  * @v rs        right side
00035  * @v ts        top
00036  * @v bs        bottom
00037  * @v tl        top left corner
00038  * @v tr        top right corner
00039  * @v bl        bottom left corner
00040  * @v br        bottom right corner
00041  * @ret rc      return status code
00042  */
00043 int wborder ( WINDOW *win, chtype ls, chtype rs,
00044               chtype ts, chtype bs, chtype tl,
00045               chtype tr, chtype bl, chtype br ) {
00046         struct cursor_pos pos;
00047 
00048         _store_curs_pos( win, &pos );
00049         wmove(win,0,0);
00050 
00051         _wputch(win,tl,WRAP);
00052         while ( ( win->width - 1 ) - win->curs_x ) {
00053                 _wputch(win,ts,WRAP);
00054         }
00055         _wputch(win,tr,WRAP);
00056 
00057         while ( ( win->height - 1 ) - win->curs_y ) {
00058                 _wputch(win,ls,WRAP);
00059                 wmove(win,win->curs_y,(win->width)-1);
00060                 _wputch(win,rs,WRAP);
00061         }
00062 
00063         _wputch(win,bl,WRAP);
00064         while ( ( win->width -1 ) - win->curs_x ) {
00065                 _wputch(win,bs,WRAP);
00066         }
00067         _wputch(win,br,NOWRAP); /* do not wrap last char to leave
00068                                    cursor in last position */
00069         _restore_curs_pos( win, &pos );
00070 
00071         return OK;
00072 }
00073 
00074 /**
00075  * Create a horizontal line in a window
00076  *
00077  * @v *win      subject window
00078  * @v ch        rendition and character
00079  * @v n         max number of chars (wide) to render
00080  * @ret rc      return status code
00081  */
00082 int whline ( WINDOW *win, chtype ch, int n ) {
00083         struct cursor_pos pos;
00084 
00085         _store_curs_pos ( win, &pos );
00086         while ( ( win->curs_x - win->width ) && n-- ) {
00087                 _wputch ( win, ch, NOWRAP );
00088         }
00089         _restore_curs_pos ( win, &pos );
00090 
00091         return OK;
00092 }
00093 
00094 /**
00095  * Create a vertical line in a window
00096  *
00097  * @v *win      subject window
00098  * @v ch        rendition and character
00099  * @v n         max number of chars (high) to render
00100  * @ret rc      return status code
00101  */
00102 int wvline ( WINDOW *win, chtype ch, int n ) {
00103         struct cursor_pos pos;
00104 
00105         _store_curs_pos ( win, &pos );
00106         while ( ( win->curs_y - win->height ) && n-- ) {
00107                 _wputch ( win, ch, NOWRAP );
00108                 wmove( win, ++(win->curs_y), pos.x);
00109         }
00110         _restore_curs_pos ( win, &pos );
00111 
00112         return OK;
00113 }