Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

128 linhas
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. #ifdef USE_SLANG
  24. # include <slang.h>
  25. #elif USE_NCURSES
  26. # include <curses.h>
  27. #endif
  28. #include <stdlib.h>
  29. #include "ee.h"
  30. void ee_draw_box(int x1, int y1, int x2, int y2, char c)
  31. {
  32. ee_draw_line(x1, y1, x1, y2, c);
  33. ee_draw_line(x1, y2, x2, y2, c);
  34. ee_draw_line(x2, y2, x2, y1, c);
  35. ee_draw_line(x2, y1, x1, y1, c);
  36. }
  37. void ee_draw_thin_box(int x1, int y1, int x2, int y2)
  38. {
  39. int x, y, xmax, ymax;
  40. if(x1 > x2)
  41. {
  42. int tmp = x1;
  43. x1 = x2; x2 = tmp;
  44. }
  45. if(y1 > y2)
  46. {
  47. int tmp = y1;
  48. y1 = y2; y2 = tmp;
  49. }
  50. xmax = ee_get_width() - 1;
  51. ymax = ee_get_height() - 1;
  52. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  53. return;
  54. /* Draw edges */
  55. if(y1 >= 0)
  56. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  57. ee_putchar(x, y1, '-');
  58. if(y2 <= ymax)
  59. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  60. ee_putchar(x, y2, '-');
  61. if(x1 >= 0)
  62. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  63. ee_putchar(x1, y, '|');
  64. if(x2 <= xmax)
  65. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  66. ee_putchar(x2, y, '|');
  67. /* Draw corners */
  68. if(x1 >= 0 && y1 >= 0)
  69. ee_putchar(x1, y1, ',');
  70. if(x1 >= 0 && y2 <= ymax)
  71. ee_putchar(x1, y2, '`');
  72. if(x2 <= xmax && y1 >= 0)
  73. ee_putchar(x2, y1, '.');
  74. if(x2 <= xmax && y2 <= ymax)
  75. ee_putchar(x2, y2, '\'');
  76. }
  77. void ee_fill_box(int x1, int y1, int x2, int y2, char c)
  78. {
  79. int x, y, xmax, ymax;
  80. if(x1 > x2)
  81. {
  82. int tmp = x1;
  83. x1 = x2; x2 = tmp;
  84. }
  85. if(y1 > y2)
  86. {
  87. int tmp = y1;
  88. y1 = y2; y2 = tmp;
  89. }
  90. xmax = ee_get_width() - 1;
  91. ymax = ee_get_height() - 1;
  92. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  93. return;
  94. if(x1 < 0) x1 = 0;
  95. if(y1 < 0) y1 = 0;
  96. if(x2 > xmax) x2 = xmax;
  97. if(y2 > ymax) y2 = ymax;
  98. for(y = y1; y <= y2; y++)
  99. for(x = x1; x <= x2; x++)
  100. ee_putchar(x, y, c);
  101. }