rewrote Makefile + copyright and license infos
[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 red_ramp[]   = { 16,  52,  52,  53,  53,  89,
34                                89,  90,  90, 126, 127, 127,
35                               163, 163, 164, 164, 200, 200,
36                               201, 201, 207, 207, 213, 213};
37
38         short i = 23;
39         for (;;)
40         {
41             int c = getch();
42             if(c == 'q') break;
43
44             switch(c) {
45                 case KEY_UP:
46                     if(i < 23) i = i + 1;
47                     break;
48
49                 case KEY_DOWN:
50                     if(i > 0)i = i - 1;
51                     break;
52             }
53
54             init_pair(COLOR_PAIR1,blue_ramp[i],-1);
55             init_pair(COLOR_PAIR2,red_ramp[i],-1);
56             wrefresh(stdscr);
57             wrefresh(test);
58         }
59
60         delwin(test);
61     }
62
63     endwin();
64     return 0;
65 }