C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
widget.h
Go to the documentation of this file.
1
11
12#pragma once
13
15#include "sw/ui_core/ui_core.h"
16#include "sw/widget/canvas.h"
17
18#include <vector>
19#include <string>
20
21#include "pico/stdlib.h"
24#define SSD1306_ASCII_FULL
25
26#include "font/5x8_font.h"
27#include "font/8x8_font.h"
28#include "font/12x16_font.h"
29#include "font/16x32_font.h"
30
32#define BACKSPACE '\b'
34#define HORIZONTAL_TAB '\t'
36#define LINE_FEED '\n'
38#define VERTICAL_TAB '\v'
40#define FORM_FEED '\f'
42#define CARRIAGE_RETURN '\r'
43
44class Model;
45class DisplayDevice;
46
51class Blinker
52{
53private:
55 int8_t previous_blinking_phase;
56
58 uint32_t blink_period_us{1000000};
59
61 bool blink_phase_changed;
62
63protected:
64public:
65 Blinker();
66 ~Blinker();
69 void set_blink_us(uint32_t blink_period = 1000000);
70
74
77
79 virtual void compute_blinking_phase();
80};
81
99class Widget
100{
101protected:
104
107
109 std::vector<Widget *> widgets;
110
111public:
116 DisplayDevice *graphic_display_device = nullptr);
117
118 ~Widget();
119
122 void add_widget(Widget *_sub_widget);
123
126 void set_display_device(DisplayDevice *_new_display_device);
127
132 virtual void draw() = 0;
133};
134
137class GraphicWidget : public Widget
138{
139private:
148 void ellipse(uint8_t x_center, uint8_t y_center, uint8_t x_radius, uint8_t y_radius, bool fill, uint8_t quadrant, ColorIndex color);
149
150protected:
153
155 size_t widget_width{128};
156
158 size_t widget_height{8};
159
163
167
170
173 void clear_widget();
174
176 virtual void get_value_of_interest() = 0;
177
178public:
181
188
193
197 void update_widget_anchor(uint8_t x, uint8_t y);
198
202 virtual void draw_border(ColorIndex color = ColorIndex::WHITE);
203
205 void show();
206
217 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
219 CanvasFormat canvas_format,
220 Model *displayed_object = nullptr);
221
228 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
230 CanvasFormat canvas_format,
231 Model *displayed_object = nullptr);
232
242 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
244 CanvasFormat canvas_format,
245 size_t frame_width, size_t frame_height,
246 Model *displayed_object = nullptr);
247
250
254
260 void hline(uint8_t x, uint8_t y, size_t w, ColorIndex color = ColorIndex::WHITE);
261
267 void vline(uint8_t x, uint8_t y, size_t h, ColorIndex color = ColorIndex::WHITE);
268
275 void line(int x0, int y0, int x1, int y1, ColorIndex color = ColorIndex::WHITE);
276
284 void rect(uint8_t start_x, uint8_t start_y, size_t w, size_t h, bool fill = false, ColorIndex color = ColorIndex::WHITE);
319 void circle(int radius, int x_center, int y_center, bool fill = false, ColorIndex color = ColorIndex::WHITE);
320};
321
325{
326private:
328 uint8_t current_char_line{0};
329
331 uint8_t current_char_column{0};
332
337 void write(char character, uint8_t char_column, uint8_t char_line);
338
340 void clear_line();
341
345 const unsigned char *font{nullptr};
346
348 uint8_t tab_size{2};
349
351 bool wrap{true};
352
354 bool auto_next_char{true};
355
360 void draw_glyph(const char character,
361 const uint8_t anchor_x, const uint8_t anchor_y);
362
363protected:
365 void create_text_buffer();
366
367public:
371 uint8_t number_of_line{0};
372
376
380 char *text_buffer = nullptr;
382
389 TextWidget(GraphicDisplayDevice *graphic_display_screen,
391 CanvasFormat canvas_format,
392 Model *displayed_object = nullptr);
393
402 TextWidget(GraphicDisplayDevice *graphic_display_screen,
404 CanvasFormat canvas_format,
405 size_t frame_width,
406 size_t frame_height,
407 Model *displayed_object = nullptr);
408
410 ~TextWidget();
411
415 void update_text_frame_size(const unsigned char *font);
416
418 void clear_text_buffer();
419
423 void update_canvas_buffer_size(const unsigned char *font);
424
427 void write();
428
431 void write(const char *c_str);
432
452 void process_char(char character);
453
455 void next_line();
456
458 void next_char();
459
470 void draw();
471
476 void draw_border(ColorIndex color = ColorIndex::WHITE);
477};
478
481class PrintWidget : public Widget
482{
483private:
484protected:
485public:
490 ~PrintWidget();
491};
CanvasFormat
the format of the canvas
Definition canvas.h:60
ColorIndex
define the code value for color
Definition canvas.h:26
void set_blink_us(uint32_t blink_period=1000000)
Set the blink period in microseconds.
Definition widget.cpp:608
virtual void compute_blinking_phase()
compute if the system clock divided by the blink_period is odd or even and if this has changed since ...
Definition widget.cpp:593
bool has_blinking_changed()
return the status of the flag blink_phase_changed
Definition widget.cpp:613
void clear_blinking_phase_change()
set blink_phase_changed = False
Definition widget.cpp:618
The canvas is a virtual memory in which the widget draws.
Definition canvas.h:121
A generic class for all display device.
Definition display_device.h:19
This is the abstract class to handle all generic behavior of physical graphic display devices (e....
Definition display_device.h:30
virtual void get_value_of_interest()=0
A pure virtual method that results in the transfer of the displayed values of the displayed model to ...
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.cpp:191
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.h:166
struct_ConfigGraphicWidget get_graph_frame_config()
Get the graphic frame config object.
Definition widget.cpp:172
size_t widget_width
As a widget can be surrounded by a border, the actual widget width is not the associated framebuffer ...
Definition widget.h:155
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.h:162
uint8_t widget_anchor_x
location in x of the widget within the hosting framebuffer
Definition widget.h:190
ColorIndex fg_color
the foregroung color of the graphic frame //TODO voir si fg_color n'est pas mieux dans canvas
Definition widget.h:184
void clear_widget()
fill the graphic pixel buffer with 0x00.
Definition widget.cpp:560
void show()
A short way to call GraphicDisplayDevice::show(&canvas, anchor x, anchor y)
Definition widget.cpp:39
void update_widget_anchor(uint8_t x, uint8_t y)
Modify the anchor of the widget on the display screen.
Definition widget.cpp:565
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.cpp:185
uint8_t widget_border_width
this is the border size of the widget. 0 if no border, 1 if border
Definition widget.h:169
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.cpp:197
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.cpp:225
virtual void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a rectangle around the widget.
Definition widget.cpp:33
size_t widget_height
As a widget can be surrounded by a border, the actual widget height is not the associated framebuffer...
Definition widget.h:158
~GraphicWidget()
Destroy the Widget object.
Definition widget.cpp:167
uint8_t widget_anchor_y
location in y of the widget within the hosting framebuffer
Definition widget.h:192
ColorIndex bg_color
the background color of the graphic frame //TODO voir si bg_color n'est pas mieux dans canvas
Definition widget.h:187
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.cpp:240
GraphicWidget(GraphicDisplayDevice *graphic_display_screen, struct_ConfigGraphicWidget graph_cfg, CanvasFormat canvas_format, Model *displayed_object=nullptr)
Construct a new Graphic Widget object.
Definition widget.cpp:44
Canvas * canvas
the associated canvas in which the widget writes text and draws graphics
Definition widget.h:180
bool widget_with_border
if true, the widget is surrounded by a one-pixel border
Definition widget.h:152
This is the Model abstract class of Model_View_Control design pattern.
Definition ui_core.h:67
PrintWidget(PrinterDevice *display_device, Model *actual_displayed_model=nullptr)
Construct a new Dummy Widget object.
Definition widget.cpp:623
A class dedicated to pure text display such as console, printer, ASCII character line display.
Definition display_device.h:76
void create_text_buffer()
create text buffer and delete the old one if already existing
Definition widget.cpp:289
void draw()
we need draw() to be compliant with the pure virtual draw() inherited from Widget.
Definition widget.cpp:500
void next_char()
character column steps forward one position forward.
Definition widget.cpp:454
void write()
process characters in the internal text buffer and draw it into the pixel buffer.
Definition widget.cpp:381
~TextWidget()
the destructor of TextWidget
Definition widget.cpp:346
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.cpp:371
void next_line()
character line steps one position downward.
Definition widget.cpp:446
TextWidget(GraphicDisplayDevice *graphic_display_screen, struct_ConfigTextWidget text_cfg, CanvasFormat canvas_format, Model *displayed_object=nullptr)
The max number of line with respect to frame height and font height.
Definition widget.cpp:313
void update_text_frame_size(const unsigned char *font)
Compute the text size in column x line according to the size of the font and the size of the frame in...
Definition widget.cpp:351
void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a one-pixel width around the the frame
Definition widget.cpp:513
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition widget.h:369
void clear_text_buffer()
et text buffer memory to "0" and set character current line and column to 0
Definition widget.cpp:363
struct_ConfigTextWidget get_text_frame_config()
Get the text frame config object.
Definition widget.cpp:297
char * text_buffer
the buffer where text are written
Definition widget.h:380
size_t text_buffer_size
size of the buffer that contains text as string of characters.
Definition widget.h:378
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.cpp:396
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition widget.h:371
Model * actual_displayed_model
a pointer to the Model actually displayed by the widget
Definition widget.h:106
void add_widget(Widget *_sub_widget)
add sub_widget to the current widget
Definition widget.cpp:23
DisplayDevice * display_device
the display device where the attached to the frame buffer
Definition widget.h:103
void set_display_device(DisplayDevice *_new_display_device)
Set the display screen object.
Definition widget.cpp:28
Widget(Model *actual_displayed_model, DisplayDevice *graphic_display_device=nullptr)
contructor for generic widget
Definition widget.cpp:8
virtual void draw()=0
a pure virtual member that is called to effectively draw the widget.
std::vector< Widget * > widgets
A widget can be composed by several widgets.
Definition widget.h:109
data structure used to configure graphic framebuffer
Definition canvas.h:73
the data structure used to configure textual widget
Definition canvas.h:92