From 11d5fcb9ae7a1900337841f239a0422e84620ace Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 2 Oct 2019 08:32:10 +0200 Subject: [PATCH 1/4] cpicker: on double click reset only the current color mode --- src/lv_objx/lv_cpicker.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lv_objx/lv_cpicker.c b/src/lv_objx/lv_cpicker.c index 23dbd6a30..0e3749556 100644 --- a/src/lv_objx/lv_cpicker.c +++ b/src/lv_objx/lv_cpicker.c @@ -973,7 +973,17 @@ static lv_res_t double_click_reset(lv_obj_t * cpicker) lv_indev_t * indev = lv_indev_get_act(); /*Double clicked? Use long press time as double click time out*/ if(lv_tick_elaps(ext->last_click_time) < indev->driver.long_press_time) { - lv_cpicker_set_hsv(cpicker, LV_CPICKER_DEF_HSV); + switch(ext->color_mode) { + case LV_CPICKER_COLOR_MODE_HUE: + lv_cpicker_set_hue(cpicker, LV_CPICKER_DEF_HUE); + break; + case LV_CPICKER_COLOR_MODE_SATURATION: + lv_cpicker_set_hue(cpicker, LV_CPICKER_DEF_SATURATION); + break; + case LV_CPICKER_COLOR_MODE_VALUE: + lv_cpicker_set_hue(cpicker, LV_CPICKER_DEF_VALUE); + break; + } lv_res_t res; res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); From e8625aaf65e5f212c630a060247bec102a7113a1 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 2 Oct 2019 09:02:43 +0200 Subject: [PATCH 2/4] add cpicker to lv_conf_template.h --- lv_conf_template.h | 3 +++ src/lv_conf_checker.h | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lv_conf_template.h b/lv_conf_template.h index f1f06fe07..c67e1fad6 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -411,6 +411,9 @@ typedef void * lv_obj_user_data_t; /*Container (dependencies: -*/ #define LV_USE_CONT 1 +/*Color picker (dependencies: -*/ +#define LV_USE_CPICKER 1 + /*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ #define LV_USE_DDLIST 1 #if LV_USE_DDLIST != 0 diff --git a/src/lv_conf_checker.h b/src/lv_conf_checker.h index 7accfd259..87905400c 100644 --- a/src/lv_conf_checker.h +++ b/src/lv_conf_checker.h @@ -579,6 +579,11 @@ #define LV_USE_CONT 1 #endif +/*Color picker (dependencies: -*/ +#ifndef LV_USE_CPICKER +#define LV_USE_CPICKER 1 +#endif + /*Drop down list (dependencies: lv_page, lv_label, lv_symbol_def.h)*/ #ifndef LV_USE_DDLIST #define LV_USE_DDLIST 1 From d4196c75349fedc495a0ab26c485308e67ef562b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 2 Oct 2019 16:47:08 +0200 Subject: [PATCH 3/4] cpicker: add preview feature --- src/lv_objx/lv_cpicker.c | 44 ++++++++++++++++++++++++++++++++++++++++ src/lv_objx/lv_cpicker.h | 15 ++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/lv_objx/lv_cpicker.c b/src/lv_objx/lv_cpicker.c index 0e3749556..d7e30d5d5 100644 --- a/src/lv_objx/lv_cpicker.c +++ b/src/lv_objx/lv_cpicker.c @@ -110,7 +110,9 @@ lv_obj_t * lv_cpicker_create(lv_obj_t * par, const lv_obj_t * copy) ext->indic.colored = 0; ext->color_mode = LV_CPICKER_COLOR_MODE_HUE; ext->color_mode_fixed = 0; + ext->preview = 0; ext->last_click_time = 0; + ext->last_change_time = 0; /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_cb(new_cpicker, lv_cpicker_signal); @@ -133,6 +135,7 @@ lv_obj_t * lv_cpicker_create(lv_obj_t * par, const lv_obj_t * copy) ext->type = copy_ext->type; ext->color_mode = copy_ext->color_mode; ext->color_mode_fixed = copy_ext->color_mode_fixed; + ext->preview = copy_ext->preview; ext->hsv = copy_ext->hsv; ext->indic.colored = copy_ext->indic.colored; ext->indic.style = copy_ext->indic.style; @@ -314,6 +317,19 @@ void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en) invalidate_indic(cpicker); } +/** + * Add a color preview in the middle of the DISC type color picker + * @param cpicker pointer to colorpicker object + * @param en true: enable preview; false: disable preview + */ +void lv_cpicker_set_preview(lv_obj_t * cpicker, bool en) +{ + LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME); + + lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); + ext->preview = en ? 1 : 0; + lv_obj_invalidate(cpicker); +} /*===================== * Getter functions *====================*/ @@ -455,6 +471,21 @@ bool lv_cpicker_get_indic_colored(lv_obj_t * cpicker) return ext->indic.colored ? true : false; } +/** + * Whether the preview is enabled or not + * @param cpicker pointer to colorpicker object + * @return en true: preview is enabled; false: preview is disabled + */ +bool lv_cpicker_get_preview(lv_obj_t * cpicker) +{ + LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME); + + lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); + + return ext->preview ? true : false; +} + + /*===================== * Other functions *====================*/ @@ -502,6 +533,7 @@ static bool lv_cpicker_design(lv_obj_t * cpicker, const lv_area_t * mask, lv_des static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale) { + lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); int16_t start_angle = 0; /*Default*/ int16_t end_angle = 360 - LV_CPICKER_DEF_QF; /*Default*/ @@ -625,6 +657,18 @@ static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t area_mid.y2 -= style_main->line.width; lv_draw_rect(&area_mid, mask, &style, opa_scale); + + if(ext->preview) { + lv_color_t color = lv_cpicker_get_color(cpicker); + style.body.main_color = color; + style.body.grad_color = color; + area_mid.x1 += style_main->line.width; + area_mid.y1 += style_main->line.width; + area_mid.x2 -= style_main->line.width; + area_mid.y2 -= style_main->line.width; + + lv_draw_rect(&area_mid, mask, &style, opa_scale); + } } static void draw_rect_grad(lv_obj_t * cpicker, const lv_area_t * mask, lv_opa_t opa_scale) diff --git a/src/lv_objx/lv_cpicker.h b/src/lv_objx/lv_cpicker.h index 0e6bea594..7bce0fec8 100644 --- a/src/lv_objx/lv_cpicker.h +++ b/src/lv_objx/lv_cpicker.h @@ -61,6 +61,7 @@ typedef struct { lv_cpicker_color_mode_t color_mode :2; uint8_t color_mode_fixed :1; lv_cpicker_type_t type :1; + uint8_t preview :1; } lv_cpicker_ext_t; /*Styles*/ @@ -158,6 +159,13 @@ void lv_cpicker_set_color_mode_fixed(lv_obj_t * cpicker, bool fixed); */ void lv_cpicker_set_indic_colored(lv_obj_t * cpicker, bool en); +/** + * Add a color preview in the middle of the DISC type color picker + * @param cpicker pointer to colorpicker object + * @param en true: enable preview; false: disable preview + */ +void lv_cpicker_set_preview(lv_obj_t * cpicker, bool en); + /*===================== * Getter functions *====================*/ @@ -226,6 +234,13 @@ lv_color_t lv_cpicker_get_color(lv_obj_t * cpicker); */ bool lv_cpicker_get_indic_colored(lv_obj_t * cpicker); +/** + * Whether the preview is enabled or not + * @param cpicker pointer to colorpicker object + * @return en true: preview is enabled; false: preview is disabled + */ +bool lv_cpicker_get_preview(lv_obj_t * cpicker); + /*===================== * Other functions *====================*/ From 434ef7e667b359188e5b5ef4278b3b8bf2de61ba Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 2 Oct 2019 16:58:41 +0200 Subject: [PATCH 4/4] cpicker: minor fixes --- src/lv_objx/lv_cpicker.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/lv_objx/lv_cpicker.c b/src/lv_objx/lv_cpicker.c index d7e30d5d5..467c62ee2 100644 --- a/src/lv_objx/lv_cpicker.c +++ b/src/lv_objx/lv_cpicker.c @@ -209,7 +209,11 @@ void lv_cpicker_set_hue(lv_obj_t * cpicker, uint16_t hue) ext->hsv.h = hue % 360; - if(ext->color_mode_fixed == LV_CPICKER_COLOR_MODE_HUE) refr_indic_pos(cpicker); + if(ext->color_mode == LV_CPICKER_COLOR_MODE_HUE) refr_indic_pos(cpicker); + + if(ext->preview && ext->type == LV_CPICKER_TYPE_DISC) { + lv_obj_invalidate(cpicker); + } } /** @@ -223,9 +227,13 @@ void lv_cpicker_set_saturation(lv_obj_t * cpicker, uint8_t saturation) lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); - ext->hsv.s = saturation % 100; + ext->hsv.s = saturation > 100 ? 100 : saturation; - if(ext->color_mode_fixed == LV_CPICKER_COLOR_MODE_SATURATION) refr_indic_pos(cpicker); + if(ext->color_mode == LV_CPICKER_COLOR_MODE_SATURATION) refr_indic_pos(cpicker); + + if(ext->preview && ext->type == LV_CPICKER_TYPE_DISC) { + lv_obj_invalidate(cpicker); + } } /** @@ -239,9 +247,13 @@ void lv_cpicker_set_value(lv_obj_t * cpicker, uint8_t val) lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); - ext->hsv.v = val % 100; + ext->hsv.v = val > 100 ? 100 : val; - if(ext->color_mode_fixed == LV_CPICKER_COLOR_MODE_VALUE) refr_indic_pos(cpicker); + if(ext->color_mode == LV_CPICKER_COLOR_MODE_VALUE) refr_indic_pos(cpicker); + + if(ext->preview && ext->type == LV_CPICKER_TYPE_DISC) { + lv_obj_invalidate(cpicker); + } } /** @@ -256,7 +268,6 @@ void lv_cpicker_set_hsv(lv_obj_t * cpicker, lv_color_hsv_t hsv) lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); ext->hsv = hsv; - refr_indic_pos(cpicker); lv_obj_invalidate(cpicker); } @@ -1022,10 +1033,10 @@ static lv_res_t double_click_reset(lv_obj_t * cpicker) lv_cpicker_set_hue(cpicker, LV_CPICKER_DEF_HUE); break; case LV_CPICKER_COLOR_MODE_SATURATION: - lv_cpicker_set_hue(cpicker, LV_CPICKER_DEF_SATURATION); + lv_cpicker_set_saturation(cpicker, LV_CPICKER_DEF_SATURATION); break; case LV_CPICKER_COLOR_MODE_VALUE: - lv_cpicker_set_hue(cpicker, LV_CPICKER_DEF_VALUE); + lv_cpicker_set_value(cpicker, LV_CPICKER_DEF_VALUE); break; }