aboutsummaryrefslogtreecommitdiff
path: root/main/DisplayText.cpp
blob: ceeed86ebc4167e8ccce2536987f6ac001b9ccad (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "DisplayText.h"

#include "InovaLedDisplay.h"


DisplayText::DisplayText(std::string text, int16_t y, uint16_t color, int16_t alignment) {
    this->text = text;
    this->width = text.length() * 6;
    this->scroll = (this->width > NUM_COL);
    this->y = y;
    this->color = color;

    if(!scroll) {
        // we only use alignment if we don't have to scroll

        if(alignment < 0) {
            this->x = 0;
        }

        else if(alignment == 0) {
            this->x = (NUM_COL - this->width) / 2;
        }

        else if(alignment > 0) {
            this->x = (NUM_COL - this->width);
        }
    }
    else {
        this->x = NUM_COL;
    }
}


const char* DisplayText::getText() {
    return text.c_str();
}


int16_t DisplayText::getX() {
    return x;
}


int16_t DisplayText::getY() {
    return y;
}


uint16_t DisplayText::getColor() {
    return color;
}


void DisplayText::step() {
    if(scroll) {
        x--;

        if(x < -width) {
            x = NUM_COL;
        }
    }
}