From 467fd77a28dbeb9087128338ee97192a49cddf83 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 6 Sep 2018 01:28:58 +0200 Subject: [PATCH 1/3] lv_theme: add live update feature --- lv_conf_templ.h | 15 ++++++++---- lv_themes/lv_theme.c | 57 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/lv_conf_templ.h b/lv_conf_templ.h index 3742ab927..e8d83641b 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -24,11 +24,6 @@ #define LV_MEM_CUSTOM_ALLOC malloc /*Wrapper to malloc*/ #define LV_MEM_CUSTOM_FREE free /*Wrapper to free*/ #endif /*LV_MEM_CUSTOM*/ -#define LV_TICK_CUSTOM 0 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */ -#if LV_TICK_CUSTOM == 1 -#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the sys time function*/ -#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ -#endif /*LV_TICK_CUSTOM*/ /*=================== Graphical settings @@ -95,6 +90,14 @@ #define LV_COMPILER_NON_CONST_INIT_SUPPORTED 0 /* 1: Initialization with non constant values are supported (In Visual studio it is not supported)*/ //#define _CRT_SECURE_NO_WARNINGS /* Visual Studio needs it to use `strcpy`, `sprintf` etc*/ +/*HAL settings*/ +#define LV_TICK_CUSTOM 0 /*1: use a custom tick source (removing the need to manually update the tick with `lv_tick_inc`) */ +#if LV_TICK_CUSTOM == 1 +#define LV_TICK_CUSTOM_INCLUDE "Arduino.h" /*Header for the sys time function*/ +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (millis()) /*Expression evaluating to current systime in ms*/ +#endif /*LV_TICK_CUSTOM*/ + + /*Log settings*/ #define USE_LV_LOG 1 /*Enable/disable the log module*/ #if USE_LV_LOG @@ -113,6 +116,8 @@ /*================ * THEME USAGE *================*/ +#define LV_THEME_LIVE_UPDATE 0 /*Enable to change the theme in run time. Requires 8..10 kB extra RAM*/ + #define USE_LV_THEME_TEMPL 0 /*Just for test*/ #define USE_LV_THEME_DEFAULT 0 /*Built mainly from the built-in styles. Consumes very few RAM*/ #define USE_LV_THEME_ALIEN 0 /*Dark futuristic theme*/ diff --git a/lv_themes/lv_theme.c b/lv_themes/lv_theme.c index b55f4e1fe..a1c8ee2e5 100644 --- a/lv_themes/lv_theme.c +++ b/lv_themes/lv_theme.c @@ -7,6 +7,7 @@ * INCLUDES *********************/ #include "lv_theme.h" +#include "../lv_core/lv_obj.h" /********************* * DEFINES @@ -23,7 +24,23 @@ /********************** * STATIC VARIABLES **********************/ + +#if LV_THEME_LIVE_UPDATE == 0 static lv_theme_t * current_theme; +#else +/* If live update is used then a big `lv_style_t` array is used to store the real styles of the theme not only pointers. + * On `lv_theme_set_current` the styles of the theme are copied to this array. + * The pointers in `current_theme` are initialized to point to the styles in the array. + * This way the theme styles will always point to the same memory address even after theme is change. + * (The pointers in the theme points to the styles declared by the theme itself) */ + +/* Store the styles in this array. + * Can't determine the size in compile time because sizeof is not evaluated (should be `sizeof(lv_theme_t) / sizeof(lv_style_t*)`). + * Error will be generated in run time if too small.*/ +static lv_style_t th_styles[100]; +static bool inited = false; +static lv_theme_t current_theme; +#endif /********************** * MACROS @@ -38,9 +55,42 @@ static lv_theme_t * current_theme; * From now, all the created objects will use styles from this theme by default * @param th pointer to theme (return value of: 'lv_theme_init_xxx()') */ -void lv_theme_set_current(lv_theme_t * th) +void lv_theme_set_current(lv_theme_t *th) { +#if LV_THEME_LIVE_UPDATE == 0 current_theme = th; +#else + uint32_t style_num = sizeof(lv_theme_t) / sizeof(lv_style_t*); /*Number of styles in a theme*/ + + if(!inited) { + /*It's not sure `th_styles` is big enough. Check it now!*/ + if(style_num > sizeof(th_styles) / sizeof(lv_style_t)) { + LV_LOG_ERROR("Themes: th_styles array is too small. Increase it's size!"); + while(1); + } + + /*Initialize the style pointers `current_theme` to point to the `th_styles` style array */ + uint16_t i; + lv_style_t ** cur_th_style_p = (lv_style_t **) ¤t_theme; + for(i = 0; i < style_num; i++) { + uint64_t adr = (uint64_t)&th_styles[i]; + memcpy(&cur_th_style_p[i], &adr, sizeof(lv_style_t*)); + } + inited = true; + } + + + /*Copy the styles pointed by the new theme to the `th_styles` style array*/ + uint16_t i; + lv_style_t ** th_style = (lv_style_t **) th; + for(i = 0; i < style_num; i++) { + uint64_t s = (uint64_t)th_style[i]; + if(s) memcpy(&th_styles[i], (void*)s, sizeof(lv_style_t)); + } + + /*Let the object know their style might change*/ + lv_obj_report_style_mod(NULL); +#endif } /** @@ -49,7 +99,12 @@ void lv_theme_set_current(lv_theme_t * th) */ lv_theme_t * lv_theme_get_current(void) { +#if LV_THEME_LIVE_UPDATE == 0 return current_theme; +#else + if(!inited) return NULL; + else return ¤t_theme; +#endif } /********************** From 4db5e54737c992292f5d558e9609904f9f5f5f51 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 6 Sep 2018 20:57:59 +0200 Subject: [PATCH 2/3] add lv_imgbtn --- lv_conf_templ.h | 3 + lv_objx/lv_btn.c | 3 +- lv_objx/lv_btn.h | 5 +- lv_objx/lv_img.c | 8 +- lv_objx/lv_imgbtn.c | 255 ++++++++++++++++++++++++++++++++++++++++ lv_objx/lv_imgbtn.h | 199 +++++++++++++++++++++++++++++++ lv_objx/lv_objx_templ.c | 8 +- lv_objx/lv_objx_templ.h | 4 +- lvgl.h | 2 +- 9 files changed, 470 insertions(+), 17 deletions(-) create mode 100644 lv_objx/lv_imgbtn.c create mode 100644 lv_objx/lv_imgbtn.h diff --git a/lv_conf_templ.h b/lv_conf_templ.h index e8d83641b..1c9b4ba60 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -262,6 +262,9 @@ /*Button (dependencies: lv_cont*/ #define USE_LV_BTN 1 +/*Image Button (dependencies: lv_btn*/ +#define USE_LV_IMGBTN 1 + /*Button matrix (dependencies: -)*/ #define USE_LV_BTNM 1 diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index bf5fa0d78..2adcac2f2 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -23,6 +23,7 @@ *********************/ #define LV_BTN_INK_VALUE_MAX 256 #define LV_BTN_INK_VALUE_MAX_SHIFT 8 + /********************** * TYPEDEFS **********************/ @@ -209,7 +210,7 @@ void lv_btn_toggle(lv_obj_t * btn) } /** - * Set a function to call when the button event happens + * Set a function to call when a button event happens * @param btn pointer to a button object * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) */ diff --git a/lv_objx/lv_btn.h b/lv_objx/lv_btn.h index d48a50133..a726d23e0 100644 --- a/lv_objx/lv_btn.h +++ b/lv_objx/lv_btn.h @@ -37,7 +37,8 @@ extern "C" { * TYPEDEFS **********************/ -/*Button states*/ +/* Button states + * It can be used not only by buttons but other button-like objects too*/ typedef enum { LV_BTN_STATE_REL, @@ -120,7 +121,7 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state); void lv_btn_toggle(lv_obj_t * btn); /** - * Set a function to call when the button event happens + * Set a function to call when a button event happens * @param btn pointer to a button object * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) */ diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 9b8594efc..bc6cbba7a 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -124,12 +124,6 @@ void lv_img_set_src(lv_obj_t * img, const void * src_img) lv_img_src_t src_type = lv_img_src_get_type(src_img); lv_img_ext_t * ext = lv_obj_get_ext_attr(img); - -#if USE_LV_FILESYSTEM == 0 - if(src_type == LV_IMG_SRC_FILE) src_type = LV_IMG_SRC_UNKNOWN; -#endif - - /*If the new source type is unknown free the memories of the old source*/ if(src_type == LV_IMG_SRC_UNKNOWN) { if(ext->src_type == LV_IMG_SRC_SYMBOL || ext->src_type == LV_IMG_SRC_FILE) { @@ -260,7 +254,7 @@ static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode bool cover = false; if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL) return false; - if(ext->cf == LV_IMG_FORMAT_TRUE_COLOR) cover = lv_area_is_in(mask, &img->coords); + if(ext->cf == LV_IMG_FORMAT_TRUE_COLOR || ext->cf == LV_IMG_FORMAT_RAW) cover = lv_area_is_in(mask, &img->coords); return cover; } else if(mode == LV_DESIGN_DRAW_MAIN) { diff --git a/lv_objx/lv_imgbtn.c b/lv_objx/lv_imgbtn.c new file mode 100644 index 000000000..dae4b9e7c --- /dev/null +++ b/lv_objx/lv_imgbtn.c @@ -0,0 +1,255 @@ +/** + * @file lv_imgbtn.c + * + */ + +/********************* + * INCLUDES + *********************/ +#include "lv_imgbtn.h" +#if USE_LV_IMGBTN != 0 + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static bool lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * mask, lv_design_mode_t mode); +static lv_res_t lv_imgbtn_signal(lv_obj_t * imgbtn, lv_signal_t sign, void * param); +static void refr_img(lv_obj_t * imgbtn); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_signal_func_t ancestor_signal; +static lv_design_func_t ancestor_design; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +/** + * Create a image button object + * @param par pointer to an object, it will be the parent of the new image button + * @param copy pointer to a image button object, if not NULL then the new object will be copied from it + * @return pointer to the created image button + */ +lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) +{ + LV_LOG_TRACE("image button create started"); + + /*Create the ancestor of image button*/ + lv_obj_t * new_imgbtn = lv_btn_create(par, copy); + lv_mem_assert(new_imgbtn); + if(new_imgbtn == NULL) return NULL; + + /*Allocate the image button type specific extended data*/ + lv_imgbtn_ext_t * ext = lv_obj_allocate_ext_attr(new_imgbtn, sizeof(lv_imgbtn_ext_t)); + lv_mem_assert(ext); + if(ext == NULL) return NULL; + if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_imgbtn); + if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_imgbtn); + + /*Initialize the allocated 'ext' */ + ext->img_src[LV_BTN_STATE_REL] = NULL; + ext->img_src[LV_BTN_STATE_PR] = NULL; + ext->img_src[LV_BTN_STATE_TGL_REL] = NULL; + ext->img_src[LV_BTN_STATE_TGL_PR] = NULL;; + ext->img_src[LV_BTN_STATE_INA] = NULL; + ext->act_cf = LV_IMG_FORMAT_UNKOWN; + + /*The signal and design functions are not copied so set them here*/ + lv_obj_set_signal_func(new_imgbtn, lv_imgbtn_signal); + lv_obj_set_design_func(new_imgbtn, lv_imgbtn_design); + + /*Init the new image button image button*/ + if(copy == NULL) { + + } + /*Copy an existing image button*/ + else { + lv_imgbtn_ext_t * copy_ext = lv_obj_get_ext_attr(copy); + + /*Refresh the style with new signal function*/ + lv_obj_refresh_style(new_imgbtn); + } + + LV_LOG_INFO("image button created"); + + return new_imgbtn; +} + +/*===================== + * Setter functions + *====================*/ + +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image (from `lv_btn_state_t`) ` + * @param src pointer to an image source (a C array or path to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, void * src) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + ext->img_src[state] = src; + + refr_img(imgbtn); +} + +/** + * Set a style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t * style) +{ + lv_btn_set_style(imgbtn, type, style); +} + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the images in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to an image source (a C array or path to a file) + */ +void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + + return ext->img_src[state]; +} + +/** + * Get style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type) +{ + return lv_btn_get_style(imgbtn, type); +} + +/*===================== + * Other functions + *====================*/ + +/* + * New object specific "other" functions come here + */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +/** + * Handle the drawing related tasks of the image buttons + * @param imgbtn pointer to an object + * @param mask the object will be drawn only in this area + * @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area + * (return 'true' if yes) + * LV_DESIGN_DRAW: draw the object (always return 'true') + * LV_DESIGN_DRAW_POST: drawing after every children are drawn + * @param return true/false, depends on 'mode' + */ +static bool lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * mask, lv_design_mode_t mode) +{ + /*Return false if the object is not covers the mask_p area*/ + if(mode == LV_DESIGN_COVER_CHK) { + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + bool cover = false; + if(ext->act_cf == LV_IMG_FORMAT_TRUE_COLOR || ext->act_cf == LV_IMG_FORMAT_RAW) { + cover = lv_area_is_in(mask, &imgbtn->coords); + } + + return cover; + } + /*Draw the object*/ + else if(mode == LV_DESIGN_DRAW_MAIN) { + /*Just draw an image*/ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + lv_btn_state_t state = lv_imgbtn_get_state(imgbtn); + void * src = ext->img_src[state]; + lv_style_t * style = lv_imgbtn_get_style(imgbtn, state); + lv_opa_t opa_scale = lv_obj_get_opa_scale(imgbtn); + lv_draw_img(&imgbtn->coords, mask, src, style, opa_scale); + } + /*Post draw when the children are drawn*/ + else if(mode == LV_DESIGN_DRAW_POST) { + + } + + return true; +} + +/** + * Signal function of the image button + * @param imgbtn pointer to a image button object + * @param sign a signal type from lv_signal_t enum + * @param param pointer to a signal specific variable + * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted + */ +static lv_res_t lv_imgbtn_signal(lv_obj_t * imgbtn, lv_signal_t sign, void * param) +{ + lv_res_t res; + + /* Include the ancient signal function */ + res = ancestor_signal(imgbtn, sign, param); + if(res != LV_RES_OK) return res; + + if(sign == LV_SIGNAL_STYLE_CHG) { + /* If the style changed then the button was clicked, released etc. so probably the state was changed as well + * Set the new image for the new state.*/ + refr_img(imgbtn); + } + else if(sign == LV_SIGNAL_CLEANUP) { + /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + } else if(sign == LV_SIGNAL_GET_TYPE) { + lv_obj_type_t * buf = param; + uint8_t i; + for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/ + if(buf->type[i] == NULL) break; + } + buf->type[i] = "lv_imgbtn"; + } + + return res; +} + + +static void refr_img(lv_obj_t * imgbtn) +{ + lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); + lv_btn_state_t state = lv_imgbtn_get_state(imgbtn); + lv_img_header_t header; + void * src = ext->img_src[state]; + + lv_res_t info_res; + info_res = lv_img_dsc_get_info(src, &header); + if(info_res == LV_RES_OK) { + ext->act_cf = header.cf; + lv_obj_set_size(imgbtn, header.w, header.h); + } else { + ext->act_cf = LV_IMG_FORMAT_UNKOWN; + } + +} + +#endif diff --git a/lv_objx/lv_imgbtn.h b/lv_objx/lv_imgbtn.h new file mode 100644 index 000000000..e3f935a28 --- /dev/null +++ b/lv_objx/lv_imgbtn.h @@ -0,0 +1,199 @@ +/** + * @file lv_imgbtn.h + * + */ + +#ifndef LV_IMGBTN_H +#define LV_IMGBTN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#ifdef LV_CONF_INCLUDE_SIMPLE +#include "lv_conf.h" +#else +#include "../../lv_conf.h" +#endif + +#if USE_LV_IMGBTN != 0 + +/*Testing of dependencies*/ +#if USE_LV_BTN == 0 +#error "lv_imgbtn: lv_btn is required. Enable it in lv_conf.h (USE_LV_BTN 1) " +#endif + +#include "../lv_core/lv_obj.h" +#include "lv_btn.h" +#include "../lv_draw/lv_draw_img.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ +/*Data of image button*/ +typedef struct { + lv_btn_ext_t btn; /*Ext. of ancestor*/ + /*New data for this type */ + void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/ + lv_img_color_format_t act_cf; /*Color format of the currently active image*/ +} lv_imgbtn_ext_t; + + +/*Styles*/ +typedef enum { + LV_IMGBTN_STYLE_REL, + LV_IMGBTN_STYLE_PR, + LV_IMGBTN_STYLE_TGL_REL, + LV_IMGBTN_STYLE_TGL_PR, + LV_IMGBTN_STYLE_INA, +} lv_imgbtn_style_t; + + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Create a image button objects + * @param par pointer to an object, it will be the parent of the new image button + * @param copy pointer to a image button object, if not NULL then the new object will be copied from it + * @return pointer to the created image button + */ +lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy); + +/*====================== + * Add/remove functions + *=====================*/ + + +/*===================== + * Setter functions + *====================*/ + +/** + * Set images for a state of the image button + * @param imgbtn pointer to an image button object + * @param state for which state set the new image (from `lv_btn_state_t`) ` + * @param src pointer to an image source (a C array or path to a file) + */ +void lv_imgbtn_set_src(lv_obj_t * imgbtn, lv_btn_state_t state, void * src); + +/** + * Enable the toggled states. On release the button will change from/to toggled state. + * @param imgbtn pointer to an image button object + * @param tgl true: enable toggled states, false: disable + */ +static inline void lv_imgbtn_set_toggle(lv_obj_t * imgbtn, bool tgl) +{ + lv_btn_set_toggle(imgbtn, tgl); +} + +/** + * Set the state of the image button + * @param imgbtn pointer to an image button object + * @param state the new state of the button (from lv_btn_state_t enum) + */ +static inline void lv_imgbtn_set_state(lv_obj_t * imgbtn, lv_btn_state_t state) +{ + lv_btn_set_state(imgbtn, state); +} + +/** + * Toggle the state of the image button (ON->OFF, OFF->ON) + * @param imgbtn pointer to a image button object + */ +static inline void lv_imgbtn_toggle(lv_obj_t * imgbtn) +{ + lv_btn_toggle(imgbtn); +} + +/** + * Set a function to call when a button event happens + * @param imgbtn pointer to an image button object + * @param action type of event form 'lv_action_t' (press, release, long press, long press repeat) + */ +static inline void lv_imgbtn_set_action(lv_obj_t * imgbtn, lv_btn_action_t type, lv_action_t action) +{ + lv_btn_set_action(imgbtn, type, action); +} + +/** + * Set a style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be set + * @param style pointer to a style + */ +void lv_imgbtn_set_style(lv_obj_t * imgbtn, lv_imgbtn_style_t type, lv_style_t *style); + +/*===================== + * Getter functions + *====================*/ + +/** + * Get the images in a given state + * @param imgbtn pointer to an image button object + * @param state the state where to get the image (from `lv_btn_state_t`) ` + * @return pointer to an image source (a C array or path to a file) + */ +void * lv_imgbtn_get_src(lv_obj_t * imgbtn, lv_btn_state_t state); + +/** + * Get the current state of the image button + * @param imgbtn pointer to a image button object + * @return the state of the button (from lv_btn_state_t enum) + */ +static inline lv_btn_state_t lv_imgbtn_get_state(const lv_obj_t * imgbtn) +{ + return lv_btn_get_state(imgbtn); +} + +/** + * Get the toggle enable attribute of the image button + * @param imgbtn pointer to a image button object + * @return ture: toggle enabled, false: disabled + */ +static inline bool lv_imgbtn_get_toggle(const lv_obj_t * imgbtn) +{ + return lv_btn_get_toggle(imgbtn); +} + +/** + * Get the release action of a image button + * @param imgbtn pointer to a image button object + * @return pointer to the release action function + */ +static inline lv_action_t lv_imgbtn_get_action(const lv_obj_t * imgbtn, lv_btn_action_t type) +{ + return lv_btn_get_action(imgbtn, type); +} + +/** + * Get style of a image button. + * @param imgbtn pointer to image button object + * @param type which style should be get + * @return style pointer to the style + */ +lv_style_t * lv_imgbtn_get_style(const lv_obj_t * imgbtn, lv_imgbtn_style_t type); + +/*===================== + * Other functions + *====================*/ + +/********************** + * MACROS + **********************/ + +#endif /*USE_LV_IMGBTN*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_IMGBTN_H*/ diff --git a/lv_objx/lv_objx_templ.c b/lv_objx/lv_objx_templ.c index 8947ad66f..b5c051009 100644 --- a/lv_objx/lv_objx_templ.c +++ b/lv_objx/lv_objx_templ.c @@ -16,7 +16,6 @@ //#include "lv_templ.h" /*TODO uncomment this*/ #if USE_LV_TEMPL != 0 - /********************* * DEFINES *********************/ @@ -59,10 +58,12 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy) /*TODO modify it to the ancestor create function */ lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy); lv_mem_assert(new_templ); + if(new_templ == NULL) return NULL; /*Allocate the template type specific extended data*/ lv_templ_ext_t * ext = lv_obj_allocate_ext_attr(new_templ, sizeof(lv_templ_ext_t)); lv_mem_assert(ext); + if(ext == NULL) return NULL; if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_templ); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_func(new_templ); @@ -87,7 +88,6 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy) LV_LOG_INFO("template created"); - return new_templ; } @@ -114,7 +114,7 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy) * @param templ pointer to template object * @param type which style should be set * @param style pointer to a style - * */ + */ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t * style) { lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ); @@ -140,7 +140,7 @@ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t * st * @param templ pointer to template object * @param type which style should be get * @return style pointer to the style - * */ + */ lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type) { lv_templ_ext_t * ext = lv_obj_get_ext_attr(templ); diff --git a/lv_objx/lv_objx_templ.h b/lv_objx/lv_objx_templ.h index afe20b90b..17dab72f8 100644 --- a/lv_objx/lv_objx_templ.h +++ b/lv_objx/lv_objx_templ.h @@ -78,7 +78,7 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); * @param templ pointer to template object * @param type which style should be set * @param style pointer to a style - * */ + */ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); /*===================== @@ -90,7 +90,7 @@ void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *sty * @param templ pointer to template object * @param type which style should be get * @return style pointer to the style - * */ + */ lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); /*===================== diff --git a/lvgl.h b/lvgl.h index ceee7358b..80538b6c6 100644 --- a/lvgl.h +++ b/lvgl.h @@ -27,7 +27,7 @@ extern "C" { #include "lv_themes/lv_theme.h" #include "lv_objx/lv_btn.h" -#include "lv_objx/lv_img.h" +#include "lv_objx/lv_imgbtn.h" #include "lv_objx/lv_img.h" #include "lv_objx/lv_label.h" #include "lv_objx/lv_line.h" From 61a2540ed4d69febbd0406ecdf4f5c9080cdb42d Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 6 Sep 2018 21:15:29 +0200 Subject: [PATCH 3/3] rename LV_IMG_FORMAT_... to LV_IMG_CF_... --- lv_draw/lv_draw_img.c | 140 +++++++++++++++++++++--------------------- lv_draw/lv_draw_img.h | 47 ++++++-------- lv_objx/lv_img.c | 4 +- lv_objx/lv_imgbtn.c | 6 +- lv_objx/lv_imgbtn.h | 2 +- 5 files changed, 96 insertions(+), 103 deletions(-) diff --git a/lv_draw/lv_draw_img.c b/lv_draw/lv_draw_img.c index b00dee06f..34919f6e3 100644 --- a/lv_draw/lv_draw_img.c +++ b/lv_draw/lv_draw_img.c @@ -121,7 +121,7 @@ lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header) if(res != LV_FS_RES_OK || rn != sizeof(lv_img_header_t)) { header->w = LV_DPI; header->h = LV_DPI; - header->cf = LV_IMG_FORMAT_UNKOWN; + header->cf = LV_IMG_CF_UNKOWN; } lv_fs_close(&file); @@ -133,7 +133,7 @@ lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header) header->h = 1; /* Symbols always have transparent parts. Important because of cover check in the design function. * The actual value doesn't matter because lv_draw_label will draw it*/ - header->cf = LV_IMG_FORMAT_ALPHA_1BIT; + header->cf = LV_IMG_CF_ALPHA_1BIT; } else { LV_LOG_WARN("Image get info found unknown src type"); return false; @@ -142,35 +142,35 @@ lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header) } -uint8_t lv_img_color_format_get_px_size(lv_img_color_format_t cf) +uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf) { switch(cf) { - case LV_IMG_FORMAT_UNKOWN: - case LV_IMG_FORMAT_RAW: + case LV_IMG_CF_UNKOWN: + case LV_IMG_CF_RAW: return 0; - case LV_IMG_FORMAT_TRUE_COLOR: - case LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED: + case LV_IMG_CF_TRUE_COLOR: + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: return LV_COLOR_SIZE; - case LV_IMG_FORMAT_TRUE_COLOR_ALPHA: + case LV_IMG_CF_TRUE_COLOR_ALPHA: #if LV_COLOR_DEPTH != 24 return LV_COLOR_SIZE; #else return LV_COLOR_SIZE + 1; #endif - case LV_IMG_FORMAT_INDEXED_1BIT: - case LV_IMG_FORMAT_ALPHA_1BIT: + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_ALPHA_1BIT: return 1; - case LV_IMG_FORMAT_INDEXED_2BIT: - case LV_IMG_FORMAT_ALPHA_2BIT: + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_ALPHA_2BIT: return 2; - case LV_IMG_FORMAT_INDEXED_4BIT: - case LV_IMG_FORMAT_ALPHA_4BIT: + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_ALPHA_4BIT: return 4; - case LV_IMG_FORMAT_INDEXED_8BIT: - case LV_IMG_FORMAT_ALPHA_8BIT: + case LV_IMG_CF_INDEXED_8BIT: + case LV_IMG_CF_ALPHA_8BIT: return 8; default: @@ -180,15 +180,15 @@ uint8_t lv_img_color_format_get_px_size(lv_img_color_format_t cf) return 0; } -bool lv_img_color_format_is_chroma_keyed(lv_img_color_format_t cf) +bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf) { switch(cf) { - case LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED: - case LV_IMG_FORMAT_RAW_CHROMA_KEYED: - case LV_IMG_FORMAT_INDEXED_1BIT: - case LV_IMG_FORMAT_INDEXED_2BIT: - case LV_IMG_FORMAT_INDEXED_4BIT: - case LV_IMG_FORMAT_INDEXED_8BIT: + case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: + case LV_IMG_CF_RAW_CHROMA_KEYED: + case LV_IMG_CF_INDEXED_1BIT: + case LV_IMG_CF_INDEXED_2BIT: + case LV_IMG_CF_INDEXED_4BIT: + case LV_IMG_CF_INDEXED_8BIT: return true; default: return false; @@ -198,15 +198,15 @@ bool lv_img_color_format_is_chroma_keyed(lv_img_color_format_t cf) } -bool lv_img_color_format_has_alpha(lv_img_color_format_t cf) +bool lv_img_color_format_has_alpha(lv_img_cf_t cf) { switch(cf) { - case LV_IMG_FORMAT_TRUE_COLOR_ALPHA: - case LV_IMG_FORMAT_RAW_ALPHA: - case LV_IMG_FORMAT_ALPHA_1BIT: - case LV_IMG_FORMAT_ALPHA_2BIT: - case LV_IMG_FORMAT_ALPHA_4BIT: - case LV_IMG_FORMAT_ALPHA_8BIT: + case LV_IMG_CF_TRUE_COLOR_ALPHA: + case LV_IMG_CF_RAW_ALPHA: + case LV_IMG_CF_ALPHA_1BIT: + case LV_IMG_CF_ALPHA_2BIT: + case LV_IMG_CF_ALPHA_4BIT: + case LV_IMG_CF_ALPHA_8BIT: return true; default: return false; @@ -384,10 +384,10 @@ static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * #endif /*Process the different color formats*/ - lv_img_color_format_t cf = decoder_header.cf; - if(cf == LV_IMG_FORMAT_TRUE_COLOR || - cf == LV_IMG_FORMAT_TRUE_COLOR_ALPHA || - cf == LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED) + lv_img_cf_t cf = decoder_header.cf; + if(cf == LV_IMG_CF_TRUE_COLOR || + cf == LV_IMG_CF_TRUE_COLOR_ALPHA || + cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { if(decoder_src_type == LV_IMG_SRC_VARIABLE) { /*In case of uncompressed formats if the image stored in the ROM/RAM simply give it's pointer*/ @@ -397,10 +397,10 @@ static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * return NULL; } } - else if (cf == LV_IMG_FORMAT_INDEXED_1BIT || - cf == LV_IMG_FORMAT_INDEXED_2BIT || - cf == LV_IMG_FORMAT_INDEXED_4BIT || - cf == LV_IMG_FORMAT_INDEXED_8BIT) + else if (cf == LV_IMG_CF_INDEXED_1BIT || + cf == LV_IMG_CF_INDEXED_2BIT || + cf == LV_IMG_CF_INDEXED_4BIT || + cf == LV_IMG_CF_INDEXED_8BIT) { lv_color24_t palette_file[256]; lv_color24_t * palette_p = NULL; @@ -425,10 +425,10 @@ static const uint8_t * lv_img_decoder_open(const void * src, const lv_style_t * } return NULL; } - else if (cf == LV_IMG_FORMAT_ALPHA_1BIT || - cf == LV_IMG_FORMAT_ALPHA_2BIT || - cf == LV_IMG_FORMAT_ALPHA_4BIT || - cf == LV_IMG_FORMAT_ALPHA_8BIT) + else if (cf == LV_IMG_CF_ALPHA_1BIT || + cf == LV_IMG_CF_ALPHA_2BIT || + cf == LV_IMG_CF_ALPHA_4BIT || + cf == LV_IMG_CF_ALPHA_8BIT) { return NULL; /*Nothing to process*/ } @@ -460,9 +460,9 @@ static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t lv_fs_res_t res; - if(decoder_header.cf == LV_IMG_FORMAT_TRUE_COLOR || - decoder_header.cf == LV_IMG_FORMAT_TRUE_COLOR_ALPHA || - decoder_header.cf == LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED) + if(decoder_header.cf == LV_IMG_CF_TRUE_COLOR || + decoder_header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA || + decoder_header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { uint32_t pos = ((y * decoder_header.w + x) * px_size) >> 3; res = lv_fs_seek(&decoder_file, pos); @@ -478,16 +478,16 @@ static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t return false; } } - else if(decoder_header.cf == LV_IMG_FORMAT_ALPHA_1BIT || - decoder_header.cf == LV_IMG_FORMAT_ALPHA_2BIT || - decoder_header.cf == LV_IMG_FORMAT_ALPHA_4BIT || - decoder_header.cf == LV_IMG_FORMAT_ALPHA_8BIT) + else if(decoder_header.cf == LV_IMG_CF_ALPHA_1BIT || + decoder_header.cf == LV_IMG_CF_ALPHA_2BIT || + decoder_header.cf == LV_IMG_CF_ALPHA_4BIT || + decoder_header.cf == LV_IMG_CF_ALPHA_8BIT) { lv_img_built_in_decoder_line_alpha(x, y, len, buf); - } else if(decoder_header.cf == LV_IMG_FORMAT_INDEXED_1BIT || - decoder_header.cf == LV_IMG_FORMAT_INDEXED_2BIT || - decoder_header.cf == LV_IMG_FORMAT_INDEXED_4BIT || - decoder_header.cf == LV_IMG_FORMAT_INDEXED_8BIT) + } else if(decoder_header.cf == LV_IMG_CF_INDEXED_1BIT || + decoder_header.cf == LV_IMG_CF_INDEXED_2BIT || + decoder_header.cf == LV_IMG_CF_INDEXED_4BIT || + decoder_header.cf == LV_IMG_CF_INDEXED_8BIT) { lv_img_built_in_decoder_line_indexed(x, y, len, buf); } else { @@ -501,16 +501,16 @@ static lv_res_t lv_img_decoder_read_line(lv_coord_t x, lv_coord_t y, lv_coord_t } else if (decoder_src_type == LV_IMG_SRC_VARIABLE) { const lv_img_dsc_t * img_dsc = decoder_src; - if(img_dsc->header.cf == LV_IMG_FORMAT_ALPHA_1BIT || - img_dsc->header.cf == LV_IMG_FORMAT_ALPHA_2BIT || - img_dsc->header.cf == LV_IMG_FORMAT_ALPHA_4BIT || - img_dsc->header.cf == LV_IMG_FORMAT_ALPHA_8BIT) + if(img_dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || + img_dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || + img_dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || + img_dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { lv_img_built_in_decoder_line_alpha(x, y, len, buf); - } else if(img_dsc->header.cf == LV_IMG_FORMAT_INDEXED_1BIT || - img_dsc->header.cf == LV_IMG_FORMAT_INDEXED_2BIT || - img_dsc->header.cf == LV_IMG_FORMAT_INDEXED_4BIT || - img_dsc->header.cf == LV_IMG_FORMAT_INDEXED_8BIT) + } else if(img_dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || + img_dsc->header.cf == LV_IMG_CF_INDEXED_2BIT || + img_dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || + img_dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { lv_img_built_in_decoder_line_indexed(x, y, len, buf); } else { @@ -574,28 +574,28 @@ static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, l uint32_t ofs = 0; int8_t pos = 0; switch(decoder_header.cf) { - case LV_IMG_FORMAT_ALPHA_1BIT: + case LV_IMG_CF_ALPHA_1BIT: w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/ if(decoder_header.w & 0x7) w++; ofs += w * y + (x >> 3); /*First pixel*/ pos = 7 - (x & 0x7); opa_table = alpha1_opa_table; break; - case LV_IMG_FORMAT_ALPHA_2BIT: + case LV_IMG_CF_ALPHA_2BIT: w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/ if(decoder_header.w & 0x3) w++; ofs += w * y + (x >> 2); /*First pixel*/ pos = 6 - ((x & 0x3) * 2); opa_table = alpha2_opa_table; break; - case LV_IMG_FORMAT_ALPHA_4BIT: + case LV_IMG_CF_ALPHA_4BIT: w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/ if(decoder_header.w & 0x1) w++; ofs += w * y + (x >> 1); /*First pixel*/ pos = 4 - ((x & 0x1) * 4); opa_table = alpha4_opa_table; break; - case LV_IMG_FORMAT_ALPHA_8BIT: + case LV_IMG_CF_ALPHA_8BIT: w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/ ofs += w * y + x; /*First pixel*/ pos = 0; @@ -636,7 +636,7 @@ static lv_res_t lv_img_built_in_decoder_line_alpha(lv_coord_t x, lv_coord_t y, l val_act = (data_tmp[byte_act] & (mask << pos)) >> pos; buf[i * LV_IMG_PX_SIZE_ALPHA_BYTE + LV_IMG_PX_SIZE_ALPHA_BYTE - 1] = - decoder_header.cf == LV_IMG_FORMAT_ALPHA_8BIT ? val_act : opa_table[val_act]; + decoder_header.cf == LV_IMG_CF_ALPHA_8BIT ? val_act : opa_table[val_act]; pos -= px_size; if(pos < 0) { @@ -658,28 +658,28 @@ static lv_res_t lv_img_built_in_decoder_line_indexed(lv_coord_t x, lv_coord_t y, int8_t pos = 0; uint32_t ofs = 0; switch(decoder_header.cf) { - case LV_IMG_FORMAT_INDEXED_1BIT: + case LV_IMG_CF_INDEXED_1BIT: w = (decoder_header.w >> 3); /*E.g. w = 20 -> w = 2 + 1*/ if(decoder_header.w & 0x7) w++; ofs += w * y + (x >> 3); /*First pixel*/ ofs += 8; /*Skip the palette*/ pos = 7 - (x & 0x7); break; - case LV_IMG_FORMAT_INDEXED_2BIT: + case LV_IMG_CF_INDEXED_2BIT: w = (decoder_header.w >> 2); /*E.g. w = 13 -> w = 3 + 1 (bytes)*/ if(decoder_header.w & 0x3) w++; ofs += w * y + (x >> 2); /*First pixel*/ ofs += 16; /*Skip the palette*/ pos = 6 - ((x & 0x3) * 2); break; - case LV_IMG_FORMAT_INDEXED_4BIT: + case LV_IMG_CF_INDEXED_4BIT: w = (decoder_header.w >> 1); /*E.g. w = 13 -> w = 6 + 1 (bytes)*/ if(decoder_header.w & 0x1) w++; ofs += w * y + (x >> 1); /*First pixel*/ ofs += 64; /*Skip the palette*/ pos = 4 - ((x & 0x1) * 4); break; - case LV_IMG_FORMAT_INDEXED_8BIT: + case LV_IMG_CF_INDEXED_8BIT: w = decoder_header.w; /*E.g. x = 7 -> w = 7 (bytes)*/ ofs += w * y + x; /*First pixel*/ ofs += 1024; /*Skip the palette*/ diff --git a/lv_draw/lv_draw_img.h b/lv_draw/lv_draw_img.h index add871d11..b11a9ca22 100644 --- a/lv_draw/lv_draw_img.h +++ b/lv_draw/lv_draw_img.h @@ -39,35 +39,28 @@ typedef struct { uint32_t h:11; /*Height of the image map*/ }lv_img_header_t; - +/*Image color format*/ typedef enum { - LV_IMG_COMPRESSION_NONE, - LV_IMG_COMPRESSION_RLE, /*Run length encoded*/ - LV_IMG_COMPRESSION_RESERVED1, - LV_IMG_COMPRESSION_RESERVED2 -}lv_img_compression_t; + LV_IMG_CF_UNKOWN = 0, -typedef enum { - LV_IMG_FORMAT_UNKOWN = 0, + LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/ + LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/ + LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/ - LV_IMG_FORMAT_RAW, /*Contains the file as it is. Needs custom decoder function*/ - LV_IMG_FORMAT_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/ - LV_IMG_FORMAT_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/ + LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/ + LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/ + LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/ - LV_IMG_FORMAT_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/ - LV_IMG_FORMAT_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_FORMAT_TRUE_COLOR` but every pixel has an alpha byte*/ - LV_IMG_FORMAT_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_FORMAT_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/ + LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/ + LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/ + LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/ + LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/ - LV_IMG_FORMAT_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/ - LV_IMG_FORMAT_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/ - LV_IMG_FORMAT_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/ - LV_IMG_FORMAT_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/ - - LV_IMG_FORMAT_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/ - LV_IMG_FORMAT_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/ - LV_IMG_FORMAT_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/ - LV_IMG_FORMAT_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/ -} lv_img_color_format_t; + LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/ + LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/ + LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/ + LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/ +} lv_img_cf_t; /* Image header it is compatible with * the result image converter utility*/ @@ -154,11 +147,11 @@ void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_ lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header); -uint8_t lv_img_color_format_get_px_size(lv_img_color_format_t cf); +uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf); -bool lv_img_color_format_is_chroma_keyed(lv_img_color_format_t cf); +bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf); -bool lv_img_color_format_has_alpha(lv_img_color_format_t cf); +bool lv_img_color_format_has_alpha(lv_img_cf_t cf); /********************** diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index bc6cbba7a..9ef2ec689 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -72,7 +72,7 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy) ext->src = NULL; ext->src_type = LV_IMG_SRC_UNKNOWN; - ext->cf = LV_IMG_FORMAT_UNKOWN; + ext->cf = LV_IMG_CF_UNKOWN; ext->w = lv_obj_get_width(new_img); ext->h = lv_obj_get_height(new_img); ext->auto_size = 1; @@ -254,7 +254,7 @@ static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode bool cover = false; if(ext->src_type == LV_IMG_SRC_UNKNOWN || ext->src_type == LV_IMG_SRC_SYMBOL) return false; - if(ext->cf == LV_IMG_FORMAT_TRUE_COLOR || ext->cf == LV_IMG_FORMAT_RAW) cover = lv_area_is_in(mask, &img->coords); + if(ext->cf == LV_IMG_CF_TRUE_COLOR || ext->cf == LV_IMG_CF_RAW) cover = lv_area_is_in(mask, &img->coords); return cover; } else if(mode == LV_DESIGN_DRAW_MAIN) { diff --git a/lv_objx/lv_imgbtn.c b/lv_objx/lv_imgbtn.c index dae4b9e7c..641bdaedf 100644 --- a/lv_objx/lv_imgbtn.c +++ b/lv_objx/lv_imgbtn.c @@ -66,7 +66,7 @@ lv_obj_t * lv_imgbtn_create(lv_obj_t * par, const lv_obj_t * copy) ext->img_src[LV_BTN_STATE_TGL_REL] = NULL; ext->img_src[LV_BTN_STATE_TGL_PR] = NULL;; ext->img_src[LV_BTN_STATE_INA] = NULL; - ext->act_cf = LV_IMG_FORMAT_UNKOWN; + ext->act_cf = LV_IMG_CF_UNKOWN; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_func(new_imgbtn, lv_imgbtn_signal); @@ -175,7 +175,7 @@ static bool lv_imgbtn_design(lv_obj_t * imgbtn, const lv_area_t * mask, lv_desig if(mode == LV_DESIGN_COVER_CHK) { lv_imgbtn_ext_t * ext = lv_obj_get_ext_attr(imgbtn); bool cover = false; - if(ext->act_cf == LV_IMG_FORMAT_TRUE_COLOR || ext->act_cf == LV_IMG_FORMAT_RAW) { + if(ext->act_cf == LV_IMG_CF_TRUE_COLOR || ext->act_cf == LV_IMG_CF_RAW) { cover = lv_area_is_in(mask, &imgbtn->coords); } @@ -247,7 +247,7 @@ static void refr_img(lv_obj_t * imgbtn) ext->act_cf = header.cf; lv_obj_set_size(imgbtn, header.w, header.h); } else { - ext->act_cf = LV_IMG_FORMAT_UNKOWN; + ext->act_cf = LV_IMG_CF_UNKOWN; } } diff --git a/lv_objx/lv_imgbtn.h b/lv_objx/lv_imgbtn.h index e3f935a28..678c3b08e 100644 --- a/lv_objx/lv_imgbtn.h +++ b/lv_objx/lv_imgbtn.h @@ -42,7 +42,7 @@ typedef struct { lv_btn_ext_t btn; /*Ext. of ancestor*/ /*New data for this type */ void * img_src[LV_BTN_STATE_NUM]; /*Store images to each state*/ - lv_img_color_format_t act_cf; /*Color format of the currently active image*/ + lv_img_cf_t act_cf; /*Color format of the currently active image*/ } lv_imgbtn_ext_t;