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 <map>
23
25enum class ColorIndex
26{
28 BLACK = 0, // "BLACK" must be coded with code 0x0 for monochrome display device
29 WHITE = 1, // "WHITE" must be coded with code 0x1 for monochrome display device
30
31 BLUE, // {ColorIndex::BLUE, {0x00, 0x00, 0xFF}},
32 LIME, // {ColorIndex::LIME, {0x00, 0xFF, 0x00}},
33 RED, // {ColorIndex::RED, {0xFF, 0x00, 0x00}},
34
35 CYAN, // {ColorIndex::CYAN, {0x00, 0xFF, 0xFF}},
36 YELLOW, // {ColorIndex::YELLOW, {0xFF, 0xFF, 0x00}},
37 MAGENTA, // {ColorIndex::MAGENTA, {0xFF, 0x00, 0xFF}},
38
39 NAVY, // {ColorIndex::NAVY, {0x00, 0x00, 0x80}},
40 GREEN, // {ColorIndex::GREEN, {0x00, 0x80, 0x00}},
41 TEAL, // {ColorIndex::TEAL, {0x00, 0x80, 0x80}},
42 BURGUNDY, // {ColorIndex::BURGUNDY, {0x80, 0x00, 0x00}},
43 PURPLE, // {ColorIndex::PURPLE, {0x80, 0x00, 0x80}},
44 OLIVE, // {ColorIndex::OLIVE, {0x80, 0x80, 0x00}},
45 GRAY, // {ColorIndex::GRAY, {0x80, 0x80, 0x80}},
46
47 SILVER, // {ColorIndex::SILVER, {0xC0, 0xC0, 0xC0}},
48 MAROON, // {ColorIndex::MAROON, {0xA5, 0x2A, 0x2A}},
49 ORANGE, // {ColorIndex::ORANGE, {0xFF, 0xA5, 0x00}},
50 GOLD, // {ColorIndex::GOLD, {0xFF, 0xD7, 0x00}},
51 FOREST // {ColorIndex::FOREST, {0x22, 0x8B, 0x22}}};
53};
54
56extern std::map<ColorIndex, uint16_t> color565_palette;
57
70
73{
79 ColorIndex fg_color{ColorIndex::WHITE};
81 ColorIndex bg_color{ColorIndex::BLACK};
83 uint8_t widget_anchor_x{0};
85 uint8_t widget_anchor_y{0};
87 bool widget_with_border{false};
88};
89
92{
94 uint8_t number_of_column{0};
96 uint8_t number_of_line{0};
98 uint8_t widget_anchor_x{0};
100 uint8_t widget_anchor_y{0};
103 const unsigned char *font{nullptr};
105 uint8_t tab_size{2};
107 ColorIndex fg_color{ColorIndex::WHITE};
109 ColorIndex bg_color{ColorIndex::BLACK};
111 bool wrap{true};
113 bool auto_next_char{true};
116};
117
121{
122protected:
123public:
130
132 virtual void create_canvas_buffer() = 0;
133
136 virtual void fill_canvas_with_color(ColorIndex color) = 0;
137
140
143
146
148 uint8_t *canvas_buffer{nullptr};
149
154 uint8_t canvas_height_pixel);
155 ~Canvas();
156
158 void clear_canvas_buffer();
159
164 virtual void draw_pixel(const int x, const int y,
165 const ColorIndex color = ColorIndex::WHITE) = 0;
166};
167
170class CanvasVLSB : public Canvas
171{
172private:
173 void create_canvas_buffer();
174
175public:
180 uint8_t canvas_height_pixel);
181 ~CanvasVLSB();
182
186
187 void draw_pixel(const int x, const int y,
188 const ColorIndex color = ColorIndex::WHITE);
189};
190
193class CanvasRGB : public Canvas
194{
195private:
196 void create_canvas_buffer();
197
198public:
203 uint8_t canvas_height_pixel);
204 ~CanvasRGB();
205
210
211 void draw_pixel(const int x, const int y,
212 const ColorIndex color = ColorIndex::WHITE);
213};
214
218class CanvasHMSB : public Canvas
219{
220private:
221 void create_canvas_buffer();
222
223public:
224
229 uint8_t canvas_height_pixel);
230 ~CanvasHMSB();
235
236 void draw_pixel(const int x, const int y,
237 const ColorIndex color = ColorIndex::WHITE);
238};
CanvasFormat
the format of the canvas
Definition canvas.h:60
@ MONO_HLSB
monochrome canvas, pixel arranged horizontally, LSB is left pixel
Definition canvas.h:64
@ RGB565
color canvas, 16bits/pixel arranged 5b-red,6b-green,5b-blue
Definition canvas.h:68
@ MONO_VLSB
monochrome canvas, pixel arranged vertically, LSB is top pixel
Definition canvas.h:62
@ MONO_HMSB
monochrome canvas, pixel arranged horizontally, MSB is left pixel
Definition canvas.h:66
ColorIndex
define the code value for color
Definition canvas.h:26
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:74
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with 0x00 (i.e. BLACK) of 0xFF (WHITE)
Definition canvas.cpp:66
CanvasHMSB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
constructor for CanvasHMSB
Definition canvas.cpp:55
The canvas is a virtual memory in which the widget draws.
Definition canvas.h:121
size_t canvas_buffer_size
the size (in bytes) of the buffer
Definition canvas.h:145
virtual void create_canvas_buffer()=0
Create a canvas buffer object.
CanvasFormat canvas_format
the actual format of the canvas
Definition canvas.h:125
virtual void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)=0
the graphic primitive to draw a pixel
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:31
uint8_t * canvas_buffer
the buffer
Definition canvas.h:148
void clear_canvas_buffer()
fill the canvas buffer with 0x00
Definition canvas.cpp:42
ColorIndex canvas_bg_color
a copy of the widget background color
Definition canvas.h:129
uint8_t canvas_height_pixel
the height (in pixel) of the canvas and also of those of the associated widget
Definition canvas.h:142
uint8_t canvas_width_pixel
the width (in pixel) of the canvas and also of those of the associated widget
Definition canvas.h:139
ColorIndex canvas_fg_color
a copy of the widget foreground color
Definition canvas.h:127
CanvasRGB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas R G B object.
Definition canvas.cpp:143
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with the given color index
Definition canvas.cpp:155
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:160
void fill_canvas_with_color(ColorIndex color)
fill the canvas buffer with 0x00 (i.e. BLACK) of 0xFF (WHITE)
Definition canvas.cpp:111
CanvasVLSB(uint8_t canvas_width_pixel, uint8_t canvas_height_pixel)
Construct a new Canvas V L S B object.
Definition canvas.cpp:99
void draw_pixel(const int x, const int y, const ColorIndex color=ColorIndex::WHITE)
the graphic primitive to draw a pixel
Definition canvas.cpp:119
data structure used to configure graphic framebuffer
Definition canvas.h:73
bool widget_with_border
a flag that indicates if the widget has a 1-pixel width border
Definition canvas.h:87
uint8_t widget_anchor_y
the y-axis anchor of the widget
Definition canvas.h:85
size_t pixel_frame_height
the frame height of the graphic frame
Definition canvas.h:77
uint8_t widget_anchor_x
the x_axis anchor of the widget
Definition canvas.h:83
ColorIndex bg_color
the background color
Definition canvas.h:81
ColorIndex fg_color
the foreground color
Definition canvas.h:79
size_t pixel_frame_width
the frame width of the graphic frame
Definition canvas.h:75
the data structure used to configure textual widget
Definition canvas.h:92
uint8_t widget_anchor_x
the x_axis anchor of the widget
Definition canvas.h:98
ColorIndex fg_color
The foreground color, default to WHITE.
Definition canvas.h:107
bool wrap
Wrap flag : if true, text wrap to the next line when end of line is reached.
Definition canvas.h:111
ColorIndex bg_color
The background color, default to BLACK.
Definition canvas.h:109
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:103
bool widget_with_border
a flag that indicates if the widget has a 1-pixel width border
Definition canvas.h:115
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition canvas.h:94
uint8_t tab_size
The number of space that ASCII character HT (aka TAB , "\t", 0x9) generates, default to 2.
Definition canvas.h:105
uint8_t widget_anchor_y
the y-axis anchor of the widget
Definition canvas.h:100
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition canvas.h:96
bool auto_next_char
auto_next_char flag : if true each char steps one position after being written.
Definition canvas.h:113