diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2015-03-22 15:28:29 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2015-03-22 15:28:29 +0000 |
commit | efc20a224bb3f9e7636d391296ca9f8c8f371b01 (patch) | |
tree | 9968f7dc810e7b4ef712e868eb5a481bce86f749 | |
parent | 614ce60ee66189eada508a0bfb9185689c09c601 (diff) | |
download | c-stuff-efc20a224bb3f9e7636d391296ca9f8c8f371b01.tar.gz c-stuff-efc20a224bb3f9e7636d391296ca9f8c8f371b01.tar.xz c-stuff-efc20a224bb3f9e7636d391296ca9f8c8f371b01.zip |
ncurses_windows: testing a box with max size which always fits in root window.
-rw-r--r-- | ncurses_windows.c | 57 |
1 files changed, 57 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <ncurses.h> +#include <unistd.h> + +#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; +} |