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.
 
 
 
 
 
 

124 lines
2.9 KiB

  1. /*
  2. * libcaca ASCII-Art library
  3. * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library 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 GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. */
  23. #include "config.h"
  24. #include <stdlib.h>
  25. #include "caca.h"
  26. #include "caca_internals.h"
  27. void caca_draw_box(int x1, int y1, int x2, int y2, char c)
  28. {
  29. caca_draw_line(x1, y1, x1, y2, c);
  30. caca_draw_line(x1, y2, x2, y2, c);
  31. caca_draw_line(x2, y2, x2, y1, c);
  32. caca_draw_line(x2, y1, x1, y1, c);
  33. }
  34. void caca_draw_thin_box(int x1, int y1, int x2, int y2)
  35. {
  36. int x, y, xmax, ymax;
  37. if(x1 > x2)
  38. {
  39. int tmp = x1;
  40. x1 = x2; x2 = tmp;
  41. }
  42. if(y1 > y2)
  43. {
  44. int tmp = y1;
  45. y1 = y2; y2 = tmp;
  46. }
  47. xmax = caca_get_width() - 1;
  48. ymax = caca_get_height() - 1;
  49. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  50. return;
  51. /* Draw edges */
  52. if(y1 >= 0)
  53. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  54. caca_putchar(x, y1, '-');
  55. if(y2 <= ymax)
  56. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  57. caca_putchar(x, y2, '-');
  58. if(x1 >= 0)
  59. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  60. caca_putchar(x1, y, '|');
  61. if(x2 <= xmax)
  62. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  63. caca_putchar(x2, y, '|');
  64. /* Draw corners */
  65. if(x1 >= 0 && y1 >= 0)
  66. caca_putchar(x1, y1, ',');
  67. if(x1 >= 0 && y2 <= ymax)
  68. caca_putchar(x1, y2, '`');
  69. if(x2 <= xmax && y1 >= 0)
  70. caca_putchar(x2, y1, '.');
  71. if(x2 <= xmax && y2 <= ymax)
  72. caca_putchar(x2, y2, '\'');
  73. }
  74. void caca_fill_box(int x1, int y1, int x2, int y2, char c)
  75. {
  76. int x, y, xmax, ymax;
  77. if(x1 > x2)
  78. {
  79. int tmp = x1;
  80. x1 = x2; x2 = tmp;
  81. }
  82. if(y1 > y2)
  83. {
  84. int tmp = y1;
  85. y1 = y2; y2 = tmp;
  86. }
  87. xmax = caca_get_width() - 1;
  88. ymax = caca_get_height() - 1;
  89. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  90. return;
  91. if(x1 < 0) x1 = 0;
  92. if(y1 < 0) y1 = 0;
  93. if(x2 > xmax) x2 = xmax;
  94. if(y2 > ymax) y2 = ymax;
  95. for(y = y1; y <= y2; y++)
  96. for(x = x1; x <= x2; x++)
  97. caca_putchar(x, y, c);
  98. }