テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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