diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index af989002..ceefa7bb 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -1147,20 +1147,34 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, c++; // Handle 'classic' charset behavior startWrite(); - for (int8_t i = 0; i < 5; i++) { // Char bitmap = 5 columns + int8_t rp, rb; // Count sequential FG and BG pixels in column + for (int8_t i = 0; i < 5; i++, rp = 0, rb = 0) { // Char bitmap = 5 columns uint8_t line = pgm_read_byte(&font[c * 5 + i]); for (int8_t j = 0; j < 8; j++, line >>= 1) { if (line & 1) { - if (size_x == 1 && size_y == 1) - writePixel(x + i, y + j, color); - else - writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y, - color); + rp++; + if (!(1 & (line >> 1)) || + j == 7) { // write sequential pixels with writeFillRect + if (rp == 1 && size_x == 1 && size_y == 1) { + writePixel(x + i, y + j, color); + } else if (rp > 0) { + writeFillRect(x + i * size_x, y + (j - (rp - 1)) * size_y, size_x, + size_y * rp, color); + } + rp = 0; + } } else if (bg != color) { - if (size_x == 1 && size_y == 1) - writePixel(x + i, y + j, bg); - else - writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y, bg); + rb++; + if (1 & (line >> 1) || + j == 7) { // write sequential pixels with writeFillRect + if (rb == 1 && size_x == 1 && size_y == 1) { + writePixel(x + i, y + j, bg); + } else if (rb > 0) { + writeFillRect(x + i * size_x, y + (j - (rb - 1)) * size_y, size_x, + size_y * rb, bg); + } + rb = 0; + } } } } diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index 63c6ab68..30ec03ba 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -294,16 +294,21 @@ class Adafruit_GFX_Button { /**********************************************************************/ bool isPressed(void) { return currstate; }; -private: - Adafruit_GFX *_gfx; - int16_t _x1, _y1; // Coordinates of top-left corner - uint16_t _w, _h; - uint8_t _textsize_x; - uint8_t _textsize_y; - uint16_t _outlinecolor, _fillcolor, _textcolor; - char _label[10]; - - bool currstate, laststate; +protected: + Adafruit_GFX *_gfx; ///< gfx display pointer + int16_t _x1; ///< x Coordinate of top-left corner + int16_t _y1; ///< y Coordinate of top-left corner + uint16_t _w; ///< width of button + uint16_t _h; ///< height of button + uint8_t _textsize_x; ///< width of text character in pixels + uint8_t _textsize_y; ///< height of text character in pixels + uint16_t _outlinecolor; ///< button outline color + uint16_t _fillcolor; ///< button fill color + uint16_t _textcolor; ///< text color + char _label[10]; ///< text label on button + + bool currstate; ///< current pressed state + bool laststate; ///< previous pressed state }; /// A GFX 1-bit canvas context for graphics