C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
TextWriter Class Reference

A class dedicated to text drawing within a widget. More...

#include <widget_primitives.h>

Inheritance diagram for TextWriter:
Inheritance graph
Collaboration diagram for TextWriter:
Collaboration graph

Public Member Functions

 TextWriter (struct_ConfigTextWidget text_cfg, CanvasFormat canvas_format)
 Construct a new Text Writer object.
 
 TextWriter (struct_ConfigTextWidget text_cfg, CanvasFormat canvas_format, size_t frame_width, size_t frame_height)
 Construct a new Text Widget object.
 
void update_text_line_column_number (const unsigned char *font)
 The max number of line with respect to frame height and font height.
 
void clear_text_buffer ()
 et text buffer memory to "0" and set character current line and column to 0
 
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 the bitmap font. Delete the previous pixel buffer if any and create a new buffer.
 
void write ()
 process characters in the internal text buffer and draw it into the pixel buffer.
 
void write (const char *c_str)
 process the string c_str and then draw each character into the pixel buffer, without using the text buffer.
 
void process_char (char character)
 interpret the character and draw it into the pixel buffer at the current line and column character position.
 
void next_line ()
 character line steps one position downward.
 
void next_char ()
 character column steps forward one position forward.
 
void draw_border (ColorIndex color=ColorIndex::WHITE)
 draw a one-pixel width around the the frame
 
- Public Member Functions inherited from GraphicDrawer
 GraphicDrawer (struct_ConfigGraphicWidget graph_cfg, CanvasFormat canvas_format)
 Constructor of the GraphicDrawer class.
 
 GraphicDrawer (struct_ConfigTextWidget text_cfg, CanvasFormat canvas_format)
 Constructor of the GraphicDrawer class.
 
 GraphicDrawer (struct_ConfigTextWidget text_cfg, CanvasFormat canvas_format, size_t frame_width, size_t frame_height)
 Constructor of the GraphicDrawer class.
 
void clear_widget ()
 fill the graphic pixel buffer with 0x00.
 
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.
 
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.
 
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,y1)
 
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.
 
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.org/wiki/Algorithme_de_trac%C3%A9_d%27arc_de_cercle_de_Bresenham https://en.wikipedia.org/wiki/Midpoint_circle_algorithm procédure tracerCercle (entier rayon, entier x_centre, entier y_centre) déclarer entier x, y, m ; x ← 0 ; y ← rayon ; // on se place en haut du cercle m ← 5 - 4*rayon ; // initialisation Tant que x <= y // tant qu'on est dans le second octant tracerPixel( x+x_centre, y+y_centre ) ; tracerPixel( y+x_centre, x+y_centre ) ; tracerPixel( -x+x_centre, y+y_centre ) ; tracerPixel( -y+x_centre, x+y_centre ) ; tracerPixel( x+x_centre, -y+y_centre ) ; tracerPixel( y+x_centre, -x+y_centre ) ; tracerPixel( -x+x_centre, -y+y_centre ) ; tracerPixel( -y+x_centre, -x+y_centre ) ; si m > 0 alors //choix du point F y ← y - 1 ; m ← m - 8*y ; fin si ; x ← x + 1 ; m ← m + 8*x + 4 ; fin tant que ; fin de procédure ;
 

Public Attributes

uint8_t number_of_column {0}
 The max number of line with respect to frame height and font height.
 
uint8_t number_of_line {0}
 The max number of column with respect to frame width and font width.
 
size_t text_buffer_size
 size of the buffer that contains text as string of characters.
 
char * text_buffer = nullptr
 the buffer where text are written
 
- Public Attributes inherited from GraphicDrawer
uint8_t widget_border_width
 this is the border size of the widget. 0 if no border, 1 if border
 
Canvascanvas
 the associated canvas in which the widget writes text and draws graphics
 

Protected Member Functions

void create_text_buffer ()
 create text buffer and delete the old one if already existing
 

Private Member Functions

void write (char character, uint8_t char_column, uint8_t char_line)
 a graphic primitive to draw a character at a character position
 
void clear_line ()
 clean th full current line (writing " " in the text buffer)
 
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 organisation.
 

Private Attributes

uint8_t current_char_line {0}
 the line number where the next character will be written.
 
uint8_t current_char_column {0}
 the column where the next character will be written.
 
const unsigned char * font {nullptr}
 The font used. Current font are defined according to IBM CP437. The font files are derived from https://github.com/Harbys/pico-ssd1306 works. They come is size 5x8, 8x8, 12x16 and 16x32.
 
uint8_t tab_size {2}
 The number of space that ASCII character HT (aka TAB , "\t", 0x9) generates, default to 2.
 
bool wrap {true}
 Wrap flag : if true, text wrap to the next line when end of line is reached.
 
bool auto_next_char {true}
 auto_next_char flag : if true each char steps one position after being written.
 

Additional Inherited Members

- Protected Attributes inherited from GraphicDrawer
bool widget_with_border {false}
 if true, the widget is surrounded by a one-pixel border
 
size_t widget_width {128}
 As a widget can be surrounded by a border, the actual widget width is not the associated framebuffer width.
 
size_t widget_height {8}
 As a widget can be surrounded by a border, the actual widget height is not the associated framebuffer height.
 
uint8_t widget_start_x
 this is the actual horizontal start of the widget drawing area, taken into account the presence of border.
 
uint8_t widget_start_y
 this is the actual vertical start of the widget drawing area, taken into account the presence of border.
 

Detailed Description

A class dedicated to text drawing within a widget.

Constructor & Destructor Documentation

◆ TextWriter() [1/2]

TextWriter::TextWriter ( struct_ConfigTextWidget text_cfg,
CanvasFormat canvas_format )

Construct a new Text Writer object.

Note
USAGE: when the text frame is defined by the number of characters width and height.
Parameters
text_cfgthe configuration data for the textual frame
canvas_formatthe format of the associated canvas (see CanvasFormat)
Here is the call graph for this function:

◆ TextWriter() [2/2]

TextWriter::TextWriter ( struct_ConfigTextWidget text_cfg,
CanvasFormat canvas_format,
size_t frame_width,
size_t frame_height )

Construct a new Text Widget object.

Note
USAGE: when the text frame is defined by the frame size width and height in pixel.
Parameters
text_cfgthe configuration data for the textual frame
canvas_formatthe format of the associated canvas (see CanvasFormat)
frame_widththe frame size width
frame_heightthe frame size height
Here is the call graph for this function:

Member Function Documentation

◆ draw_border()

void TextWriter::draw_border ( ColorIndex color = ColorIndex::WHITE)
virtual

draw a one-pixel width around the the frame

Note
This border can overwrite the characters! To be improve with the use of pixel frame memory not based on byte page such as the OLED SSD1306.
Parameters
color

Reimplemented from GraphicDrawer.

Here is the call graph for this function:

◆ draw_glyph()

void TextWriter::draw_glyph ( const char character,
const uint8_t anchor_x,
const uint8_t anchor_y )
private

a graphic primitive to draw a character at a pixel position. Strongly dependent on font memory organisation.

Parameters
characterthe character to draw
anchor_xthe pixel position on x-axis to start drawing the character (upper left corner)
anchor_ythe pixel position on y-axis to start drawing the character (upper left corner)
Here is the caller graph for this function:

◆ process_char()

void TextWriter::process_char ( char character)

interpret the character and draw it into the pixel buffer at the current line and column character position.

Text wrapping is done if wrap flag is true. Character position steps forward according to auto_next_char flag.

Some special characters are processed:

  • "LINE_FEED" (\n 0x0A) : line position steps forward, column position is set to 0.
  • "BACKSPACE" (\b 0x08) : column position steps backward, a space (" ") character is overwritten.
  • "FORM_FEED" (\f 0x0C) : the text buffer is cleared.
  • "CARRIAGE_RETURN" (\r 0x0D) : column position is set to 0.
  • "HORIZONTAL_TAB" (\t 0x09) : " " characters are added according to tab_size configuration value.
    Parameters
    character
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_canvas_buffer_size()

void TextWriter::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 the bitmap font. Delete the previous pixel buffer if any and create a new buffer.

Parameters
fontthe new font

◆ update_text_line_column_number()

void TextWriter::update_text_line_column_number ( const unsigned char * font)

The max number of line with respect to frame height and font height.

Compute the text size in column x line according to the size of the font and the size of the frame in pixel. Delete the previous text buffer if any and create a new buffer.

Parameters
fontthe new font
Here is the call graph for this function:

◆ write() [1/3]

void TextWriter::write ( )

process characters in the internal text buffer and draw it into the pixel buffer.

Note
USAGE: this is useful if we have to fill the text_buffer, e.g. with sprintf and formatted text.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/3]

void TextWriter::write ( char character,
uint8_t char_column,
uint8_t char_line )
private

a graphic primitive to draw a character at a character position

Parameters
characterthe foreground color of the character. The font is given by the frame_text_config
char_columnthe column position of the character
char_linethe line position of the character
Here is the call graph for this function:

◆ write() [3/3]

void TextWriter::write ( const char * c_str)

process the string c_str and then draw each character into the pixel buffer, without using the text buffer.

Parameters
c_strA C_style character string.
Here is the call graph for this function:

The documentation for this class was generated from the following files: