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.
 
 
 
 
 
 

134 lines
2.9 KiB

  1. /*
  2. * libee ASCII-Art library
  3. * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  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. #if defined(USE_SLANG)
  24. # include <slang.h>
  25. #elif defined(USE_NCURSES)
  26. # include <curses.h>
  27. #elif defined(USE_CONIO)
  28. # include <conio.h>
  29. #else
  30. # error "no graphics library detected"
  31. #endif
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include "ee.h"
  35. static int ee_color = 0;
  36. #if defined(USE_CONIO)
  37. static enum COLORS dos_colors[] = {
  38. 0,
  39. BLACK,
  40. GREEN,
  41. YELLOW,
  42. WHITE,
  43. RED,
  44. DARKGRAY,
  45. LIGHTGRAY,
  46. BLUE,
  47. CYAN,
  48. MAGENTA
  49. };
  50. #endif
  51. void ee_set_color(int color)
  52. {
  53. ee_color = color;
  54. #if defined(USE_SLANG)
  55. SLsmg_set_color(color);
  56. #elif defined(USE_NCURSES)
  57. attrset(COLOR_PAIR(color));
  58. #elif defined(USE_CONIO)
  59. if(color >= 1 && color <= 10)
  60. textcolor(dos_colors[color]);
  61. #endif
  62. }
  63. int ee_get_color(void)
  64. {
  65. return ee_color;
  66. }
  67. extern char *_screen_buffer;
  68. void ee_putchar(int x, int y, char c)
  69. {
  70. #if defined(USE_SLANG)
  71. SLsmg_gotorc(y,x);
  72. SLsmg_write_char(c);
  73. #elif defined(USE_NCURSES)
  74. move(y,x);
  75. addch(c);
  76. #elif defined(USE_CONIO)
  77. if(x<0 || x>=ee_get_width() || y<0 || y>=ee_get_height())
  78. return;
  79. _screen_buffer[2 * (x + y * ee_get_width())] = c;
  80. _screen_buffer[2 * (x + y * ee_get_width()) + 1] = dos_colors[ee_color];
  81. // gotoxy(x+1,y+1);
  82. // putch(c);
  83. #endif
  84. }
  85. void ee_putstr(int x, int y, char *s)
  86. {
  87. if(y<0 || y>=ee_get_height())
  88. return;
  89. #if defined(USE_SLANG)
  90. SLsmg_gotorc(y,x);
  91. SLsmg_write_string(s);
  92. #elif defined(USE_NCURSES)
  93. move(y,x);
  94. addstr(s);
  95. #elif defined(USE_CONIO)
  96. char *buf = _screen_buffer + 2 * (x + y * ee_get_width());
  97. while(*s)
  98. {
  99. *buf++ = *s++;
  100. *buf++ = dos_colors[ee_color];
  101. }
  102. // gotoxy(x+1,y+1);
  103. // cputs(s);
  104. #endif
  105. }
  106. void ee_clear(void)
  107. {
  108. /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
  109. int x = ee_get_width(), y = ee_get_height();
  110. char *empty_line = malloc((x + 1) * sizeof(char));
  111. memset(empty_line, ' ', x);
  112. empty_line[x] = '\0';
  113. while(y--)
  114. {
  115. ee_putstr(0, y, empty_line);
  116. }
  117. free(empty_line);
  118. }