Merge symbols: solve conficts
This commit is contained in:
119
lv_objx/lv_img.c
119
lv_objx/lv_img.c
@@ -15,6 +15,10 @@
|
||||
#include "misc/fs/fsint.h"
|
||||
#include "misc/fs/ufs/ufs.h"
|
||||
|
||||
#if LV_IMG_ENABLE_SYMBOLS != 0
|
||||
#include "../lv_misc/text.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@@ -29,6 +33,8 @@
|
||||
static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t mode);
|
||||
static void lv_imgs_init(void);
|
||||
|
||||
static bool lv_img_is_symbol(const char * txt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
@@ -186,28 +192,53 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
|
||||
{
|
||||
lv_img_ext_t * ext = lv_obj_get_ext(img);
|
||||
|
||||
fs_file_t file;
|
||||
fs_res_t res;
|
||||
lv_img_raw_header_t header;
|
||||
uint32_t rn;
|
||||
|
||||
res = fs_open(&file, fn, FS_MODE_RD);
|
||||
if(res == FS_RES_OK) {
|
||||
res = fs_read(&file, &header, sizeof(header), &rn);
|
||||
}
|
||||
/*Handle normal images*/
|
||||
if(lv_img_is_symbol(fn) == false) {
|
||||
|
||||
/*Create a dummy header on fs error*/
|
||||
if(res != FS_RES_OK || rn != sizeof(header)) {
|
||||
header.w = lv_obj_get_width(img);
|
||||
header.h = lv_obj_get_height(img);
|
||||
header.transp = 0;
|
||||
fs_file_t file;
|
||||
fs_res_t res;
|
||||
lv_img_raw_header_t header;
|
||||
uint32_t rn;
|
||||
res = fs_open(&file, fn, FS_MODE_RD);
|
||||
if(res == FS_RES_OK) {
|
||||
res = fs_read(&file, &header, sizeof(header), &rn);
|
||||
}
|
||||
|
||||
/*Create a dummy header on fs error*/
|
||||
if(res != FS_RES_OK || rn != sizeof(header)) {
|
||||
header.w = lv_obj_get_width(img);
|
||||
header.h = lv_obj_get_height(img);
|
||||
header.transp = 0;
|
||||
}
|
||||
|
||||
fs_close(&file);
|
||||
|
||||
ext->w = header.w;
|
||||
ext->h = header.h;
|
||||
ext->transp = header.transp;
|
||||
|
||||
if(ext->upscale != 0) {
|
||||
ext->w *= 2;
|
||||
ext->h *= 2;
|
||||
}
|
||||
}
|
||||
/*Handle symbol texts*/
|
||||
else {
|
||||
#if LV_IMG_ENABLE_SYMBOLS
|
||||
lv_imgs_t * imgs = lv_obj_get_style(img);
|
||||
point_t size;
|
||||
txt_get_size(&size, fn, font_get(imgs->sym_font), 0, 0, LV_CORD_MAX);
|
||||
ext->w = size.x;
|
||||
ext->h = size.y;
|
||||
ext->transp = 0;
|
||||
#else
|
||||
/*Never goes here, just to be sure handle this */
|
||||
ext->w = lv_obj_get_width(img);
|
||||
ext->h = lv_obj_get_height(img);
|
||||
ext->transp = 0;
|
||||
#endif
|
||||
|
||||
fs_close(&file);
|
||||
|
||||
ext->w = header.w;
|
||||
ext->h = header.h;
|
||||
ext->transp = header.transp;
|
||||
}
|
||||
|
||||
if(ext->upscale != 0) {
|
||||
ext->w *= LV_DOWNSCALE;
|
||||
@@ -221,8 +252,9 @@ void lv_img_set_file(lv_obj_t * img, const char * fn)
|
||||
ext->fn = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(lv_img_get_auto_size(img) != false) {
|
||||
lv_obj_set_size(img, ext->w, ext->h);
|
||||
lv_obj_set_size(img, ext->w, ext->h);
|
||||
}
|
||||
|
||||
lv_obj_inv(img);
|
||||
@@ -241,6 +273,7 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en)
|
||||
ext->auto_size = (en == false ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enable the upscaling with LV_DOWNSCALE.
|
||||
* If enabled the object size will be same as the picture size.
|
||||
@@ -313,6 +346,17 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
if(ext->h == 0 || ext->w == 0) return true;
|
||||
area_t cords;
|
||||
/*Create a default style for symbol texts*/
|
||||
#if LV_IMG_ENABLE_SYMBOLS != 0
|
||||
bool sym = lv_img_is_symbol(ext->fn);
|
||||
lv_labels_t sym_style;
|
||||
lv_labels_get(LV_LABELS_DEF, &sym_style);
|
||||
sym_style.font = imgs_p->sym_font;
|
||||
sym_style.letter_space = 0;
|
||||
sym_style.line_space = 0;
|
||||
sym_style.mid = 0;
|
||||
sym_style.objs.color = imgs_p->objs.color;
|
||||
#endif
|
||||
|
||||
lv_obj_get_cords(img, &cords);
|
||||
opa_t opa = lv_obj_get_opa(img);
|
||||
@@ -325,13 +369,42 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t
|
||||
cords_tmp.x1 = cords.x1;
|
||||
cords_tmp.x2 = cords.x1 + ext->w - 1;
|
||||
for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
|
||||
lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn);
|
||||
|
||||
#if LV_IMG_ENABLE_SYMBOLS == 0
|
||||
lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn);
|
||||
#else
|
||||
if(sym == false) lv_draw_img(&cords_tmp, mask, imgs_p, opa, ext->fn);
|
||||
else lv_draw_label(&cords_tmp, mask, &sym_style, opa, ext->fn);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* From the settings in lv_conf.h and the file name
|
||||
* tells it a filename or a symbol text.
|
||||
* @param txt a file name (e.g. "U:/file1") or a symbol (e.g. SYMBOL_OK)
|
||||
* @return true: 'txt' is a symbol text, false: 'txt' is a file name
|
||||
*/
|
||||
static bool lv_img_is_symbol(const char * txt)
|
||||
{
|
||||
/*If the symbols are not enabled always tell false*/
|
||||
#if LV_IMG_ENABLE_SYMBOLS == 0
|
||||
return false;
|
||||
#endif
|
||||
|
||||
/* if txt begins with an upper case letter then it refers to a driver
|
||||
* so it is a file name*/
|
||||
if(txt[0] >= 'A' && txt[0] <= 'Z') return false;
|
||||
|
||||
/*If not returned during the above tests then it is symbol text*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the image styles
|
||||
*/
|
||||
@@ -340,7 +413,9 @@ static void lv_imgs_init(void)
|
||||
/*Default style*/
|
||||
lv_imgs_def.objs.color = COLOR_BLACK;
|
||||
lv_imgs_def.recolor_opa = OPA_TRANSP;
|
||||
|
||||
#if LV_IMG_ENABLE_SYMBOLS != 0
|
||||
lv_imgs_def.sym_font = LV_IMG_DEF_SYMBOL_FONT;
|
||||
#endif
|
||||
/*Dark style*/
|
||||
memcpy(&lv_imgs_dark, &lv_imgs_def, sizeof(lv_imgs_t));
|
||||
lv_imgs_dark.objs.color = COLOR_BLACK; lv_imgs_dark.recolor_opa = OPA_50;
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
#include "../lv_obj/lv_obj.h"
|
||||
#include "misc/fs/fsint.h"
|
||||
|
||||
#if LV_IMG_ENABLE_SYMBOLS
|
||||
#include "lv_label.h"
|
||||
#include "../lv_misc/fonts/symbol_def.h"
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
@@ -49,7 +54,10 @@ typedef struct
|
||||
{
|
||||
lv_objs_t objs; /*Style of ancestor*/
|
||||
/*New style element for this type */
|
||||
opa_t recolor_opa; /*Intensity of recoloring (OPA_TRANSP, OPA_10 ... OPA_COVER)*/
|
||||
opa_t recolor_opa; /*Intensity of recoloring (OPA_TRANSP, OPA_10 ... OPA_COVER)*/
|
||||
#if LV_IMG_ENABLE_SYMBOLS != 0
|
||||
font_types_t sym_font; /*Symbol font*/
|
||||
#endif
|
||||
}lv_imgs_t;
|
||||
|
||||
/*Built-in styles of image*/
|
||||
@@ -60,16 +68,18 @@ typedef enum
|
||||
LV_IMGS_DARK,
|
||||
}lv_imgs_builtin_t;
|
||||
|
||||
|
||||
/* Image header it is compatible with
|
||||
* the result image converter utility*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t w; /*Width of the image map*/
|
||||
uint16_t h; /*Height of the image map*/
|
||||
uint16_t cd; /*Color depth (8/16 or 24)*/
|
||||
uint16_t transp :1; /*1: Do not draw LV_IMG_TRANSP_COLOR pixels*/
|
||||
uint16_t w; /*Width of the image map*/
|
||||
uint16_t h; /*Height of the image map*/
|
||||
uint16_t cd; /*Color depth (8/16 or 24)*/
|
||||
uint16_t transp :1; /*1: Do not draw LV_IMG_TRANSP_COLOR pixels*/
|
||||
}lv_img_raw_header_t;
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
@@ -136,6 +146,7 @@ void lv_img_set_upscale(lv_obj_t * img, bool en);
|
||||
*/
|
||||
bool lv_img_get_auto_size(lv_obj_t * img);
|
||||
|
||||
|
||||
/**
|
||||
* Get the upscale enable attribute
|
||||
* @param img pointer to an image
|
||||
@@ -143,6 +154,10 @@ bool lv_img_get_auto_size(lv_obj_t * img);
|
||||
*/
|
||||
bool lv_img_get_upscale(lv_obj_t * img);
|
||||
|
||||
|
||||
lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
Reference in New Issue
Block a user