C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
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
27
29#define BACKSPACE '\b'
31#define HORIZONTAL_TAB '\t'
33#define LINE_FEED '\n'
35#define VERTICAL_TAB '\v'
37#define FORM_FEED '\f'
39#define CARRIAGE_RETURN '\r'
40
41
44{
45protected:
47 bool widget_with_border{false};
48
50 size_t widget_width{128};
51
53 size_t widget_height{8};
54
58
62
63public:
68 CanvasFormat canvas_format);
69
74 CanvasFormat canvas_format);
75
82 CanvasFormat canvas_format, size_t frame_width,
83 size_t frame_height);
84 virtual ~GraphicDrawer();
85
90 void clear_widget();
93
99 void hline(uint8_t x, uint8_t y, size_t w, ColorIndex color = ColorIndex::WHITE);
100
106 void vline(uint8_t x, uint8_t y, size_t h, ColorIndex color = ColorIndex::WHITE);
107
114 void line(int x0, int y0, int x1, int y1, ColorIndex color = ColorIndex::WHITE);
115
123 void rect(uint8_t start_x, uint8_t start_y, size_t w, size_t h, bool fill = false, ColorIndex color = ColorIndex::WHITE);
158 void circle(int radius, int x_center, int y_center, bool fill = false, ColorIndex color = ColorIndex::WHITE);
159
163 virtual void draw_border(ColorIndex color = ColorIndex::WHITE);
164};
165
169{
170private:
173
176
181 void write(char character, uint8_t char_column, uint8_t char_line);
182
184 void clear_line();
185
189 const unsigned char *font{nullptr};
190
192 uint8_t tab_size{2};
193
195 bool wrap{true};
196
198 bool auto_next_char{true};
199
204 void draw_glyph(const char character,
205 const uint8_t anchor_x, const uint8_t anchor_y);
206
207protected:
209 void create_text_buffer();
210
211public:
217 CanvasFormat canvas_format);
218
226 CanvasFormat canvas_format,
227 size_t frame_width,
228 size_t frame_height);
229 ~TextWriter();
230
234 uint8_t number_of_line{0};
235
239 char *text_buffer = nullptr;
241
245 void update_text_line_column_number(const unsigned char *font);
246
248 void clear_text_buffer();
249
253 void update_canvas_buffer_size(const unsigned char *font);
254
257 void write();
258
261 void write(const char *c_str);
262
282 void process_char(char character);
283
285 void next_line();
286
288 void next_char();
289
294 void draw_border(ColorIndex color = ColorIndex::WHITE);
295};
CanvasFormat
the format of the canvas
Definition canvas.h:61
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:129
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:57
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:61
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:87
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:50
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:47
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:92
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:53
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:169
size_t text_buffer_size
size of the buffer that contains text as string of characters.
Definition widget_primitives.h:237
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:172
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:239
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:192
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:198
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition widget_primitives.h:234
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:232
uint8_t current_char_column
the column where the next character will be written.
Definition widget_primitives.h:175
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:189
bool wrap
Wrap flag : if true, text wrap to the next line when end of line is reached.
Definition widget_primitives.h:195
data structure used to configure graphic framebuffer
Definition canvas.h:81
the data structure used to configure textual widget
Definition canvas.h:100