From efc20a224bb3f9e7636d391296ca9f8c8f371b01 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sun, 22 Mar 2015 15:28:29 +0000 Subject: ncurses_windows: testing a box with max size which always fits in root window. --- ncurses_windows.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 ncurses_windows.c diff --git a/ncurses_windows.c b/ncurses_windows.c new file mode 100644 index 0000000..702aa27 --- /dev/null +++ b/ncurses_windows.c @@ -0,0 +1,57 @@ +// -*- compile-command: "make LDLIBS=-lncurses ncurses_windows" -*- +#include +#include +#include +#include + +#define WIDTH 20 +#define HEIGHT 10 + +int main(void) +{ + WINDOW *box; + int c; + + initscr(); + cbreak(); + noecho(); + nonl(); + intrflush(stdscr, FALSE); + keypad(stdscr, TRUE); + start_color(); + + init_pair(1, COLOR_WHITE, COLOR_BLUE); + init_pair(2, COLOR_WHITE, COLOR_RED); + + box = derwin(stdscr, 10, 10, 10, 10); + + bkgd(COLOR_PAIR(1)); + wbkgd(box, COLOR_PAIR(2)); + + while ((c = getch()) != EOF) { + if (c == KEY_RESIZE) { + int x, y, width, height; + + erase(); + + getmaxyx(stdscr, y, x); + + width = x < WIDTH ? x : WIDTH; + height = y < HEIGHT ? y : HEIGHT; + + wresize(box, height, width); + + mvderwin(box, (y - height) / 2, (x - width) / 2); + + bkgd(COLOR_PAIR(1)); + + wbkgd(box, COLOR_PAIR(2)); + + box(box, 0, 0); + + refresh(); + } + } + + return EXIT_SUCCESS; +} -- cgit v1.2.3-54-g00ecf