C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
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 TEAL, // {ColorIndex::TEAL, {0x00, 0x80, 0x80}},
43 BURGUNDY, // {ColorIndex::BURGUNDY, {0x80, 0x00, 0x00}},
44 PURPLE, // {ColorIndex::PURPLE, {0x80, 0x00, 0x80}},
45 OLIVE, // {ColorIndex::OLIVE, {0x80, 0x80, 0x00}},
46 GRAY, // {ColorIndex::GRAY, {0x80, 0x80, 0x80}},
47
48 SILVER, // {ColorIndex::SILVER, {0xC0, 0xC0, 0xC0}},
49 MAROON, // {ColorIndex::MAROON, {0xA5, 0x2A, 0x2A}},
50 ORANGE, // {ColorIndex::ORANGE, {0xFF, 0xA5, 0x00}},
51 GOLD, // {ColorIndex::GOLD, {0xFF, 0xD7, 0x00}},
52 FOREST // {ColorIndex::FOREST, {0x22, 0x8B, 0x22}}};
54};
55
57extern std::map<ColorIndex, uint16_t> color565_palette;
58
78
81{
87 ColorIndex fg_color{ColorIndex::WHITE};
89 ColorIndex bg_color{ColorIndex::BLACK};
91 uint8_t widget_anchor_x{0};
93 uint8_t widget_anchor_y{0};
95 bool widget_with_border{false};
96};
97
100{
104 uint8_t number_of_line{0};
106 uint8_t widget_anchor_x{0};
108 uint8_t widget_anchor_y{0};
111 const unsigned char *font{nullptr};
113 uint8_t tab_size{2};
115 ColorIndex fg_color{ColorIndex::WHITE};
117 ColorIndex bg_color{ColorIndex::BLACK};
119 bool wrap{true};
121 bool auto_next_char{true};
124};
125
129{
130protected:
131public:
138
140 virtual void create_canvas_buffer() = 0;
141
144 virtual void fill_canvas_with_color(ColorIndex color) = 0;
145
148
151
154
157
159 uint8_t *canvas_buffer{nullptr};
160
162 uint16_t *canvas_16buffer{nullptr};
163
168 uint8_t canvas_height_pixel);
169
170 virtual ~Canvas();
171
173 virtual void clear_canvas_buffer();
174
179 virtual void draw_pixel(const int x, const int y,
180 const ColorIndex color = ColorIndex::WHITE) = 0;
181};
182
185class CanvasVLSB : public Canvas
186{
187private:
188 void create_canvas_buffer();
189
190public:
195 uint8_t canvas_height_pixel);
196 ~CanvasVLSB();
197
201
202 void draw_pixel(const int x, const int y,
203 const ColorIndex color = ColorIndex::WHITE);
204};
205
208class CanvasRGB : public Canvas
209{
210private:
211 void create_canvas_buffer();
212
213public:
218 uint8_t canvas_height_pixel);
219 ~CanvasRGB();
220
225
226 void draw_pixel(const int x, const int y,
227 const ColorIndex color = ColorIndex::WHITE);
228};
229
231class CanvasTrueRGB : public Canvas
232{
233private:
234 void create_canvas_buffer();
235
236public:
241 uint8_t canvas_height_pixel);
243
245 virtual void clear_canvas_buffer();
246
251
252 void draw_pixel(const int x, const int y,
253 const ColorIndex color = ColorIndex::WHITE);
254};
255
259class CanvasHMSB : public Canvas
260{
261private:
262 void create_canvas_buffer();
263
264public:
269 uint8_t canvas_height_pixel);
270 ~CanvasHMSB();
275
276 void draw_pixel(const int x, const int y,
277 const ColorIndex color = ColorIndex::WHITE);
278};
CanvasFormat
the format of the canvas
Definition canvas.h:61
@ MONO_HLSB
monochrome canvas, pixel arranged horizontally, LSB is left pixel
Definition canvas.h:67
@ RGB_COLOR_INDEX_8b
color canvas, 8-bit/pixel coded according to ColorIndex in color565_palette. Converted to RGB565 just...
Definition canvas.h:73
@ MONO_VLSB
monochrome canvas, pixel arranged vertically, LSB is top pixel.
Definition canvas.h:64
@ MONO_HMSB
monochrome canvas, pixel arranged horizontally, MSB is left pixel
Definition canvas.h:70
@ 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:76
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:93
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with 0x00 (i.e. BLACK) of 0xFF (WHITE)
Definition canvas.cpp:85
CanvasHMSB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
constructor for CanvasHMSB
Definition canvas.cpp:68
The canvas is a virtual memory in which the widget draws.
Definition canvas.h:129
size_t canvas_buffer_size_byte
the size (in bytes) of the buffer
Definition canvas.h:153
uint16_t * canvas_16buffer
the 16bit canvasbuffer
Definition canvas.h:162
virtual void create_canvas_buffer()=0
Create a canvas buffer object.
CanvasFormat canvas_format
the actual format of the canvas
Definition canvas.h:133
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:137
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:33
uint8_t * canvas_buffer
the 8bit canvas buffer
Definition canvas.h:159
size_t canvas_buffer_size_pixel
the size (in pixel) of the buffer
Definition canvas.h:156
ColorIndex fg_color
a copy of the widget foreground color
Definition canvas.h:135
virtual void clear_canvas_buffer()
fill the canvas buffer with 0x00
Definition canvas.cpp:51
uint8_t canvas_height_pixel
the height (in pixel) of the canvas and also of those of the associated widget
Definition canvas.h:150
uint8_t canvas_width_pixel
the width (in pixel) of the canvas and also of those of the associated widget
Definition canvas.h:147
CanvasRGB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas R G B object.
Definition canvas.cpp:176
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with the given color index
Definition canvas.cpp:194
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:199
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:250
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with the given color index
Definition canvas.cpp:242
CanvasTrueRGB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas R G B object.
Definition canvas.cpp:219
virtual void clear_canvas_buffer()
fill the 16bit canvas buffer with 0x00
Definition canvas.cpp:237
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with 0x00 (i.e. BLACK) of 0xFF (WHITE)
Definition canvas.cpp:140
CanvasVLSB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas V L S B object.
Definition canvas.cpp:122
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:148
data structure used to configure graphic framebuffer
Definition canvas.h:81
bool widget_with_border
a flag that indicates if the widget has a 1-pixel width border
Definition canvas.h:95
uint8_t widget_anchor_y
the y-axis anchor of the widget
Definition canvas.h:93
size_t pixel_frame_height
the frame height of the graphic frame
Definition canvas.h:85
uint8_t widget_anchor_x
the x_axis anchor of the widget
Definition canvas.h:91
ColorIndex bg_color
the background color
Definition canvas.h:89
ColorIndex fg_color
the foreground color
Definition canvas.h:87
size_t pixel_frame_width
the frame width of the graphic frame
Definition canvas.h:83
the data structure used to configure textual widget
Definition canvas.h:100
uint8_t widget_anchor_x
the x_axis anchor of the widget
Definition canvas.h:106
ColorIndex fg_color
The foreground color, default to WHITE.
Definition canvas.h:115
bool wrap
Wrap flag : if true, text wrap to the next line when end of line is reached.
Definition canvas.h:119
ColorIndex bg_color
The background color, default to BLACK.
Definition canvas.h:117
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:111
bool widget_with_border
a flag that indicates if the widget has a 1-pixel width border
Definition canvas.h:123
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition canvas.h:102
uint8_t tab_size
The number of space that ASCII character HT (aka TAB , "\t", 0x9) generates, default to 2.
Definition canvas.h:113
uint8_t widget_anchor_y
the y-axis anchor of the widget
Definition canvas.h:108
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition canvas.h:104
bool auto_next_char
auto_next_char flag : if true each char steps one position after being written.
Definition canvas.h:121