BLYNK TEST

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Thu Jun 16 08:12:33 2016 +0000
Revision:
4:e5018e5ba340
Parent:
1:0e75de2a5d21
ok

Who changed what in which revision?

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