You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

184 lines
3.6 KiB

  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.6 2002/12/23 16:21:38 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. #include "config.h"
  23. #include <stdlib.h>
  24. #include <unistd.h>
  25. #include "common.h"
  26. int init_graphics( void )
  27. {
  28. #ifdef USE_SLANG
  29. /* Initialize slang library */
  30. SLsig_block_signals();
  31. SLtt_get_terminfo();
  32. if( SLkp_init() == -1 )
  33. {
  34. SLsig_unblock_signals();
  35. return 1;
  36. }
  37. SLang_init_tty (-1, 0, 1);
  38. if( SLsmg_init_smg() == -1 )
  39. {
  40. SLsig_unblock_signals();
  41. return 1;
  42. }
  43. SLsig_unblock_signals();
  44. SLsmg_cls();
  45. SLsmg_refresh();
  46. #elif USE_NCURSES
  47. /* Initialize ncurses library */
  48. initscr();
  49. keypad(stdscr, TRUE);
  50. nonl();
  51. cbreak();
  52. noecho();
  53. nodelay(stdscr, TRUE);
  54. #else
  55. /* Dummy driver */
  56. #endif
  57. return 0;
  58. }
  59. void init_game( game *g )
  60. {
  61. #ifdef USE_SLANG
  62. static char * const colors[] =
  63. {
  64. "black", "green", "yellow", "white",
  65. "red", "gray", "lightgray", "blue", "cyan", "magenta", NULL
  66. };
  67. int i;
  68. for( i = 0; colors[i] ; i++ )
  69. {
  70. SLtt_set_color( i+1, NULL, colors[i], "black" );
  71. }
  72. g->w = SLtt_Screen_Cols;
  73. g->h = SLtt_Screen_Rows;
  74. #elif USE_NCURSES
  75. start_color();
  76. init_pair( BLACK, COLOR_BLACK, COLOR_BLACK );
  77. init_pair( GREEN, COLOR_GREEN, COLOR_BLACK );
  78. init_pair( YELLOW, COLOR_YELLOW, COLOR_BLACK );
  79. init_pair( WHITE, COLOR_WHITE, COLOR_BLACK );
  80. init_pair( RED, COLOR_RED, COLOR_BLACK );
  81. init_pair( GRAY, COLOR_WHITE, COLOR_BLACK ); // XXX
  82. init_pair( LIGHTGRAY, COLOR_WHITE, COLOR_BLACK ); // XXX
  83. init_pair( BLUE, COLOR_BLUE, COLOR_BLACK );
  84. init_pair( CYAN, COLOR_CYAN, COLOR_BLACK );
  85. init_pair( MAGENTA, COLOR_MAGENTA, COLOR_BLACK );
  86. g->w = COLS;
  87. g->h = LINES;
  88. #else
  89. /* Use dummy driver */
  90. g->w = 80;
  91. g->h = 25;
  92. #endif
  93. }
  94. char get_key( void )
  95. {
  96. #ifdef USE_SLANG
  97. if( SLang_input_pending (0) )
  98. {
  99. return SLang_getkey();
  100. }
  101. #elif USE_NCURSES
  102. char key;
  103. if( ( key = getch() ) != ERR )
  104. {
  105. return key;
  106. }
  107. #else
  108. /* Use dummy driver */
  109. char key = GET_RAND(0,256);
  110. if( key != 'q' && key != 'p' && key != '\t' )
  111. {
  112. return key;
  113. }
  114. #endif
  115. return 0;
  116. }
  117. void gfx_delay( void )
  118. {
  119. #ifdef USE_SLANG
  120. usleep(40000);
  121. #elif USE_NCURSES
  122. usleep(40000);
  123. #else
  124. /* Use dummy driver */
  125. #endif
  126. }
  127. void clear_graphics( void )
  128. {
  129. #ifdef USE_SLANG
  130. SLsmg_cls();
  131. #elif USE_NCURSES
  132. clear();
  133. #else
  134. /* Use dummy driver */
  135. #endif
  136. }
  137. void refresh_graphics( void )
  138. {
  139. gfx_goto( 0, 0 );
  140. #ifdef USE_SLANG
  141. SLsmg_refresh();
  142. #elif USE_NCURSES
  143. refresh();
  144. #else
  145. /* Use dummy driver */
  146. #endif
  147. }
  148. void end_graphics( void )
  149. {
  150. #ifdef USE_SLANG
  151. SLang_reset_tty();
  152. SLsmg_reset_smg();
  153. #elif USE_NCURSES
  154. endwin();
  155. #else
  156. /* Use dummy driver */
  157. #endif
  158. }