MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
Text.h
Go to the documentation of this file.
1// Copyright 2020 Andreas Burnickl
2// SPDX-License-Identifier: GPL-3.0-or-later
3
11
12#ifndef MAXMATRIX_SRC_TEXT_TEXT_H_
13#define MAXMATRIX_SRC_TEXT_TEXT_H_
14
15#include "Arduino.h"
16#include "Font/Font.h"
17#include "Matrix/Panel.h"
18#include "MaxMatrixAttributes.h"
19#include "MaxMatrixConfig.h"
20#include "Utility/span.h"
21
22namespace max_matrix {
23namespace internal {
24
33class Text {
34 private:
35 /*
36 * Every function that draws is given the panel rather than the class keeping
37 * a reference to it. A reference costs two bytes of RAM, and avr-gcc no
38 * longer sees through it that the panel is the one inside the global
39 * Matrix of the sketch: ScrollText was 86 bytes of flash larger with it.
40 */
41
42 /*
43 * The columns of a char shifted in so far, its space included: kShiftIdle
44 * while no char is shifting, and kShiftStart when one begins. A count rather
45 * than a state, so the two values are constants, not an enum.
46 */
47 static constexpr uint16_t kShiftIdle{0};
48 static constexpr uint16_t kShiftStart{1};
49
50 /*
51 * The font every char is drawn in, empty for kDefaultFont: only a
52 * function that draws a char names the default font then, and a sketch that
53 * draws none does not link its 614 bytes, as Animation and Sprites did with
54 * the default font set here. And the char that shifts in, which lies in the
55 * font.
56 */
58 Glyph glyph_{};
59 /* 16 bits, as a char and its space take up to 255 + 255 columns */
60 uint16_t sprite_shift_counter_{kShiftIdle};
61 uint8_t space_between_chars_{MAXMATRIX_SPACE_BETWEEN_CHARS_INIT_VALUE};
62 /* the text that shifts in, the position of its next char, and whether it
63 * starts over after its last char */
64 span<char const> text_;
65 size_t position_{0};
66 bool repeat_{false};
67
68 void ReadNextChar();
69 static span<uint8_t const> DefaultFont();
70
71 public:
74
77 return space_between_chars_;
78 }
79
82 return font_.size() != 0 ? font_ : DefaultFont();
83 }
84
95
108 MAXMATRIX_NODISCARD Status SetChar(Panel& panel, int16_t x, int16_t y,
109 char c) const;
110
120
132
147 bool repeat);
148
154 void SetSpaceBetweenChars(uint8_t space_between_chars);
155
166 static void SetSprite(Panel& panel, int16_t x, int16_t y,
167 Sprite const& sprite);
168
179 static void SetGlyph(Panel& panel, int16_t x, int16_t y, Glyph const& glyph);
180
190 bool CharShiftTask(Panel& panel);
191
200 bool StringShiftTask(Panel& panel);
201};
202
203} // namespace internal
204} // namespace max_matrix
205
206#endif // MAXMATRIX_SRC_TEXT_TEXT_H_
The font of the MaxMatrix library.
The attributes of a later standard, as macros, where the compiler has them.
#define MAXMATRIX_NODISCARD
Marks a function whose result must not be dropped: the compiler warns where it is.
Definition MaxMatrixAttributes.h:37
Configuration of the MaxMatrix library.
#define MAXMATRIX_SPACE_BETWEEN_CHARS_INIT_VALUE
The empty columns between two chars of a text, until Matrix::SetSpaceBetweenChars().
Definition MaxMatrixConfig.h:47
The matrix as the viewer sees it.
What a function that can fail returns when it has no value to return.
Definition MaxMatrixError.h:73
The matrix as the viewer sees it: columns, rows and dots in the viewer's coordinates.
Definition Panel.h:94
MAXMATRIX_NODISCARD Status SetCharWithShift(char c)
Starts shifting a char in from the right, until it stands at the right edge.
MAXMATRIX_NODISCARD uint8_t GetSpaceBetweenChars() const
Returns the empty columns between two chars of a text.
Definition Text.h:76
MAXMATRIX_NODISCARD Status SetTextWithShift(span< char const > text, bool repeat)
Starts shifting a text in from the right, until its last char stands at the right edge,...
MAXMATRIX_NODISCARD Status SetChar(Panel &panel, int16_t x, int16_t y, char c) const
Draws a char with its top left corner at x, y.
MAXMATRIX_NODISCARD Status SetText(Panel &panel, span< char const > text) const
Draws a text from the left edge, as far as it fits.
static void SetSprite(Panel &panel, int16_t x, int16_t y, Sprite const &sprite)
Draws a sprite with its top left corner at x, y.
MAXMATRIX_NODISCARD span< uint8_t const > GetFont() const
Returns the font every char is drawn in.
Definition Text.h:81
Text()
Makes a text with nothing to shift.
MAXMATRIX_NODISCARD Status SetFont(span< uint8_t const > font)
Sets the font every char is drawn in from now on.
bool CharShiftTask(Panel &panel)
Shifts the char one column further.
void SetSpaceBetweenChars(uint8_t space_between_chars)
Sets the empty columns between two chars of a text.
static void SetGlyph(Panel &panel, int16_t x, int16_t y, Glyph const &glyph)
Draws a glyph of a font with its top left corner at x, y.
bool StringShiftTask(Panel &panel)
Shifts the text one column further.
A view of size() elements that another owns: a font, a bitmap, a text or a buffer.
Definition span.h:64
MAXMATRIX_NODISCARD constexpr size_type size() const
Returns the number of elements.
Definition span.h:126
Elements that lie elsewhere, reached by index within their size, as std::span.
A char of a font, as it lies in flash: where its columns are, and how many.
Definition Font.h:48
A sprite of your own: its width, its height and up to five columns.
Definition Font.h:38