d39533b30395a899499b9a0eff4d0ff453f1add4
[coreboot.git] / payloads / libpayload / curses / PDCurses-3.4 / sdl1 / sdltest.c
1 /* Here's a simple example of combining SDL and PDCurses functionality.
2    The top portion of the window is devoted to SDL, with a four-line
3    (assuming the default 8x16 font) stdscr at the bottom.
4
5    $Id: sdltest.c,v 1.2 2008/07/14 04:24:52 wmcbrine Exp $
6 */
7
8 #include <SDL/SDL.h>
9 #include <curses.h>
10 #include <stdlib.h>
11 #include <time.h>
12
13 /* You could #include pdcsdl.h, or just add the relevant declarations 
14    here: */
15
16 PDCEX SDL_Surface *pdc_screen;
17 PDCEX int pdc_yoffset;
18
19 int main(int argc, char **argv)
20 {
21     char inp[60];
22     int i, j, seed;
23
24     seed = time((time_t *)0);
25     srand(seed);
26
27     /* Initialize SDL */
28
29     if (SDL_Init(SDL_INIT_VIDEO) < 0)
30         exit(1);
31
32     atexit(SDL_Quit);
33
34     pdc_screen = SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE|SDL_ANYFORMAT);
35
36     /* Initialize PDCurses */
37
38     pdc_yoffset = 416;  /* 480 - 4 * 16 */
39
40     initscr();
41     start_color();
42     scrollok(stdscr, TRUE);
43
44     PDC_set_title("PDCurses for SDL");
45
46     /* Do some SDL stuff */
47
48     for (i = 640, j = 416; j; i -= 2, j -= 2)
49     {
50         SDL_Rect dest;
51
52         dest.x = (640 - i) / 2;
53         dest.y = (416 - j) / 2;
54         dest.w = i;
55         dest.h = j;
56
57         SDL_FillRect(pdc_screen, &dest, 
58                      SDL_MapRGB(pdc_screen->format, rand() % 256,
59                                 rand() % 256, rand() % 256));
60     }
61
62     SDL_UpdateRect(pdc_screen, 0, 0, 640, 416);
63
64     /* Do some curses stuff */
65
66     init_pair(1, COLOR_WHITE + 8, COLOR_BLUE);
67     bkgd(COLOR_PAIR(1));
68
69     addstr("This is a demo of ");
70     attron(A_UNDERLINE);
71     addstr("PDCurses for SDL");
72     attroff(A_UNDERLINE);
73     addstr(".\nYour comments here: ");
74     getnstr(inp, 59);
75     addstr("Press any key to exit.");
76
77     getch();
78     endwin();
79
80     return 0;
81 }