framebuffer.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #ifndef __FRAMEBUFFER_H__
  2. #define __FRAMEBUFFER_H__ 1
  3. // Framebuffer routines for drawing module
  4. // Copyright (C) 2015 fgalliat (Xtase)
  5. //
  6. // This file is part of Duktape-nspire.
  7. //
  8. // Duktape-nspire is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU Lesser General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // Duktape-nspire 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 Lesser General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Lesser General Public License
  19. // along with Duktape-nspire. If not, see <http://www.gnu.org/licenses/>.
  20. // STILL TODO : cuttedCornerRect + drawString
  21. const float __cos[] = {1.0F,0.9998477F,0.99939084F,0.9986295F,0.9975641F,0.9961947F,0.9945219F,0.99254614F,0.99026805F,0.98768836F,0.9848077F,0.98162717F,0.9781476F,0.97437006F,0.9702957F,0.9659258F,0.9612617F,0.9563047F,0.95105654F,0.94551855F,0.9396926F,0.9335804F,0.92718387F,0.92050487F,0.9135454F,0.9063078F,0.89879405F,0.8910065F,0.88294756F,0.8746197F,0.8660254F,0.8571673F,0.8480481F,0.83867055F,0.82903755F,0.81915206F,0.809017F,0.7986355F,0.7880108F,0.777146F,0.76604444F,0.7547096F,0.7431448F,0.7313537F,0.7193398F,0.70710677F,0.6946584F,0.6819984F,0.6691306F,0.656059F,0.64278764F,0.6293204F,0.6156615F,0.60181504F,0.58778524F,0.57357645F,0.5591929F,0.54463905F,0.52991927F,0.5150381F,0.5F,0.4848096F,0.46947157F,0.4539905F,0.43837115F,0.42261827F,0.40673664F,0.39073113F,0.37460658F,0.35836795F,0.34202015F,0.32556817F,0.309017F,0.2923717F,0.27563736F,0.25881904F,0.2419219F,0.22495106F,0.20791169F,0.190809F,0.17364818F,0.15643446F,0.1391731F,0.12186934F,0.104528464F,0.087155744F,0.06975647F,0.052335955F,0.034899496F,0.017452406F,6.123234E-17F,-0.017452406F,-0.034899496F,-0.052335955F,-0.06975647F,-0.087155744F,-0.104528464F,-0.12186934F,-0.1391731F,-0.15643446F,-0.17364818F,-0.190809F,-0.20791169F,-0.22495106F,-0.2419219F,-0.25881904F,-0.27563736F,-0.2923717F,-0.309017F,-0.32556817F,-0.34202015F,-0.35836795F,-0.37460658F,-0.39073113F,-0.40673664F,-0.42261827F,-0.43837115F,-0.4539905F,-0.46947157F,-0.4848096F,-0.5F,-0.5150381F,-0.52991927F,-0.54463905F,-0.5591929F,-0.57357645F,-0.58778524F,-0.60181504F,-0.6156615F,-0.6293204F,-0.64278764F,-0.656059F,-0.6691306F,-0.6819984F,-0.6946584F,-0.70710677F,-0.7193398F,-0.7313537F,-0.7431448F,-0.7547096F,-0.76604444F,-0.777146F,-0.7880108F,-0.7986355F,-0.809017F,-0.81915206F,-0.82903755F,-0.83867055F,-0.8480481F,-0.8571673F,-0.8660254F,-0.8746197F,-0.88294756F,-0.8910065F,-0.89879405F,-0.9063078F,-0.9135454F,-0.92050487F,-0.92718387F,-0.9335804F,-0.9396926F,-0.94551855F,-0.95105654F,-0.9563047F,-0.9612617F,-0.9659258F,-0.9702957F,-0.97437006F,-0.9781476F,-0.98162717F,-0.9848077F,-0.98768836F,-0.99026805F,-0.99254614F,-0.9945219F,-0.9961947F,-0.9975641F,-0.9986295F,-0.99939084F,-0.9998477F,-1.0F,-0.9998477F,-0.99939084F,-0.9986295F,-0.9975641F,-0.9961947F,-0.9945219F,-0.99254614F,-0.99026805F,-0.98768836F,-0.9848077F,-0.98162717F,-0.9781476F,-0.97437006F,-0.9702957F,-0.9659258F,-0.9612617F,-0.9563047F,-0.95105654F,-0.94551855F,-0.9396926F,-0.9335804F,-0.92718387F,-0.92050487F,-0.9135454F,-0.9063078F,-0.89879405F,-0.8910065F,-0.88294756F,-0.8746197F,-0.8660254F,-0.8571673F,-0.8480481F,-0.83867055F,-0.82903755F,-0.81915206F,-0.809017F,-0.7986355F,-0.7880108F,-0.777146F,-0.76604444F,-0.7547096F,-0.7431448F,-0.7313537F,-0.7193398F,-0.70710677F,-0.6946584F,-0.6819984F,-0.6691306F,-0.656059F,-0.64278764F,-0.6293204F,-0.6156615F,-0.60181504F,-0.58778524F,-0.57357645F,-0.5591929F,-0.54463905F,-0.52991927F,-0.5150381F,-0.5F,-0.4848096F,-0.46947157F,-0.4539905F,-0.43837115F,-0.42261827F,-0.40673664F,-0.39073113F,-0.37460658F,-0.35836795F,-0.34202015F,-0.32556817F,-0.309017F,-0.2923717F,-0.27563736F,-0.25881904F,-0.2419219F,-0.22495106F,-0.20791169F,-0.190809F,-0.17364818F,-0.15643446F,-0.1391731F,-0.12186934F,-0.104528464F,-0.087155744F,-0.06975647F,-0.052335955F,-0.034899496F,-0.017452406F,-1.8369701E-16F,0.017452406F,0.034899496F,0.052335955F,0.06975647F,0.087155744F,0.104528464F,0.12186934F,0.1391731F,0.15643446F,0.17364818F,0.190809F,0.20791169F,0.22495106F,0.2419219F,0.25881904F,0.27563736F,0.2923717F,0.309017F,0.32556817F,0.34202015F,0.35836795F,0.37460658F,0.39073113F,0.40673664F,0.42261827F,0.43837115F,0.4539905F,0.46947157F,0.4848096F,0.5F,0.5150381F,0.52991927F,0.54463905F,0.5591929F,0.57357645F,0.58778524F,0.60181504F,0.6156615F,0.6293204F,0.64278764F,0.656059F,0.6691306F,0.6819984F,0.6946584F,0.70710677F,0.7193398F,0.7313537F,0.7431448F,0.7547096F,0.76604444F,0.777146F,0.7880108F,0.7986355F,0.809017F,0.81915206F,0.82903755F,0.83867055F,0.8480481F,0.8571673F,0.8660254F,0.8746197F,0.88294756F,0.8910065F,0.89879405F,0.9063078F,0.9135454F,0.92050487F,0.92718387F,0.9335804F,0.9396926F,0.94551855F,0.95105654F,0.9563047F,0.9612617F,0.9659258F,0.9702957F,0.97437006F,0.9781476F,0.98162717F,0.9848077F,0.98768836F,0.99026805F,0.99254614F,0.9945219F,0.9961947F,0.9975641F,0.9986295F,0.99939084F,0.9998477F};
  22. const float __sin[] = {0.0F,0.017452406F,0.034899496F,0.052335955F,0.06975647F,0.087155744F,0.104528464F,0.12186934F,0.1391731F,0.15643446F,0.17364818F,0.190809F,0.20791169F,0.22495106F,0.2419219F,0.25881904F,0.27563736F,0.2923717F,0.309017F,0.32556817F,0.34202015F,0.35836795F,0.37460658F,0.39073113F,0.40673664F,0.42261827F,0.43837115F,0.4539905F,0.46947157F,0.4848096F,0.5F,0.5150381F,0.52991927F,0.54463905F,0.5591929F,0.57357645F,0.58778524F,0.60181504F,0.6156615F,0.6293204F,0.64278764F,0.656059F,0.6691306F,0.6819984F,0.6946584F,0.70710677F,0.7193398F,0.7313537F,0.7431448F,0.7547096F,0.76604444F,0.777146F,0.7880108F,0.7986355F,0.809017F,0.81915206F,0.82903755F,0.83867055F,0.8480481F,0.8571673F,0.8660254F,0.8746197F,0.88294756F,0.8910065F,0.89879405F,0.9063078F,0.9135454F,0.92050487F,0.92718387F,0.9335804F,0.9396926F,0.94551855F,0.95105654F,0.9563047F,0.9612617F,0.9659258F,0.9702957F,0.97437006F,0.9781476F,0.98162717F,0.9848077F,0.98768836F,0.99026805F,0.99254614F,0.9945219F,0.9961947F,0.9975641F,0.9986295F,0.99939084F,0.9998477F,1.0F,0.9998477F,0.99939084F,0.9986295F,0.9975641F,0.9961947F,0.9945219F,0.99254614F,0.99026805F,0.98768836F,0.9848077F,0.98162717F,0.9781476F,0.97437006F,0.9702957F,0.9659258F,0.9612617F,0.9563047F,0.95105654F,0.94551855F,0.9396926F,0.9335804F,0.92718387F,0.92050487F,0.9135454F,0.9063078F,0.89879405F,0.8910065F,0.88294756F,0.8746197F,0.8660254F,0.8571673F,0.8480481F,0.83867055F,0.82903755F,0.81915206F,0.809017F,0.7986355F,0.7880108F,0.777146F,0.76604444F,0.7547096F,0.7431448F,0.7313537F,0.7193398F,0.70710677F,0.6946584F,0.6819984F,0.6691306F,0.656059F,0.64278764F,0.6293204F,0.6156615F,0.60181504F,0.58778524F,0.57357645F,0.5591929F,0.54463905F,0.52991927F,0.5150381F,0.5F,0.4848096F,0.46947157F,0.4539905F,0.43837115F,0.42261827F,0.40673664F,0.39073113F,0.37460658F,0.35836795F,0.34202015F,0.32556817F,0.309017F,0.2923717F,0.27563736F,0.25881904F,0.2419219F,0.22495106F,0.20791169F,0.190809F,0.17364818F,0.15643446F,0.1391731F,0.12186934F,0.104528464F,0.087155744F,0.06975647F,0.052335955F,0.034899496F,0.017452406F,1.2246469E-16F,-0.017452406F,-0.034899496F,-0.052335955F,-0.06975647F,-0.087155744F,-0.104528464F,-0.12186934F,-0.1391731F,-0.15643446F,-0.17364818F,-0.190809F,-0.20791169F,-0.22495106F,-0.2419219F,-0.25881904F,-0.27563736F,-0.2923717F,-0.309017F,-0.32556817F,-0.34202015F,-0.35836795F,-0.37460658F,-0.39073113F,-0.40673664F,-0.42261827F,-0.43837115F,-0.4539905F,-0.46947157F,-0.4848096F,-0.5F,-0.5150381F,-0.52991927F,-0.54463905F,-0.5591929F,-0.57357645F,-0.58778524F,-0.60181504F,-0.6156615F,-0.6293204F,-0.64278764F,-0.656059F,-0.6691306F,-0.6819984F,-0.6946584F,-0.70710677F,-0.7193398F,-0.7313537F,-0.7431448F,-0.7547096F,-0.76604444F,-0.777146F,-0.7880108F,-0.7986355F,-0.809017F,-0.81915206F,-0.82903755F,-0.83867055F,-0.8480481F,-0.8571673F,-0.8660254F,-0.8746197F,-0.88294756F,-0.8910065F,-0.89879405F,-0.9063078F,-0.9135454F,-0.92050487F,-0.92718387F,-0.9335804F,-0.9396926F,-0.94551855F,-0.95105654F,-0.9563047F,-0.9612617F,-0.9659258F,-0.9702957F,-0.97437006F,-0.9781476F,-0.98162717F,-0.9848077F,-0.98768836F,-0.99026805F,-0.99254614F,-0.9945219F,-0.9961947F,-0.9975641F,-0.9986295F,-0.99939084F,-0.9998477F,-1.0F,-0.9998477F,-0.99939084F,-0.9986295F,-0.9975641F,-0.9961947F,-0.9945219F,-0.99254614F,-0.99026805F,-0.98768836F,-0.9848077F,-0.98162717F,-0.9781476F,-0.97437006F,-0.9702957F,-0.9659258F,-0.9612617F,-0.9563047F,-0.95105654F,-0.94551855F,-0.9396926F,-0.9335804F,-0.92718387F,-0.92050487F,-0.9135454F,-0.9063078F,-0.89879405F,-0.8910065F,-0.88294756F,-0.8746197F,-0.8660254F,-0.8571673F,-0.8480481F,-0.83867055F,-0.82903755F,-0.81915206F,-0.809017F,-0.7986355F,-0.7880108F,-0.777146F,-0.76604444F,-0.7547096F,-0.7431448F,-0.7313537F,-0.7193398F,-0.70710677F,-0.6946584F,-0.6819984F,-0.6691306F,-0.656059F,-0.64278764F,-0.6293204F,-0.6156615F,-0.60181504F,-0.58778524F,-0.57357645F,-0.5591929F,-0.54463905F,-0.52991927F,-0.5150381F,-0.5F,-0.4848096F,-0.46947157F,-0.4539905F,-0.43837115F,-0.42261827F,-0.40673664F,-0.39073113F,-0.37460658F,-0.35836795F,-0.34202015F,-0.32556817F,-0.309017F,-0.2923717F,-0.27563736F,-0.25881904F,-0.2419219F,-0.22495106F,-0.20791169F,-0.190809F,-0.17364818F,-0.15643446F,-0.1391731F,-0.12186934F,-0.104528464F,-0.087155744F,-0.06975647F,-0.052335955F,-0.034899496F,-0.017452406F};
  23. // FrameBuffer virtual device
  24. typedef struct FbDev {
  25. int width;
  26. int height;
  27. uint16_t* fb;
  28. int fb_size; // width * height || nb of pixels (but not nb of bytes)
  29. } FbDev;
  30. #define _setPixel(x,y,rgb, fbDev) fbDev->fb[(y*fbDev->width)+x]=rgb
  31. #define _getPixel(x,y , fbDev) fbDev->fb[(y*fbDev->width)+x]
  32. #define _getAddr(x, y, fbDev) ((y * fbDev->width) + x)
  33. #define Color_t uint16_t
  34. #include "floodfill.h"
  35. void __floodFill(int x, int y, Color_t color, FbDev* fb) {
  36. /* -makes a stack overflow -
  37. if ( x >= 0 && x < fb->width && y >= 0 && y < fb->height && _getPixel(x,y,fb) != color) {
  38. _setPixel(x,y,color,fb);
  39. __floodFill(x - 1, y, color, fb);
  40. __floodFill(x, y - 1, color, fb);
  41. __floodFill(x, y + 1, color, fb);
  42. __floodFill(x + 1, y, color, fb);
  43. }
  44. */
  45. flood_fill(fb->fb, fb->width, fb->height, x, y, color);
  46. }
  47. // not the real scan lines impl.
  48. // yes it's a dirty impl. ;(
  49. void __scanFill(int xMin, int yMin, int xMax, int yMax, int* xys, int nbPts, Color_t color, FbDev* fb) {
  50. //int xpts[20]; // max 20 sommets par lignes
  51. int xptsCnt = 0;
  52. int insideX = -999;
  53. int insideY = -999;
  54. for (int y = yMin; y <= yMax; y++) {
  55. xptsCnt = 0;
  56. for (int i = 0; i < nbPts; i++) {
  57. if (xys[(i * 2) + 1] == y) {
  58. //xpts[xptsCnt++] = (i * 2) + 0;
  59. xptsCnt++;
  60. }
  61. }
  62. bool inside = false;
  63. int startX = -999, stopX = -999;
  64. for (int x = xMin; x <= xMax; x++) {
  65. if (xptsCnt > 0) {
  66. // noting
  67. break;
  68. } else {
  69. if (_getPixel(x, y, fb) == color) {
  70. inside = !inside;
  71. }
  72. if (inside && startX == -999) {
  73. startX = x;
  74. }
  75. if (!inside && x == startX + 1) {
  76. break;
  77. }
  78. if (!inside && startX > -999 && x > startX + 1) {
  79. stopX = x;
  80. }
  81. if (startX > -999 && stopX > -999 && stopX - startX > 2) {
  82. insideX = startX + 1;
  83. break;
  84. }
  85. }
  86. }
  87. if (insideX > -999) {
  88. insideY = y;
  89. break;
  90. }
  91. }
  92. if (insideX > -999 && insideY > -999) {
  93. __floodFill(insideX, insideY, color, fb);
  94. }
  95. }
  96. // just a Color for during the fill Op
  97. // const Color_t TEMP_FILL_COLOR = (15 << 11 | 15 << 5 | 15);
  98. const Color_t TEMP_FILL_COLOR = (1 << 11 | 1 << 5 | 1);
  99. void __replaceByFillColor(int startAddr, int endAddr, Color_t color, FbDev* fb) {
  100. if (startAddr < 0) {
  101. startAddr = 0;
  102. }
  103. if (endAddr >= fb->fb_size) {
  104. endAddr = fb->fb_size - 1;
  105. }
  106. for (int i = startAddr; i <= endAddr; i++) {
  107. if (fb->fb[i] == TEMP_FILL_COLOR)
  108. fb->fb[i] = color;
  109. }
  110. }
  111. // ========================================
  112. void setPixel(int x, int y, Color_t color, FbDev* fb) {
  113. if (x < 0) {
  114. return;
  115. } else if (x >= fb->width) {
  116. return;
  117. }
  118. if (y < 0) {
  119. return;
  120. } else if (y >= fb->height) {
  121. return;
  122. }
  123. _setPixel(x,y,color,fb);
  124. }
  125. int getPixel(int x, int y, FbDev* fb) {
  126. return _getPixel(x,y,fb);
  127. }
  128. // ====================
  129. // where a is float
  130. #define __round(a) ( (int) (a + 0.5F) )
  131. // where a is int
  132. #define __fabs(a) ( a >= 0 ? a : -a )
  133. void drawHorizLine(int x1, int x2, int y, Color_t rgb, FbDev* fb) {
  134. if (x2 < x1) {
  135. int tmp = x1;
  136. x1 = x2;
  137. x2 = tmp;
  138. }
  139. // int row = (y * SCREEN_WIDTH);
  140. for (int i = x1; i <= x2; i++) {
  141. setPixel(i, y, rgb, fb);
  142. // fb[row + i] = rgb;
  143. }
  144. }
  145. void drawVertLine(int y1, int y2, int x, Color_t rgb, FbDev* fb) {
  146. if (y2 < y1) {
  147. int tmp = y1;
  148. y1 = y2;
  149. y2 = tmp;
  150. }
  151. for (int i = y1; i <= y2; i++) {
  152. setPixel(x, i, rgb, fb);
  153. }
  154. }
  155. void drawLine(int x1, int y1, int x2, int y2, Color_t rgb, FbDev* fb) {
  156. if (y1 == y2) {
  157. drawHorizLine(x1, x2, y1, rgb, fb);
  158. } else if (x1 == x2) {
  159. drawVertLine(y1, y2, x1, rgb, fb);
  160. } else {
  161. int dx = x2 - x1, dy = y2 - y1, steps, k;
  162. float xIncrement, yIncrement, x = x1, y = y1;
  163. if (__fabs(dx) > __fabs(dy)) {
  164. steps = __fabs(dx);
  165. } else {
  166. steps = __fabs(dy);
  167. }
  168. xIncrement = (float) dx / (float) steps;
  169. yIncrement = (float) dy / (float) steps;
  170. setPixel(__round(x), __round(y), rgb, fb);
  171. for (k = 0; k < steps; k++) {
  172. x += xIncrement;
  173. y += yIncrement;
  174. setPixel(__round(x), __round(y), rgb, fb);
  175. }
  176. }
  177. }
  178. // ============
  179. void drawRect(int x, int y, int w, int h, Color_t color, FbDev* fb) {
  180. drawHorizLine(x, x + w, y, color, fb);
  181. drawHorizLine(x, x + w, y + h, color, fb);
  182. drawVertLine(y, y + h, x, color, fb);
  183. drawVertLine(y, y + h, x + w, color, fb);
  184. }
  185. void fillRect(int x, int y, int w, int h, Color_t color, FbDev* fb) {
  186. drawRect(x, y, w, h, TEMP_FILL_COLOR, fb);
  187. __floodFill(x + (w >> 1), y + (h >> 1), TEMP_FILL_COLOR, fb);
  188. // /!\ let () around (y+h) Cf defined macro & args
  189. __replaceByFillColor(_getAddr(x, y, fb), _getAddr( (x + w), (y + h), fb), color, fb);
  190. }
  191. // ========================================
  192. void drawPolyLines(int* xys, int nbPts, Color_t color, FbDev* fb) {
  193. for (int i = 0; i < nbPts - 1; i++) {
  194. drawLine(xys[(2 * i) + 0], xys[(2 * i) + 1], xys[(2 * i) + 2], xys[(2 * i) + 3], color, fb);
  195. }
  196. }
  197. void fillPolygon(int* xys, int nbPts, Color_t color, FbDev* fb) {
  198. int x1, x2, y1, y2, xMin = SCREEN_WIDTH + 10, xMax = -10, yMin = SCREEN_HEIGHT + 10, yMax = -10;
  199. // drawPolyLines(xys, nbPts, TEMP_FILL_COLOR);
  200. for (int i = 0; i < nbPts - 1; i++) {
  201. x1 = xys[(2 * i) + 0];
  202. y1 = xys[(2 * i) + 1];
  203. x2 = xys[(2 * i) + 2];
  204. y2 = xys[(2 * i) + 3];
  205. if (x1 < xMin) {
  206. xMin = x1;
  207. }
  208. if (x1 > xMax) {
  209. xMax = x1;
  210. }
  211. if (x2 < xMin) {
  212. xMin = x2;
  213. }
  214. if (x2 > xMax) {
  215. xMax = x2;
  216. }
  217. if (y1 < yMin) {
  218. yMin = y1;
  219. }
  220. if (y1 > yMax) {
  221. yMax = y1;
  222. }
  223. if (y2 < yMin) {
  224. yMin = y2;
  225. }
  226. if (y2 > yMax) {
  227. yMax = y2;
  228. }
  229. drawLine(x1, y1, x2, y2, TEMP_FILL_COLOR, fb);
  230. }
  231. // if polygon isn't closed : close it
  232. if (!(xys[0] == xys[(nbPts * 2) - 2] && xys[1] == xys[(nbPts * 2) - 1])) {
  233. x1 = xys[0];
  234. y1 = xys[1];
  235. x2 = xys[(nbPts * 2) - 2];
  236. y2 = xys[(nbPts * 2) - 1];
  237. if (x1 < xMin) {
  238. xMin = x1;
  239. }
  240. if (x1 > xMax) {
  241. xMax = x1;
  242. }
  243. if (x2 < xMin) {
  244. xMin = x2;
  245. }
  246. if (x2 > xMax) {
  247. xMax = x2;
  248. }
  249. if (y1 < yMin) {
  250. yMin = y1;
  251. }
  252. if (y1 > yMax) {
  253. yMax = y1;
  254. }
  255. if (y2 < yMin) {
  256. yMin = y2;
  257. }
  258. if (y2 > yMax) {
  259. yMax = y2;
  260. }
  261. drawLine(x1, y1, x2, y2, TEMP_FILL_COLOR, fb);
  262. }
  263. __scanFill(xMin, yMin, xMax, yMax, xys, nbPts, TEMP_FILL_COLOR, fb);
  264. __replaceByFillColor(_getAddr(xMin, yMin, fb), _getAddr(xMax, yMax, fb), color, fb);
  265. }
  266. // ============
  267. void drawCircle(int x, int y, int radius, Color_t color, FbDev* fb) {
  268. int startAngle = 0, stopAngle = 90;
  269. float fradius = (float) radius;
  270. for (int a = startAngle; a <= stopAngle; a++) {
  271. int xc = (int) (fradius * __cos[a]);
  272. int ys = (int) (fradius * __sin[a]);
  273. setPixel(x + xc, y + ys, color, fb);
  274. setPixel(x - xc, y + ys, color, fb);
  275. setPixel(x + xc, y - ys, color, fb);
  276. setPixel(x - xc, y - ys, color, fb);
  277. }
  278. }
  279. void fillCircle(int x, int y, int radius, Color_t color, FbDev* fb) {
  280. drawCircle(x, y, radius, TEMP_FILL_COLOR, fb);
  281. __floodFill(x, y, TEMP_FILL_COLOR, fb);
  282. __replaceByFillColor(_getAddr( (x - radius), (y - radius), fb), _getAddr( (x + radius), (y + radius), fb), color, fb);
  283. }
  284. #endif