mikroSDK Reference Manual

Text Writing API. More...

Functions list

void gl_draw_char (char ch, gl_coord_t x, gl_coord_t y)
 Write a single character on a display. More...
 
void gl_draw_text (const char *__generic text, gl_coord_t x, gl_coord_t y)
 Write a text on display. More...
 
gl_size_t gl_get_text_dimensions (const char *__generic text)
 Calculate text dimension. More...
 

Detailed Description

This API is used for writing and managing text on the display. Desired font must be generated by the resource manager from NECTO Studio.

Function Documentation

◆ gl_draw_char()

void gl_draw_char ( char  ch,
gl_coord_t  x,
gl_coord_t  y 
)

This function writes a single character on a display with top left pixel situated at given x and y coordinates. Character look depends on currently active font, pen, and orientation. Background color can also be specified. It is possible to rotate character using the gl_set_font_orientation. If the given character is written out of the display, the surplus will be cropped. Character that can be drawn is determined by the used font; if not supported by the font, it won't be printed and the behavior in that case is undefined. Character '\n' is not suported.

Parameters
[in]chCharacter to write.
[in]xX coordinate. See gl_coord_t definition for detailed explanation.
[in]yY coordinate. See gl_coord_t definition for detailed explanation.
Returns
Nothing.
Precondition
Before calling this function, be sure to initialize driver and font. Use gl_set_driver and gl_set_font for that purpose.
See also
gl_set_font gl_set_font_orientation gl_set_pen_color gl_set_font_background_color gl_set_font_background

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
#include "resource.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
void main()
{
uint8_t distance = 20;
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_clear(GL_CHARLESTON_GREEN); // clear display
// it's necesary to set the font
gl_set_font(test_font);
/*
* HORIZONTAL CHAR
* (x, y) coordinates determins top left of rect area that character is going to be drawn in
*/
gl_draw_char('H', 0, 0);
gl_draw_char('e', 13, 9);
gl_draw_char('l', 25, 19);
gl_draw_char('l', 30, 24);
gl_draw_char('o', 35, 32);
/*
* VERTICAL CHAR
* (x, y) coordinates determins bottom left of rect area that character is going to be drawn in
*/
gl_draw_char('w', 46, 55);
gl_draw_char('o', 55, 42);
gl_draw_char('r', 60, 30);
gl_draw_char('l', 65, 23);
gl_draw_char('d', 68, 18);
gl_draw_char('!', 70, 5);
// characters out of display will not be drawn at all
gl_draw_char('a', -50, 50); // left of display - invisible
gl_draw_char('b', gl_get_screen_width() + 50, 50); // right of display - invisible
gl_draw_char('c', 50, -50); // above the display - invisible
gl_draw_char('d', 50, gl_get_screen_height() + 50); // under the display - invisible
// characters on the border will be croped (by default border is set to display dimension)
gl_draw_char('e', -10, 100); // on the left line of display - cut off
gl_draw_char('F', gl_get_screen_width() - 10, 100); // on the right line of display - cut off
gl_draw_char('G', 100, 5); // on the top line of display - cut off
gl_draw_char('H', 100, gl_get_screen_height()+3); // on the bottom line of display - cut off
}

◆ gl_draw_text()

void gl_draw_text ( const char *__generic  text,
gl_coord_t  x,
gl_coord_t  y 
)

This function writes a text on a display with top left pixel situated at given x and y coordinates using current font and pen. To write a text with background use gl_set_font_background and gl_set_font_background_color. It is possible to choose text orientation using the gl_set_font_orientation. If a given text is written out of the display, the surplus will be cropped. Character that can be drawn is determined by the used font; if not supported by the font, it won't be printed and the behavior in that case is undefined. Character '\n' is not suported. If text is NULL nothing will be drawn.

Parameters
[in]textText to draw.
[in]xX coordinate. See gl_coord_t definition for detailed explanation.
[in]yY coordinate. See gl_coord_t definition for detailed explanation.
Returns
Nothing.
Precondition
Before calling this function, be sure to initialize driver and font. Use gl_set_driver and gl_set_font for that purpose.
See also
gl_set_font, gl_set_font_orientation, gl_set_pen_color, gl_set_font_background_color, gl_set_font_background.

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
#include "resource.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
static const char lorem[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.";
void main()
{
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_clear(GL_CHARLESTON_GREEN); // clear display
// before drawing text, font must be set
gl_set_font(test_font);
// horizontal and vertical text starts from same coordinates
// does not overlaps
gl_draw_text("Horizontal text", 50, 200); // drawing goes from given point to left display side
gl_draw_text("Vertical text", 50, 200); // drawing goes from given point to top display side
// vertical and vertical-column text starts from same coordinates
// does not overlaps
gl_draw_text("Column", 300, 200); // drawing goes from given point to bottom display side
gl_draw_text("Vertical text", 300, 200);
// horizontal and vertical-column text starts from same coordinates
// does overlaps
gl_draw_text("Horizontal text", 500, 200);
gl_draw_text("Column", 500, 200);
// special characters
gl_draw_text("Make sure your font supports any special characters you're using!", 100, 20);
gl_draw_text(NULL, 150, 160); // NULL pointers are ignored
// gl_draw_text("\t", 150, 160); // if character out of font is drawn, undefined behavior will occur
// gl_draw_text("Newline \n is not supported", 150, 180); // new line is not supported
}

◆ gl_get_text_dimensions()

gl_size_t gl_get_text_dimensions ( const char *__generic  text)

This function calculates text dimension. The size of the text depends on the font which has been set by gl_set_font.

Parameters
[in]textText to measure.
Returns
Size of text if font is set, otherwise returns size = {0, 0}. See gl_size_t definition for detailed explanation.
Precondition
Before calling this function, be sure to initialize font by calling gl_set_font.
See also
gl_draw_text, gl_draw_char, gl_set_font.

Example

#include "gl.h"
#include "board.h"
#include "tft8.h"
#include "resource.h"
#include "conversions.h"
static gl_driver_t driver;
static tft8_cfg_t tft_cfg;
static const char* strings[] =
{
"a",
"aa",
"ab",
"word",
"two words",
};
void print_dimension(gl_size_t size, gl_coord_t x, gl_coord_t y)
{
char buff[10];
uint16_to_str(size.width, buff);
gl_draw_text(buff, x, y);
uint16_to_str(size.height, buff);
gl_draw_text(buff, x + 30, y);
}
void main()
{
int y = 10;
gl_size_t dim;
// initialize driver
TFT8_MAP_PINOUTS_16BIT(tft_cfg);
tft_cfg.board = &TFT_BOARD_7_CAPACITIVE;
tft8_init(&tft_cfg, &driver);
// prepare display for drawing
gl_set_driver(&driver); // set initialized driver
gl_clear(GL_CHARLESTON_GREEN); // clear display
gl_set_font(test_font);
// strings
for (int i = 0; i < 5; i++)
{
dim = gl_get_text_dimensions(strings[i]);
gl_draw_text(strings[i], 10, y );
print_dimension(dim, dim.width + 30, y);
y += 30;
}
// NULL pointer for text argument returns 0,0
gl_draw_text("NULL ptr dimensions", 10, y);
print_dimension(dim, 300, y);
y += 30;
// empty string for text argument returns 0,0
gl_draw_text("Empty string dimensions", 10, y);
print_dimension(dim, 300, y);
return;
}
GL_FONT_VERTICAL_COLUMN
Definition: gl_types.h:87
gl_set_pen_color
void gl_set_pen_color(gl_color_t color)
Sets the active pen's color.
gl_size_t::height
gl_uint_t height
Definition: gl_types.h:121
uint16_to_str
void uint16_to_str(uint16_t input, char *output)
Converts uint16_t to string.
gl_set_font_orientation
void gl_set_font_orientation(gl_font_orientation_t orientation)
Sets the active font orientation.
gl_set_font
void gl_set_font(const uint8_t *font)
Initialize the active font.
gl_driver_t
The context structure for storing driver configuration.
Definition: gl_types.h:145
GL_GREEN
Definition: gl_colors.h:147
GL_RED
Definition: gl_colors.h:212
GL_FONT_HORIZONTAL
Definition: gl_types.h:85
GL_CHARLESTON_GREEN
Definition: gl_colors.h:246
GL_YELLOW
Definition: gl_colors.h:238
gl_draw_text
void gl_draw_text(const char *__generic text, gl_coord_t x, gl_coord_t y)
Write a text on display.
gl_get_screen_height
uint16_t gl_get_screen_height()
Returns the height of the display.
gl_set_driver
void gl_set_driver(gl_driver_t *driver)
Sets the driver to the active state and enables drawing on whole display.
gl_draw_char
void gl_draw_char(char ch, gl_coord_t x, gl_coord_t y)
Write a single character on a display.
conversions.h
Conversion function prototypes.
gl_get_screen_width
uint16_t gl_get_screen_width()
Returns the width of the display.
gl_coord_t
int16_t gl_coord_t
Definition: gl_types.h:102
gl_size_t::width
gl_uint_t width
Definition: gl_types.h:120
gl_clear
void gl_clear(gl_color_t color)
Paint whole display.
GL_FONT_VERTICAL
Definition: gl_types.h:86
gl.h
Graphics Library.
gl_get_text_dimensions
gl_size_t gl_get_text_dimensions(const char *__generic text)
Calculate text dimension.
gl_size_t
The context structure for storing width and height in number of pixels on the screen.
Definition: gl_types.h:118