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.
 
 
 
 
 

102 lines
2.1 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. #endif
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include "ee.h"
  31. static int ee_color = 0;
  32. void ee_set_color(int color)
  33. {
  34. ee_color = color;
  35. #ifdef USE_SLANG
  36. SLsmg_set_color(color);
  37. #elif USE_NCURSES
  38. attrset(COLOR_PAIR(color));
  39. #else
  40. /* Use dummy driver */
  41. #endif
  42. }
  43. int ee_get_color(void)
  44. {
  45. return ee_color;
  46. }
  47. void ee_putchar(int x, int y, char c)
  48. {
  49. #ifdef USE_SLANG
  50. SLsmg_gotorc(y,x);
  51. SLsmg_write_char(c);
  52. #elif USE_NCURSES
  53. move(y,x);
  54. addch(c);
  55. #else
  56. /* Use dummy driver */
  57. #endif
  58. }
  59. void ee_putstr(int x, int y, char *s)
  60. {
  61. #ifdef USE_SLANG
  62. SLsmg_gotorc(y,x);
  63. SLsmg_write_string(s);
  64. #elif USE_NCURSES
  65. move(y,x);
  66. addstr(s);
  67. #else
  68. /* Use dummy driver */
  69. #endif
  70. }
  71. void ee_clear(void)
  72. {
  73. #if defined(USE_SLANG) || defined(USE_NCURSES)
  74. /* We could use SLsmg_cls(), but drawing empty lines is much faster */
  75. int x = ee_get_width(), y = ee_get_height();
  76. char *empty_line = malloc((x + 1) * sizeof(char));
  77. memset(empty_line, ' ', x);
  78. empty_line[x] = '\0';
  79. while(y--)
  80. {
  81. ee_putstr(0, y, empty_line);
  82. }
  83. free(empty_line);
  84. #else
  85. /* Use dummy driver */
  86. #endif
  87. }