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
58
59
60
61
62
63
64
65
66
|
/*
* Copyright (C) 2015 Tomasz Kramkowski <tk@the-tk.com>
*
* This program is free software. It is licensed under version 3 of the
* GNU General Public License.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [http://www.gnu.org/licenses/].
*/
// -*- 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;
}
|