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.
 
 
 
 
 

120 lines
2.4 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. #ifdef USE_SLANG
  24. # include <slang.h>
  25. #elif USE_NCURSES
  26. # include <curses.h>
  27. #elif 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. #ifdef 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. #ifdef USE_SLANG
  55. SLsmg_set_color(color);
  56. #elif USE_NCURSES
  57. attrset(COLOR_PAIR(color));
  58. #elif 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. void ee_putchar(int x, int y, char c)
  68. {
  69. #ifdef USE_SLANG
  70. SLsmg_gotorc(y,x);
  71. SLsmg_write_char(c);
  72. #elif USE_NCURSES
  73. move(y,x);
  74. addch(c);
  75. #elif USE_CONIO
  76. gotoxy(x+1,y+1);
  77. putch(c);
  78. #endif
  79. }
  80. void ee_putstr(int x, int y, char *s)
  81. {
  82. #ifdef USE_SLANG
  83. SLsmg_gotorc(y,x);
  84. SLsmg_write_string(s);
  85. #elif USE_NCURSES
  86. move(y,x);
  87. addstr(s);
  88. #elif USE_CONIO
  89. gotoxy(x+1,y+1);
  90. cputs(s);
  91. #endif
  92. }
  93. void ee_clear(void)
  94. {
  95. /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
  96. int x = ee_get_width(), y = ee_get_height();
  97. char *empty_line = malloc((x + 1) * sizeof(char));
  98. memset(empty_line, ' ', x);
  99. empty_line[x] = '\0';
  100. while(y--)
  101. {
  102. ee_putstr(0, y, empty_line);
  103. }
  104. free(empty_line);
  105. }