17 #include "Adafruit_GFX.h"
20 void Adafruit_GFX::constructor(int16_t w, int16_t h) {
25 cursor_y = cursor_x = 0;
27 textcolor = textbgcolor = 0xFFFF;
33 void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
37 int16_t ddF_y = -2 * r;
41 drawPixel(x0, y0+r, color);
42 drawPixel(x0, y0-r, color);
43 drawPixel(x0+r, y0, color);
44 drawPixel(x0-r, y0, color);
56 drawPixel(x0 +
x, y0 + y, color);
57 drawPixel(x0 -
x, y0 + y, color);
58 drawPixel(x0 +
x, y0 - y, color);
59 drawPixel(x0 -
x, y0 - y, color);
60 drawPixel(x0 + y, y0 +
x, color);
61 drawPixel(x0 - y, y0 +
x, color);
62 drawPixel(x0 + y, y0 -
x, color);
63 drawPixel(x0 - y, y0 -
x, color);
68 void Adafruit_GFX::drawCircleHelper( int16_t x0, int16_t y0,
69 int16_t r, uint8_t cornername, uint16_t color) {
72 int16_t ddF_y = -2 * r;
85 if (cornername & 0x4) {
86 drawPixel(x0 +
x, y0 + y, color);
87 drawPixel(x0 + y, y0 +
x, color);
89 if (cornername & 0x2) {
90 drawPixel(x0 +
x, y0 - y, color);
91 drawPixel(x0 + y, y0 -
x, color);
93 if (cornername & 0x8) {
94 drawPixel(x0 - y, y0 +
x, color);
95 drawPixel(x0 -
x, y0 + y, color);
97 if (cornername & 0x1) {
98 drawPixel(x0 - y, y0 -
x, color);
99 drawPixel(x0 -
x, y0 - y, color);
104 void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,
106 drawFastVLine(x0, y0-r, 2*r+1, color);
107 fillCircleHelper(x0, y0, r, 3, 0, color);
111 void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
112 uint8_t cornername, int16_t delta, uint16_t color) {
116 int16_t ddF_y = -2 * r;
130 if (cornername & 0x1) {
131 drawFastVLine(x0+
x, y0-y, 2*y+1+delta, color);
132 drawFastVLine(x0+y, y0-
x, 2*
x+1+delta, color);
134 if (cornername & 0x2) {
135 drawFastVLine(x0-
x, y0-y, 2*y+1+delta, color);
136 drawFastVLine(x0-y, y0-
x, 2*
x+1+delta, color);
142 void Adafruit_GFX::drawLine(int16_t x0, int16_t y0,
143 int16_t x1, int16_t y1,
145 int16_t steep = abs(y1 - y0) > abs(x1 - x0);
160 int16_t err = dx / 2;
169 for (; x0<=x1; x0++) {
171 drawPixel(y0, x0, color);
173 drawPixel(x0, y0, color);
185 void Adafruit_GFX::drawRect(int16_t
x, int16_t y,
186 int16_t w, int16_t h,
188 drawFastHLine(
x, y, w, color);
189 drawFastHLine(
x, y+h-1, w, color);
190 drawFastVLine(
x, y, h, color);
191 drawFastVLine(
x+w-1, y, h, color);
194 void Adafruit_GFX::drawFastVLine(int16_t
x, int16_t y,
195 int16_t h, uint16_t color) {
197 drawLine(
x, y,
x, y+h-1, color);
201 void Adafruit_GFX::drawFastHLine(int16_t
x, int16_t y,
202 int16_t w, uint16_t color) {
204 drawLine(
x, y,
x+w-1, y, color);
207 void Adafruit_GFX::fillRect(int16_t
x, int16_t y, int16_t w, int16_t h,
210 for (int16_t i=
x; i<
x+w; i++) {
211 drawFastVLine(i, y, h, color);
216 void Adafruit_GFX::fillScreen(uint16_t color) {
217 fillRect(0, 0, _width, _height, color);
221 void Adafruit_GFX::drawRoundRect(int16_t
x, int16_t y, int16_t w,
222 int16_t h, int16_t r, uint16_t color) {
224 drawFastHLine(
x+r , y , w-2*r, color);
225 drawFastHLine(
x+r , y+h-1, w-2*r, color);
226 drawFastVLine(
x , y+r , h-2*r, color);
227 drawFastVLine(
x+w-1, y+r , h-2*r, color);
229 drawCircleHelper(
x+r , y+r , r, 1, color);
230 drawCircleHelper(
x+w-r-1, y+r , r, 2, color);
231 drawCircleHelper(
x+w-r-1, y+h-r-1, r, 4, color);
232 drawCircleHelper(
x+r , y+h-r-1, r, 8, color);
236 void Adafruit_GFX::fillRoundRect(int16_t
x, int16_t y, int16_t w,
237 int16_t h, int16_t r, uint16_t color) {
239 fillRect(
x+r, y, w-2*r, h, color);
242 fillCircleHelper(
x+w-r-1, y+r, r, 1, h-2*r-1, color);
243 fillCircleHelper(
x+r , y+r, r, 2, h-2*r-1, color);
247 void Adafruit_GFX::drawTriangle(int16_t x0, int16_t y0,
248 int16_t x1, int16_t y1,
249 int16_t x2, int16_t y2, uint16_t color) {
250 drawLine(x0, y0, x1, y1, color);
251 drawLine(x1, y1, x2, y2, color);
252 drawLine(x2, y2, x0, y0, color);
256 void Adafruit_GFX::fillTriangle ( int16_t x0, int16_t y0,
257 int16_t x1, int16_t y1,
258 int16_t x2, int16_t y2, uint16_t color) {
260 int16_t a, b, y, last;
264 swap(y0, y1); swap(x0, x1);
267 swap(y2, y1); swap(x2, x1);
270 swap(y0, y1); swap(x0, x1);
276 else if(x1 > b) b = x1;
278 else if(x2 > b) b = x2;
279 drawFastHLine(a, y0, b-a+1, color);
299 if(y1 == y2) last = y1;
302 for(y=y0; y<=last; y++) {
312 drawFastHLine(a, y, b-a+1, color);
317 sa = dx12 * (y - y1);
318 sb = dx02 * (y - y0);
329 drawFastHLine(a, y, b-a+1, color);
333 void Adafruit_GFX::drawBitmap(int16_t
x, int16_t y,
334 const uint8_t *bitmap, int16_t w, int16_t h,
337 int16_t i, j, byteWidth = (w + 7) / 8;
340 for(i=0; i<w; i++ ) {
341 if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (128 >> (i & 7))) {
342 drawPixel(
x+i, y+j, color);
350 size_t Adafruit_GFX::write(uint8_t c) {
352 void Adafruit_GFX::write(uint8_t c) {
355 cursor_y += textsize*8;
357 }
else if (c ==
'\r') {
360 drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
361 cursor_x += textsize*6;
362 if (wrap && (cursor_x > (_width - textsize*6))) {
363 cursor_y += textsize*8;
373 void Adafruit_GFX::drawChar(int16_t
x, int16_t y,
unsigned char c,
374 uint16_t color, uint16_t bg, uint8_t size) {
378 ((
x + 5 * size - 1) < 0) ||
379 ((y + 8 * size - 1) < 0))
382 for (int8_t i=0; i<6; i++ ) {
387 line = font[(c*5)+i];
389 for (int8_t j = 0; j<8; j++) {
392 drawPixel(
x+i, y+j, color);
394 fillRect(
x+(i*size), y+(j*size), size, size, color);
396 }
else if (bg != color) {
398 drawPixel(
x+i, y+j, bg);
400 fillRect(
x+i*size, y+j*size, size, size, bg);
408 void Adafruit_GFX::setCursor(int16_t
x, int16_t y) {
414 void Adafruit_GFX::setTextSize(uint8_t s) {
415 textsize = (s > 0) ? s : 1;
419 void Adafruit_GFX::setTextColor(uint16_t c) {
426 void Adafruit_GFX::setTextColor(uint16_t c, uint16_t b) {
431 void Adafruit_GFX::setTextWrap(
boolean w) {
435 uint8_t Adafruit_GFX::getRotation(
void) {
440 void Adafruit_GFX::setRotation(uint8_t
x) {
457 void Adafruit_GFX::invertDisplay(
boolean i) {
463 int16_t Adafruit_GFX::width(
void) {
467 int16_t Adafruit_GFX::height(
void) {