@@ -108,7 +108,7 @@ WIDTH(w), HEIGHT(h)
108108 _height = HEIGHT;
109109 rotation = 0 ;
110110 cursor_y = cursor_x = 0 ;
111- textsize = 1 ;
111+ textsize_x = textsize_y = 1 ;
112112 textcolor = textbgcolor = 0xFFFF ;
113113 wrap = true ;
114114 _cp437 = false ;
@@ -796,7 +796,7 @@ void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
796796
797797/* *************************************************************************/
798798/* !
799- @brief Draw PROGMEM-resident XBitMap Files (*.xbm), exported from GIMP.
799+ @brief Draw PROGMEM-resident XBitMap Files (*.xbm), exported from GIMP.
800800 Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
801801 C Array can be directly used with this function.
802802 There is no RAM-resident version of this function; if generating bitmaps
@@ -831,7 +831,7 @@ void Adafruit_GFX::drawXBitmap(int16_t x, int16_t y,
831831
832832/* *************************************************************************/
833833/* !
834- @brief Draw a PROGMEM-resident 8-bit image (grayscale) at the specified (x,y) pos.
834+ @brief Draw a PROGMEM-resident 8-bit image (grayscale) at the specified (x,y) pos.
835835 Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed.
836836 @param x Top left corner x coordinate
837837 @param y Top left corner y coordinate
@@ -853,7 +853,7 @@ void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
853853
854854/* *************************************************************************/
855855/* !
856- @brief Draw a RAM-resident 8-bit image (grayscale) at the specified (x,y) pos.
856+ @brief Draw a RAM-resident 8-bit image (grayscale) at the specified (x,y) pos.
857857 Specifically for 8-bit display devices such as IS31FL3731; no color reduction/expansion is performed.
858858 @param x Top left corner x coordinate
859859 @param y Top left corner y coordinate
@@ -940,7 +940,7 @@ void Adafruit_GFX::drawGrayscaleBitmap(int16_t x, int16_t y,
940940
941941/* *************************************************************************/
942942/* !
943- @brief Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
943+ @brief Draw a PROGMEM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
944944 For 16-bit display devices; no color reduction performed.
945945 @param x Top left corner x coordinate
946946 @param y Top left corner y coordinate
@@ -962,7 +962,7 @@ void Adafruit_GFX::drawRGBBitmap(int16_t x, int16_t y,
962962
963963/* *************************************************************************/
964964/* !
965- @brief Draw a RAM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
965+ @brief Draw a RAM-resident 16-bit image (RGB 5/6/5) at the specified (x,y) position.
966966 For 16-bit display devices; no color reduction performed.
967967 @param x Top left corner x coordinate
968968 @param y Top left corner y coordinate
@@ -1056,13 +1056,31 @@ void Adafruit_GFX::drawRGBBitmap(int16_t x, int16_t y,
10561056/* *************************************************************************/
10571057void Adafruit_GFX::drawChar (int16_t x, int16_t y, unsigned char c,
10581058 uint16_t color, uint16_t bg, uint8_t size) {
1059+ drawChar (x, y, c, color, bg, size, size);
1060+ }
1061+
1062+ // Draw a character
1063+ /* *************************************************************************/
1064+ /* !
1065+ @brief Draw a single character
1066+ @param x Bottom left corner x coordinate
1067+ @param y Bottom left corner y coordinate
1068+ @param c The 8-bit font-indexed character (likely ascii)
1069+ @param color 16-bit 5-6-5 Color to draw chraracter with
1070+ @param bg 16-bit 5-6-5 Color to fill background with (if same as color, no background)
1071+ @param size_x Font magnification level in X-axis, 1 is 'original' size
1072+ @param size_y Font magnification level in Y-axis, 1 is 'original' size
1073+ */
1074+ /* *************************************************************************/
1075+ void Adafruit_GFX::drawChar (int16_t x, int16_t y, unsigned char c,
1076+ uint16_t color, uint16_t bg, uint8_t size_x, uint8_t size_y) {
10591077
10601078 if (!gfxFont) { // 'Classic' built-in font
10611079
10621080 if ((x >= _width) || // Clip right
10631081 (y >= _height) || // Clip bottom
1064- ((x + 6 * size - 1 ) < 0 ) || // Clip left
1065- ((y + 8 * size - 1 ) < 0 )) // Clip top
1082+ ((x + 6 * size_x - 1 ) < 0 ) || // Clip left
1083+ ((y + 8 * size_y - 1 ) < 0 )) // Clip top
10661084 return ;
10671085
10681086 if (!_cp437 && (c >= 176 )) c++; // Handle 'classic' charset behavior
@@ -1072,21 +1090,21 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
10721090 uint8_t line = pgm_read_byte (&font[c * 5 + i]);
10731091 for (int8_t j=0 ; j<8 ; j++, line >>= 1 ) {
10741092 if (line & 1 ) {
1075- if (size == 1 )
1093+ if (size_x == 1 && size_y == 1 )
10761094 writePixel (x+i, y+j, color);
10771095 else
1078- writeFillRect (x+i*size , y+j*size, size, size , color);
1096+ writeFillRect (x+i*size_x , y+j*size_y, size_x, size_y , color);
10791097 } else if (bg != color) {
1080- if (size == 1 )
1098+ if (size_x == 1 && size_y == 1 )
10811099 writePixel (x+i, y+j, bg);
10821100 else
1083- writeFillRect (x+i*size , y+j*size, size, size , bg);
1101+ writeFillRect (x+i*size_x , y+j*size_y, size_x, size_y , bg);
10841102 }
10851103 }
10861104 }
10871105 if (bg != color) { // If opaque, draw vertical line for last column
1088- if (size == 1 ) writeFastVLine (x+5 , y, 8 , bg);
1089- else writeFillRect (x+5 *size , y, size , 8 *size , bg);
1106+ if (size_x == 1 && size_y == 1 ) writeFastVLine (x+5 , y, 8 , bg);
1107+ else writeFillRect (x+5 *size_x , y, size_x , 8 *size_y , bg);
10901108 }
10911109 endWrite ();
10921110
@@ -1108,7 +1126,7 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
11081126 uint8_t xx, yy, bits = 0 , bit = 0 ;
11091127 int16_t xo16 = 0 , yo16 = 0 ;
11101128
1111- if (size > 1 ) {
1129+ if (size_x > 1 || size_y > 1 ) {
11121130 xo16 = xo;
11131131 yo16 = yo;
11141132 }
@@ -1138,11 +1156,11 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
11381156 bits = pgm_read_byte (&bitmap[bo++]);
11391157 }
11401158 if (bits & 0x80 ) {
1141- if (size == 1 ) {
1159+ if (size_x == 1 && size_y == 1 ) {
11421160 writePixel (x+xo+xx, y+yo+yy, color);
11431161 } else {
1144- writeFillRect (x+(xo16+xx)*size , y+(yo16+yy)*size ,
1145- size, size , color);
1162+ writeFillRect (x+(xo16+xx)*size_x , y+(yo16+yy)*size_y ,
1163+ size_x, size_y , color);
11461164 }
11471165 }
11481166 bits <<= 1 ;
@@ -1163,21 +1181,21 @@ size_t Adafruit_GFX::write(uint8_t c) {
11631181
11641182 if (c == ' \n ' ) { // Newline?
11651183 cursor_x = 0 ; // Reset x to zero,
1166- cursor_y += textsize * 8 ; // advance y one line
1184+ cursor_y += textsize_y * 8 ; // advance y one line
11671185 } else if (c != ' \r ' ) { // Ignore carriage returns
1168- if (wrap && ((cursor_x + textsize * 6 ) > _width)) { // Off right?
1186+ if (wrap && ((cursor_x + textsize_x * 6 ) > _width)) { // Off right?
11691187 cursor_x = 0 ; // Reset x to zero,
1170- cursor_y += textsize * 8 ; // advance y one line
1188+ cursor_y += textsize_y * 8 ; // advance y one line
11711189 }
1172- drawChar (cursor_x, cursor_y, c, textcolor, textbgcolor, textsize );
1173- cursor_x += textsize * 6 ; // Advance x one char
1190+ drawChar (cursor_x, cursor_y, c, textcolor, textbgcolor, textsize_x, textsize_y );
1191+ cursor_x += textsize_x * 6 ; // Advance x one char
11741192 }
11751193
11761194 } else { // Custom font
11771195
11781196 if (c == ' \n ' ) {
11791197 cursor_x = 0 ;
1180- cursor_y += (int16_t )textsize *
1198+ cursor_y += (int16_t )textsize_y *
11811199 (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
11821200 } else if (c != ' \r ' ) {
11831201 uint8_t first = pgm_read_byte (&gfxFont->first );
@@ -1187,14 +1205,14 @@ size_t Adafruit_GFX::write(uint8_t c) {
11871205 h = pgm_read_byte (&glyph->height );
11881206 if ((w > 0 ) && (h > 0 )) { // Is there an associated bitmap?
11891207 int16_t xo = (int8_t )pgm_read_byte (&glyph->xOffset ); // sic
1190- if (wrap && ((cursor_x + textsize * (xo + w)) > _width)) {
1208+ if (wrap && ((cursor_x + textsize_x * (xo + w)) > _width)) {
11911209 cursor_x = 0 ;
1192- cursor_y += (int16_t )textsize *
1210+ cursor_y += (int16_t )textsize_y *
11931211 (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
11941212 }
1195- drawChar (cursor_x, cursor_y, c, textcolor, textbgcolor, textsize );
1213+ drawChar (cursor_x, cursor_y, c, textcolor, textbgcolor, textsize_x, textsize_y );
11961214 }
1197- cursor_x += (uint8_t )pgm_read_byte (&glyph->xAdvance ) * (int16_t )textsize ;
1215+ cursor_x += (uint8_t )pgm_read_byte (&glyph->xAdvance ) * (int16_t )textsize_x ;
11981216 }
11991217 }
12001218
@@ -1209,7 +1227,19 @@ size_t Adafruit_GFX::write(uint8_t c) {
12091227*/
12101228/* *************************************************************************/
12111229void Adafruit_GFX::setTextSize (uint8_t s) {
1212- textsize = (s > 0 ) ? s : 1 ;
1230+ setTextSize (s, s);
1231+ }
1232+
1233+ /* *************************************************************************/
1234+ /* !
1235+ @brief Set text 'magnification' size. Each increase in s makes 1 pixel that much bigger.
1236+ @param s_x Desired text width magnification level in X-axis. 1 is default
1237+ @param s_y Desired text width magnification level in Y-axis. 1 is default
1238+ */
1239+ /* *************************************************************************/
1240+ void Adafruit_GFX::setTextSize (uint8_t s_x, uint8_t s_y) {
1241+ textsize_x = (s_x > 0 ) ? s_x : 1 ;
1242+ textsize_y = (s_y > 0 ) ? s_y : 1 ;
12131243}
12141244
12151245/* *************************************************************************/
@@ -1276,7 +1306,7 @@ void Adafruit_GFX::charBounds(char c, int16_t *x, int16_t *y,
12761306
12771307 if (c == ' \n ' ) { // Newline?
12781308 *x = 0 ; // Reset x to zero, advance y by one line
1279- *y += textsize * (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
1309+ *y += textsize_y * (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
12801310 } else if (c != ' \r ' ) { // Not a carriage return; is normal char
12811311 uint8_t first = pgm_read_byte (&gfxFont->first ),
12821312 last = pgm_read_byte (&gfxFont->last );
@@ -1287,41 +1317,42 @@ void Adafruit_GFX::charBounds(char c, int16_t *x, int16_t *y,
12871317 xa = pgm_read_byte (&glyph->xAdvance );
12881318 int8_t xo = pgm_read_byte (&glyph->xOffset ),
12891319 yo = pgm_read_byte (&glyph->yOffset );
1290- if (wrap && ((*x+(((int16_t )xo+gw)*textsize )) > _width)) {
1320+ if (wrap && ((*x+(((int16_t )xo+gw)*textsize_x )) > _width)) {
12911321 *x = 0 ; // Reset x to zero, advance y by one line
1292- *y += textsize * (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
1322+ *y += textsize_y * (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
12931323 }
1294- int16_t ts = (int16_t )textsize,
1295- x1 = *x + xo * ts,
1296- y1 = *y + yo * ts,
1297- x2 = x1 + gw * ts - 1 ,
1298- y2 = y1 + gh * ts - 1 ;
1324+ int16_t tsx = (int16_t )textsize_x,
1325+ tsy = (int16_t )textsize_y,
1326+ x1 = *x + xo * tsx,
1327+ y1 = *y + yo * tsy,
1328+ x2 = x1 + gw * tsx - 1 ,
1329+ y2 = y1 + gh * tsy - 1 ;
12991330 if (x1 < *minx) *minx = x1;
13001331 if (y1 < *miny) *miny = y1;
13011332 if (x2 > *maxx) *maxx = x2;
13021333 if (y2 > *maxy) *maxy = y2;
1303- *x += xa * ts ;
1334+ *x += xa * tsx ;
13041335 }
13051336 }
13061337
13071338 } else { // Default font
13081339
13091340 if (c == ' \n ' ) { // Newline?
13101341 *x = 0 ; // Reset x to zero,
1311- *y += textsize * 8 ; // advance y one line
1342+ *y += textsize_y * 8 ; // advance y one line
13121343 // min/max x/y unchaged -- that waits for next 'normal' character
13131344 } else if (c != ' \r ' ) { // Normal char; ignore carriage returns
1314- if (wrap && ((*x + textsize * 6 ) > _width)) { // Off right?
1345+ if (wrap && ((*x + textsize_x * 6 ) > _width)) { // Off right?
13151346 *x = 0 ; // Reset x to zero,
1316- *y += textsize * 8 ; // advance y one line
1347+ *y += textsize_y * 8 ; // advance y one line
13171348 }
1318- int x2 = *x + textsize * 6 - 1 , // Lower-right pixel of char
1319- y2 = *y + textsize * 8 - 1 ;
1349+ int x2 = *x + textsize_x * 6 - 1 , // Lower-right pixel of char
1350+ y2 = *y + textsize_y * 8 - 1 ;
13201351 if (x2 > *maxx) *maxx = x2; // Track max x, y
13211352 if (y2 > *maxy) *maxy = y2;
13221353 if (*x < *minx) *minx = *x; // Track min x, y
13231354 if (*y < *miny) *miny = *y;
1324- *x += textsize * 6 ; // Advance x one char
1355+ *x += textsize_x * 6 ; // Advance x one char
13251356 }
13261357 }
13271358}
@@ -1463,6 +1494,33 @@ void Adafruit_GFX_Button::initButton(
14631494 textcolor, label, textsize);
14641495}
14651496
1497+ /* *************************************************************************/
1498+ /* !
1499+ @brief Initialize button with our desired color/size/settings
1500+ @param gfx Pointer to our display so we can draw to it!
1501+ @param x The X coordinate of the center of the button
1502+ @param y The Y coordinate of the center of the button
1503+ @param w Width of the buttton
1504+ @param h Height of the buttton
1505+ @param outline Color of the outline (16-bit 5-6-5 standard)
1506+ @param fill Color of the button fill (16-bit 5-6-5 standard)
1507+ @param textcolor Color of the button label (16-bit 5-6-5 standard)
1508+ @param label Ascii string of the text inside the button
1509+ @param textsize_x The font magnification in X-axis of the label text
1510+ @param textsize_y The font magnification in Y-axis of the label text
1511+ */
1512+ /* *************************************************************************/
1513+ // Classic initButton() function: pass center & size
1514+ void Adafruit_GFX_Button::initButton (
1515+ Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h,
1516+ uint16_t outline, uint16_t fill, uint16_t textcolor,
1517+ char *label, uint8_t textsize_x, uint8_t textsize_y)
1518+ {
1519+ // Tweak arguments and pass to the newer initButtonUL() function...
1520+ initButtonUL (gfx, x - (w / 2 ), y - (h / 2 ), w, h, outline, fill,
1521+ textcolor, label, textsize_x, textsize_y);
1522+ }
1523+
14661524/* *************************************************************************/
14671525/* !
14681526 @brief Initialize button with our desired color/size/settings, with upper-left coordinates
@@ -1482,6 +1540,30 @@ void Adafruit_GFX_Button::initButtonUL(
14821540 Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
14831541 uint16_t outline, uint16_t fill, uint16_t textcolor,
14841542 char *label, uint8_t textsize)
1543+ {
1544+ initButtonUL (gfx, x1, y1, w, h, outline, fill, textcolor, label, textsize, textsize);
1545+ }
1546+
1547+ /* *************************************************************************/
1548+ /* !
1549+ @brief Initialize button with our desired color/size/settings, with upper-left coordinates
1550+ @param gfx Pointer to our display so we can draw to it!
1551+ @param x1 The X coordinate of the Upper-Left corner of the button
1552+ @param y1 The Y coordinate of the Upper-Left corner of the button
1553+ @param w Width of the buttton
1554+ @param h Height of the buttton
1555+ @param outline Color of the outline (16-bit 5-6-5 standard)
1556+ @param fill Color of the button fill (16-bit 5-6-5 standard)
1557+ @param textcolor Color of the button label (16-bit 5-6-5 standard)
1558+ @param label Ascii string of the text inside the button
1559+ @param textsize_x The font magnification in X-axis of the label text
1560+ @param textsize_y The font magnification in Y-axis of the label text
1561+ */
1562+ /* *************************************************************************/
1563+ void Adafruit_GFX_Button::initButtonUL (
1564+ Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
1565+ uint16_t outline, uint16_t fill, uint16_t textcolor,
1566+ char *label, uint8_t textsize_x, uint8_t textsize_y)
14851567{
14861568 _x1 = x1;
14871569 _y1 = y1;
@@ -1490,7 +1572,8 @@ void Adafruit_GFX_Button::initButtonUL(
14901572 _outlinecolor = outline;
14911573 _fillcolor = fill;
14921574 _textcolor = textcolor;
1493- _textsize = textsize;
1575+ _textsize_x = textsize_x;
1576+ _textsize_y = textsize_y;
14941577 _gfx = gfx;
14951578 strncpy (_label, label, 9 );
14961579}
@@ -1518,10 +1601,10 @@ void Adafruit_GFX_Button::drawButton(boolean inverted) {
15181601 _gfx->fillRoundRect (_x1, _y1, _w, _h, r, fill);
15191602 _gfx->drawRoundRect (_x1, _y1, _w, _h, r, outline);
15201603
1521- _gfx->setCursor (_x1 + (_w/2 ) - (strlen (_label) * 3 * _textsize ),
1522- _y1 + (_h/2 ) - (4 * _textsize ));
1604+ _gfx->setCursor (_x1 + (_w/2 ) - (strlen (_label) * 3 * _textsize_x ),
1605+ _y1 + (_h/2 ) - (4 * _textsize_y ));
15231606 _gfx->setTextColor (text);
1524- _gfx->setTextSize (_textsize );
1607+ _gfx->setTextSize (_textsize_x, _textsize_y );
15251608 _gfx->print (_label);
15261609}
15271610
0 commit comments