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.

преди 18 години
преди 21 години
преди 18 години
преди 18 години
преди 18 години
преди 18 години
преди 18 години
преди 18 години
преди 18 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * This file contains box drawing functions, both filled and outline.
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #if !defined(__KERNEL__)
  20. # include <stdlib.h>
  21. #endif
  22. #include "cucul.h"
  23. #include "cucul_internals.h"
  24. /** \brief Draw a box on the canvas using the given character.
  25. *
  26. * This function never fails.
  27. *
  28. * \param cv The handle to the libcucul canvas.
  29. * \param x1 X coordinate of the upper-left corner of the box.
  30. * \param y1 Y coordinate of the upper-left corner of the box.
  31. * \param x2 X coordinate of the lower-right corner of the box.
  32. * \param y2 Y coordinate of the lower-right corner of the box.
  33. * \param ch UTF-32 character to be used to draw the box.
  34. * \return This function always returns 0.
  35. */
  36. int cucul_draw_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
  37. unsigned long int ch)
  38. {
  39. cucul_draw_line(cv, x1, y1, x1, y2, ch);
  40. cucul_draw_line(cv, x1, y2, x2, y2, ch);
  41. cucul_draw_line(cv, x2, y2, x2, y1, ch);
  42. cucul_draw_line(cv, x2, y1, x1, y1, ch);
  43. return 0;
  44. }
  45. /** \brief Draw a thin box on the canvas.
  46. *
  47. * This function never fails.
  48. *
  49. * \param cv The handle to the libcucul canvas.
  50. * \param x1 X coordinate of the upper-left corner of the box.
  51. * \param y1 Y coordinate of the upper-left corner of the box.
  52. * \param x2 X coordinate of the lower-right corner of the box.
  53. * \param y2 Y coordinate of the lower-right corner of the box.
  54. * \return This function always returns 0.
  55. */
  56. int cucul_draw_thin_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
  57. {
  58. int x, y, xmax, ymax;
  59. if(x1 > x2)
  60. {
  61. int tmp = x1;
  62. x1 = x2; x2 = tmp;
  63. }
  64. if(y1 > y2)
  65. {
  66. int tmp = y1;
  67. y1 = y2; y2 = tmp;
  68. }
  69. xmax = cv->width - 1;
  70. ymax = cv->height - 1;
  71. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  72. return 0;
  73. /* Draw edges */
  74. if(y1 >= 0)
  75. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  76. cucul_put_char(cv, x, y1, '-');
  77. if(y2 <= ymax)
  78. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  79. cucul_put_char(cv, x, y2, '-');
  80. if(x1 >= 0)
  81. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  82. cucul_put_char(cv, x1, y, '|');
  83. if(x2 <= xmax)
  84. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  85. cucul_put_char(cv, x2, y, '|');
  86. /* Draw corners */
  87. cucul_put_char(cv, x1, y1, ',');
  88. cucul_put_char(cv, x1, y2, '`');
  89. cucul_put_char(cv, x2, y1, '.');
  90. cucul_put_char(cv, x2, y2, '\'');
  91. return 0;
  92. }
  93. /** \brief Draw a box on the canvas using CP437 characters.
  94. *
  95. * This function never fails.
  96. *
  97. * \param cv The handle to the libcucul canvas.
  98. * \param x1 X coordinate of the upper-left corner of the box.
  99. * \param y1 Y coordinate of the upper-left corner of the box.
  100. * \param x2 X coordinate of the lower-right corner of the box.
  101. * \param y2 Y coordinate of the lower-right corner of the box.
  102. * \return This function always returns 0.
  103. */
  104. int cucul_draw_cp437_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2)
  105. {
  106. int x, y, xmax, ymax;
  107. if(x1 > x2)
  108. {
  109. int tmp = x1;
  110. x1 = x2; x2 = tmp;
  111. }
  112. if(y1 > y2)
  113. {
  114. int tmp = y1;
  115. y1 = y2; y2 = tmp;
  116. }
  117. xmax = cv->width - 1;
  118. ymax = cv->height - 1;
  119. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  120. return 0;
  121. /* Draw edges */
  122. if(y1 >= 0)
  123. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  124. cucul_put_char(cv, x, y1, 0x2500); /* ─ */
  125. if(y2 <= ymax)
  126. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  127. cucul_put_char(cv, x, y2, 0x2500); /* ─ */
  128. if(x1 >= 0)
  129. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  130. cucul_put_char(cv, x1, y, 0x2502); /* │ */
  131. if(x2 <= xmax)
  132. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  133. cucul_put_char(cv, x2, y, 0x2502); /* │ */
  134. /* Draw corners */
  135. cucul_put_char(cv, x1, y1, 0x250c); /* ┌ */
  136. cucul_put_char(cv, x1, y2, 0x2514); /* └ */
  137. cucul_put_char(cv, x2, y1, 0x2510); /* ┐ */
  138. cucul_put_char(cv, x2, y2, 0x2518); /* ┘ */
  139. return 0;
  140. }
  141. /** \brief Fill a box on the canvas using the given character.
  142. *
  143. * This function never fails.
  144. *
  145. * \param cv The handle to the libcucul canvas.
  146. * \param x1 X coordinate of the upper-left corner of the box.
  147. * \param y1 Y coordinate of the upper-left corner of the box.
  148. * \param x2 X coordinate of the lower-right corner of the box.
  149. * \param y2 Y coordinate of the lower-right corner of the box.
  150. * \param ch UTF-32 character to be used to draw the box.
  151. * \return This function always returns 0.
  152. */
  153. int cucul_fill_box(cucul_canvas_t *cv, int x1, int y1, int x2, int y2,
  154. unsigned long int ch)
  155. {
  156. int x, y, xmax, ymax;
  157. if(x1 > x2)
  158. {
  159. int tmp = x1;
  160. x1 = x2; x2 = tmp;
  161. }
  162. if(y1 > y2)
  163. {
  164. int tmp = y1;
  165. y1 = y2; y2 = tmp;
  166. }
  167. xmax = cv->width - 1;
  168. ymax = cv->height - 1;
  169. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  170. return 0;
  171. if(x1 < 0) x1 = 0;
  172. if(y1 < 0) y1 = 0;
  173. if(x2 > xmax) x2 = xmax;
  174. if(y2 > ymax) y2 = ymax;
  175. for(y = y1; y <= y2; y++)
  176. for(x = x1; x <= x2; x++)
  177. cucul_put_char(cv, x, y, ch);
  178. return 0;
  179. }