Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
GrFont.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file GrFont.h
3 * @brief Defines the base class used by all Graphical Fonts
4 ******************************************************************************/
5
6#ifndef GRFONT_DEFINED
7#define GRFONT_DEFINED
8
9#include <arduino.h>
10#include "Canvas.h"
11
18{
19 uint16_t x;
20 uint16_t y;
21 uint16_t width;
22 uint16_t height;
23 int16_t xoffset;
24 int16_t yoffset;
25 uint16_t xadvance;
26};
27
28/******************************************************************************/
29/*** ***/
30/*** Class Definition: GrFont ***/
31/*** ***/
32/******************************************************************************
33 * @brief Base class used by all Graphical Fonts
34 ******************************************************************************/
35class GrFont
36{
37public:
39
40 const uint16_t LINE_HEIGHT;
41 const uint16_t BASE;
42
43private:
44 ROM_Canvas _FontCanvas; // Canvas containing the font imagery
45
46 // Tracks whether this instance has been initialized via the begin(...) method.
47 bool _isInitialized = false;
48
49 // Private method for initializing the font with a 12-bit color. This encoding
50 // scheme uses bits 12:0 to encode RGB respectively.
51 void _begin12Bit(uint16_t color12Bit);
52
53public:
55 GrFont(void) = delete;
56
63 GrFont(ROM_Image imgLoc, uint16_t lineHeight, uint16_t base)
64 : imgLoc{imgLoc}, LINE_HEIGHT{lineHeight}, BASE{base}, _FontCanvas{imgLoc} {};
65
70 void begin(uint16_t color16Bit);
71
78 void begin(uint8_t red, uint8_t green, uint8_t blue);
79
86 virtual bool charDef(char cc, CharDef_t &results) const = 0;
87
94 inline int8_t kerning(uint8_t first, uint8_t second) const
95 {
96 uint16_t ID = (static_cast<uint16_t>(first) << 8) | second;
97 return kerning(ID);
98 };
99
108 uint8_t placeText(Canvas &canvas, char cc, uint16_t x, uint16_t y) const;
109
119 uint8_t placeText(Canvas &canvas, const char *const text, uint16_t buffSize, uint16_t x, uint16_t y) const;
120
126 uint16_t textWidth(const char cc) const;
127
134 uint16_t textWidth(const char *const text, uint16_t buffSize) const;
135
136protected:
142 virtual int8_t kerning(uint16_t ID) const = 0;
143};
144
145#endif
ROM_Image base
Definition ROM_Images.h:24
Definition Canvas.h:33
uint16_t textWidth(const char cc) const
Determines the with of character, cc, in screen pixels.
Definition GrFont.cpp:117
int8_t kerning(uint8_t first, uint8_t second) const
Finds the amount of kerning that should be used between two characters.
Definition GrFont.h:94
GrFont(ROM_Image imgLoc, uint16_t lineHeight, uint16_t base)
Constructs a new GrFont object.
Definition GrFont.h:63
virtual int8_t kerning(uint16_t ID) const =0
Finds the amount of kerning that should be used between two characters.
uint8_t placeText(Canvas &canvas, char cc, uint16_t x, uint16_t y) const
Places a character onto the canvas.
Definition GrFont.cpp:67
virtual bool charDef(char cc, CharDef_t &results) const =0
Abstract function, used to define the characteristics of each character.
const uint16_t LINE_HEIGHT
Recommended vertical spacing between lines of text.
Definition GrFont.h:40
const ROM_Image imgLoc
Location of the font in Flash ROM.
Definition GrFont.h:38
const uint16_t BASE
Definition GrFont.h:41
void begin(uint16_t color16Bit)
Initializes the font and sets the font's foreground color.
Definition GrFont.cpp:10
Definition Canvas.h:373
Data Structure that defines an individual character.
Definition GrFont.h:18
int16_t yoffset
Cursor y-offset that should be used when copying character to the screen.
Definition GrFont.h:24
uint16_t y
UL y-position of the character within the DRAM image.
Definition GrFont.h:20
uint16_t height
Height of the character in the DRAM image.
Definition GrFont.h:22
uint16_t width
Width of the character in the DRAM image.
Definition GrFont.h:21
int16_t xoffset
Cursor x-offset that should be used when copying character to the screen.
Definition GrFont.h:23
uint16_t xadvance
How far to advance the curso x-pos after this character.
Definition GrFont.h:25
uint16_t x
UL x-position of the character within the DRAM image.
Definition GrFont.h:19
Structure to define the size and location of an image in Flash.
Definition Common.h:44