Skip to content

Commit 362d498

Browse files
committed
Code Review requested changes
_textsize_x -> _textSizeX (ditto for y) setTextSize() -> textSize() scaledBitmap -> bitmap with the extra parameters with defaults
1 parent 6d1e09e commit 362d498

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

src/ArduinoGraphics.cpp

+16-22
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ ArduinoGraphics::ArduinoGraphics(int width, int height) :
2727
_width(width),
2828
_height(height),
2929
_font(NULL),
30-
_textsize_x(1),
31-
_textsize_y(1)
30+
_textSizeX(1),
31+
_textSizeY(1)
3232
{
3333
}
3434

@@ -243,7 +243,7 @@ void ArduinoGraphics::text(const char* str, int x, int y)
243243
uint8_t const c = (uint8_t)*str++;
244244

245245
if (c == '\n') {
246-
y += _font->height * _textsize_y;
246+
y += _font->height * _textSizeY;
247247
} else if (c == '\r') {
248248
x = 0;
249249
} else if (c == 0xc2 || c == 0xc3) {
@@ -256,10 +256,10 @@ void ArduinoGraphics::text(const char* str, int x, int y)
256256
}
257257

258258
if (b) {
259-
scaledBitmap(b, x, y, _font->width, _font->height, _textsize_x, _textsize_y);
259+
bitmap(b, x, y, _font->width, _font->height, _textSizeX, _textSizeY);
260260
}
261261

262-
x += _font->width * _textsize_x;
262+
x += _font->width * _textSizeX;
263263
}
264264
}
265265
}
@@ -271,28 +271,22 @@ void ArduinoGraphics::textFont(const Font& which)
271271

272272
int ArduinoGraphics::textFontWidth() const
273273
{
274-
return (_font ? _font->width * _textsize_x : 0);
274+
return (_font ? _font->width * _textSizeX : 0);
275275
}
276276

277277
int ArduinoGraphics::textFontHeight() const
278278
{
279-
return (_font ? _font->height* _textsize_y : 0);
279+
return (_font ? _font->height* _textSizeY : 0);
280280
}
281281

282-
void ArduinoGraphics::setTextSize(uint8_t sx, uint8_t sy)
282+
void ArduinoGraphics::textSize(uint8_t sx, uint8_t sy)
283283
{
284-
_textsize_x = (sx > 0)? sx : 1;
285-
_textsize_y = (sy > 0)? sy : 1;
284+
_textSizeX = (sx > 0)? sx : 1;
285+
_textSizeY = (sy > 0)? sy : 1;
286286
}
287287

288288

289-
void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int width, int height)
290-
{
291-
// forward to scaled version
292-
scaledBitmap(data, x, y, width, height, 1, 1);
293-
}
294-
295-
void ArduinoGraphics::scaledBitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) {
289+
void ArduinoGraphics::bitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) {
296290
if (!_stroke || !scale_x || !scale_y) {
297291
return;
298292
}
@@ -380,7 +374,7 @@ void ArduinoGraphics::image(const Image& img, int x, int y)
380374

381375
void ArduinoGraphics::image(const Image& img, int x, int y, int width, int height)
382376
{
383-
if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > height)) {
377+
if (!img || ((x + width) < 0) || ((y + height) < 0) || (x > _width) || (y > _height)) {
384378
// offscreen
385379
return;
386380
}
@@ -459,7 +453,7 @@ void ArduinoGraphics::endText(int scrollDirection)
459453
beginDraw();
460454
int const text_x = _textX - i;
461455
text(_textBuffer, text_x, _textY);
462-
scaledBitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textsize_x, _textsize_y);
456+
bitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textSizeX, _textSizeY);
463457
endDraw();
464458

465459
delay(_textScrollSpeed);
@@ -471,7 +465,7 @@ void ArduinoGraphics::endText(int scrollDirection)
471465
beginDraw();
472466
int const text_x = _textX - (scrollLength - i - 1);
473467
text(_textBuffer, text_x, _textY);
474-
scaledBitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textsize_x, _textsize_y);
468+
bitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textSizeX, _textSizeY);
475469
endDraw();
476470

477471
delay(_textScrollSpeed);
@@ -483,7 +477,7 @@ void ArduinoGraphics::endText(int scrollDirection)
483477
beginDraw();
484478
int const text_y = _textY - i;
485479
text(_textBuffer, _textX, text_y);
486-
scaledBitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textsize_x, _textsize_y);
480+
bitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textSizeX, _textSizeY);
487481
endDraw();
488482

489483
delay(_textScrollSpeed);
@@ -495,7 +489,7 @@ void ArduinoGraphics::endText(int scrollDirection)
495489
beginDraw();
496490
int const text_y = _textY - (scrollLength - i - 1);
497491
text(_textBuffer, _textX, text_y);
498-
scaledBitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textsize_x, _textsize_y);
492+
bitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textSizeX, _textSizeY);
499493
endDraw();
500494

501495
delay(_textScrollSpeed);

src/ArduinoGraphics.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class ArduinoGraphics : public Print {
7070
virtual void text(const char* str, int x = 0, int y = 0);
7171
virtual void text(const String& str, int x = 0, int y = 0) { text(str.c_str(), x, y); }
7272
virtual void textFont(const Font& which);
73-
virtual void setTextSize(uint8_t s) {setTextSize(s, s);}
74-
virtual void setTextSize(uint8_t sx, uint8_t sy);
73+
virtual void textSize(uint8_t s) {textSize(s, s);}
74+
virtual void textSize(uint8_t sx, uint8_t sy);
7575

7676
virtual int textFontWidth() const;
7777
virtual int textFontHeight() const;
@@ -93,9 +93,8 @@ class ArduinoGraphics : public Print {
9393
virtual void textScrollSpeed(unsigned long speed = 150);
9494

9595
protected:
96-
virtual void bitmap(const uint8_t* data, int x, int y, int width, int height);
97-
virtual void scaledBitmap(const uint8_t* data, int x, int y, int width, int height,
98-
uint8_t scale_x, uint8_t);
96+
virtual void bitmap(const uint8_t* data, int x, int y, int w, int h, uint8_t scale_x = 1,
97+
uint8_t scale_y = 1);
9998
virtual void imageRGB(const Image& img, int x, int y, int width, int height);
10099
virtual void imageRGB24(const Image& img, int x, int y, int width, int height);
101100
virtual void imageRGB16(const Image& img, int x, int y, int width, int height);
@@ -118,8 +117,8 @@ class ArduinoGraphics : public Print {
118117
uint8_t _textR, _textG, _textB;
119118
int _textX;
120119
int _textY;
121-
uint8_t _textsize_x;
122-
uint8_t _textsize_y;
120+
uint8_t _textSizeX;
121+
uint8_t _textSizeY;
123122
unsigned long _textScrollSpeed;
124123
};
125124

0 commit comments

Comments
 (0)