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.
 
 
 
 
 

130 lines
2.1 KiB

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