Solo Controller Documentation 1.0
Documentation for the Solo Controller
 
Loading...
Searching...
No Matches
Canvas.h
Go to the documentation of this file.
1/******************************************************************************/
12
13#ifndef Canvas_DEFINED
14#define Canvas_DEFINED
15
16#include "ROM_Images.h"
17
18/******************************************************************************/
19/*** ***/
20/*** Class Definition: Canvas ***/
21/*** ***/
22/******************************************************************************/
33class Canvas
34{
35
36 const uint16_t _width; // Width of the canvas
37 const uint16_t _height; // Height of the canvas
38 const uint32_t _DRAM_address; // Starting address for the canvas in Display RAM
39
40 static uint32_t _nextDRAM_Address; // Keeps track of the next available location in DRAM
41
42protected:
48 void _validate(void) const;
49
50public:
54
58 Canvas(void) : Canvas(false) {};
59
64 Canvas(bool temporary);
65
72 Canvas(uint16_t width, uint16_t height, bool temporary = false);
73
79 ~Canvas(void) = default;
80
85
94 virtual void loadImage(void) const
95 {
96 // validate that the width of the image is a multiple of 4.
97 _validate();
98 };
99
105 void setActive(void) const;
106
112 void setMainWindow(void) const;
113
118
125 inline uint16_t width(void) const
126 {
127 return _width;
128 };
129
136 inline uint16_t height(void) const
137 {
138 return _height;
139 };
140
147 inline uint32_t address(void) const
148 {
149 return _DRAM_address;
150 }
151
156
165 static void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
166
172 inline void clear(void)
173 {
174 clear(Black);
175 }
176
181 inline void clear(uint16_t color)
182 {
183 setActive();
184 solidFill(0, 0, width(), height(), color);
185 }
186
195 void solidFill(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t color) const;
196
206 void text(uint16_t x0, uint16_t y0, uint16_t fColor, uint16_t bColor, const char *text, bool small = false) const;
207
216 void drawRect(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned short color) const;
217
228 void drawRoundedRect(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1,
229 unsigned short color, unsigned short radius, bool fill = false) const;
230
235
240 void BTE_CopyFrom(const Canvas &source) const;
241
248 void BTE_CopyFrom(const Canvas &source, uint16_t DT_x0, uint16_t DT_y0) const;
249
265 void BTE_ROP(const Canvas &S0, uint16_t S0_x0, uint16_t S0_y0,
266 const Canvas &S1, uint16_t S1_x0, uint16_t S1_y0,
267 uint16_t DT_x0, uint16_t DT_y0, uint16_t DT_width, uint16_t DT_height,
268 uint8_t ROP, bool S1_OpacityOn = false) const;
269
280 inline void BTE_CopyFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
281 {
282 const uint8_t ROP = 0x0C; // DT = S0 (source)
283 BTE_ROP(source, Src_x0, Src_y0, source, Src_x0, Src_y0, DT_x0, DT_y0, width, height, ROP, false);
284 };
285
300 inline void BTE_AddImageFrom(const Canvas &S0, uint16_t S0_x0, uint16_t S0_y0,
301 const Canvas &S1, uint16_t S1_x0, uint16_t S1_y0,
302 uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height, bool S1OpacityOn=false) const
303 {
304 const uint8_t ROP = 0x0E; // DT = S0 + S1 (source)
305 // Assumes that this object is both S0 and DT
306 BTE_ROP(S0, S0_x0, S0_y0, S1, S1_x0, S1_y0, DT_x0, DT_y0, width, height, ROP, S1OpacityOn);
307 };
308
319 inline void BTE_AddImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0,
320 uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
321 {
322 const uint8_t ROP = 0x0E; // DT = S0 + S1 (source)
323 // Assumes that this object is both S0 and DT
324 BTE_ROP(*this, DT_x0, DT_y0, source, Src_x0, Src_y0, DT_x0, DT_y0, width, height, ROP, false);
325 };
326
337 inline void BTE_AddTransparentImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
338 {
339 const uint8_t ROP = 0x0E; // DT = S0 + S1 (source)
340 // Assumes that this object is both S0 and DT
341 BTE_ROP(*this, DT_x0, DT_y0, source, Src_x0, Src_y0, DT_x0, DT_y0, width, height, ROP, true);
342 };
343
345
351 static void BL_ON(void);
352
358 static void BL_OFF(void);
359
365 static inline uint32_t nextAddress(void)
366 {
367 return _nextDRAM_Address;
368 }
369
370protected:
376 void BTE_SetAsS0(uint16_t x0, uint16_t y0) const;
377
383 void BTE_SetAsS1(uint16_t x0, uint16_t y0) const;
384
390 void BTE_SetAsDT(uint16_t x0, uint16_t y0) const;
391};
392
393/******************************************************************************/
394/*** ***/
395/*** Class Definition: ROM_Canvas ***/
396/*** ***/
397/******************************************************************************/
404class ROM_Canvas : public Canvas
405{
406
407 uint32_t _ROM_Address; // Starting address of the image in Flash ROM
408
409public:
411 ROM_Canvas(void) = delete;
412
417 ROM_Canvas(ROM_Image image, bool temporary = false);
418
424 ~ROM_Canvas(void) = default;
425
431 void loadImage(void) const override;
432};
433
434/******************************************************************************/
435/*** ***/
436/*** Class Definition: DRAM_Canvas ***/
437/*** ***/
438/******************************************************************************/
443class DRAM_Canvas : public Canvas
444{
445
446 const Canvas &_srcCanvas; // Canvas containing the source imagery
447 const Block_Image _imgBlock; // The image block within _srcCanvas that is
448 // to be copied over
449
450public:
452 DRAM_Canvas(void) = delete;
453
459 DRAM_Canvas(const Canvas &srcCanvas, bool temporary = false);
460
467 DRAM_Canvas(const Canvas &srcCanvas, const Block_Image imgBlock, bool temporary = false);
468
474 ~DRAM_Canvas(void) = default;
475
481 void loadImage(void) const override;
482};
483
484/******************************************************************************/
485/*** ***/
486/*** Support Functions ***/
487/*** ***/
488/******************************************************************************/
489
493template <typename T>
494inline T nearest4(T num)
495{
496 return static_cast<T>(ceil(num / 4.0) * 4);
497};
498
499#endif
Defines the locations of individual sub-images stored in ROM.
#define Black
Definition TFTM070A1.h:56
Provides higher level TFT graphic functionality used by the menu system.
Definition Canvas.h:34
void drawRoundedRect(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned short color, unsigned short radius, bool fill=false) const
Draws an unfilled rounded square.
Definition Canvas.cpp:190
static void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color)
Draws a line onto the display.
Definition Canvas.cpp:142
~Canvas(void)=default
Default destructor.
void clear(uint16_t color)
Erases the canvas, setting all pixels to the specified color.
Definition Canvas.h:181
void BTE_ROP(const Canvas &S0, uint16_t S0_x0, uint16_t S0_y0, const Canvas &S1, uint16_t S1_x0, uint16_t S1_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t DT_width, uint16_t DT_height, uint8_t ROP, bool S1_OpacityOn=false) const
Gneralized ROP operation. This assumes that object calling this method is the destimation DT canvas.
Definition Canvas.cpp:95
void BTE_AddImageFrom(const Canvas &S0, uint16_t S0_x0, uint16_t S0_y0, const Canvas &S1, uint16_t S1_x0, uint16_t S1_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height, bool S1OpacityOn=false) const
Adds image from source to the image on this canvas.
Definition Canvas.h:300
void clear(void)
Erases the canvas, setting all pixels to Black.
Definition Canvas.h:172
void setActive(void) const
Sets this canvas as both the active canvas and active window.
Definition Canvas.cpp:31
static void BL_OFF(void)
Turns the TFT backlight off.
Definition Canvas.cpp:55
void setMainWindow(void) const
Sets this canvas as the Main Window, displaying it in the TFT.
Definition Canvas.cpp:42
Canvas(void)
Default constructor sets canvass to the full size of the display.
Definition Canvas.h:58
void BTE_AddTransparentImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
Adds an opacity encoded image from source to the image on this canvas.
Definition Canvas.h:337
static void BL_ON(void)
Turns the TFT backlight on.
Definition Canvas.cpp:50
void BTE_SetAsDT(uint16_t x0, uint16_t y0) const
Sets the location of the destination (DT) image for the BTE engine.
Definition Canvas.cpp:76
void BTE_SetAsS0(uint16_t x0, uint16_t y0) const
Sets the location of the S0 source image for the BTE engine.
Definition Canvas.cpp:60
static uint32_t nextAddress(void)
Location in DRAM whether the next image Canvas will be placed.
Definition Canvas.h:365
uint16_t width(void) const
Accessor method providing the canvas width.
Definition Canvas.h:125
void BTE_AddImageFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
Adds image from source to the image on this canvas.
Definition Canvas.h:319
uint16_t height(void) const
Accessor method providing the canvas height.
Definition Canvas.h:136
void BTE_CopyFrom(const Canvas &source, uint16_t Src_x0, uint16_t Src_y0, uint16_t DT_x0, uint16_t DT_y0, uint16_t width, uint16_t height) const
Uses BTE engine to copy imagery from source canvas to this one.
Definition Canvas.h:280
void BTE_SetAsS1(uint16_t x0, uint16_t y0) const
Sets the location of the S1 source image for the BTE engine.
Definition Canvas.cpp:68
void BTE_CopyFrom(const Canvas &source) const
Uses BTE engine to copy entire image from source canvas to this one.
Definition Canvas.cpp:85
void _validate(void) const
Protected method used to validate that the images used to create this canvas are appropriately size.
Definition Canvas.cpp:208
void solidFill(uint16_t x0, uint16_t y0, uint16_t width, uint16_t height, uint16_t color) const
Draws a filled square onto the canvas.
Definition Canvas.cpp:150
void drawRect(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1, unsigned short color) const
Draws an unfilled square.
Definition Canvas.cpp:182
uint32_t address(void) const
Accessor method providing the canvas' starting address in DRAM.
Definition Canvas.h:147
virtual void loadImage(void) const
Loads imagery onto the canvas.
Definition Canvas.h:94
void text(uint16_t x0, uint16_t y0, uint16_t fColor, uint16_t bColor, const char *text, bool small=false) const
Draws text onto the canvas.
Definition Canvas.cpp:165
void loadImage(void) const override
Loads the image from Flash ROM onto this Canvas.
Definition Canvas.cpp:265
~DRAM_Canvas(void)=default
Default destructor.
~ROM_Canvas(void)=default
Default destructor.
void loadImage(void) const override
Loads the image from Flash ROM onto this Canvas.
Definition Canvas.cpp:228
Structure to define sub-images. Generally associated with a ROM_Image.
Definition ROM_Images.h:22
Structure to define the size and location of an image in Flash.
Definition ROM_Images.h:14