C++ DevKit
C++ set of OOP library
canvas.h
Go to the documentation of this file.
1
11
12#pragma once
13
15#define FONT_WIDTH_INDEX 0
17#define FONT_HEIGHT_INDEX 1
19#define BYTE_SIZE 8
20
21#include "pico/stdlib.h"
22#include <stdio.h>
23#include <map>
24
26enum class ColorIndex
27{
29 BLACK = 0, // "BLACK" must be coded with code 0x0 for monochrome display device
30 WHITE = 1, // "WHITE" must be coded with code 0x1 for monochrome display device
31
32 BLUE, // {ColorIndex::BLUE, {0x00, 0x00, 0xFF}},
33 LIME, // {ColorIndex::LIME, {0x00, 0xFF, 0x00}},
34 RED, // {ColorIndex::RED, {0xFF, 0x00, 0x00}},
35
36 CYAN, // {ColorIndex::CYAN, {0x00, 0xFF, 0xFF}},
37 YELLOW, // {ColorIndex::YELLOW, {0xFF, 0xFF, 0x00}},
38 MAGENTA, // {ColorIndex::MAGENTA, {0xFF, 0x00, 0xFF}},
39
40 NAVY, // {ColorIndex::NAVY, {0x00, 0x00, 0x80}},
41 GREEN, // {ColorIndex::GREEN, {0x00, 0x80, 0x00}},
42 PHOSPHOR, // {ColorIndex::PHOSPHOR, {0x00, 0x80, 0x00}},
43 TEAL, // {ColorIndex::TEAL, {0xAA, 0xFF, 0x00}},
44 BURGUNDY, // {ColorIndex::BURGUNDY, {0x80, 0x00, 0x00}},
45 PURPLE, // {ColorIndex::PURPLE, {0x80, 0x00, 0x80}},
46 OLIVE, // {ColorIndex::OLIVE, {0x80, 0x80, 0x00}},
47 GRAY, // {ColorIndex::GRAY, {0x80, 0x80, 0x80}},
48
49 SILVER, // {ColorIndex::SILVER, {0xC0, 0xC0, 0xC0}},
50 MAROON, // {ColorIndex::MAROON, {0xA5, 0x2A, 0x2A}},
51 ORANGE, // {ColorIndex::ORANGE, {0xFF, 0xA5, 0x00}},
52 GOLD, // {ColorIndex::GOLD, {0xFF, 0xD7, 0x00}},
53 FOREST // {ColorIndex::FOREST, {0x22, 0x8B, 0x22}}};
55};
56
58extern std::map<ColorIndex, uint16_t> color565_palette;
59
79
98
101{
105 uint8_t number_of_line{0};
107 uint8_t widget_anchor_x{0};
109 uint8_t widget_anchor_y{0};
112 const unsigned char *font{nullptr};
114 uint8_t tab_size{2};
116 ColorIndex fg_color{ColorIndex::WHITE};
118 ColorIndex bg_color{ColorIndex::BLACK};
120 bool wrap{true};
122 bool auto_next_char{true};
125};
126
130{
131protected:
132public:
139
141 virtual void create_canvas_buffer() = 0;
142
145 virtual void fill_canvas_with_color(ColorIndex color) = 0;
146
149
152
155
158
160 uint8_t *canvas_buffer{nullptr};
161
163 uint16_t *canvas_16buffer{nullptr};
164
169 uint8_t canvas_height_pixel);
170
171 virtual ~Canvas();
172
174 virtual void clear_canvas_buffer();
175
180 virtual void draw_pixel(const int x, const int y,
181 const ColorIndex color = ColorIndex::WHITE) = 0;
182};
183
186class CanvasVLSB : public Canvas
187{
188private:
190
191public:
196 uint8_t canvas_height_pixel);
197 ~CanvasVLSB();
198
202
203 void draw_pixel(const int x, const int y,
204 const ColorIndex color = ColorIndex::WHITE);
205};
206
209class CanvasRGB : public Canvas
210{
211private:
213
214public:
219 uint8_t canvas_height_pixel);
220 ~CanvasRGB();
221
226
227 void draw_pixel(const int x, const int y,
228 const ColorIndex color = ColorIndex::WHITE);
229};
230
232class CanvasTrueRGB : public Canvas
233{
234private:
236
237public:
242 uint8_t canvas_height_pixel);
244
246 virtual void clear_canvas_buffer();
247
252
253 void draw_pixel(const int x, const int y,
254 const ColorIndex color = ColorIndex::WHITE);
255};
256
260class CanvasHMSB : public Canvas
261{
262private:
264
265public:
270 uint8_t canvas_height_pixel);
271 ~CanvasHMSB();
276
277 void draw_pixel(const int x, const int y,
278 const ColorIndex color = ColorIndex::WHITE);
279};
CanvasFormat
the format of the canvas
Definition canvas.h:62
@ MONO_HLSB
monochrome canvas, pixel arranged horizontally, LSB is left pixel
Definition canvas.h:68
@ RGB_COLOR_INDEX_8b
color canvas, 8-bit/pixel coded according to ColorIndex in color565_palette. Converted to RGB565 just...
Definition canvas.h:74
@ MONO_VLSB
monochrome canvas, pixel arranged vertically, LSB is top pixel.
Definition canvas.h:65
@ MONO_HMSB
monochrome canvas, pixel arranged horizontally, MSB is left pixel
Definition canvas.h:71
@ RGB565_16b
color canvas, 16bits/pixel arranged 5b-red,6b-green,5b-blue stored in buffer. This is to allow the us...
Definition canvas.h:77
ColorIndex
define the code value for color
Definition canvas.h:27
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:94
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with 0x00 (i.e. BLACK) of 0xFF (WHITE)
Definition canvas.cpp:86
CanvasHMSB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
constructor for CanvasHMSB
Definition canvas.cpp:69
void create_canvas_buffer()
Create a canvas buffer object.
Definition canvas.cpp:57
The canvas is a virtual memory in which the widget draws.
Definition canvas.h:130
size_t canvas_buffer_size_byte
the size (in bytes) of the buffer
Definition canvas.h:154
uint16_t * canvas_16buffer
the 16bit canvasbuffer
Definition canvas.h:163
virtual void create_canvas_buffer()=0
Create a canvas buffer object.
CanvasFormat canvas_format
the actual format of the canvas
Definition canvas.h:134
virtual void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)=0
the graphic primitive to draw a pixel
ColorIndex bg_color
a copy of the widget background color
Definition canvas.h:138
virtual void fill_canvas_with_color(ColorIndex color)=0
fill the canvas with a given color
Canvas(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas object.
Definition canvas.cpp:34
uint8_t * canvas_buffer
the 8bit canvas buffer
Definition canvas.h:160
size_t canvas_buffer_size_pixel
the size (in pixel) of the buffer
Definition canvas.h:157
ColorIndex fg_color
a copy of the widget foreground color
Definition canvas.h:136
virtual void clear_canvas_buffer()
fill the canvas buffer with 0x00
Definition canvas.cpp:52
uint8_t canvas_height_pixel
the height (in pixel) of the canvas and also of those of the associated widget
Definition canvas.h:151
uint8_t canvas_width_pixel
the width (in pixel) of the canvas and also of those of the associated widget
Definition canvas.h:148
CanvasRGB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas object according to ColorIndex coding.
Definition canvas.cpp:177
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with the given color index
Definition canvas.cpp:195
void create_canvas_buffer()
Create a canvas buffer object.
Definition canvas.cpp:166
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:200
void create_canvas_buffer()
Create a canvas buffer object.
Definition canvas.cpp:209
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:251
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with the given color index
Definition canvas.cpp:243
CanvasTrueRGB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas R G B object.
Definition canvas.cpp:220
virtual void clear_canvas_buffer()
fill the 16bit canvas buffer with 0x00
Definition canvas.cpp:238
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with 0x00 (i.e. BLACK) of 0xFF (WHITE)
Definition canvas.cpp:141
CanvasVLSB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas V L S B object.
Definition canvas.cpp:123
void create_canvas_buffer()
Create a canvas buffer object.
Definition canvas.cpp:111
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:149
data structure used to configure graphic framebuffer
Definition canvas.h:82
size_t canvas_width_pixel
the frame width of the graphic frame
Definition canvas.h:84
bool widget_with_border
a flag that indicates if the widget has a 1-pixel width border
Definition canvas.h:96
uint8_t widget_anchor_y
the y-axis anchor of the widget
Definition canvas.h:94
uint8_t widget_anchor_x
the x_axis anchor of the widget
Definition canvas.h:92
size_t canvas_height_pixel
the frame height of the graphic frame
Definition canvas.h:86
ColorIndex canvas_foreground_color
the foreground color
Definition canvas.h:88
ColorIndex canvas_background_color
the background color
Definition canvas.h:90
the data structure used to configure textual widget
Definition canvas.h:101
uint8_t widget_anchor_x
the x_axis anchor of the widget
Definition canvas.h:107
ColorIndex fg_color
The foreground color, default to WHITE.
Definition canvas.h:116
bool wrap
Wrap flag : if true, text wrap to the next line when end of line is reached.
Definition canvas.h:120
ColorIndex bg_color
The background color, default to BLACK.
Definition canvas.h:118
const unsigned char * font
The font used. Current font are defined according to IBM CP437. The font files are derived from https...
Definition canvas.h:112
bool widget_with_border
a flag that indicates if the widget has a 1-pixel width border
Definition canvas.h:124
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition canvas.h:103
uint8_t tab_size
The number of space that ASCII character HT (aka TAB , "\t", 0x9) generates, default to 2.
Definition canvas.h:114
uint8_t widget_anchor_y
the y-axis anchor of the widget
Definition canvas.h:109
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition canvas.h:105
bool auto_next_char
auto_next_char flag : if true each char steps one position after being written.
Definition canvas.h:122