Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
GrFont.h
Go to the documentation of this file.
1/******************************************************************************/
7
8#ifndef GRFONT_DEFINED
9#define GRFONT_DEFINED
10
11#include "Canvas.h"
12
19{
20 uint16_t x;
21 uint16_t y;
22 uint16_t width;
23 uint16_t height;
24 int16_t xoffset;
25 int16_t yoffset;
26 uint16_t xadvance;
27};
28
35uint16_t rgb16to12(uint16_t color16Bit);
36
37/******************************************************************************/
38/*** ***/
39/*** Class Definition: GrFont ***/
40/*** ***/
41/******************************************************************************/
45class GrFont
46{
47public:
49
50 const uint16_t LINE_HEIGHT;
51 const uint16_t BASE;
52
53private:
54 ROM_Canvas _FontCanvas; // Canvas containing the font imagery
55
56 // Tracks whether this instance has been initialized via the begin(...) method.
57 bool _isInitialized = false;
58
59 // Private method for initializing the font with a 12-bit color. This encoding
60 // scheme uses bits 11:0 to encode RGB respectively.
61 void _begin12Bit(uint16_t color12Bit);
62
63public:
65 GrFont(void) = delete;
66
73 GrFont(ROM_Image imgLoc, uint16_t lineHeight, uint16_t base)
74 : imgLoc{imgLoc}, LINE_HEIGHT{lineHeight}, BASE{base}, _FontCanvas{imgLoc} {};
75
81 void begin(uint16_t color16Bit);
82
90 void begin(uint8_t red, uint8_t green, uint8_t blue);
91
99 virtual bool charDef(char cc, CharDef_t &results) const = 0;
100
108 inline int8_t kerning(uint8_t first, uint8_t second) const
109 {
110 uint16_t ID = (static_cast<uint16_t>(first) << 8) | second;
111 return kerning(ID);
112 };
113
123 uint8_t placeText(Canvas &canvas, char cc, uint16_t x, uint16_t y) const;
124
135 uint8_t placeText(Canvas &canvas, const char *const text, uint16_t buffSize, uint16_t x, uint16_t y) const;
136
143 uint16_t textWidth(const char cc) const;
144
152 uint16_t textWidth(const char *const text, uint16_t buffSize) const;
153
154protected:
161 virtual int8_t kerning(uint16_t ID) const = 0;
162};
163
164#endif
Defines higher level TFT graphics functionality.
uint16_t rgb16to12(uint16_t color16Bit)
Function for converting 16-bit colors into the 12-bit color used by the TFT.
Definition GrFont.cpp:16
ROM_Image base
Definition ROM_Images.h:46
Provides higher level TFT graphic functionality used by the menu system.
Definition Canvas.h:34
uint16_t textWidth(const char cc) const
Determines the width of character, cc, in screen pixels.
Definition GrFont.cpp:143
int8_t kerning(uint8_t first, uint8_t second) const
Returns the amount of kerning that should be used between two characters.
Definition GrFont.h:108
GrFont(ROM_Image imgLoc, uint16_t lineHeight, uint16_t base)
Constructs a new GrFont object.
Definition GrFont.h:73
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:80
virtual bool charDef(char cc, CharDef_t &results) const =0
Abstract function. Used by derived classes to define the characteristics of each character.
const uint16_t LINE_HEIGHT
Recommended vertical spacing between lines of text.
Definition GrFont.h:50
const ROM_Image imgLoc
Location of the font in Flash ROM.
Definition GrFont.h:48
const uint16_t BASE
Distance between the top of the pixel and its base.
Definition GrFont.h:51
void begin(uint16_t color16Bit)
Initializes the font and sets the font's foreground color.
Definition GrFont.cpp:32
A variation of the Canvas class that can load imagery from Flash ROM.
Definition Canvas.h:405
Data Structure that defines an individual character.
Definition GrFont.h:19
int16_t yoffset
Cursor y-offset that should be used when copying character to the screen.
Definition GrFont.h:25
uint16_t y
UL y-position of the character within the DRAM image.
Definition GrFont.h:21
uint16_t height
Height of the character in the DRAM image.
Definition GrFont.h:23
uint16_t width
Width of the character in the DRAM image.
Definition GrFont.h:22
int16_t xoffset
Cursor x-offset that should be used when copying character to the screen.
Definition GrFont.h:24
uint16_t xadvance
How far to advance the curso x-pos after this character.
Definition GrFont.h:26
uint16_t x
UL x-position of the character within the DRAM image.
Definition GrFont.h:20
Structure to define the size and location of an image in Flash.
Definition ROM_Images.h:14