-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollingLine.cpp
More file actions
46 lines (38 loc) · 1.37 KB
/
ScrollingLine.cpp
File metadata and controls
46 lines (38 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "ScrollingLine.h"
ScrollingLine::ScrollingLine(TFT_eSPI* tft, int32_t lineY, uint16_t textColor, uint16_t bgColor, uint8_t textSize)
: lineSprite(tft), cursorX(0), lineY(lineY), textColor(textColor), bgColor(bgColor), textSize(textSize), scrollSpeed(textSize) {
lineSprite.setColorDepth(8);
lineSprite.createSprite(160, textSize * 8);
lineSprite.fillSprite(bgColor);
lineSprite.setTextColor(textColor, bgColor);
lineSprite.setTextSize(textSize);
lineSprite.setTextWrap(false);
}
void ScrollingLine::setText(String newText) {
text = newText;
textWidth = lineSprite.textWidth(text);
int16_t horizontalMargin = lineSprite.width() - textWidth;
cursorX = horizontalMargin > 0 ? horizontalMargin / 2 : 0;
scrollSpeed = horizontalMargin > 0 ? 0 : textSize;
}
void ScrollingLine::setBgColor(uint16_t newBgColor) {
bgColor = newBgColor;
lineSprite.setTextColor(textColor, newBgColor);
}
void ScrollingLine::setTextColor(uint16_t newTextColor) {
textColor = newTextColor;
lineSprite.setTextColor(newTextColor, bgColor);
}
void ScrollingLine::scrollText() {
lineSprite.fillSprite(bgColor);
lineSprite.setCursor(cursorX, 0);
lineSprite.print(text);
lineSprite.pushSprite(0, lineY);
cursorX -= scrollSpeed;
if (cursorX <= -textWidth) {
cursorX = lineSprite.width();
}
}
int ScrollingLine::getBottomY() {
return lineY + lineSprite.height();
}