C++ DevKit
C++ set of OOP library
widget_primitives.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include "canvas.h"
15#include <cstdlib>
16#include <cstring>
17
20#define SSD1306_ASCII_FULL
21#include "font/5x8_font.h"
22#include "font/8x8_font.h"
23#include "font/12x16_font.h"
24#include "font/16x32_font.h"
25#include <cstdint>
26
28#define BACKSPACE '\b'
30#define HORIZONTAL_TAB '\t'
32#define LINE_FEED '\n'
34#define VERTICAL_TAB '\v'
36#define FORM_FEED '\f'
38#define CARRIAGE_RETURN '\r'
39
42{
43protected:
45 size_t widget_width{128};
46
48 size_t widget_height{8};
49
53
57
58public:
60 bool widget_with_border{false};
61
66 CanvasFormat canvas_format);
67
72 CanvasFormat canvas_format);
73
80 CanvasFormat canvas_format, size_t frame_width,
81 size_t frame_height);
82 virtual ~GraphicDrawer();
83
88 void clear_widget();
91
97 void hline(uint8_t x, uint8_t y, size_t w, ColorIndex color = ColorIndex::WHITE);
98
104 void vline(uint8_t x, uint8_t y, size_t h, ColorIndex color = ColorIndex::WHITE);
105
112 void line(int x0, int y0, int x1, int y1, ColorIndex color = ColorIndex::WHITE);
113
121 void rect(uint8_t start_x, uint8_t start_y, size_t w, size_t h, bool fill = false, ColorIndex color = ColorIndex::WHITE);
156 void circle(int radius, int x_center, int y_center, bool fill = false, ColorIndex color = ColorIndex::WHITE);
157
161 virtual void draw_border(ColorIndex color = ColorIndex::WHITE);
162};
163
167{
168private:
171
174
179 void write(char character, uint8_t char_column, uint8_t char_line);
180
182 void clear_line();
183
187 const unsigned char *font{nullptr};
188
190 uint8_t tab_size{2};
191
193 bool wrap{true};
194
196 // TODO consider case where \n is conflicting with auto_next_char when the string is right the same cahr number than the widget
197 bool auto_next_char{true};
198
203 void draw_glyph(const char character,
204 const uint8_t anchor_x, const uint8_t anchor_y);
205
206protected:
208 void create_text_buffer();
209
210public:
216 CanvasFormat canvas_format);
217
225 CanvasFormat canvas_format,
226 size_t frame_width,
227 size_t frame_height);
228 ~TextWriter();
229
233 uint8_t number_of_line{0};
234
238 char *text_buffer = nullptr;
240
244 void update_text_line_column_number(const unsigned char *font);
245
247 void clear_text_buffer();
248
252 void update_canvas_buffer_size(const unsigned char *font);
253
256 void write();
257
260 void write(const char *c_str);
261
281 void process_char(char character);
282
284 void next_line();
285
287 void next_char();
288
293 void draw_border(ColorIndex color = ColorIndex::WHITE);
294};
CanvasFormat
the format of the canvas
Definition canvas.h:62
ColorIndex
define the code value for color
Definition canvas.h:27
The canvas is a virtual memory in which the widget draws.
Definition canvas.h:130
A class that implements basic graphic drawing primitives for widgets.
Definition widget_primitives.h:42
uint8_t widget_start_x
this is the actual horizontal start of the widget drawing area, taken into account the presence of bo...
Definition widget_primitives.h:52
uint8_t widget_start_y
this is the actual vertical start of the widget drawing area, taken into account the presence of bord...
Definition widget_primitives.h:56
void rect(uint8_t start_x, uint8_t start_y, size_t w, size_t h, bool fill=false, ColorIndex color=ColorIndex::WHITE)
Draw a rectangle, starting at frame position (x,y), w wide and h high.
Definition widget_primitives.cpp:154
void hline(uint8_t x, uint8_t y, size_t w, ColorIndex color=ColorIndex::WHITE)
Draw a color horizontal line, starting at frame position (x,y), on w number of pixel.
Definition widget_primitives.cpp:114
uint8_t widget_border_width
this is the border size of the widget. 0 if no border, 1 if border
Definition widget_primitives.h:85
size_t widget_width
As a widget can be surrounded by a border, the actual widget width is not the associated framebuffer ...
Definition widget_primitives.h:45
void circle(int radius, int x_center, int y_center, bool fill=false, ColorIndex color=ColorIndex::WHITE)
draw a cercle of size radius, centered at (x_center, y_center) https://fr.wikipedia....
Definition widget_primitives.cpp:169
bool widget_with_border
if true, the widget is surrounded by a one-pixel border
Definition widget_primitives.h:60
GraphicDrawer(struct_ConfigGraphicWidget graph_cfg, CanvasFormat canvas_format)
Constructor of the GraphicDrawer class.
Definition widget_primitives.cpp:8
void clear_widget()
fill the graphic pixel buffer with 0x00.
Definition widget_primitives.cpp:3
virtual void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a rectangle around the widget.
Definition widget_primitives.cpp:205
Canvas * canvas
the associated canvas in which the widget writes text and draws graphics
Definition widget_primitives.h:90
void vline(uint8_t x, uint8_t y, size_t h, ColorIndex color=ColorIndex::WHITE)
Draw a color vertical line, starting at frame position (x,y), on w number of pixel.
Definition widget_primitives.cpp:120
size_t widget_height
As a widget can be surrounded by a border, the actual widget height is not the associated framebuffer...
Definition widget_primitives.h:48
void line(int x0, int y0, int x1, int y1, ColorIndex color=ColorIndex::WHITE)
Draw a color line, starting at frame position (x0,y0), ending at frame position (x1,...
Definition widget_primitives.cpp:126
A class dedicated to text drawing within a widget.
Definition widget_primitives.h:167
size_t text_buffer_size
size of the buffer that contains text as string of characters.
Definition widget_primitives.h:236
TextWriter(struct_ConfigTextWidget text_cfg, CanvasFormat canvas_format)
Construct a new Text Writer object.
Definition widget_primitives.cpp:264
uint8_t current_char_line
the line number where the next character will be written.
Definition widget_primitives.h:170
void write()
process characters in the internal text buffer and draw it into the pixel buffer.
Definition widget_primitives.cpp:337
void draw_glyph(const char character, const uint8_t anchor_x, const uint8_t anchor_y)
a graphic primitive to draw a character at a pixel position. Strongly dependent on font memory organi...
Definition widget_primitives.cpp:224
char * text_buffer
the buffer where text are written
Definition widget_primitives.h:238
void update_text_line_column_number(const unsigned char *font)
The max number of line with respect to frame height and font height.
Definition widget_primitives.cpp:302
void create_text_buffer()
create text buffer and delete the old one if already existing
Definition widget_primitives.cpp:257
void clear_line()
clean th full current line (writing " " in the text buffer)
Definition widget_primitives.cpp:218
void update_canvas_buffer_size(const unsigned char *font)
compute canvas width and height according to the size of the text (column x line ) and the size of th...
Definition widget_primitives.cpp:321
uint8_t tab_size
The number of space that ASCII character HT (aka TAB , "\t", 0x9) generates, default to 2.
Definition widget_primitives.h:190
void clear_text_buffer()
et text buffer memory to "0" and set character current line and column to 0
Definition widget_primitives.cpp:313
void next_char()
character column steps forward one position forward.
Definition widget_primitives.cpp:410
bool auto_next_char
auto_next_char flag : if true each char steps one position after being written.
Definition widget_primitives.h:197
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition widget_primitives.h:233
void process_char(char character)
interpret the character and draw it into the pixel buffer at the current line and column character po...
Definition widget_primitives.cpp:352
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition widget_primitives.h:231
uint8_t current_char_column
the column where the next character will be written.
Definition widget_primitives.h:173
void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a one-pixel width around the the frame
Definition widget_primitives.cpp:423
void next_line()
character line steps one position downward.
Definition widget_primitives.cpp:402
const unsigned char * font
The font used. Current font are defined according to IBM CP437. The font files are derived from https...
Definition widget_primitives.h:187
bool wrap
Wrap flag : if true, text wrap to the next line when end of line is reached.
Definition widget_primitives.h:193
data structure used to configure graphic framebuffer
Definition canvas.h:82
the data structure used to configure textual widget
Definition canvas.h:101