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 "FreeRTOS.h"
19#include "task.h"
20#include "queue.h"
21#include "semphr.h"
22
23#include <vector>
24#include <string>
25
26#include "pico/stdlib.h"
29#define SSD1306_ASCII_FULL
30
31#include "font/5x8_font.h"
32#include "font/8x8_font.h"
33#include "font/12x16_font.h"
34#include "font/16x32_font.h"
35
37#define BACKSPACE '\b'
39#define HORIZONTAL_TAB '\t'
41#define LINE_FEED '\n'
43#define VERTICAL_TAB '\v'
45#define FORM_FEED '\f'
47#define CARRIAGE_RETURN '\r'
48
49class Model;
50class DisplayDevice;
51
56class Blinker
57{
58private:
60 int8_t previous_blinking_phase;
61
63 uint32_t blink_period_us{1000000};
64
66 bool blink_phase_changed;
67
68protected:
69public:
70 Blinker();
71 ~Blinker();
74 void set_blink_us(uint32_t blink_period = 1000000);
75
79
82
84 virtual void compute_blinking_phase();
85};
86
105{
106protected:
109
112
114 std::vector<Widget *> widgets;
115
116public:
121 DisplayDevice *graphic_display_device = nullptr);
122
123 virtual ~Widget();
124
127 void add_widget(Widget *_sub_widget);
128
131 void set_display_device(DisplayDevice *_new_display_device);
132
137 virtual void draw() = 0;
138};
139
142class GraphicWidget : public Widget
143{
144private:
153 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);
154
155protected:
158
160 size_t widget_width{128};
161
163 size_t widget_height{8};
164
168
172
175
178 void clear_widget();
179
181 virtual void get_value_of_interest() = 0;
182
183public:
186
191
194
198 void update_widget_anchor(uint8_t x, uint8_t y);
199
203 virtual void draw_border(ColorIndex color = ColorIndex::WHITE);
204
206 void show();
207
208
212 void send_image_to_DisplayGateKeeper(QueueHandle_t display_queue,SemaphoreHandle_t sending_done);
213
214
215
216
227 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
229 CanvasFormat canvas_format,
230 Model *displayed_object = nullptr);
231
238 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
240 CanvasFormat canvas_format,
241 Model *displayed_object = nullptr);
242
252 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
254 CanvasFormat canvas_format,
255 size_t frame_width, size_t frame_height,
256 Model *displayed_object = nullptr);
257
259 virtual ~GraphicWidget();
260
264
270 void hline(uint8_t x, uint8_t y, size_t w, ColorIndex color = ColorIndex::WHITE);
271
277 void vline(uint8_t x, uint8_t y, size_t h, ColorIndex color = ColorIndex::WHITE);
278
285 void line(int x0, int y0, int x1, int y1, ColorIndex color = ColorIndex::WHITE);
286
294 void rect(uint8_t start_x, uint8_t start_y, size_t w, size_t h, bool fill = false, ColorIndex color = ColorIndex::WHITE);
329 void circle(int radius, int x_center, int y_center, bool fill = false, ColorIndex color = ColorIndex::WHITE);
330};
331
335{
336private:
338 uint8_t current_char_line{0};
339
341 uint8_t current_char_column{0};
342
347 void write(char character, uint8_t char_column, uint8_t char_line);
348
350 void clear_line();
351
355 const unsigned char *font{nullptr};
356
358 uint8_t tab_size{2};
359
361 bool wrap{true};
362
364 bool auto_next_char{true};
365
370 void draw_glyph(const char character,
371 const uint8_t anchor_x, const uint8_t anchor_y);
372
373protected:
375 void create_text_buffer();
376
377public:
381 uint8_t number_of_line{0};
382
386
390 char *text_buffer = nullptr;
392
399 TextWidget(GraphicDisplayDevice *graphic_display_screen,
401 CanvasFormat canvas_format,
402 Model *displayed_object = nullptr);
403
412 TextWidget(GraphicDisplayDevice *graphic_display_screen,
414 CanvasFormat canvas_format,
415 size_t frame_width,
416 size_t frame_height,
417 Model *displayed_object = nullptr);
418
420 virtual ~TextWidget();
421
425 void update_text_frame_size(const unsigned char *font);
426
428 void clear_text_buffer();
429
433 void update_canvas_buffer_size(const unsigned char *font);
434
437 void write();
438
441 void write(const char *c_str);
442
462 void process_char(char character);
463
465 void next_line();
466
468 void next_char();
469
480 void draw();
481
486 void draw_border(ColorIndex color = ColorIndex::WHITE);
487};
488
491class PrintWidget : public Widget
492{
493private:
494protected:
495public:
500 virtual ~PrintWidget();
501};
CanvasFormat
the format of the canvas
Definition canvas.h:61
ColorIndex
define the code value for color
Definition canvas.h:27
void set_blink_us(uint32_t blink_period=1000000)
Set the blink period in microseconds.
Definition widget.cpp:671
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:656
bool has_blinking_changed()
return the status of the flag blink_phase_changed
Definition widget.cpp:676
void clear_blinking_phase_change()
set blink_phase_changed = False
Definition widget.cpp:681
The canvas is a virtual memory in which the widget draws.
Definition canvas.h:129
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:238
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:171
struct_ConfigGraphicWidget get_graph_frame_config()
Get the graphic frame config object.
Definition widget.cpp:219
struct_DataToShow data_to_display
the data structure used to send the canvas to the display task when a FreeRTOS queue is used.
Definition widget.h:193
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:160
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:167
uint8_t widget_anchor_x
location in x of the widget within the hosting framebuffer
Definition widget.h:188
void clear_widget()
fill the graphic pixel buffer with 0x00.
Definition widget.cpp:623
void send_image_to_DisplayGateKeeper(QueueHandle_t display_queue, SemaphoreHandle_t sending_done)
used with FreeRTOS. send the widget data_to_display structure to the task in charge of the display ma...
Definition widget.cpp:52
void show()
A short way to call GraphicDisplayDevice::show(&canvas, anchor x, anchor y)
Definition widget.cpp:47
void update_widget_anchor(uint8_t x, uint8_t y)
Modify the anchor of the widget on the display screen.
Definition widget.cpp:628
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:232
uint8_t widget_border_width
this is the border size of the widget. 0 if no border, 1 if border
Definition widget.h:174
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:244
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:272
virtual void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a rectangle around the widget.
Definition widget.cpp:41
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:163
virtual ~GraphicWidget()
Destroy the Widget object.
Definition widget.cpp:211
uint8_t widget_anchor_y
location in y of the widget within the hosting framebuffer
Definition widget.h:190
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:287
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:59
Canvas * canvas
the associated canvas in which the widget writes text and draws graphics
Definition widget.h:185
bool widget_with_border
if true, the widget is surrounded by a one-pixel border
Definition widget.h:157
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:686
A class dedicated to pure text display such as console, printer, ASCII character line display.
Definition display_device.h:95
void create_text_buffer()
create text buffer and delete the old one if already existing
Definition widget.cpp:336
void draw()
we need draw() to be compliant with the pure virtual draw() inherited from Widget.
Definition widget.cpp:563
void next_char()
character column steps forward one position forward.
Definition widget.cpp:517
void write()
process characters in the internal text buffer and draw it into the pixel buffer.
Definition widget.cpp:444
virtual ~TextWidget()
the destructor of TextWidget
Definition widget.cpp:400
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:428
void next_line()
character line steps one position downward.
Definition widget.cpp:509
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:360
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:408
void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a one-pixel width around the the frame
Definition widget.cpp:576
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition widget.h:379
void clear_text_buffer()
et text buffer memory to "0" and set character current line and column to 0
Definition widget.cpp:420
struct_ConfigTextWidget get_text_frame_config()
Get the text frame config object.
Definition widget.cpp:344
char * text_buffer
the buffer where text are written
Definition widget.h:390
size_t text_buffer_size
size of the buffer that contains text as string of characters.
Definition widget.h:388
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:459
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition widget.h:381
Model * actual_displayed_model
a pointer to the Model actually displayed by the widget
Definition widget.h:111
void add_widget(Widget *_sub_widget)
add sub_widget to the current widget
Definition widget.cpp:31
DisplayDevice * display_device
the display device where the attached to the frame buffer
Definition widget.h:108
void set_display_device(DisplayDevice *_new_display_device)
Set the display screen object.
Definition widget.cpp:36
Widget(Model *actual_displayed_model, DisplayDevice *graphic_display_device=nullptr)
contructor for generic widget
Definition widget.cpp:10
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:114
data structure used to configure graphic framebuffer
Definition canvas.h:81
the data structure used to configure textual widget
Definition canvas.h:100
data structure used to queue data to send to the display task
Definition display_device.h:77