Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

151 рядки
3.8 KiB

  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. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Do What The Fuck You Want To
  8. * Public License, Version 2, as published by Sam Hocevar. See
  9. * http://sam.zoy.org/wtfpl/COPYING for more details.
  10. */
  11. /** \file box.c
  12. * \version \$Id$
  13. * \author Sam Hocevar <sam@zoy.org>
  14. * \brief Simple box drawing
  15. *
  16. * This file contains box drawing functions, both filled and outline.
  17. */
  18. #include "config.h"
  19. #if !defined(__KERNEL__)
  20. # include <stdlib.h>
  21. #endif
  22. #include "cucul.h"
  23. #include "cucul_internals.h"
  24. /**
  25. * \brief Draw a box on the screen using the given character.
  26. *
  27. * \param x1 X coordinate of the upper-left corner of the box.
  28. * \param y1 Y coordinate of the upper-left corner of the box.
  29. * \param x2 X coordinate of the lower-right corner of the box.
  30. * \param y2 Y coordinate of the lower-right corner of the box.
  31. * \param c Character to draw the box outline with.
  32. * \return void
  33. */
  34. void cucul_draw_box(cucul_t *qq, int x1, int y1, int x2, int y2, char c)
  35. {
  36. cucul_draw_line(qq, x1, y1, x1, y2, c);
  37. cucul_draw_line(qq, x1, y2, x2, y2, c);
  38. cucul_draw_line(qq, x2, y2, x2, y1, c);
  39. cucul_draw_line(qq, x2, y1, x1, y1, c);
  40. }
  41. /**
  42. * \brief Draw a thin box on the screen.
  43. *
  44. * \param x1 X coordinate of the upper-left corner of the box.
  45. * \param y1 Y coordinate of the upper-left corner of the box.
  46. * \param x2 X coordinate of the lower-right corner of the box.
  47. * \param y2 Y coordinate of the lower-right corner of the box.
  48. * \return void
  49. */
  50. void cucul_draw_thin_box(cucul_t *qq, int x1, int y1, int x2, int y2)
  51. {
  52. int x, y, xmax, ymax;
  53. if(x1 > x2)
  54. {
  55. int tmp = x1;
  56. x1 = x2; x2 = tmp;
  57. }
  58. if(y1 > y2)
  59. {
  60. int tmp = y1;
  61. y1 = y2; y2 = tmp;
  62. }
  63. xmax = qq->width - 1;
  64. ymax = qq->height - 1;
  65. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  66. return;
  67. /* Draw edges */
  68. if(y1 >= 0)
  69. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  70. cucul_putchar(qq, x, y1, '-');
  71. if(y2 <= ymax)
  72. for(x = x1 < 0 ? 1 : x1 + 1; x < x2 && x < xmax; x++)
  73. cucul_putchar(qq, x, y2, '-');
  74. if(x1 >= 0)
  75. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  76. cucul_putchar(qq, x1, y, '|');
  77. if(x2 <= xmax)
  78. for(y = y1 < 0 ? 1 : y1 + 1; y < y2 && y < ymax; y++)
  79. cucul_putchar(qq, x2, y, '|');
  80. /* Draw corners */
  81. if(x1 >= 0 && y1 >= 0)
  82. cucul_putchar(qq, x1, y1, ',');
  83. if(x1 >= 0 && y2 <= ymax)
  84. cucul_putchar(qq, x1, y2, '`');
  85. if(x2 <= xmax && y1 >= 0)
  86. cucul_putchar(qq, x2, y1, '.');
  87. if(x2 <= xmax && y2 <= ymax)
  88. cucul_putchar(qq, x2, y2, '\'');
  89. }
  90. /**
  91. * \brief Fill a box on the screen using the given character.
  92. *
  93. * \param x1 X coordinate of the upper-left corner of the box.
  94. * \param y1 Y coordinate of the upper-left corner of the box.
  95. * \param x2 X coordinate of the lower-right corner of the box.
  96. * \param y2 Y coordinate of the lower-right corner of the box.
  97. * \param c Character to fill the box with.
  98. * \return void
  99. */
  100. void cucul_fill_box(cucul_t *qq, int x1, int y1, int x2, int y2, char c)
  101. {
  102. int x, y, xmax, ymax;
  103. if(x1 > x2)
  104. {
  105. int tmp = x1;
  106. x1 = x2; x2 = tmp;
  107. }
  108. if(y1 > y2)
  109. {
  110. int tmp = y1;
  111. y1 = y2; y2 = tmp;
  112. }
  113. xmax = qq->width - 1;
  114. ymax = qq->height - 1;
  115. if(x2 < 0 || y2 < 0 || x1 > xmax || y1 > ymax)
  116. return;
  117. if(x1 < 0) x1 = 0;
  118. if(y1 < 0) y1 = 0;
  119. if(x2 > xmax) x2 = xmax;
  120. if(y2 > ymax) y2 = ymax;
  121. for(y = y1; y <= y2; y++)
  122. for(x = x1; x <= x2; x++)
  123. cucul_putchar(qq, x, y, c);
  124. }