Adafruit-GFX porting for mbed

Dependents:   Adafruit_SHARP_Memory_Display

Fork of Adafruit-GFX by EIC

Committer:
lelect
Date:
Tue May 27 10:47:49 2014 +0000
Revision:
3:3ffdf181555c
Parent:
1:c2715acb7466
Correct doxygen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lelect 0:3e9c32359703 1 /*
lelect 1:c2715acb7466 2 This is the core graphics library for all our displays,
lelect 1:c2715acb7466 3 providing a common set of graphics primitives (points, lines, circles, etc.).
lelect 1:c2715acb7466 4 It needs to be paired with a hardware-specific library for each display device we carry (to handle the lower-level functions).
lelect 0:3e9c32359703 5
lelect 1:c2715acb7466 6 Adafruit invests time and resources providing this open source code,
lelect 1:c2715acb7466 7 please support Adafruit and open-source hardware by purchasing products from Adafruit!
lelect 0:3e9c32359703 8
lelect 1:c2715acb7466 9 Written by Limor Fried/Ladyada for Adafruit Industries.
lelect 1:c2715acb7466 10 BSD license, check license.txt for more information.
lelect 1:c2715acb7466 11 All text above must be included in any redistribution.
lelect 0:3e9c32359703 12 */
lelect 0:3e9c32359703 13
lelect 1:c2715acb7466 14 /*
lelect 1:c2715acb7466 15 * Modified by Tatsuki Fukuda 25/5/2014 for use in mbed
lelect 1:c2715acb7466 16 */
lelect 1:c2715acb7466 17
lelect 0:3e9c32359703 18 #include "Adafruit_GFX.h"
lelect 0:3e9c32359703 19
lelect 0:3e9c32359703 20 // Draw a circle outline
lelect 0:3e9c32359703 21 void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
lelect 0:3e9c32359703 22 uint16_t color)
lelect 0:3e9c32359703 23 {
lelect 0:3e9c32359703 24 int16_t f = 1 - r;
lelect 0:3e9c32359703 25 int16_t ddF_x = 1;
lelect 0:3e9c32359703 26 int16_t ddF_y = -2 * r;
lelect 0:3e9c32359703 27 int16_t x = 0;
lelect 0:3e9c32359703 28 int16_t y = r;
lelect 0:3e9c32359703 29
lelect 0:3e9c32359703 30 drawPixel(x0 , y0+r, color);
lelect 0:3e9c32359703 31 drawPixel(x0 , y0-r, color);
lelect 0:3e9c32359703 32 drawPixel(x0+r, y0 , color);
lelect 0:3e9c32359703 33 drawPixel(x0-r, y0 , color);
lelect 0:3e9c32359703 34
lelect 0:3e9c32359703 35 while (x<y) {
lelect 0:3e9c32359703 36 if (f >= 0) {
lelect 0:3e9c32359703 37 y--;
lelect 0:3e9c32359703 38 ddF_y += 2;
lelect 0:3e9c32359703 39 f += ddF_y;
lelect 0:3e9c32359703 40 }
lelect 0:3e9c32359703 41 x++;
lelect 0:3e9c32359703 42 ddF_x += 2;
lelect 0:3e9c32359703 43 f += ddF_x;
lelect 0:3e9c32359703 44
lelect 0:3e9c32359703 45 drawPixel(x0 + x, y0 + y, color);
lelect 0:3e9c32359703 46 drawPixel(x0 - x, y0 + y, color);
lelect 0:3e9c32359703 47 drawPixel(x0 + x, y0 - y, color);
lelect 0:3e9c32359703 48 drawPixel(x0 - x, y0 - y, color);
lelect 0:3e9c32359703 49 drawPixel(x0 + y, y0 + x, color);
lelect 0:3e9c32359703 50 drawPixel(x0 - y, y0 + x, color);
lelect 0:3e9c32359703 51 drawPixel(x0 + y, y0 - x, color);
lelect 0:3e9c32359703 52 drawPixel(x0 - y, y0 - x, color);
lelect 0:3e9c32359703 53 }
lelect 0:3e9c32359703 54 }
lelect 0:3e9c32359703 55
lelect 0:3e9c32359703 56 void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0,
lelect 0:3e9c32359703 57 int16_t r, uint8_t cornername, uint16_t color)
lelect 0:3e9c32359703 58 {
lelect 0:3e9c32359703 59 int16_t f = 1 - r;
lelect 0:3e9c32359703 60 int16_t ddF_x = 1;
lelect 0:3e9c32359703 61 int16_t ddF_y = -2 * r;
lelect 0:3e9c32359703 62 int16_t x = 0;
lelect 0:3e9c32359703 63 int16_t y = r;
lelect 0:3e9c32359703 64
lelect 0:3e9c32359703 65 while (x<y) {
lelect 0:3e9c32359703 66 if (f >= 0) {
lelect 0:3e9c32359703 67 y--;
lelect 0:3e9c32359703 68 ddF_y += 2;
lelect 0:3e9c32359703 69 f += ddF_y;
lelect 0:3e9c32359703 70 }
lelect 0:3e9c32359703 71 x++;
lelect 0:3e9c32359703 72 ddF_x += 2;
lelect 0:3e9c32359703 73 f += ddF_x;
lelect 0:3e9c32359703 74 if (cornername & 0x4) {
lelect 0:3e9c32359703 75 drawPixel(x0 + x, y0 + y, color);
lelect 0:3e9c32359703 76 drawPixel(x0 + y, y0 + x, color);
lelect 0:3e9c32359703 77 }
lelect 0:3e9c32359703 78 if (cornername & 0x2) {
lelect 0:3e9c32359703 79 drawPixel(x0 + x, y0 - y, color);
lelect 0:3e9c32359703 80 drawPixel(x0 + y, y0 - x, color);
lelect 0:3e9c32359703 81 }
lelect 0:3e9c32359703 82 if (cornername & 0x8) {
lelect 0:3e9c32359703 83 drawPixel(x0 - y, y0 + x, color);
lelect 0:3e9c32359703 84 drawPixel(x0 - x, y0 + y, color);
lelect 0:3e9c32359703 85 }
lelect 0:3e9c32359703 86 if (cornername & 0x1) {
lelect 0:3e9c32359703 87 drawPixel(x0 - y, y0 - x, color);
lelect 0:3e9c32359703 88 drawPixel(x0 - x, y0 - y, color);
lelect 0:3e9c32359703 89 }
lelect 0:3e9c32359703 90 }
lelect 0:3e9c32359703 91 }
lelect 0:3e9c32359703 92
lelect 0:3e9c32359703 93 void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,
lelect 0:3e9c32359703 94 uint16_t color)
lelect 0:3e9c32359703 95 {
lelect 0:3e9c32359703 96 drawFastVLine(x0, y0-r, 2*r+1, color);
lelect 0:3e9c32359703 97 fillCircleHelper(x0, y0, r, 3, 0, color);
lelect 0:3e9c32359703 98 }
lelect 0:3e9c32359703 99
lelect 0:3e9c32359703 100 // Used to do circles and roundrects
lelect 0:3e9c32359703 101 void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
lelect 0:3e9c32359703 102 uint8_t cornername, int16_t delta, uint16_t color)
lelect 0:3e9c32359703 103 {
lelect 0:3e9c32359703 104
lelect 0:3e9c32359703 105 int16_t f = 1 - r;
lelect 0:3e9c32359703 106 int16_t ddF_x = 1;
lelect 0:3e9c32359703 107 int16_t ddF_y = -2 * r;
lelect 0:3e9c32359703 108 int16_t x = 0;
lelect 0:3e9c32359703 109 int16_t y = r;
lelect 0:3e9c32359703 110
lelect 0:3e9c32359703 111 while (x<y) {
lelect 0:3e9c32359703 112 if (f >= 0) {
lelect 0:3e9c32359703 113 y--;
lelect 0:3e9c32359703 114 ddF_y += 2;
lelect 0:3e9c32359703 115 f += ddF_y;
lelect 0:3e9c32359703 116 }
lelect 0:3e9c32359703 117 x++;
lelect 0:3e9c32359703 118 ddF_x += 2;
lelect 0:3e9c32359703 119 f += ddF_x;
lelect 0:3e9c32359703 120
lelect 0:3e9c32359703 121 if (cornername & 0x1) {
lelect 0:3e9c32359703 122 drawFastVLine(x0+x, y0-y, 2*y+1+delta, color);
lelect 0:3e9c32359703 123 drawFastVLine(x0+y, y0-x, 2*x+1+delta, color);
lelect 0:3e9c32359703 124 }
lelect 0:3e9c32359703 125 if (cornername & 0x2) {
lelect 0:3e9c32359703 126 drawFastVLine(x0-x, y0-y, 2*y+1+delta, color);
lelect 0:3e9c32359703 127 drawFastVLine(x0-y, y0-x, 2*x+1+delta, color);
lelect 0:3e9c32359703 128 }
lelect 0:3e9c32359703 129 }
lelect 0:3e9c32359703 130 }
lelect 0:3e9c32359703 131
lelect 0:3e9c32359703 132 // Bresenham's algorithm - thx wikpedia
lelect 0:3e9c32359703 133 void Adafruit_GFX::drawLine(int16_t x0, int16_t y0,
lelect 0:3e9c32359703 134 int16_t x1, int16_t y1,
lelect 0:3e9c32359703 135 uint16_t color)
lelect 0:3e9c32359703 136 {
lelect 0:3e9c32359703 137 int16_t steep = abs(y1 - y0) > abs(x1 - x0);
lelect 0:3e9c32359703 138 if (steep) {
lelect 0:3e9c32359703 139 swap(x0, y0);
lelect 0:3e9c32359703 140 swap(x1, y1);
lelect 0:3e9c32359703 141 }
lelect 0:3e9c32359703 142
lelect 0:3e9c32359703 143 if (x0 > x1) {
lelect 0:3e9c32359703 144 swap(x0, x1);
lelect 0:3e9c32359703 145 swap(y0, y1);
lelect 0:3e9c32359703 146 }
lelect 0:3e9c32359703 147
lelect 0:3e9c32359703 148 int16_t dx, dy;
lelect 0:3e9c32359703 149 dx = x1 - x0;
lelect 0:3e9c32359703 150 dy = abs(y1 - y0);
lelect 0:3e9c32359703 151
lelect 0:3e9c32359703 152 int16_t err = dx / 2;
lelect 0:3e9c32359703 153 int16_t ystep;
lelect 0:3e9c32359703 154
lelect 0:3e9c32359703 155 if (y0 < y1) {
lelect 0:3e9c32359703 156 ystep = 1;
lelect 0:3e9c32359703 157 } else {
lelect 0:3e9c32359703 158 ystep = -1;
lelect 0:3e9c32359703 159 }
lelect 0:3e9c32359703 160
lelect 0:3e9c32359703 161 for (; x0<=x1; x0++) {
lelect 0:3e9c32359703 162 if (steep) {
lelect 0:3e9c32359703 163 drawPixel(y0, x0, color);
lelect 0:3e9c32359703 164 } else {
lelect 0:3e9c32359703 165 drawPixel(x0, y0, color);
lelect 0:3e9c32359703 166 }
lelect 0:3e9c32359703 167 err -= dy;
lelect 0:3e9c32359703 168 if (err < 0) {
lelect 0:3e9c32359703 169 y0 += ystep;
lelect 0:3e9c32359703 170 err += dx;
lelect 0:3e9c32359703 171 }
lelect 0:3e9c32359703 172 }
lelect 0:3e9c32359703 173 }
lelect 0:3e9c32359703 174
lelect 0:3e9c32359703 175 // Draw a rectangle
lelect 0:3e9c32359703 176 void Adafruit_GFX::drawRect(int16_t x, int16_t y,
lelect 0:3e9c32359703 177 int16_t w, int16_t h,
lelect 0:3e9c32359703 178 uint16_t color)
lelect 0:3e9c32359703 179 {
lelect 0:3e9c32359703 180 drawFastHLine(x, y, w, color);
lelect 0:3e9c32359703 181 drawFastHLine(x, y+h-1, w, color);
lelect 0:3e9c32359703 182 drawFastVLine(x, y, h, color);
lelect 0:3e9c32359703 183 drawFastVLine(x+w-1, y, h, color);
lelect 0:3e9c32359703 184 }
lelect 0:3e9c32359703 185
lelect 0:3e9c32359703 186 void Adafruit_GFX::drawFastVLine(int16_t x, int16_t y,
lelect 0:3e9c32359703 187 int16_t h, uint16_t color)
lelect 0:3e9c32359703 188 {
lelect 0:3e9c32359703 189 // Update in subclasses if desired!
lelect 0:3e9c32359703 190 drawLine(x, y, x, y+h-1, color);
lelect 0:3e9c32359703 191 }
lelect 0:3e9c32359703 192
lelect 0:3e9c32359703 193 void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y,
lelect 0:3e9c32359703 194 int16_t w, uint16_t color)
lelect 0:3e9c32359703 195 {
lelect 0:3e9c32359703 196 // Update in subclasses if desired!
lelect 0:3e9c32359703 197 drawLine(x, y, x+w-1, y, color);
lelect 0:3e9c32359703 198 }
lelect 0:3e9c32359703 199
lelect 0:3e9c32359703 200 void Adafruit_GFX::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
lelect 0:3e9c32359703 201 uint16_t color)
lelect 0:3e9c32359703 202 {
lelect 0:3e9c32359703 203 // Update in subclasses if desired!
lelect 0:3e9c32359703 204 for (int16_t i=x; i<x+w; i++) {
lelect 0:3e9c32359703 205 drawFastVLine(i, y, h, color);
lelect 0:3e9c32359703 206 }
lelect 0:3e9c32359703 207 }
lelect 0:3e9c32359703 208
lelect 0:3e9c32359703 209 void Adafruit_GFX::fillScreen(uint16_t color)
lelect 0:3e9c32359703 210 {
lelect 0:3e9c32359703 211 fillRect(0, 0, _width, _height, color);
lelect 0:3e9c32359703 212 }
lelect 0:3e9c32359703 213
lelect 0:3e9c32359703 214 // Draw a rounded rectangle
lelect 0:3e9c32359703 215 void Adafruit_GFX::drawRoundRect(int16_t x, int16_t y, int16_t w,
lelect 0:3e9c32359703 216 int16_t h, int16_t r, uint16_t color)
lelect 0:3e9c32359703 217 {
lelect 0:3e9c32359703 218 // smarter version
lelect 0:3e9c32359703 219 drawFastHLine(x+r , y , w-2*r, color); // Top
lelect 0:3e9c32359703 220 drawFastHLine(x+r , y+h-1, w-2*r, color); // Bottom
lelect 0:3e9c32359703 221 drawFastVLine(x , y+r , h-2*r, color); // Left
lelect 0:3e9c32359703 222 drawFastVLine(x+w-1, y+r , h-2*r, color); // Right
lelect 0:3e9c32359703 223 // draw four corners
lelect 0:3e9c32359703 224 drawCircleHelper(x+r , y+r , r, 1, color);
lelect 0:3e9c32359703 225 drawCircleHelper(x+w-r-1, y+r , r, 2, color);
lelect 0:3e9c32359703 226 drawCircleHelper(x+w-r-1, y+h-r-1, r, 4, color);
lelect 0:3e9c32359703 227 drawCircleHelper(x+r , y+h-r-1, r, 8, color);
lelect 0:3e9c32359703 228 }
lelect 0:3e9c32359703 229
lelect 0:3e9c32359703 230 // Fill a rounded rectangle
lelect 0:3e9c32359703 231 void Adafruit_GFX::fillRoundRect(int16_t x, int16_t y, int16_t w,
lelect 0:3e9c32359703 232 int16_t h, int16_t r, uint16_t color)
lelect 0:3e9c32359703 233 {
lelect 0:3e9c32359703 234 // smarter version
lelect 0:3e9c32359703 235 fillRect(x+r, y, w-2*r, h, color);
lelect 0:3e9c32359703 236
lelect 0:3e9c32359703 237 // draw four corners
lelect 0:3e9c32359703 238 fillCircleHelper(x+w-r-1, y+r, r, 1, h-2*r-1, color);
lelect 0:3e9c32359703 239 fillCircleHelper(x+r , y+r, r, 2, h-2*r-1, color);
lelect 0:3e9c32359703 240 }
lelect 0:3e9c32359703 241
lelect 0:3e9c32359703 242 // Draw a triangle
lelect 0:3e9c32359703 243 void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0,
lelect 0:3e9c32359703 244 int16_t x1, int16_t y1,
lelect 0:3e9c32359703 245 int16_t x2, int16_t y2, uint16_t color)
lelect 0:3e9c32359703 246 {
lelect 0:3e9c32359703 247 drawLine(x0, y0, x1, y1, color);
lelect 0:3e9c32359703 248 drawLine(x1, y1, x2, y2, color);
lelect 0:3e9c32359703 249 drawLine(x2, y2, x0, y0, color);
lelect 0:3e9c32359703 250 }
lelect 0:3e9c32359703 251
lelect 0:3e9c32359703 252 // Fill a triangle
lelect 0:3e9c32359703 253 void Adafruit_GFX::fillTriangle ( int16_t x0, int16_t y0,
lelect 0:3e9c32359703 254 int16_t x1, int16_t y1,
lelect 0:3e9c32359703 255 int16_t x2, int16_t y2, uint16_t color)
lelect 0:3e9c32359703 256 {
lelect 0:3e9c32359703 257
lelect 0:3e9c32359703 258 int16_t a, b, y, last;
lelect 0:3e9c32359703 259
lelect 0:3e9c32359703 260 // Sort coordinates by Y order (y2 >= y1 >= y0)
lelect 0:3e9c32359703 261 if (y0 > y1) {
lelect 0:3e9c32359703 262 swap(y0, y1);
lelect 0:3e9c32359703 263 swap(x0, x1);
lelect 0:3e9c32359703 264 }
lelect 0:3e9c32359703 265 if (y1 > y2) {
lelect 0:3e9c32359703 266 swap(y2, y1);
lelect 0:3e9c32359703 267 swap(x2, x1);
lelect 0:3e9c32359703 268 }
lelect 0:3e9c32359703 269 if (y0 > y1) {
lelect 0:3e9c32359703 270 swap(y0, y1);
lelect 0:3e9c32359703 271 swap(x0, x1);
lelect 0:3e9c32359703 272 }
lelect 0:3e9c32359703 273
lelect 0:3e9c32359703 274 if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing
lelect 0:3e9c32359703 275 a = b = x0;
lelect 0:3e9c32359703 276 if(x1 < a) a = x1;
lelect 0:3e9c32359703 277 else if(x1 > b) b = x1;
lelect 0:3e9c32359703 278 if(x2 < a) a = x2;
lelect 0:3e9c32359703 279 else if(x2 > b) b = x2;
lelect 0:3e9c32359703 280 drawFastHLine(a, y0, b-a+1, color);
lelect 0:3e9c32359703 281 return;
lelect 0:3e9c32359703 282 }
lelect 0:3e9c32359703 283
lelect 0:3e9c32359703 284 int16_t
lelect 0:3e9c32359703 285 dx01 = x1 - x0,
lelect 0:3e9c32359703 286 dy01 = y1 - y0,
lelect 0:3e9c32359703 287 dx02 = x2 - x0,
lelect 0:3e9c32359703 288 dy02 = y2 - y0,
lelect 0:3e9c32359703 289 dx12 = x2 - x1,
lelect 0:3e9c32359703 290 dy12 = y2 - y1,
lelect 0:3e9c32359703 291 sa = 0,
lelect 0:3e9c32359703 292 sb = 0;
lelect 0:3e9c32359703 293
lelect 0:3e9c32359703 294 // For upper part of triangle, find scanline crossings for segments
lelect 0:3e9c32359703 295 // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1
lelect 0:3e9c32359703 296 // is included here (and second loop will be skipped, avoiding a /0
lelect 0:3e9c32359703 297 // error there), otherwise scanline y1 is skipped here and handled
lelect 0:3e9c32359703 298 // in the second loop...which also avoids a /0 error here if y0=y1
lelect 0:3e9c32359703 299 // (flat-topped triangle).
lelect 0:3e9c32359703 300 if(y1 == y2) last = y1; // Include y1 scanline
lelect 0:3e9c32359703 301 else last = y1-1; // Skip it
lelect 0:3e9c32359703 302
lelect 0:3e9c32359703 303 for(y=y0; y<=last; y++) {
lelect 0:3e9c32359703 304 a = x0 + sa / dy01;
lelect 0:3e9c32359703 305 b = x0 + sb / dy02;
lelect 0:3e9c32359703 306 sa += dx01;
lelect 0:3e9c32359703 307 sb += dx02;
lelect 0:3e9c32359703 308 /* longhand:
lelect 0:3e9c32359703 309 a = x0 + (x1 - x0) * (y - y0) / (y1 - y0);
lelect 0:3e9c32359703 310 b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
lelect 0:3e9c32359703 311 */
lelect 0:3e9c32359703 312 if(a > b) swap(a,b);
lelect 0:3e9c32359703 313 drawFastHLine(a, y, b-a+1, color);
lelect 0:3e9c32359703 314 }
lelect 0:3e9c32359703 315
lelect 0:3e9c32359703 316 // For lower part of triangle, find scanline crossings for segments
lelect 0:3e9c32359703 317 // 0-2 and 1-2. This loop is skipped if y1=y2.
lelect 0:3e9c32359703 318 sa = dx12 * (y - y1);
lelect 0:3e9c32359703 319 sb = dx02 * (y - y0);
lelect 0:3e9c32359703 320 for(; y<=y2; y++) {
lelect 0:3e9c32359703 321 a = x1 + sa / dy12;
lelect 0:3e9c32359703 322 b = x0 + sb / dy02;
lelect 0:3e9c32359703 323 sa += dx12;
lelect 0:3e9c32359703 324 sb += dx02;
lelect 0:3e9c32359703 325 /* longhand:
lelect 0:3e9c32359703 326 a = x1 + (x2 - x1) * (y - y1) / (y2 - y1);
lelect 0:3e9c32359703 327 b = x0 + (x2 - x0) * (y - y0) / (y2 - y0);
lelect 0:3e9c32359703 328 */
lelect 0:3e9c32359703 329 if(a > b) swap(a,b);
lelect 0:3e9c32359703 330 drawFastHLine(a, y, b-a+1, color);
lelect 0:3e9c32359703 331 }
lelect 0:3e9c32359703 332 }
lelect 0:3e9c32359703 333
lelect 0:3e9c32359703 334 void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
lelect 0:3e9c32359703 335 {
lelect 0:3e9c32359703 336 int16_t i, j;
lelect 0:3e9c32359703 337 for(j=0; j<h; j++) {
lelect 0:3e9c32359703 338 for(i=0; i<w; i++ ) {
lelect 0:3e9c32359703 339 if(bitmap[i+(j/8)*w]& _BV(j%8) )
lelect 0:3e9c32359703 340 drawPixel(x+i, y+j, color);
lelect 0:3e9c32359703 341 }
lelect 0:3e9c32359703 342 }
lelect 0:3e9c32359703 343 }
lelect 0:3e9c32359703 344
lelect 0:3e9c32359703 345 size_t Adafruit_GFX::writeChar(uint8_t c)
lelect 0:3e9c32359703 346 {
lelect 0:3e9c32359703 347 if (c == '\n') {
lelect 0:3e9c32359703 348 cursor_y += textsize*8;
lelect 0:3e9c32359703 349 cursor_x = 0;
lelect 0:3e9c32359703 350 } else if (c == '\r') {
lelect 0:3e9c32359703 351 cursor_x = 0;
lelect 0:3e9c32359703 352 } else {
lelect 0:3e9c32359703 353 drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
lelect 0:3e9c32359703 354 cursor_x += textsize*6;
lelect 0:3e9c32359703 355 if (wrap && (cursor_x > (_width - textsize*6))) {
lelect 0:3e9c32359703 356 cursor_y += textsize*8;
lelect 0:3e9c32359703 357 cursor_x = 0;
lelect 0:3e9c32359703 358 }
lelect 0:3e9c32359703 359 }
lelect 0:3e9c32359703 360 return 1;
lelect 0:3e9c32359703 361 }
lelect 0:3e9c32359703 362
lelect 0:3e9c32359703 363 // Draw a character
lelect 0:3e9c32359703 364 void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
lelect 0:3e9c32359703 365 {
lelect 0:3e9c32359703 366 if((x >= _width)|| // Clip right
lelect 0:3e9c32359703 367 (y >= _height)|| // Clip bottom
lelect 0:3e9c32359703 368 ((x + 6 * size - 1) < 0) || // Clip left
lelect 0:3e9c32359703 369 ((y + 8 * size - 1) < 0))// Clip top
lelect 0:3e9c32359703 370 return;
lelect 0:3e9c32359703 371
lelect 0:3e9c32359703 372 for (int8_t i=0; i<6; i++ ) {
lelect 0:3e9c32359703 373 uint8_t line;
lelect 0:3e9c32359703 374 if (i == 5)
lelect 0:3e9c32359703 375 line = 0x0;
lelect 0:3e9c32359703 376 else
lelect 0:3e9c32359703 377 line = font[(c*5)+i];
lelect 0:3e9c32359703 378 for (int8_t j = 0; j<8; j++) {
lelect 0:3e9c32359703 379 if (line & 0x1) {
lelect 0:3e9c32359703 380 if (size == 1) // default size
lelect 0:3e9c32359703 381 drawPixel(x+i, y+j, color);
lelect 0:3e9c32359703 382 else { // big size
lelect 0:3e9c32359703 383 fillRect(x+(i*size), y+(j*size), size, size, color);
lelect 0:3e9c32359703 384 }
lelect 0:3e9c32359703 385 } else if (bg != color) {
lelect 0:3e9c32359703 386 if (size == 1) // default size
lelect 0:3e9c32359703 387 drawPixel(x+i, y+j, bg);
lelect 0:3e9c32359703 388 else { // big size
lelect 0:3e9c32359703 389 fillRect(x+i*size, y+j*size, size, size, bg);
lelect 0:3e9c32359703 390 }
lelect 0:3e9c32359703 391 }
lelect 0:3e9c32359703 392 line >>= 1;
lelect 0:3e9c32359703 393 }
lelect 0:3e9c32359703 394 }
lelect 0:3e9c32359703 395 }
lelect 0:3e9c32359703 396
lelect 0:3e9c32359703 397
lelect 0:3e9c32359703 398 void Adafruit_GFX::invertDisplay(bool i)
lelect 0:3e9c32359703 399 {
lelect 0:3e9c32359703 400 // Do nothing, must be subclassed if supported
lelect 0:3e9c32359703 401 }