c358d58d38c110f0a5120a59b4d05b61cc7feba9
[smdp.git] / test / fade.c
1 #include <ncurses.h>
2 #include <signal.h>
3 #include <stdlib.h>
4 #define COLOR_PAIR1 1
5 #define COLOR_PAIR2 2
6 int main()
7 {
8     initscr();
9     curs_set(0);//sets visability of cursor
10     noecho();//disable auto-echoing
11     cbreak();//making getch() work without a buffer
12     keypad(stdscr,TRUE);//allows use of special keys, namely the arrow keys
13     if(has_colors() == TRUE)
14     {
15         start_color();
16         use_default_colors();
17         init_pair(COLOR_PAIR1,123,-1);
18         init_pair(COLOR_PAIR2,213,-1);
19         wbkgd(stdscr,COLOR_PAIR(COLOR_PAIR1));
20         wmove(stdscr,10,5);
21         printw("q = quit");
22         WINDOW *test=newwin(10,20,5,20);
23         wbkgd(test,COLOR_PAIR(COLOR_PAIR2));
24         wprintw(test,"try\nUP or DOWN");
25         wrefresh(stdscr);
26         wrefresh(test);
27
28         // fading colors
29         short blue_ramp[]  = { 16,  17,  17,  18,  18,  19,
30                                19,  20,  20,  21,  27,  32,
31                                33,  38,  39,  44,  45,  45,
32                                81,  81,  51,  51, 123, 123};
33         short white_ramp[] = {232, 233, 234, 235, 236, 237,
34                               238, 239, 240, 241, 242, 243,
35                               244, 245, 246, 247, 248, 249,
36                               250, 251, 252, 253, 254, 255};
37         short red_ramp[]   = { 16,  52,  52,  53,  53,  89,
38                                89,  90,  90, 126, 127, 127,
39                               163, 163, 164, 164, 200, 200,
40                               201, 201, 207, 207, 213, 213};
41
42         short i = 23;
43         for (;;)
44         {
45             int c = getch();
46             if(c == 'q') break;
47
48             switch(c) {
49                 case KEY_UP:
50                     if(i < 23) i = i + 1;
51                     break;
52
53                 case KEY_DOWN:
54                     if(i > 0)i = i - 1;
55                     break;
56             }
57
58             init_pair(COLOR_PAIR1,blue_ramp[i],-1);
59             init_pair(COLOR_PAIR2,red_ramp[i],-1);
60             wrefresh(stdscr);
61             wrefresh(test);
62         }
63
64         delwin(test);
65     }
66
67     endwin();
68     return 0;
69 }