source: libcaca/trunk/src/graphics.c @ 51

Last change on this file since 51 was 51, checked in by Sam Hocevar, 18 years ago
  • added support for --disable-slang.
  • fixed an overflow in the tunnel update code.
  • fragbomb is now 'f', not 'd'.
  • added a missing call to init_bonus().
File size: 3.3 KB
Line 
1/*
2 *   ttyvaders     Textmode shoot'em up
3 *   Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
6 *   $Id: graphics.c,v 1.5 2002/12/23 10:06:27 sam Exp $
7 *
8 *   This program is free software; you can redistribute it and/or modify
9 *   it under the terms of the GNU General Public License as published by
10 *   the Free Software Foundation; either version 2 of the License, or
11 *   (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <stdlib.h>
24
25#include "common.h"
26
27int init_graphics( void )
28{
29#ifdef USE_SLANG
30    /* Initialize slang library */
31    SLsig_block_signals();
32    SLtt_get_terminfo();
33
34    if( SLkp_init() == -1 )
35    {
36        SLsig_unblock_signals();
37        return 1;
38    }
39
40    SLang_init_tty (-1, 0, 1);
41
42    if( SLsmg_init_smg() == -1 )
43    {
44        SLsig_unblock_signals();
45        return 1;
46    }
47
48    SLsig_unblock_signals();
49
50    SLsmg_cls();
51    SLsmg_refresh();
52#elif USE_NCURSES
53    /* Initialize ncurses library */
54    initscr();
55    keypad(stdscr, TRUE);
56    nonl();
57    cbreak();
58    noecho();
59    nodelay(stdscr, TRUE);
60#else
61    /* Dummy driver */
62#endif
63
64    return 0;
65}
66
67void init_game( game *g )
68{
69#ifdef USE_SLANG
70    static char * const colors[] =
71    {
72        "black", "green", "yellow", "white",
73        "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL
74    };
75
76    int i;
77
78    for( i = 0; colors[i] ; i++ )
79    {
80        SLtt_set_color( i+1, NULL, colors[i], "black" );
81    }
82
83    g->w = SLtt_Screen_Cols;
84    g->h = SLtt_Screen_Rows;
85#elif USE_NCURSES
86    start_color();
87
88    init_pair( BLACK, COLOR_BLACK, COLOR_BLACK );
89    init_pair( GREEN, COLOR_GREEN, COLOR_BLACK );
90    init_pair( YELLOW, COLOR_YELLOW, COLOR_BLACK );
91    init_pair( WHITE, COLOR_WHITE, COLOR_BLACK );
92    init_pair( RED, COLOR_RED, COLOR_BLACK );
93    init_pair( GRAY, COLOR_WHITE, COLOR_BLACK ); // XXX
94    init_pair( LIGHTGRAY, COLOR_WHITE, COLOR_BLACK ); // XXX
95    init_pair( BLUE, COLOR_BLUE, COLOR_BLACK );
96    init_pair( CYAN, COLOR_CYAN, COLOR_BLACK );
97    init_pair( MAGENTA, COLOR_MAGENTA, COLOR_BLACK );
98
99    g->w = COLS;
100    g->h = LINES;
101#else
102    /* Use dummy driver */
103    g->w = 80;
104    g->h = 25;
105#endif
106}
107
108char get_key( void )
109{
110#ifdef USE_SLANG
111    if( SLang_input_pending (0) )
112    {
113        return SLang_getkey();
114    }
115#elif USE_NCURSES
116    char key;
117
118    if( ( key = getch() ) != ERR )
119    {
120        return key;
121    }
122#else
123    /* Use dummy driver */
124#endif
125
126    return 0;
127}
128
129void clear_graphics( void )
130{
131#ifdef USE_SLANG
132    SLsmg_cls();
133#elif USE_NCURSES
134    clear();
135#else
136    /* Use dummy driver */
137#endif
138}
139
140void refresh_graphics( void )
141{
142    gfx_goto( 0, 0 );
143#ifdef USE_SLANG
144    SLsmg_refresh();
145#elif USE_NCURSES
146    refresh();
147#else
148    /* Use dummy driver */
149#endif
150}
151
152void end_graphics( void )
153{
154#ifdef USE_SLANG
155    SLang_reset_tty();
156    SLsmg_reset_smg();
157#elif USE_NCURSES
158    endwin();
159#else
160    /* Use dummy driver */
161#endif
162}
163
Note: See TracBrowser for help on using the repository browser.