Other border functions
Adapted from NCURSES Programming HOWTO, by Pradeep Padala.
The window border program is grossly inefficient in that with each press of a key, a window is destroyed and another is created. So let’s write a more efficient program which uses other border related functions.
The following program uses mvhline() and mvvline() to achieve a similar effect. These two functions are simple. They create a horizontal or vertical line of the specified length at the specified position.
Example: More border functions
#include <stdlib.h>#include <curses.h>
typedef struct _win_border_struct { chtype ls, rs, ts, bs, tl, tr, bl, br;} WIN_BORDER;
typedef struct _WIN_struct {
int startx, starty; int height, width; WIN_BORDER border;} WIN;
static voidinit_win_params(WIN *p_win){ p_win->height = 3; p_win->width = 10;
p_win->border.ls = '|'; p_win->border.rs = '|'; p_win->border.ts = '-'; p_win->border.bs = '-'; p_win->border.tl = '+'; p_win->border.tr = '+'; p_win->border.bl = '+'; p_win->border.br = '+';}
static voidprint_win_params(WIN *p_win){#ifdef _DEBUG p_win->width, p_win->height);#else (void) p_win;#endif}
static void{ int i, j; int x, y, w, h;
x = p_win->startx; y = p_win->starty; w = p_win->width; h = p_win->height;
} else for (j = y; j < y + h; ++j) for (i = x; i < x + w; ++i)
}
intmain(void){ WIN win; int ch;
* editing control characters */
/* Initialize the window parameters */ init_win_params(&win); print_win_params(&win);
switch (ch) { --win.startx; break; ++win.startx; break; --win.starty; break; ++win.starty; break; } } return EXIT_SUCCESS;}print_win_params() prints the box’s starting position and size on the bottom line, but only when the macro _DEBUG is defined, so the default build shows nothing there. The Run with _DEBUG defined button runs a build with it defined.