aboutsummaryrefslogtreecommitdiffstats
path: root/ncurses_windows.c
blob: 702aa27f7bed289add1262166357cad4212009d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
}