Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
ButtonState.h
Go to the documentation of this file.
1/******************************************************************************/
9
10#ifndef BUTTON_STATE_INCLUDED
11#define BUTTON_STATE_INCLUDED
12
13#include "TextBox.h"
14
15/******************************************************************************/
16/*** ***/
17/*** Class Definition: ButtonState ***/
18/*** ***/
19/******************************************************************************/
27{
28public:
29 typedef void (*buttonCallbackFunction)(void);
30
31private:
32 buttonCallbackFunction _callback; // Function to call when the button is pressed
33 Canvas _ButtonFrame; // Canvas that holds the button frame
34
35 Canvas &_DestCanvas; // Reference to the destination canvas where the button will be drawn
36 const uint16_t _DEST_X; // X location of the button on the destination canvas
37 const uint16_t _DEST_Y; // Y location of the button on the destination canvas
38
39 const uint16_t _WIDTH; // Width of the button
40 const uint16_t _HEIGHT; // Height of the button
41
42 // Button border definition
43 const uint8_t _BORDER_WIDTH = 0; // Border width in pixels
44 const uint16_t _BORDER_COLOR = 0xFFFF; // 16-bit ARGB format
45 const uint16_t _FILL_COLOR = 0x0000; // 16-bit ARGB format
46 const unsigned short _CORNER_RADIUS = 30; // Corner radius in pixels
47
48protected:
54
55public:
59
73 ButtonState(Canvas &destCanvas, uint16_t x, uint16_t y, uint16_t width, uint16_t height, buttonCallbackFunction callback,
74 unsigned short cornerRadius, uint8_t borderWidth, uint16_t borderColor, uint16_t fillColor16)
75 : _callback{callback},
76 _ButtonFrame{width, height},
77 _DestCanvas{destCanvas},
78 _DEST_X{x},
79 _DEST_Y{y},
80 _WIDTH{width},
81 _HEIGHT{height},
82 _BORDER_WIDTH{borderWidth},
83 _BORDER_COLOR{borderColor},
84 _FILL_COLOR{fillColor16}, // Convert 16 to 12 bit
85 _CORNER_RADIUS{cornerRadius} {};
86
92 virtual ~ButtonState() = default;
93
95
99
105 virtual void updateBackground(void);
106
112 virtual void draw(void);
113
119 virtual void drawOpaque(void);
120
126 virtual void draw(Canvas &newCanvas, bool TransparentOn = true);
127
133 virtual void begin(void)
134 {
136 }
137
143 inline void callback(void) const
144 {
145 _callback();
146 };
147
149
153
158 inline uint16_t width(void) const
159 {
160 return _WIDTH;
161 };
162
167 inline uint16_t height(void) const
168 {
169 return _HEIGHT;
170 };
171
176 inline uint16_t x(void) const
177 {
178 return _DEST_X;
179 }
180
185 inline uint16_t y(void) const
186 {
187 return _DEST_Y;
188 }
189
190};
191
192/******************************************************************************/
193/*** ***/
194/*** Class Definition: ImageButtonState ***/
195/*** ***/
196/******************************************************************************/
201{
202 const uint16_t _buttonGfxColor; // Background color to use for the button
203
204public:
218 uint16_t buttonGfxColor16, unsigned short cornerRadius, uint8_t borderWidth, uint16_t borderColor16, uint16_t fillColor16)
219 : ButtonState(destCanvas, destLoc.x, destLoc.y, destLoc.width, destLoc.height, callback,
220 cornerRadius, borderWidth, borderColor16, fillColor16),
221 _buttonGfxColor{rgb16to12(buttonGfxColor16)} // Convert 16 to 12 bit
222 {
223 _ButtonGfxCanvas = new ROM_Canvas(buttonImage);
224 }
225
231 ~ImageButtonState(void) = default;
232
238 void begin(void) override;
239};
240
241/******************************************************************************/
242/*** ***/
243/*** Class Definition: TextButtonState ***/
244/*** ***/
245/******************************************************************************/
250{
251 DynamicText *_DynamicTextObj; // Canvas that holds the text to be drawn on the button graphic
252 const char *_buttonText; // Current text to be displayed on the button
253
254public:
258
272 TextButtonState(Canvas &Destination, const Block_Image &DestLoc, const char *_buttonText,
274 uint16_t baseline, unsigned short cornerRadius, uint16_t borderWidth,
275 uint16_t borderColor16, uint16_t fillColor16)
276 : ButtonState(Destination, DestLoc.x, DestLoc.y, DestLoc.width, DestLoc.height, callback, cornerRadius, borderWidth, borderColor16, fillColor16),
277 _buttonText{_buttonText}
278 {
279 _ButtonGfxCanvas = new Canvas(DestLoc.width, DestLoc.height);
280 _DynamicTextObj = new DynamicText(*_ButtonGfxCanvas, 0, 0, _ButtonGfxCanvas->width(), _ButtonGfxCanvas->height(), baseline, Font);
281 }
282
288 ~TextButtonState(void) = default;
289
291
297 void begin(void) override;
298};
299
300/******************************************************************************/
301/*** ***/
302/*** Class Definition: TextBoxButtonState ***/
303/*** ***/
304/******************************************************************************/
310{
311 TextBox *_TextBoxObj; // Canvas that holds the text to be drawn on the button graphic
312
313public:
317
325 : ButtonState(Destination, config.x, config.y, config.textWidth + config.shape.unitsWidth, config.shape.height,
326 callback, 0, 0, 0, 0)
327 {
328 _ButtonGfxCanvas = new Canvas(config.textWidth + config.shape.unitsWidth, config.shape.height);
329 _TextBoxObj = new TextBox(*_ButtonGfxCanvas, 0, 0, config.textWidth,
330 config.shape.unitsWidth, config.shape.height,
331 config.shape.baseline, config.TextFont, config.UnitsFont);
332 }
333
339 ~TextBoxButtonState(void) = default;
340
342
346
352 void begin(void) override;
353
359 void draw(void) override
360 {
361 drawOpaque();
362 }
363
368 inline void update(const char *text)
369 {
370 _TextBoxObj->Value.update(text, strlen(text));
371 }
372
377 inline void update(int value)
378 {
379 _TextBoxObj->Value.update(value);
380 }
381
386 inline void setUnits(const char *text)
387 {
388 _TextBoxObj->Units.update(text, strlen(text));
389 }
390
391};
392
393#endif // BUTTON_STATE_INCLUDED
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
Defines TextBox and TextBox which are used to display dynamic text within a canvas.
virtual void begin(void)
Initializes the button state object. This method should be called before first use of the object.
Definition ButtonState.h:133
uint16_t x(void) const
Returns the X location of the button state on the destination canvas.
Definition ButtonState.h:176
virtual void drawOpaque(void)
Draw the button assuming images have an opaque background.
Definition ButtonState.cpp:34
uint16_t width(void) const
Returns the width of the button state.
Definition ButtonState.h:158
uint16_t y(void) const
Returns the Y location of the button state on the destination canvas.
Definition ButtonState.h:185
uint16_t height(void) const
Returns the height of the button state.
Definition ButtonState.h:167
ButtonState(Canvas &destCanvas, uint16_t x, uint16_t y, uint16_t width, uint16_t height, buttonCallbackFunction callback, unsigned short cornerRadius, uint8_t borderWidth, uint16_t borderColor, uint16_t fillColor16)
Construct a new Button State object.
Definition ButtonState.h:73
void callback(void) const
Calls the callback function associated with this button state.
Definition ButtonState.h:143
Canvas * _ButtonGfxCanvas
Canvas that holds the colorized button graphics. Derived classes will define this canvas as appropria...
Definition ButtonState.h:53
virtual ~ButtonState()=default
Default destructor.
virtual void updateBackground(void)
Update the button background graphics.
Definition ButtonState.cpp:15
virtual void draw(void)
Draw the button assuming images have transparent background.
Definition ButtonState.cpp:29
void(* buttonCallbackFunction)(void)
Defines the form of the callback functions expected by the Button class.
Definition ButtonState.h:29
Provides higher level TFT graphic functionality used by the menu system.
Definition Canvas.h:34
Defines a simple text box for displaying dynamic text onto a Canvas.
Definition TextBox.h:46
FontID
Enumeration listing available fonts.
Definition FontList.h:35
void begin(void) override
Initializes the button state object. This method should be called before first use of the object.
Definition ButtonState.cpp:50
~ImageButtonState(void)=default
Destroys the Image Button State object.
ImageButtonState(Canvas &destCanvas, const Block_Image &destLoc, buttonCallbackFunction callback, ROM_Image buttonImage, uint16_t buttonGfxColor16, unsigned short cornerRadius, uint8_t borderWidth, uint16_t borderColor16, uint16_t fillColor16)
Constructs a new Image Button State object.
Definition ButtonState.h:217
A variation of the Canvas class that can load imagery from Flash ROM.
Definition Canvas.h:405
void setUnits(const char *text)
Update the units text inside the TextBox.
Definition ButtonState.h:386
void update(const char *text)
Update the text inside the TextBox.
Definition ButtonState.h:368
void draw(void) override
Draw the button onto Destination canvas at the specified location.
Definition ButtonState.h:359
~TextBoxButtonState(void)=default
Destroys the Text Box Button State object.
TextBoxButtonState(Canvas &Destination, const ConfigTextBox_t &config, buttonCallbackFunction callback)
Construct a new Text Box Button State object.
Definition ButtonState.h:324
void update(int value)
Update the text inside the TextBox.
Definition ButtonState.h:377
void begin(void) override
Initializes the button state object. This method should be called before first use of the object.
Definition ButtonState.cpp:89
Composite object containing a "Value" and "Units" Text Box.
Definition TextBox.h:157
void begin(void) override
Initializes the button state object. This method should be called before first use of the object.
Definition ButtonState.cpp:72
~TextButtonState(void)=default
Destroys the Text Button State object.
TextButtonState(Canvas &Destination, const Block_Image &DestLoc, const char *_buttonText, FontList::FontID Font, ButtonState::buttonCallbackFunction callback, uint16_t baseline, unsigned short cornerRadius, uint16_t borderWidth, uint16_t borderColor16, uint16_t fillColor16)
Construct a new Text Button State object.
Definition ButtonState.h:272
Structure to define sub-images. Generally associated with a ROM_Image.
Definition ROM_Images.h:22
uint16_t width
Definition ROM_Images.h:25
uint16_t height
Definition ROM_Images.h:26
Configuration information for a TextBox object.
Definition Definitions.h:38
FontList::FontID UnitsFont
Font object used to render units text.
Definition Definitions.h:54
Shape_t shape
Geometric configuration information.
Definition Definitions.h:51
FontList::FontID TextFont
Font object used to render the primary text.
Definition Definitions.h:53
uint16_t textWidth
Width in pixels of the DynamicText holding the main text.
Definition Definitions.h:41
Structure to define the size and location of an image in Flash.
Definition ROM_Images.h:14
uint16_t unitsWidth
Width in pixels of the DynamicText used to write the 'units' text to the screen.
Definition Definitions.h:20
uint16_t baseline
Location within DynamicText where the font baseline is to be placed.
Definition Definitions.h:30
uint16_t height
Overall height of the DynamicText. This height is selected to accommodate the height of the selected ...
Definition Definitions.h:21