Adafruit-GFX porting for mbed

Dependents:   RGB_matrix_Panel RGB_matrix_Panel_modif RGB_matrix_Panel Pmod_OLEDrgb_ALS1_K64F ... more

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