Skip to content

Commit d188fcc

Browse files
committed
Change endText(...) to accept scroll direction
1 parent 1d4237e commit d188fcc

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

keywords.txt

+6
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ ENCODING_NONE LITERAL1
6464
ENCODING_RGB LITERAL1
6565
ENCODING_RGB24 LITERAL1
6666
ENCODING_RGB16 LITERAL1
67+
68+
NO_SCROLL LITERAL1
69+
SCROLL_LEFT LITERAL1
70+
SCROLL_RIGHT LITERAL1
71+
SCROLL_UP LITERAL1
72+
SCROLL_DOWN LITERAL1

src/ArduinoGraphics.cpp

+32-9
Original file line numberDiff line numberDiff line change
@@ -373,32 +373,55 @@ void ArduinoGraphics::beginText(int x, int y, uint32_t color)
373373
beginText(x, y, COLOR_R(color), COLOR_G(color), COLOR_B(color));
374374
}
375375

376-
void ArduinoGraphics::endText(bool scroll)
376+
void ArduinoGraphics::endText(int scrollDirection)
377377
{
378378
// backup the stroke color and set the color to the text color
379379
bool strokeOn = _stroke;
380380
uint8_t strokeR = _strokeR;
381381
uint8_t strokeG = _strokeG;
382382
uint8_t strokeB = _strokeB;
383383

384-
Serial.println(_textBuffer);
385-
Serial.println(_textX);
386-
Serial.println(_textY);
387-
Serial.println(_textR);
388-
Serial.println(_textG);
389-
Serial.println(_textB);
390-
391384

392385
stroke(_textR, _textG, _textB);
393386

394-
if (scroll) {
387+
if (scrollDirection == SCROLL_LEFT) {
395388
int scrollLength = _textBuffer.length() * textFontWidth() + _textX;
396389

397390
for (int i = 0; i < scrollLength; i++) {
398391
beginDraw();
399392
text(_textBuffer, _textX - i, _textY);
400393
endDraw();
401394

395+
delay(_textScrollSpeed);
396+
}
397+
} else if (scrollDirection == SCROLL_RIGHT) {
398+
int scrollLength = _textBuffer.length() * textFontWidth() + _textX;
399+
400+
for (int i = 0; i < scrollLength; i++) {
401+
beginDraw();
402+
text(_textBuffer, _textX - (scrollLength - i - 1), _textY);
403+
endDraw();
404+
405+
delay(_textScrollSpeed);
406+
}
407+
} else if (scrollDirection == SCROLL_UP) {
408+
int scrollLength = textFontHeight() + _textY;
409+
410+
for (int i = 0; i < scrollLength; i++) {
411+
beginDraw();
412+
text(_textBuffer, _textX, _textY - i);
413+
endDraw();
414+
415+
delay(_textScrollSpeed);
416+
}
417+
} else if (scrollDirection == SCROLL_DOWN) {
418+
int scrollLength = textFontHeight() + _textY;
419+
420+
for (int i = 0; i < scrollLength; i++) {
421+
beginDraw();
422+
text(_textBuffer, _textX, _textY - (scrollLength - i - 1));
423+
endDraw();
424+
402425
delay(_textScrollSpeed);
403426
}
404427
} else {

src/ArduinoGraphics.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
#include "Font.h"
2626
#include "Image.h"
2727

28+
enum {
29+
NO_SCROLL,
30+
SCROLL_LEFT,
31+
SCROLL_RIGHT,
32+
SCROLL_UP,
33+
SCROLL_DOWN
34+
};
35+
2836
class ArduinoGraphics : public Print {
2937
public:
3038
ArduinoGraphics(int width, int height);
@@ -77,7 +85,7 @@ class ArduinoGraphics : public Print {
7785
virtual void beginText(int x = 0, int y = 0);
7886
virtual void beginText(int x, int y, uint8_t r, uint8_t g, uint8_t b);
7987
virtual void beginText(int x, int y, uint32_t color);
80-
virtual void endText(bool scroll = false);
88+
virtual void endText(int scroll = NO_SCROLL);
8189
virtual void textScrollSpeed(unsigned long speed = 150);
8290

8391
protected:

0 commit comments

Comments
 (0)