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"
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:
56
58 uint32_t blink_period_us{1000000};
59
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
106 std::vector<Widget *> widgets;
107
108public:
111
112
117 DisplayDevice *display_device = nullptr);
118
119 virtual ~Widget();
120
123 void add_widget(Widget *_sub_widget);
124
127 void set_display_device(DisplayDevice *_new_display_device);
128
133 virtual void draw() = 0;
134};
135
138class GraphicWidget : public Widget
139{
140private:
141
142
143protected:
146
148 size_t widget_width{128};
149
151 size_t widget_height{8};
152
156
160
163
166 void clear_widget();
167
169 virtual void get_value_of_interest() = 0;
170
171public:
174
179
183 void update_widget_anchor(uint8_t x, uint8_t y);
184
188 virtual void draw_border(ColorIndex color = ColorIndex::WHITE);
189
191 void show();
192
203 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
205 CanvasFormat canvas_format,
206 Model *displayed_object = nullptr);
207
214 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
216 CanvasFormat canvas_format,
217 Model *displayed_object = nullptr);
218
228 GraphicWidget(GraphicDisplayDevice *graphic_display_screen,
230 CanvasFormat canvas_format,
231 size_t frame_width, size_t frame_height,
232 Model *displayed_object = nullptr);
233
235 virtual ~GraphicWidget();
236
240
246 void hline(uint8_t x, uint8_t y, size_t w, ColorIndex color = ColorIndex::WHITE);
247
253 void vline(uint8_t x, uint8_t y, size_t h, ColorIndex color = ColorIndex::WHITE);
254
261 void line(int x0, int y0, int x1, int y1, ColorIndex color = ColorIndex::WHITE);
262
270 void rect(uint8_t start_x, uint8_t start_y, size_t w, size_t h, bool fill = false, ColorIndex color = ColorIndex::WHITE);
305 void circle(int radius, int x_center, int y_center, bool fill = false, ColorIndex color = ColorIndex::WHITE);
306};
307
311{
312private:
315
318
323 void write(char character, uint8_t char_column, uint8_t char_line);
324
326 void clear_line();
327
331 const unsigned char *font{nullptr};
332
334 uint8_t tab_size{2};
335
337 bool wrap{true};
338
340 bool auto_next_char{true};
341
346 void draw_glyph(const char character,
347 const uint8_t anchor_x, const uint8_t anchor_y);
348
349protected:
351 void create_text_buffer();
352
353public:
357 uint8_t number_of_line{0};
358
362
366 char *text_buffer = nullptr;
368
375 TextWidget(GraphicDisplayDevice *graphic_display_screen,
377 CanvasFormat canvas_format,
378 Model *displayed_object = nullptr);
379
388 TextWidget(GraphicDisplayDevice *graphic_display_screen,
390 CanvasFormat canvas_format,
391 size_t frame_width,
392 size_t frame_height,
393 Model *displayed_object = nullptr);
394
396 virtual ~TextWidget();
397
401 void update_text_frame_size(const unsigned char *font);
402
404 void clear_text_buffer();
405
409 void update_canvas_buffer_size(const unsigned char *font);
410
413 void write();
414
417 void write(const char *c_str);
418
438 void process_char(char character);
439
441 void next_line();
442
444 void next_char();
445
456 virtual void draw();
457
462 void draw_border(ColorIndex color = ColorIndex::WHITE);
463};
464
467class PrintWidget : public Widget
468{
469private:
470protected:
471
472
473public:
474
479virtual ~PrintWidget();
480};
CanvasFormat
the format of the canvas
Definition canvas.h:61
ColorIndex
define the code value for color
Definition canvas.h:27
bool blink_phase_changed
a flag that indicates the blinking phase has changed
Definition widget.h:61
int8_t previous_blinking_phase
store the value of the previous blinking phase.should be 0 or 1.
Definition widget.h:55
void set_blink_us(uint32_t blink_period=1000000)
Set the blink period in microseconds.
Definition widget.cpp:589
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:574
uint32_t blink_period_us
The period of the blinking, in microseconds.
Definition widget.h:58
bool has_blinking_changed()
return the status of the flag blink_phase_changed
Definition widget.cpp:594
void clear_blinking_phase_change()
set blink_phase_changed = False
Definition widget.cpp:599
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:33
This is the abstract class to handle all generic behavior of physical graphic display devices (e....
Definition display_device.h:58
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:217
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:159
struct_ConfigGraphicWidget get_graph_frame_config()
Get the graphic frame config object.
Definition widget.cpp:198
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:148
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:155
uint8_t widget_anchor_x
location in x of the widget within the hosting framebuffer
Definition widget.h:176
void clear_widget()
fill the graphic pixel buffer with 0x00.
Definition widget.cpp:561
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:566
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:211
uint8_t widget_border_width
this is the border size of the widget. 0 if no border, 1 if border
Definition widget.h:162
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:223
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:251
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:151
virtual ~GraphicWidget()
Destroy the Widget object.
Definition widget.cpp:190
uint8_t widget_anchor_y
location in y of the widget within the hosting framebuffer
Definition widget.h:178
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:266
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:52
Canvas * canvas
the associated canvas in which the widget writes text and draws graphics
Definition widget.h:173
bool widget_with_border
if true, the widget is surrounded by a one-pixel border
Definition widget.h:145
This is the Model abstract class of Model_View_Control design pattern.
Definition ui_core.h:37
PrintWidget(TerminalConsole *display_device, Model *actual_displayed_model=nullptr)
Construct a new Dummy Widget object.
Definition widget.cpp:604
A class dedicated to pure text display such as console, printer, ASCII character line display.
Definition display_device.h:100
uint8_t tab_size
The number of space that ASCII character HT (aka TAB , "\t", 0x9) generates, default to 2.
Definition widget.h:334
void create_text_buffer()
create text buffer and delete the old one if already existing
Definition widget.cpp:315
virtual void draw()
we need draw() to be compliant with the pure virtual draw() inherited from Widget.
Definition widget.cpp:542
void next_char()
character column steps forward one position forward.
Definition widget.cpp:496
void write()
process characters in the internal text buffer and draw it into the pixel buffer.
Definition widget.cpp:423
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.cpp:509
virtual ~TextWidget()
the destructor of TextWidget
Definition widget.cpp:379
bool auto_next_char
auto_next_char flag : if true each char steps one position after being written.
Definition widget.h:340
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:407
const unsigned char * font
The font used. Current font are defined according to IBM CP437. The font files are derived from https...
Definition widget.h:331
void next_line()
character line steps one position downward.
Definition widget.cpp:488
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:339
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:387
void draw_border(ColorIndex color=ColorIndex::WHITE)
draw a one-pixel width around the the frame
Definition widget.cpp:555
uint8_t number_of_column
The max number of line with respect to frame height and font height.
Definition widget.h:355
uint8_t current_char_line
the line number where the next character will be written.
Definition widget.h:314
void clear_text_buffer()
et text buffer memory to "0" and set character current line and column to 0
Definition widget.cpp:399
struct_ConfigTextWidget get_text_frame_config()
Get the text frame config object.
Definition widget.cpp:323
char * text_buffer
the buffer where text are written
Definition widget.h:366
void clear_line()
clean th full current line (writing " " in the text buffer)
Definition widget.cpp:309
size_t text_buffer_size
size of the buffer that contains text as string of characters.
Definition widget.h:364
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:438
uint8_t number_of_line
The max number of column with respect to frame width and font width.
Definition widget.h:357
bool wrap
Wrap flag : if true, text wrap to the next line when end of line is reached.
Definition widget.h:337
uint8_t current_char_column
the column where the next character will be written.
Definition widget.h:317
A widget is a displayed object on a device screen. This is the base widget, it is derived as GraphicW...
Definition widget.h:100
Widget(Model *actual_displayed_model, DisplayDevice *display_device=nullptr)
contructor for generic widget
Definition widget.cpp:10
Model * actual_displayed_model
a pointer to the Model actually displayed by the widget
Definition widget.h:103
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:110
void set_display_device(DisplayDevice *_new_display_device)
Set the display screen object.
Definition widget.cpp:36
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:106
data structure used to configure graphic framebuffer
Definition canvas.h:81
the data structure used to configure textual widget
Definition canvas.h:100
Basic drawing primitives for widgets.