Skip to content

Commit 83d6df0

Browse files
committed
Clear trail for full string width when scrolling text vertically
The `endText` function has the capability to scroll the printed text. In order to ensure artifacts are not left behind on the display while scrolling, the library must clear the pixels at the previous location of the text after each frame of the scrolling animation. Previously, the code to handle this clearing for vertical scrolling only cleared a single character's width. This meant that scroll trail clearing was only done for the first character in the string. This bug might not be immediately apparent to the user because many character bitmaps do not populate any pixels on the top or bottom row of the grid, and thus those characters provide incidental self scroll trail clearing. However, this is not the case for all characters and those would cause a trail of artifacts to be left behind on the display when scrolled. The vertical scroll trail clearing code is hereby corrected to cover the full width of the string. Previously the `ArduinoGraphics::bitmap` function was used by the clearing code. That approach was reasonable for clearing the scroll trail of a single character, but due to the function's eight pixel width limitation, it is not suitable to use with strings. In this application where a line of arbitrary length, but only one pixel thick is needed, the `ArduinoGraphics::line` function is the suitable tool. So the code is ported to using `ArduinoGraphics::line`. NOTE: The calculations of the length of the clearing line will still be incorrect for multi-line strings. However, this is not a regression because it was also incorrect before this change. The scroll trail clearing code has never had any provisions for handling multi-line strings so adding such support is out of scope for this commit. In addition, the text scrolling code (not the scroll trail clearing code) has never correctly handled horizontal scrolling of multi-line strings, so until that is fixed it is only the lack of correct scroll trail clearing for vertical scrolling that is impactful to users.
1 parent ce5ac8e commit 83d6df0

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

.codespellrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See: https://github.com/codespell-project/codespell#using-a-config-file
22
[codespell]
33
# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here:
4-
ignore-words-list = mis
4+
ignore-words-list = cleary,mis
55
check-filenames =
66
check-hidden =
77
skip = ./.git

src/ArduinoGraphics.cpp

+34-5
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,21 @@ void ArduinoGraphics::endText(int scrollDirection)
448448
uint8_t strokeG = _strokeG;
449449
uint8_t strokeB = _strokeB;
450450

451-
452-
stroke(_textR, _textG, _textB);
453-
454451
if (scrollDirection == SCROLL_LEFT) {
455452
int scrollLength = _textBuffer.length() * textFontWidth() + _textX;
456453

457454
for (int i = 0; i < scrollLength; i++) {
458455
beginDraw();
456+
459457
int const text_x = _textX - i;
458+
stroke(_textR, _textG, _textB);
460459
text(_textBuffer, text_x, _textY);
461-
bitmap(_font->data[0x20], text_x + _textBuffer.length() * _font->width, _textY, 1, _font->height, _textSizeX, _textSizeY);
460+
461+
// clear previous position
462+
const int clearX = text_x + _textBuffer.length() * _font->width;
463+
stroke(_backgroundR, _backgroundG, _backgroundB);
464+
line(clearX, _textY, clearX, _textY + _font->height - 1);
465+
462466
endDraw();
463467

464468
delay(_textScrollSpeed);
@@ -468,9 +472,18 @@ void ArduinoGraphics::endText(int scrollDirection)
468472

469473
for (int i = 0; i < scrollLength; i++) {
470474
beginDraw();
475+
471476
int const text_x = _textX - (scrollLength - i - 1);
477+
stroke(_textR, _textG, _textB);
472478
text(_textBuffer, text_x, _textY);
479+
480+
// clear previous position
481+
const int clearX = text_x - 1;
482+
stroke(_backgroundR, _backgroundG, _backgroundB);
483+
line(clearX, _textY, clearX, _textY + _font->height - 1);
484+
473485
bitmap(_font->data[0x20], text_x - 1, _textY, 1, _font->height, _textSizeX, _textSizeY);
486+
474487
endDraw();
475488

476489
delay(_textScrollSpeed);
@@ -480,9 +493,16 @@ void ArduinoGraphics::endText(int scrollDirection)
480493

481494
for (int i = 0; i < scrollLength; i++) {
482495
beginDraw();
496+
483497
int const text_y = _textY - i;
498+
stroke(_textR, _textG, _textB);
484499
text(_textBuffer, _textX, text_y);
485-
bitmap(_font->data[0x20], _textX, text_y + _font->height, _font->width, 1, _textSizeX, _textSizeY);
500+
501+
// clear previous position
502+
const int clearY = text_y + _font->height;
503+
stroke(_backgroundR, _backgroundG, _backgroundB);
504+
line(_textX, clearY, _textX + (_font->width * _textBuffer.length()) - 1, clearY);
505+
486506
endDraw();
487507

488508
delay(_textScrollSpeed);
@@ -492,15 +512,24 @@ void ArduinoGraphics::endText(int scrollDirection)
492512

493513
for (int i = 0; i < scrollLength; i++) {
494514
beginDraw();
515+
495516
int const text_y = _textY - (scrollLength - i - 1);
517+
stroke(_textR, _textG, _textB);
496518
text(_textBuffer, _textX, text_y);
519+
520+
// clear previous position
521+
const int clearY = text_y - 1;
522+
stroke(_backgroundR, _backgroundG, _backgroundB);
523+
line(_textX, clearY, _textX + (_font->width * _textBuffer.length()) - 1, clearY);
524+
497525
bitmap(_font->data[0x20], _textX, text_y - 1, _font->width, 1, _textSizeX, _textSizeY);
498526
endDraw();
499527

500528
delay(_textScrollSpeed);
501529
}
502530
} else {
503531
beginDraw();
532+
stroke(_textR, _textG, _textB);
504533
text(_textBuffer, _textX, _textY);
505534
endDraw();
506535
}

0 commit comments

Comments
 (0)