Skip to content

Commit 44568a8

Browse files
committed
Merge branch 'master' of github.com:adafruit/Adafruit-GFX-Library
Conflicts: Adafruit_GFX.cpp
2 parents de513d7 + b8f2200 commit 44568a8

File tree

3 files changed

+64
-57
lines changed

3 files changed

+64
-57
lines changed

Adafruit_GFX.cpp

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -970,68 +970,70 @@ void Adafruit_GFX::invertDisplay(boolean i) {
970970
// code for the GFX button UI element
971971

972972
Adafruit_GFX_Button::Adafruit_GFX_Button(void) {
973-
_gfx = 0;
974-
laststate = 0;
975-
_fillcolor = 0;
976-
_textsize = 1;
977-
_w = 0;
978-
_x = 0;
979-
currstate = 0;
980-
_textcolor = 0;
981-
_outlinecolor = 0;
982-
_h = 0;
983-
_y = 0;
973+
_gfx = 0;
984974
}
985975

976+
// Classic initButton() function: pass center & size
986977
void Adafruit_GFX_Button::initButton(
987-
Adafruit_GFX *gfx, int16_t x, int16_t y, uint8_t w, uint8_t h,
988-
uint16_t outline, uint16_t fill, uint16_t textcolor,
989-
char *label, uint8_t textsize)
978+
Adafruit_GFX *gfx, int16_t x, int16_t y, uint16_t w, uint16_t h,
979+
uint16_t outline, uint16_t fill, uint16_t textcolor,
980+
char *label, uint8_t textsize)
990981
{
991-
_x = x;
992-
_y = y;
993-
_w = w;
994-
_h = h;
995-
_outlinecolor = outline;
996-
_fillcolor = fill;
997-
_textcolor = textcolor;
998-
_textsize = textsize;
999-
_gfx = gfx;
1000-
strncpy(_label, label, 9);
1001-
_label[9] = 0;
982+
// Tweak arguments and pass to the newer initButtonUL() function...
983+
initButtonUL(gfx, x - (w / 2), y - (h / 2), w, h, outline, fill,
984+
textcolor, label, textsize);
1002985
}
1003986

1004-
void Adafruit_GFX_Button::drawButton(boolean inverted) {
1005-
uint16_t fill, outline, text;
1006-
1007-
if(!inverted) {
1008-
fill = _fillcolor;
1009-
outline = _outlinecolor;
1010-
text = _textcolor;
1011-
} else {
1012-
fill = _textcolor;
1013-
outline = _outlinecolor;
1014-
text = _fillcolor;
1015-
}
1016-
1017-
_gfx->fillRoundRect(_x - (_w/2), _y - (_h/2), _w, _h, min(_w,_h)/4, fill);
1018-
_gfx->drawRoundRect(_x - (_w/2), _y - (_h/2), _w, _h, min(_w,_h)/4, outline);
987+
// Newer function instead accepts upper-left corner & size
988+
void Adafruit_GFX_Button::initButtonUL(
989+
Adafruit_GFX *gfx, int16_t x1, int16_t y1, uint16_t w, uint16_t h,
990+
uint16_t outline, uint16_t fill, uint16_t textcolor,
991+
char *label, uint8_t textsize)
992+
{
993+
_x1 = x1;
994+
_y1 = y1;
995+
_w = w;
996+
_h = h;
997+
_outlinecolor = outline;
998+
_fillcolor = fill;
999+
_textcolor = textcolor;
1000+
_textsize = textsize;
1001+
_gfx = gfx;
1002+
strncpy(_label, label, 9);
1003+
}
10191004

1020-
_gfx->setCursor(_x - strlen(_label)*3*_textsize, _y-4*_textsize);
1021-
_gfx->setTextColor(text);
1022-
_gfx->setTextSize(_textsize);
1023-
_gfx->print(_label);
1005+
void Adafruit_GFX_Button::drawButton(boolean inverted) {
1006+
uint16_t fill, outline, text;
1007+
1008+
if(!inverted) {
1009+
fill = _fillcolor;
1010+
outline = _outlinecolor;
1011+
text = _textcolor;
1012+
} else {
1013+
fill = _textcolor;
1014+
outline = _outlinecolor;
1015+
text = _fillcolor;
1016+
}
1017+
1018+
uint8_t r = min(_w, _h) / 4; // Corner radius
1019+
_gfx->fillRoundRect(_x1, _y1, _w, _h, r, fill);
1020+
_gfx->drawRoundRect(_x1, _y1, _w, _h, r, outline);
1021+
1022+
_gfx->setCursor(_x1 + (_w/2) - (strlen(_label) * 3 * _textsize),
1023+
_y1 + (_h/2) - (4 * _textsize));
1024+
_gfx->setTextColor(text);
1025+
_gfx->setTextSize(_textsize);
1026+
_gfx->print(_label);
10241027
}
10251028

10261029
boolean Adafruit_GFX_Button::contains(int16_t x, int16_t y) {
1027-
if ((x < (_x - _w/2)) || (x > (_x + _w/2))) return false;
1028-
if ((y < (_y - _h/2)) || (y > (_y + _h/2))) return false;
1029-
return true;
1030+
return ((x >= _x1) && (x < (_x1 + _w)) &&
1031+
(y >= _y1) && (y < (_y1 + _h)));
10301032
}
10311033

10321034
void Adafruit_GFX_Button::press(boolean p) {
1033-
laststate = currstate;
1034-
currstate = p;
1035+
laststate = currstate;
1036+
currstate = p;
10351037
}
10361038

10371039
boolean Adafruit_GFX_Button::isPressed() { return currstate; }
@@ -1050,7 +1052,7 @@ boolean Adafruit_GFX_Button::justReleased() { return (!currstate && laststate);
10501052
// the buffer is in MCU memory and not the display driver...GXFcanvas1 might
10511053
// be minimally useful on an Uno-class board, but this and GFXcanvas16 are
10521054
// much more likely to require at least a Mega or various recent ARM-type
1053-
// boards (recomment, as the text+bitmap draw can be pokey). GFXcanvas1
1055+
// boards (recommended, as the text+bitmap draw can be pokey). GFXcanvas1
10541056
// requires 1 bit per pixel (rounded up to nearest byte per scanline),
10551057
// GFXcanvas16 requires 2 bytes per pixel (no scanline pad).
10561058
// NOT EXTENSIVELY TESTED YET. MAY CONTAIN WORST BUGS KNOWN TO HUMANKIND.

Adafruit_GFX.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,13 @@ class Adafruit_GFX_Button {
125125

126126
public:
127127
Adafruit_GFX_Button(void);
128+
// "Classic" initButton() uses center & size
128129
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
129-
uint8_t w, uint8_t h, uint16_t outline, uint16_t fill,
130+
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
131+
uint16_t textcolor, char *label, uint8_t textsize);
132+
// New/alt initButton() uses upper-left corner & size
133+
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1,
134+
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
130135
uint16_t textcolor, char *label, uint8_t textsize);
131136
void drawButton(boolean inverted = false);
132137
boolean contains(int16_t x, int16_t y);
@@ -138,11 +143,11 @@ class Adafruit_GFX_Button {
138143

139144
private:
140145
Adafruit_GFX *_gfx;
141-
int16_t _x, _y;
142-
uint16_t _w, _h;
143-
uint8_t _textsize;
144-
uint16_t _outlinecolor, _fillcolor, _textcolor;
145-
char _label[10];
146+
int16_t _x1, _y1; // Coordinates of top-left corner
147+
uint16_t _w, _h;
148+
uint8_t _textsize;
149+
uint16_t _outlinecolor, _fillcolor, _textcolor;
150+
char _label[10];
146151

147152
boolean currstate, laststate;
148153
};

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit GFX Library
2-
version=1.1.5
2+
version=1.1.6
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.

0 commit comments

Comments
 (0)