ucg_box.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. ucg_box.c
  3. Universal uC Color Graphics Library
  4. Copyright (c) 2013, olikraus@gmail.com
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice, this list
  9. of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice, this
  11. list of conditions and the following disclaimer in the documentation and/or other
  12. materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  14. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  15. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  16. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  19. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  25. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include "ucg.h"
  28. void ucg_DrawBox(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
  29. {
  30. while( h > 0 )
  31. {
  32. ucg_DrawHLine(ucg, x, y, w);
  33. h--;
  34. y++;
  35. }
  36. }
  37. /*
  38. - clear the screen with black color
  39. - reset clip range to max
  40. - set draw color to white
  41. */
  42. void ucg_ClearScreen(ucg_t *ucg)
  43. {
  44. ucg_SetColor(ucg, 0, 0, 0, 0);
  45. ucg_SetMaxClipRange(ucg);
  46. ucg_DrawBox(ucg, 0, 0, ucg_GetWidth(ucg), ucg_GetHeight(ucg));
  47. ucg_SetColor(ucg, 0, 255, 255, 255);
  48. }
  49. void ucg_DrawRBox(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h, ucg_int_t r)
  50. {
  51. ucg_int_t xl, yu;
  52. ucg_int_t yl, xr;
  53. xl = x;
  54. xl += r;
  55. yu = y;
  56. yu += r;
  57. xr = x;
  58. xr += w;
  59. xr -= r;
  60. xr -= 1;
  61. yl = y;
  62. yl += h;
  63. yl -= r;
  64. yl -= 1;
  65. ucg_DrawDisc(ucg, xl, yu, r, UCG_DRAW_UPPER_LEFT);
  66. ucg_DrawDisc(ucg, xr, yu, r, UCG_DRAW_UPPER_RIGHT);
  67. ucg_DrawDisc(ucg, xl, yl, r, UCG_DRAW_LOWER_LEFT);
  68. ucg_DrawDisc(ucg, xr, yl, r, UCG_DRAW_LOWER_RIGHT);
  69. {
  70. ucg_int_t ww, hh;
  71. ww = w;
  72. ww -= r;
  73. ww -= r;
  74. ww -= 2;
  75. hh = h;
  76. hh -= r;
  77. hh -= r;
  78. hh -= 2;
  79. xl++;
  80. yu++;
  81. h--;
  82. ucg_DrawBox(ucg, xl, y, ww, r+1);
  83. ucg_DrawBox(ucg, xl, yl, ww, r+1);
  84. ucg_DrawBox(ucg, x, yu, w, hh);
  85. }
  86. }
  87. ucg_ccs_t ucg_ccs_box[6]; /* color component sliders used by GradientBox */
  88. void ucg_DrawGradientBox(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
  89. {
  90. uint8_t i;
  91. /* Setup ccs for l90se. This will be updated by ucg_clip_l90se if required */
  92. /* 8. Jan 2014: correct? */
  93. //printf("%d %d %d\n", ucg->arg.rgb[3].color[0], ucg->arg.rgb[3].color[1], ucg->arg.rgb[3].color[2]);
  94. for ( i = 0; i < 3; i++ )
  95. {
  96. ucg_ccs_init(ucg_ccs_box+i, ucg->arg.rgb[0].color[i], ucg->arg.rgb[2].color[i], h);
  97. ucg_ccs_init(ucg_ccs_box+i+3, ucg->arg.rgb[1].color[i], ucg->arg.rgb[3].color[i], h);
  98. }
  99. while( h > 0 )
  100. {
  101. ucg->arg.rgb[0].color[0] = ucg_ccs_box[0].current;
  102. ucg->arg.rgb[0].color[1] = ucg_ccs_box[1].current;
  103. ucg->arg.rgb[0].color[2] = ucg_ccs_box[2].current;
  104. ucg->arg.rgb[1].color[0] = ucg_ccs_box[3].current;
  105. ucg->arg.rgb[1].color[1] = ucg_ccs_box[4].current;
  106. ucg->arg.rgb[1].color[2] = ucg_ccs_box[5].current;
  107. //printf("%d %d %d\n", ucg_ccs_box[0].current, ucg_ccs_box[1].current, ucg_ccs_box[2].current);
  108. //printf("%d %d %d\n", ucg_ccs_box[3].current, ucg_ccs_box[4].current, ucg_ccs_box[5].current);
  109. ucg->arg.pixel.pos.x = x;
  110. ucg->arg.pixel.pos.y = y;
  111. ucg->arg.len = w;
  112. ucg->arg.dir = 0;
  113. ucg_DrawL90SEWithArg(ucg);
  114. for ( i = 0; i < 6; i++ )
  115. ucg_ccs_step(ucg_ccs_box+i);
  116. h--;
  117. y++;
  118. }
  119. }
  120. /* restrictions: w > 0 && h > 0 */
  121. void ucg_DrawFrame(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h)
  122. {
  123. ucg_int_t xtmp = x;
  124. ucg_DrawHLine(ucg, x, y, w);
  125. ucg_DrawVLine(ucg, x, y, h);
  126. x+=w;
  127. x--;
  128. ucg_DrawVLine(ucg, x, y, h);
  129. y+=h;
  130. y--;
  131. ucg_DrawHLine(ucg, xtmp, y, w);
  132. }
  133. void ucg_DrawRFrame(ucg_t *ucg, ucg_int_t x, ucg_int_t y, ucg_int_t w, ucg_int_t h, ucg_int_t r)
  134. {
  135. ucg_int_t xl, yu;
  136. xl = x;
  137. xl += r;
  138. yu = y;
  139. yu += r;
  140. {
  141. ucg_int_t yl, xr;
  142. xr = x;
  143. xr += w;
  144. xr -= r;
  145. xr -= 1;
  146. yl = y;
  147. yl += h;
  148. yl -= r;
  149. yl -= 1;
  150. ucg_DrawCircle(ucg, xl, yu, r, UCG_DRAW_UPPER_LEFT);
  151. ucg_DrawCircle(ucg, xr, yu, r, UCG_DRAW_UPPER_RIGHT);
  152. ucg_DrawCircle(ucg, xl, yl, r, UCG_DRAW_LOWER_LEFT);
  153. ucg_DrawCircle(ucg, xr, yl, r, UCG_DRAW_LOWER_RIGHT);
  154. }
  155. {
  156. ucg_int_t ww, hh;
  157. ww = w;
  158. ww -= r;
  159. ww -= r;
  160. ww -= 2;
  161. hh = h;
  162. hh -= r;
  163. hh -= r;
  164. hh -= 2;
  165. xl++;
  166. yu++;
  167. h--;
  168. w--;
  169. ucg_DrawHLine(ucg, xl, y, ww);
  170. ucg_DrawHLine(ucg, xl, y+h, ww);
  171. ucg_DrawVLine(ucg, x, yu, hh);
  172. ucg_DrawVLine(ucg, x+w, yu, hh);
  173. }
  174. }