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.
 
 
 
 
 

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