fb: cfb: Add cfb_draw_text() API
Add cfb_draw_text() API for rendering text. It is similar to cfb_print(), the difference is cfb_draw_text() accepts coordinate that is not on tile boundaries and don't wrap the line. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
This commit is contained in:
parent
ca5de12503
commit
5634691d8c
2 changed files with 28 additions and 3 deletions
|
|
@ -89,6 +89,20 @@ struct cfb_font {
|
|||
*/
|
||||
int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint16_t y);
|
||||
|
||||
/**
|
||||
* @brief Print a string into the framebuffer.
|
||||
* For compare to cfb_print, cfb_draw_text accept non tile-aligned coords
|
||||
* and not line wrapping.
|
||||
*
|
||||
* @param dev Pointer to device structure for driver instance
|
||||
* @param str String to print
|
||||
* @param x Position in X direction of the beginning of the string
|
||||
* @param y Position in Y direction of the beginning of the string
|
||||
*
|
||||
* @return 0 on success, negative value otherwise
|
||||
*/
|
||||
int cfb_draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y);
|
||||
|
||||
/**
|
||||
* @brief Clear framebuffer.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -183,7 +183,8 @@ static uint8_t draw_char_vtmono(const struct char_framebuffer *fb,
|
|||
return fptr->width;
|
||||
}
|
||||
|
||||
int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint16_t y)
|
||||
static int draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y,
|
||||
bool wrap)
|
||||
{
|
||||
const struct char_framebuffer *fb = &char_fb;
|
||||
const struct cfb_font *fptr;
|
||||
|
|
@ -201,11 +202,11 @@ int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint1
|
|||
|
||||
if ((fb->screen_info & SCREEN_INFO_MONO_VTILED)) {
|
||||
for (size_t i = 0; i < strlen(str); i++) {
|
||||
if (x + fptr->width > fb->x_res) {
|
||||
if ((x + fptr->width > fb->x_res) && wrap) {
|
||||
x = 0U;
|
||||
y += fptr->height;
|
||||
}
|
||||
x += fb->kerning + draw_char_vtmono(fb, str[i], x, y, true);
|
||||
x += fb->kerning + draw_char_vtmono(fb, str[i], x, y, wrap);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -214,6 +215,16 @@ int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint1
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
int cfb_draw_text(const struct device *dev, const char *const str, int16_t x, int16_t y)
|
||||
{
|
||||
return draw_text(dev, str, x, y, false);
|
||||
}
|
||||
|
||||
int cfb_print(const struct device *dev, const char *const str, uint16_t x, uint16_t y)
|
||||
{
|
||||
return draw_text(dev, str, x, y, true);
|
||||
}
|
||||
|
||||
int cfb_invert_area(const struct device *dev, uint16_t x, uint16_t y,
|
||||
uint16_t width, uint16_t height)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue