1 | |
---|
2 | #include <stdlib.h> |
---|
3 | |
---|
4 | #include "common.h" |
---|
5 | |
---|
6 | int init_graphics( void ) |
---|
7 | { |
---|
8 | #ifdef USE_SLANG |
---|
9 | /* Initialize slang library */ |
---|
10 | SLsig_block_signals(); |
---|
11 | SLtt_get_terminfo(); |
---|
12 | |
---|
13 | if( SLkp_init() == -1 ) |
---|
14 | { |
---|
15 | SLsig_unblock_signals(); |
---|
16 | return 1; |
---|
17 | } |
---|
18 | |
---|
19 | SLang_init_tty (-1, 0, 1); |
---|
20 | |
---|
21 | if( SLsmg_init_smg() == -1 ) |
---|
22 | { |
---|
23 | SLsig_unblock_signals(); |
---|
24 | return 1; |
---|
25 | } |
---|
26 | |
---|
27 | SLsig_unblock_signals(); |
---|
28 | |
---|
29 | SLsmg_cls(); |
---|
30 | SLsmg_refresh(); |
---|
31 | #else |
---|
32 | /* Initialize ncurses library */ |
---|
33 | initscr(); |
---|
34 | keypad(stdscr, TRUE); |
---|
35 | nonl(); |
---|
36 | cbreak(); |
---|
37 | noecho(); |
---|
38 | nodelay(stdscr, TRUE); |
---|
39 | #endif |
---|
40 | |
---|
41 | return 0; |
---|
42 | } |
---|
43 | |
---|
44 | void init_game( game *g ) |
---|
45 | { |
---|
46 | #ifdef USE_SLANG |
---|
47 | static char * const colors[] = |
---|
48 | { |
---|
49 | "black", "green", "yellow", "white", |
---|
50 | "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL |
---|
51 | }; |
---|
52 | |
---|
53 | int i; |
---|
54 | |
---|
55 | for( i = 0; colors[i] ; i++ ) |
---|
56 | { |
---|
57 | SLtt_set_color( i+1, NULL, colors[i], "black" ); |
---|
58 | } |
---|
59 | |
---|
60 | g->w = SLtt_Screen_Cols; |
---|
61 | g->h = SLtt_Screen_Rows; |
---|
62 | #else |
---|
63 | start_color(); |
---|
64 | |
---|
65 | init_pair( BLACK, COLOR_BLACK, COLOR_BLACK ); |
---|
66 | init_pair( GREEN, COLOR_GREEN, COLOR_BLACK ); |
---|
67 | init_pair( YELLOW, COLOR_YELLOW, COLOR_BLACK ); |
---|
68 | init_pair( WHITE, COLOR_WHITE, COLOR_BLACK ); |
---|
69 | init_pair( RED, COLOR_RED, COLOR_BLACK ); |
---|
70 | init_pair( GRAY, COLOR_WHITE, COLOR_BLACK ); // XXX |
---|
71 | init_pair( LIGHTGRAY, COLOR_WHITE, COLOR_BLACK ); // XXX |
---|
72 | init_pair( BLUE, COLOR_BLUE, COLOR_BLACK ); |
---|
73 | init_pair( CYAN, COLOR_CYAN, COLOR_BLACK ); |
---|
74 | init_pair( MAGENTA, COLOR_MAGENTA, COLOR_BLACK ); |
---|
75 | |
---|
76 | g->w = COLS; |
---|
77 | g->h = LINES; |
---|
78 | #endif |
---|
79 | } |
---|
80 | |
---|
81 | char get_key( void ) |
---|
82 | { |
---|
83 | #ifdef USE_SLANG |
---|
84 | if( SLang_input_pending (0) ) |
---|
85 | { |
---|
86 | return SLang_getkey(); |
---|
87 | } |
---|
88 | #else |
---|
89 | char key; |
---|
90 | |
---|
91 | if( ( key = getch() ) != ERR ) |
---|
92 | { |
---|
93 | return key; |
---|
94 | } |
---|
95 | #endif |
---|
96 | |
---|
97 | return 0; |
---|
98 | } |
---|
99 | |
---|
100 | void clear_graphics( void ) |
---|
101 | { |
---|
102 | #ifdef USE_SLANG |
---|
103 | SLsmg_cls(); |
---|
104 | #else |
---|
105 | clear(); |
---|
106 | #endif |
---|
107 | } |
---|
108 | |
---|
109 | void refresh_graphics( void ) |
---|
110 | { |
---|
111 | gfx_goto( 0, 0 ); |
---|
112 | #ifdef USE_SLANG |
---|
113 | SLsmg_refresh(); |
---|
114 | #else |
---|
115 | refresh(); |
---|
116 | #endif |
---|
117 | } |
---|
118 | |
---|
119 | void end_graphics( void ) |
---|
120 | { |
---|
121 | #ifdef USE_SLANG |
---|
122 | SLang_reset_tty(); |
---|
123 | SLsmg_reset_smg(); |
---|
124 | #else |
---|
125 | endwin(); |
---|
126 | #endif |
---|
127 | } |
---|
128 | |
---|
129 | |
---|