iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_circle.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_circle.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Utility to draw empty and filled circles. |
iforce2d | 0:972874f31c98 | 6 | |
iforce2d | 0:972874f31c98 | 7 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 8 | |
iforce2d | 0:972874f31c98 | 9 | Copyright (c) 2011, bjthom@gmail.com |
iforce2d | 0:972874f31c98 | 10 | u8g_DrawCircle & u8g_DrawDisc by olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 11 | |
iforce2d | 0:972874f31c98 | 12 | All rights reserved. |
iforce2d | 0:972874f31c98 | 13 | |
iforce2d | 0:972874f31c98 | 14 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 15 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 16 | |
iforce2d | 0:972874f31c98 | 17 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 18 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 19 | |
iforce2d | 0:972874f31c98 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 21 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 22 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 23 | |
iforce2d | 0:972874f31c98 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 25 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 26 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 27 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 36 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 37 | |
iforce2d | 0:972874f31c98 | 38 | Addition to the U8G Library 02/25/12 |
iforce2d | 0:972874f31c98 | 39 | |
iforce2d | 0:972874f31c98 | 40 | |
iforce2d | 0:972874f31c98 | 41 | */ |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 44 | |
iforce2d | 0:972874f31c98 | 45 | #ifdef OLD_CODE |
iforce2d | 0:972874f31c98 | 46 | |
iforce2d | 0:972874f31c98 | 47 | void circ_upperRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) { |
iforce2d | 0:972874f31c98 | 48 | u8g_DrawPixel(u8g, x0 + x, y0 - y); |
iforce2d | 0:972874f31c98 | 49 | u8g_DrawPixel(u8g, x0 + y, y0 - x); |
iforce2d | 0:972874f31c98 | 50 | } |
iforce2d | 0:972874f31c98 | 51 | |
iforce2d | 0:972874f31c98 | 52 | void circ_upperLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) { |
iforce2d | 0:972874f31c98 | 53 | u8g_DrawPixel(u8g, x0 - x, y0 - y); |
iforce2d | 0:972874f31c98 | 54 | u8g_DrawPixel(u8g, x0 - y, y0 - x); |
iforce2d | 0:972874f31c98 | 55 | } |
iforce2d | 0:972874f31c98 | 56 | |
iforce2d | 0:972874f31c98 | 57 | void circ_lowerRight(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) { |
iforce2d | 0:972874f31c98 | 58 | u8g_DrawPixel(u8g, x0 + x, y0 + y); |
iforce2d | 0:972874f31c98 | 59 | u8g_DrawPixel(u8g, x0 + y, y0 + x); |
iforce2d | 0:972874f31c98 | 60 | } |
iforce2d | 0:972874f31c98 | 61 | |
iforce2d | 0:972874f31c98 | 62 | void circ_lowerLeft(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) { |
iforce2d | 0:972874f31c98 | 63 | u8g_DrawPixel(u8g, x0 - x, y0 + y); |
iforce2d | 0:972874f31c98 | 64 | u8g_DrawPixel(u8g, x0 - y, y0 + x); |
iforce2d | 0:972874f31c98 | 65 | } |
iforce2d | 0:972874f31c98 | 66 | |
iforce2d | 0:972874f31c98 | 67 | void circ_all(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0) { |
iforce2d | 0:972874f31c98 | 68 | circ_upperRight(u8g, x, y, x0, y0); |
iforce2d | 0:972874f31c98 | 69 | circ_upperLeft(u8g, x, y, x0, y0); |
iforce2d | 0:972874f31c98 | 70 | circ_lowerRight(u8g, x, y, x0, y0); |
iforce2d | 0:972874f31c98 | 71 | circ_lowerLeft(u8g, x, y, x0, y0); |
iforce2d | 0:972874f31c98 | 72 | } |
iforce2d | 0:972874f31c98 | 73 | |
iforce2d | 0:972874f31c98 | 74 | void u8g_DrawEmpCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) |
iforce2d | 0:972874f31c98 | 75 | { |
iforce2d | 0:972874f31c98 | 76 | if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0) |
iforce2d | 0:972874f31c98 | 77 | return; |
iforce2d | 0:972874f31c98 | 78 | |
iforce2d | 0:972874f31c98 | 79 | int f = 1 - rad; |
iforce2d | 0:972874f31c98 | 80 | int ddF_x = 1; |
iforce2d | 0:972874f31c98 | 81 | int ddF_y = -2*rad; |
iforce2d | 0:972874f31c98 | 82 | uint8_t x = 0; |
iforce2d | 0:972874f31c98 | 83 | uint8_t y = rad; |
iforce2d | 0:972874f31c98 | 84 | |
iforce2d | 0:972874f31c98 | 85 | void ( *circ_util )(u8g_t *, u8g_uint_t, u8g_uint_t, u8g_uint_t, u8g_uint_t); |
iforce2d | 0:972874f31c98 | 86 | |
iforce2d | 0:972874f31c98 | 87 | switch (option) |
iforce2d | 0:972874f31c98 | 88 | { |
iforce2d | 0:972874f31c98 | 89 | case U8G_CIRC_UPPER_RIGHT: |
iforce2d | 0:972874f31c98 | 90 | u8g_DrawPixel(u8g, x0, y0 - rad); |
iforce2d | 0:972874f31c98 | 91 | u8g_DrawPixel(u8g, x0 + rad, y0); |
iforce2d | 0:972874f31c98 | 92 | circ_util = circ_upperRight; |
iforce2d | 0:972874f31c98 | 93 | break; |
iforce2d | 0:972874f31c98 | 94 | case U8G_CIRC_UPPER_LEFT: |
iforce2d | 0:972874f31c98 | 95 | u8g_DrawPixel(u8g, x0, y0 - rad); |
iforce2d | 0:972874f31c98 | 96 | u8g_DrawPixel(u8g, x0 - rad, y0); |
iforce2d | 0:972874f31c98 | 97 | circ_util = circ_upperLeft; |
iforce2d | 0:972874f31c98 | 98 | break; |
iforce2d | 0:972874f31c98 | 99 | case U8G_CIRC_LOWER_RIGHT: |
iforce2d | 0:972874f31c98 | 100 | u8g_DrawPixel(u8g, x0, y0 + rad); |
iforce2d | 0:972874f31c98 | 101 | u8g_DrawPixel(u8g, x0 + rad, y0); |
iforce2d | 0:972874f31c98 | 102 | circ_util = circ_lowerRight; |
iforce2d | 0:972874f31c98 | 103 | break; |
iforce2d | 0:972874f31c98 | 104 | case U8G_CIRC_LOWER_LEFT: |
iforce2d | 0:972874f31c98 | 105 | u8g_DrawPixel(u8g, x0, y0 + rad); |
iforce2d | 0:972874f31c98 | 106 | u8g_DrawPixel(u8g, x0 - rad, y0); |
iforce2d | 0:972874f31c98 | 107 | circ_util = circ_lowerLeft; |
iforce2d | 0:972874f31c98 | 108 | break; |
iforce2d | 0:972874f31c98 | 109 | default: |
iforce2d | 0:972874f31c98 | 110 | case U8G_CIRC_ALL: |
iforce2d | 0:972874f31c98 | 111 | u8g_DrawPixel(u8g, x0, y0 + rad); |
iforce2d | 0:972874f31c98 | 112 | u8g_DrawPixel(u8g, x0, y0 - rad); |
iforce2d | 0:972874f31c98 | 113 | u8g_DrawPixel(u8g, x0 + rad, y0); |
iforce2d | 0:972874f31c98 | 114 | u8g_DrawPixel(u8g, x0 - rad, y0); |
iforce2d | 0:972874f31c98 | 115 | circ_util = circ_all; |
iforce2d | 0:972874f31c98 | 116 | break; |
iforce2d | 0:972874f31c98 | 117 | } |
iforce2d | 0:972874f31c98 | 118 | |
iforce2d | 0:972874f31c98 | 119 | while( x < y ) |
iforce2d | 0:972874f31c98 | 120 | { |
iforce2d | 0:972874f31c98 | 121 | if(f >= 0) |
iforce2d | 0:972874f31c98 | 122 | { |
iforce2d | 0:972874f31c98 | 123 | y--; |
iforce2d | 0:972874f31c98 | 124 | ddF_y += 2; |
iforce2d | 0:972874f31c98 | 125 | f += ddF_y; |
iforce2d | 0:972874f31c98 | 126 | } |
iforce2d | 0:972874f31c98 | 127 | x++; |
iforce2d | 0:972874f31c98 | 128 | ddF_x += 2; |
iforce2d | 0:972874f31c98 | 129 | f += ddF_x; |
iforce2d | 0:972874f31c98 | 130 | |
iforce2d | 0:972874f31c98 | 131 | circ_util(u8g, x, y, x0, y0); |
iforce2d | 0:972874f31c98 | 132 | } |
iforce2d | 0:972874f31c98 | 133 | } |
iforce2d | 0:972874f31c98 | 134 | |
iforce2d | 0:972874f31c98 | 135 | |
iforce2d | 0:972874f31c98 | 136 | void u8g_DrawFillCirc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) |
iforce2d | 0:972874f31c98 | 137 | { |
iforce2d | 0:972874f31c98 | 138 | if ( u8g_IsBBXIntersection(u8g, x0-rad-1, y0-rad-1, 2*rad+1, 2*rad+1) == 0) |
iforce2d | 0:972874f31c98 | 139 | return; |
iforce2d | 0:972874f31c98 | 140 | |
iforce2d | 0:972874f31c98 | 141 | int f = 1 - rad; |
iforce2d | 0:972874f31c98 | 142 | int ddF_x = 1; |
iforce2d | 0:972874f31c98 | 143 | int ddF_y = -2*rad; |
iforce2d | 0:972874f31c98 | 144 | uint8_t x = 0; |
iforce2d | 0:972874f31c98 | 145 | uint8_t y = rad; |
iforce2d | 0:972874f31c98 | 146 | |
iforce2d | 0:972874f31c98 | 147 | // Draw vertical diameter at the horiz. center |
iforce2d | 0:972874f31c98 | 148 | // u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1); |
iforce2d | 0:972874f31c98 | 149 | |
iforce2d | 0:972874f31c98 | 150 | if (option == U8G_CIRC_UPPER_LEFT || option == U8G_CIRC_UPPER_RIGHT) { |
iforce2d | 0:972874f31c98 | 151 | u8g_DrawVLine(u8g, x0, y0 - rad, rad+1); |
iforce2d | 0:972874f31c98 | 152 | } |
iforce2d | 0:972874f31c98 | 153 | else if (option == U8G_CIRC_LOWER_LEFT || option == U8G_CIRC_LOWER_RIGHT) { |
iforce2d | 0:972874f31c98 | 154 | u8g_DrawVLine(u8g, x0, y0, rad+1); |
iforce2d | 0:972874f31c98 | 155 | } |
iforce2d | 0:972874f31c98 | 156 | else { |
iforce2d | 0:972874f31c98 | 157 | u8g_DrawVLine(u8g, x0, y0 - rad, 2*rad+1); |
iforce2d | 0:972874f31c98 | 158 | } |
iforce2d | 0:972874f31c98 | 159 | |
iforce2d | 0:972874f31c98 | 160 | while( x < y ) |
iforce2d | 0:972874f31c98 | 161 | { |
iforce2d | 0:972874f31c98 | 162 | if(f >= 0) |
iforce2d | 0:972874f31c98 | 163 | { |
iforce2d | 0:972874f31c98 | 164 | y--; |
iforce2d | 0:972874f31c98 | 165 | ddF_y += 2; |
iforce2d | 0:972874f31c98 | 166 | f += ddF_y; |
iforce2d | 0:972874f31c98 | 167 | } |
iforce2d | 0:972874f31c98 | 168 | x++; |
iforce2d | 0:972874f31c98 | 169 | ddF_x += 2; |
iforce2d | 0:972874f31c98 | 170 | f += ddF_x; |
iforce2d | 0:972874f31c98 | 171 | |
iforce2d | 0:972874f31c98 | 172 | //Draw vertical lines from one point to another |
iforce2d | 0:972874f31c98 | 173 | |
iforce2d | 0:972874f31c98 | 174 | switch (option) |
iforce2d | 0:972874f31c98 | 175 | { |
iforce2d | 0:972874f31c98 | 176 | case U8G_CIRC_UPPER_RIGHT: |
iforce2d | 0:972874f31c98 | 177 | u8g_DrawVLine(u8g, x0+x, y0-y, y+1); |
iforce2d | 0:972874f31c98 | 178 | u8g_DrawVLine(u8g, x0+y, y0-x, x+1); |
iforce2d | 0:972874f31c98 | 179 | break; |
iforce2d | 0:972874f31c98 | 180 | case U8G_CIRC_UPPER_LEFT: |
iforce2d | 0:972874f31c98 | 181 | u8g_DrawVLine(u8g, x0-x, y0-y, y+1); |
iforce2d | 0:972874f31c98 | 182 | u8g_DrawVLine(u8g, x0-y, y0-x, x+1); |
iforce2d | 0:972874f31c98 | 183 | break; |
iforce2d | 0:972874f31c98 | 184 | case U8G_CIRC_LOWER_RIGHT: |
iforce2d | 0:972874f31c98 | 185 | u8g_DrawVLine(u8g, x0+x, y0, y+1); |
iforce2d | 0:972874f31c98 | 186 | u8g_DrawVLine(u8g, x0+y, y0, x+1); |
iforce2d | 0:972874f31c98 | 187 | break; |
iforce2d | 0:972874f31c98 | 188 | case U8G_CIRC_LOWER_LEFT: |
iforce2d | 0:972874f31c98 | 189 | u8g_DrawVLine(u8g, x0-x, y0, y+1); |
iforce2d | 0:972874f31c98 | 190 | u8g_DrawVLine(u8g, x0-y, y0, x+1); |
iforce2d | 0:972874f31c98 | 191 | break; |
iforce2d | 0:972874f31c98 | 192 | case U8G_CIRC_ALL: |
iforce2d | 0:972874f31c98 | 193 | u8g_DrawVLine(u8g, x0+x, y0-y, 2*y+1); |
iforce2d | 0:972874f31c98 | 194 | u8g_DrawVLine(u8g, x0-x, y0-y, 2*y+1); |
iforce2d | 0:972874f31c98 | 195 | u8g_DrawVLine(u8g, x0+y, y0-x, 2*x+1); |
iforce2d | 0:972874f31c98 | 196 | u8g_DrawVLine(u8g, x0-y, y0-x, 2*x+1); |
iforce2d | 0:972874f31c98 | 197 | break; |
iforce2d | 0:972874f31c98 | 198 | } |
iforce2d | 0:972874f31c98 | 199 | } |
iforce2d | 0:972874f31c98 | 200 | } |
iforce2d | 0:972874f31c98 | 201 | |
iforce2d | 0:972874f31c98 | 202 | #endif |
iforce2d | 0:972874f31c98 | 203 | |
iforce2d | 0:972874f31c98 | 204 | /*=========================================================================*/ |
iforce2d | 0:972874f31c98 | 205 | |
iforce2d | 0:972874f31c98 | 206 | static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 207 | |
iforce2d | 0:972874f31c98 | 208 | static void u8g_draw_circle_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) |
iforce2d | 0:972874f31c98 | 209 | { |
iforce2d | 0:972874f31c98 | 210 | /* upper right */ |
iforce2d | 0:972874f31c98 | 211 | if ( option & U8G_DRAW_UPPER_RIGHT ) |
iforce2d | 0:972874f31c98 | 212 | { |
iforce2d | 0:972874f31c98 | 213 | u8g_DrawPixel(u8g, x0 + x, y0 - y); |
iforce2d | 0:972874f31c98 | 214 | u8g_DrawPixel(u8g, x0 + y, y0 - x); |
iforce2d | 0:972874f31c98 | 215 | } |
iforce2d | 0:972874f31c98 | 216 | |
iforce2d | 0:972874f31c98 | 217 | /* upper left */ |
iforce2d | 0:972874f31c98 | 218 | if ( option & U8G_DRAW_UPPER_LEFT ) |
iforce2d | 0:972874f31c98 | 219 | { |
iforce2d | 0:972874f31c98 | 220 | u8g_DrawPixel(u8g, x0 - x, y0 - y); |
iforce2d | 0:972874f31c98 | 221 | u8g_DrawPixel(u8g, x0 - y, y0 - x); |
iforce2d | 0:972874f31c98 | 222 | } |
iforce2d | 0:972874f31c98 | 223 | |
iforce2d | 0:972874f31c98 | 224 | /* lower right */ |
iforce2d | 0:972874f31c98 | 225 | if ( option & U8G_DRAW_LOWER_RIGHT ) |
iforce2d | 0:972874f31c98 | 226 | { |
iforce2d | 0:972874f31c98 | 227 | u8g_DrawPixel(u8g, x0 + x, y0 + y); |
iforce2d | 0:972874f31c98 | 228 | u8g_DrawPixel(u8g, x0 + y, y0 + x); |
iforce2d | 0:972874f31c98 | 229 | } |
iforce2d | 0:972874f31c98 | 230 | |
iforce2d | 0:972874f31c98 | 231 | /* lower left */ |
iforce2d | 0:972874f31c98 | 232 | if ( option & U8G_DRAW_LOWER_LEFT ) |
iforce2d | 0:972874f31c98 | 233 | { |
iforce2d | 0:972874f31c98 | 234 | u8g_DrawPixel(u8g, x0 - x, y0 + y); |
iforce2d | 0:972874f31c98 | 235 | u8g_DrawPixel(u8g, x0 - y, y0 + x); |
iforce2d | 0:972874f31c98 | 236 | } |
iforce2d | 0:972874f31c98 | 237 | } |
iforce2d | 0:972874f31c98 | 238 | |
iforce2d | 0:972874f31c98 | 239 | void u8g_draw_circle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) |
iforce2d | 0:972874f31c98 | 240 | { |
iforce2d | 0:972874f31c98 | 241 | u8g_int_t f; |
iforce2d | 0:972874f31c98 | 242 | u8g_int_t ddF_x; |
iforce2d | 0:972874f31c98 | 243 | u8g_int_t ddF_y; |
iforce2d | 0:972874f31c98 | 244 | u8g_uint_t x; |
iforce2d | 0:972874f31c98 | 245 | u8g_uint_t y; |
iforce2d | 0:972874f31c98 | 246 | |
iforce2d | 0:972874f31c98 | 247 | f = 1; |
iforce2d | 0:972874f31c98 | 248 | f -= rad; |
iforce2d | 0:972874f31c98 | 249 | ddF_x = 1; |
iforce2d | 0:972874f31c98 | 250 | ddF_y = 0; |
iforce2d | 0:972874f31c98 | 251 | ddF_y -= rad; |
iforce2d | 0:972874f31c98 | 252 | ddF_y *= 2; |
iforce2d | 0:972874f31c98 | 253 | x = 0; |
iforce2d | 0:972874f31c98 | 254 | y = rad; |
iforce2d | 0:972874f31c98 | 255 | |
iforce2d | 0:972874f31c98 | 256 | u8g_draw_circle_section(u8g, x, y, x0, y0, option); |
iforce2d | 0:972874f31c98 | 257 | |
iforce2d | 0:972874f31c98 | 258 | while ( x < y ) |
iforce2d | 0:972874f31c98 | 259 | { |
iforce2d | 0:972874f31c98 | 260 | if (f >= 0) |
iforce2d | 0:972874f31c98 | 261 | { |
iforce2d | 0:972874f31c98 | 262 | y--; |
iforce2d | 0:972874f31c98 | 263 | ddF_y += 2; |
iforce2d | 0:972874f31c98 | 264 | f += ddF_y; |
iforce2d | 0:972874f31c98 | 265 | } |
iforce2d | 0:972874f31c98 | 266 | x++; |
iforce2d | 0:972874f31c98 | 267 | ddF_x += 2; |
iforce2d | 0:972874f31c98 | 268 | f += ddF_x; |
iforce2d | 0:972874f31c98 | 269 | |
iforce2d | 0:972874f31c98 | 270 | u8g_draw_circle_section(u8g, x, y, x0, y0, option); |
iforce2d | 0:972874f31c98 | 271 | } |
iforce2d | 0:972874f31c98 | 272 | } |
iforce2d | 0:972874f31c98 | 273 | |
iforce2d | 0:972874f31c98 | 274 | void u8g_DrawCircle(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) |
iforce2d | 0:972874f31c98 | 275 | { |
iforce2d | 0:972874f31c98 | 276 | /* check for bounding box */ |
iforce2d | 0:972874f31c98 | 277 | { |
iforce2d | 0:972874f31c98 | 278 | u8g_uint_t radp, radp2; |
iforce2d | 0:972874f31c98 | 279 | |
iforce2d | 0:972874f31c98 | 280 | radp = rad; |
iforce2d | 0:972874f31c98 | 281 | radp++; |
iforce2d | 0:972874f31c98 | 282 | radp2 = radp; |
iforce2d | 0:972874f31c98 | 283 | radp2 *= 2; |
iforce2d | 0:972874f31c98 | 284 | |
iforce2d | 0:972874f31c98 | 285 | if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0) |
iforce2d | 0:972874f31c98 | 286 | return; |
iforce2d | 0:972874f31c98 | 287 | } |
iforce2d | 0:972874f31c98 | 288 | |
iforce2d | 0:972874f31c98 | 289 | /* draw circle */ |
iforce2d | 0:972874f31c98 | 290 | u8g_draw_circle(u8g, x0, y0, rad, option); |
iforce2d | 0:972874f31c98 | 291 | } |
iforce2d | 0:972874f31c98 | 292 | |
iforce2d | 0:972874f31c98 | 293 | static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 294 | |
iforce2d | 0:972874f31c98 | 295 | static void u8g_draw_disc_section(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t x0, u8g_uint_t y0, uint8_t option) |
iforce2d | 0:972874f31c98 | 296 | { |
iforce2d | 0:972874f31c98 | 297 | /* upper right */ |
iforce2d | 0:972874f31c98 | 298 | if ( option & U8G_DRAW_UPPER_RIGHT ) |
iforce2d | 0:972874f31c98 | 299 | { |
iforce2d | 0:972874f31c98 | 300 | u8g_DrawVLine(u8g, x0+x, y0-y, y+1); |
iforce2d | 0:972874f31c98 | 301 | u8g_DrawVLine(u8g, x0+y, y0-x, x+1); |
iforce2d | 0:972874f31c98 | 302 | } |
iforce2d | 0:972874f31c98 | 303 | |
iforce2d | 0:972874f31c98 | 304 | /* upper left */ |
iforce2d | 0:972874f31c98 | 305 | if ( option & U8G_DRAW_UPPER_LEFT ) |
iforce2d | 0:972874f31c98 | 306 | { |
iforce2d | 0:972874f31c98 | 307 | u8g_DrawVLine(u8g, x0-x, y0-y, y+1); |
iforce2d | 0:972874f31c98 | 308 | u8g_DrawVLine(u8g, x0-y, y0-x, x+1); |
iforce2d | 0:972874f31c98 | 309 | } |
iforce2d | 0:972874f31c98 | 310 | |
iforce2d | 0:972874f31c98 | 311 | /* lower right */ |
iforce2d | 0:972874f31c98 | 312 | if ( option & U8G_DRAW_LOWER_RIGHT ) |
iforce2d | 0:972874f31c98 | 313 | { |
iforce2d | 0:972874f31c98 | 314 | u8g_DrawVLine(u8g, x0+x, y0, y+1); |
iforce2d | 0:972874f31c98 | 315 | u8g_DrawVLine(u8g, x0+y, y0, x+1); |
iforce2d | 0:972874f31c98 | 316 | } |
iforce2d | 0:972874f31c98 | 317 | |
iforce2d | 0:972874f31c98 | 318 | /* lower left */ |
iforce2d | 0:972874f31c98 | 319 | if ( option & U8G_DRAW_LOWER_LEFT ) |
iforce2d | 0:972874f31c98 | 320 | { |
iforce2d | 0:972874f31c98 | 321 | u8g_DrawVLine(u8g, x0-x, y0, y+1); |
iforce2d | 0:972874f31c98 | 322 | u8g_DrawVLine(u8g, x0-y, y0, x+1); |
iforce2d | 0:972874f31c98 | 323 | } |
iforce2d | 0:972874f31c98 | 324 | } |
iforce2d | 0:972874f31c98 | 325 | |
iforce2d | 0:972874f31c98 | 326 | void u8g_draw_disc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) |
iforce2d | 0:972874f31c98 | 327 | { |
iforce2d | 0:972874f31c98 | 328 | u8g_int_t f; |
iforce2d | 0:972874f31c98 | 329 | u8g_int_t ddF_x; |
iforce2d | 0:972874f31c98 | 330 | u8g_int_t ddF_y; |
iforce2d | 0:972874f31c98 | 331 | u8g_uint_t x; |
iforce2d | 0:972874f31c98 | 332 | u8g_uint_t y; |
iforce2d | 0:972874f31c98 | 333 | |
iforce2d | 0:972874f31c98 | 334 | f = 1; |
iforce2d | 0:972874f31c98 | 335 | f -= rad; |
iforce2d | 0:972874f31c98 | 336 | ddF_x = 1; |
iforce2d | 0:972874f31c98 | 337 | ddF_y = 0; |
iforce2d | 0:972874f31c98 | 338 | ddF_y -= rad; |
iforce2d | 0:972874f31c98 | 339 | ddF_y *= 2; |
iforce2d | 0:972874f31c98 | 340 | x = 0; |
iforce2d | 0:972874f31c98 | 341 | y = rad; |
iforce2d | 0:972874f31c98 | 342 | |
iforce2d | 0:972874f31c98 | 343 | u8g_draw_disc_section(u8g, x, y, x0, y0, option); |
iforce2d | 0:972874f31c98 | 344 | |
iforce2d | 0:972874f31c98 | 345 | while ( x < y ) |
iforce2d | 0:972874f31c98 | 346 | { |
iforce2d | 0:972874f31c98 | 347 | if (f >= 0) |
iforce2d | 0:972874f31c98 | 348 | { |
iforce2d | 0:972874f31c98 | 349 | y--; |
iforce2d | 0:972874f31c98 | 350 | ddF_y += 2; |
iforce2d | 0:972874f31c98 | 351 | f += ddF_y; |
iforce2d | 0:972874f31c98 | 352 | } |
iforce2d | 0:972874f31c98 | 353 | x++; |
iforce2d | 0:972874f31c98 | 354 | ddF_x += 2; |
iforce2d | 0:972874f31c98 | 355 | f += ddF_x; |
iforce2d | 0:972874f31c98 | 356 | |
iforce2d | 0:972874f31c98 | 357 | u8g_draw_disc_section(u8g, x, y, x0, y0, option); |
iforce2d | 0:972874f31c98 | 358 | } |
iforce2d | 0:972874f31c98 | 359 | } |
iforce2d | 0:972874f31c98 | 360 | |
iforce2d | 0:972874f31c98 | 361 | void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t option) |
iforce2d | 0:972874f31c98 | 362 | { |
iforce2d | 0:972874f31c98 | 363 | /* check for bounding box */ |
iforce2d | 0:972874f31c98 | 364 | { |
iforce2d | 0:972874f31c98 | 365 | u8g_uint_t radp, radp2; |
iforce2d | 0:972874f31c98 | 366 | |
iforce2d | 0:972874f31c98 | 367 | radp = rad; |
iforce2d | 0:972874f31c98 | 368 | radp++; |
iforce2d | 0:972874f31c98 | 369 | radp2 = radp; |
iforce2d | 0:972874f31c98 | 370 | radp2 *= 2; |
iforce2d | 0:972874f31c98 | 371 | |
iforce2d | 0:972874f31c98 | 372 | if ( u8g_IsBBXIntersection(u8g, x0-radp, y0-radp, radp2, radp2) == 0) |
iforce2d | 0:972874f31c98 | 373 | return; |
iforce2d | 0:972874f31c98 | 374 | } |
iforce2d | 0:972874f31c98 | 375 | |
iforce2d | 0:972874f31c98 | 376 | /* draw disc */ |
iforce2d | 0:972874f31c98 | 377 | u8g_draw_disc(u8g, x0, y0, rad, option); |
iforce2d | 0:972874f31c98 | 378 | } |
iforce2d | 0:972874f31c98 | 379 | |
iforce2d | 0:972874f31c98 | 380 | |
iforce2d | 0:972874f31c98 | 381 | |
iforce2d | 0:972874f31c98 | 382 | |
iforce2d | 0:972874f31c98 | 383 |