選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

136 行
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. #include "ee_internals.h"
  36. static int ee_color = 0;
  37. void ee_set_color(int color)
  38. {
  39. if(color < 0 || color > 15)
  40. return;
  41. ee_color = color;
  42. #if defined(USE_SLANG)
  43. SLsmg_set_color(color + 1);
  44. #elif defined(USE_NCURSES)
  45. attrset(_ee_attr[color]);
  46. #elif defined(USE_CONIO)
  47. textcolor(color);
  48. #endif
  49. }
  50. int ee_get_color(void)
  51. {
  52. return ee_color;
  53. }
  54. void ee_putchar(int x, int y, char c)
  55. {
  56. if(x < 0 || x >= ee_get_width() || y < 0 || y >= ee_get_height())
  57. return;
  58. #if defined(USE_SLANG)
  59. SLsmg_gotorc(y, x);
  60. SLsmg_write_char(c);
  61. #elif defined(USE_NCURSES)
  62. move(y, x);
  63. addch(c);
  64. #elif defined(USE_CONIO)
  65. _ee_screen[2 * (x + y * ee_get_width())] = c;
  66. _ee_screen[2 * (x + y * ee_get_width()) + 1] = ee_color;
  67. // gotoxy(x + 1, y + 1);
  68. // putch(c);
  69. #endif
  70. }
  71. void ee_putstr(int x, int y, char *s)
  72. {
  73. int len;
  74. if(y < 0 || y >= ee_get_height())
  75. return;
  76. len = strlen(s);
  77. if(x < 0)
  78. {
  79. len -= -x;
  80. if(len < 0)
  81. return;
  82. s += -x;
  83. x = 0;
  84. }
  85. #if defined(USE_SLANG)
  86. SLsmg_gotorc(y, x);
  87. SLsmg_write_string(s);
  88. #elif defined(USE_NCURSES)
  89. move(y, x);
  90. addstr(s);
  91. #elif defined(USE_CONIO)
  92. char *buf = _ee_screen + 2 * (x + y * ee_get_width());
  93. while(*s)
  94. {
  95. *buf++ = *s++;
  96. *buf++ = ee_color;
  97. }
  98. // gotoxy(x + 1, y + 1);
  99. // cputs(s);
  100. #endif
  101. }
  102. void ee_clear(void)
  103. {
  104. /* We could use SLsmg_cls() etc., but drawing empty lines is much faster */
  105. int x = ee_get_width();
  106. int y = ee_get_height();
  107. char *empty_line = malloc((x + 1) * sizeof(char));
  108. memset(empty_line, ' ', x);
  109. empty_line[x] = '\0';
  110. while(y--)
  111. {
  112. ee_putstr(0, y, empty_line);
  113. }
  114. free(empty_line);
  115. }