From 305db3686e36343ffc1ca5d310f8cb67364d77f4 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 15 Jun 2016 10:23:10 +0200 Subject: [PATCH 1/7] label auto_break style attribut moved to label attribute as fixw (fixwidth) --- lv_draw/lv_draw.c | 12 +++------ lv_misc/text.c | 2 +- lv_objx/lv_label.c | 64 +++++++++++++++++++++++++++++++--------------- lv_objx/lv_label.h | 10 +++++--- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 71942f1de..8910edcdf 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -60,8 +60,7 @@ static lv_rects_t lv_img_no_pic_rects = { static lv_labels_t lv_img_no_pic_labels = { .font = LV_FONT_DEFAULT, .color = COLOR_WHITE, .letter_space = 1 * LV_STYLE_MULT, .line_space = 1 * LV_STYLE_MULT, - .mid = 1, .auto_break = 1 - + .mid = 1, }; /********************** @@ -113,16 +112,11 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, const font_t * font_p = font_get(labels_p->font); cord_t w = area_get_width(cords_p); - cord_t max_w = w; - /*If the auto-break is not enabled the set the max length to very big */ - if(labels_p->auto_break == 0) { - max_w = LV_CORD_MAX; - } /*Init variables for the first line*/ cord_t line_length = 0; uint32_t line_start = 0; - uint32_t line_end = txt_get_next_line(txt, font_p, labels_p->letter_space, max_w); + uint32_t line_end = txt_get_next_line(txt, font_p, labels_p->letter_space, w); point_t pos; pos.x = cords_p->x1; @@ -146,7 +140,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, } /*Go to next line*/ line_start = line_end; - line_end += txt_get_next_line(&txt[line_start], font_p, labels_p->letter_space, max_w); + line_end += txt_get_next_line(&txt[line_start], font_p, labels_p->letter_space, w); pos.x = cords_p->x1; /*Align to middle*/ diff --git a/lv_misc/text.c b/lv_misc/text.c index 7e9930eeb..babc61cfc 100644 --- a/lv_misc/text.c +++ b/lv_misc/text.c @@ -62,7 +62,7 @@ uint16_t txt_get_next_line(const char * txt, const font_t * font_p, act_l += font_get_width(font_p, txt[i]); /*If the txt is too long then finish, this is the line end*/ - if(act_l >= max_l) { + if(act_l > max_l) { /*If already a break character is found, then break there*/ if(last_break != TXT_NO_BREAK_FOUND) { i = last_break; diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 635893f56..6fdc8a488 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -33,26 +33,26 @@ static bool lv_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_m **********************/ static lv_labels_t lv_labels_def = { .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0x10, 0x18, 0x20), - .letter_space = 3 * LV_STYLE_MULT, .line_space = 3 * LV_STYLE_MULT, - .mid = 1, .auto_break = 0 + .letter_space = 2 * LV_STYLE_MULT, .line_space = 2 * LV_STYLE_MULT, + .mid = 1 }; static lv_labels_t lv_labels_btn = { .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0xd0, 0xe0, 0xf0), .letter_space = 2 * LV_STYLE_MULT, .line_space = 2 * LV_STYLE_MULT, - .mid = 1, .auto_break = 0 + .mid = 1, }; static lv_labels_t lv_labels_title = { .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0x10, 0x20, 0x30), .letter_space = 4 * LV_STYLE_MULT, .line_space = 4 * LV_STYLE_MULT, - .mid = 0, .auto_break = 1 + .mid = 0, }; static lv_labels_t lv_labels_txt = { .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0x16, 0x23, 0x34), .letter_space = 1 * LV_STYLE_MULT, .line_space = 2 * LV_STYLE_MULT, - .mid = 0, .auto_break = 1 + .mid = 0, }; @@ -81,7 +81,7 @@ lv_obj_t* lv_label_create(lv_obj_t* par_dp, lv_obj_t * ori_dp) lv_obj_alloc_ext(new_obj, sizeof(lv_label_ext_t)); lv_label_ext_t * label_p = lv_obj_get_ext(new_obj); - label_p->txt = NULL; + label_p->txt_dp = NULL; lv_obj_set_design_f(new_obj, lv_label_design); lv_obj_set_signal_f(new_obj, lv_label_signal); @@ -124,8 +124,8 @@ bool lv_label_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param) /*No signal handling*/ switch(sign) { case LV_SIGNAL_CLEANUP: - dm_free(label_p->txt); - label_p->txt = NULL; + dm_free(label_p->txt_dp); + label_p->txt_dp = NULL; break; case LV_SIGNAL_STYLE_CHG: lv_label_set_text(obj_dp, lv_label_get_text(obj_dp)); @@ -145,7 +145,7 @@ bool lv_label_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param) /** * Set a new text for a label * @param obj_dp pointer to a label object - * @param text '\0' terminated chacter string + * @param text '\0' terminated character string */ void lv_label_set_text(lv_obj_t * obj_dp, const char * text) { @@ -153,15 +153,15 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text) lv_obj_inv(obj_dp); - lv_label_ext_t * label_p = lv_obj_get_ext(obj_dp); + lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp); uint32_t len = strlen(text) + 1; - if(label_p->txt != NULL && text != label_p->txt) { - dm_free(label_p->txt); + if(ext_p->txt_dp != NULL && text != ext_p->txt_dp) { + dm_free(ext_p->txt_dp); } - label_p->txt = dm_alloc(len); - strcpy(label_p->txt, text); + ext_p->txt_dp = dm_alloc(len); + strcpy(ext_p->txt_dp, text); uint32_t line_start = 0; uint32_t new_line_start = 0; @@ -173,8 +173,8 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text) cord_t longest_line = 0; cord_t act_line_length; - /*If the auto-break is not enabled the set the max length to very big */ - if(labels_p->auto_break == 0) { + /*If the fix width is not enabled the set the max length to very big */ + if(ext_p->fixw == 0) { max_length = LV_CORD_MAX; } @@ -185,8 +185,8 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text) new_height += letter_height; new_height += labels_p->line_space; - /*If no auto break then calc. the longest line */ - if(labels_p->auto_break == false) { + /*If no fix width then calc. the longest line */ + if(ext_p->fixw == false) { act_line_length = txt_get_length(&text[line_start], new_line_start - line_start, font_p, labels_p->letter_space); if(act_line_length > longest_line) { @@ -202,8 +202,8 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text) lv_obj_set_height(obj_dp, new_height); - /*Refresh the length if no autobreak*/ - if(labels_p->auto_break == 0) { + /*Refresh the length if no fix width*/ + if(ext_p->fixw == 0) { lv_obj_set_width(obj_dp, longest_line); } @@ -213,6 +213,17 @@ void lv_label_set_text(lv_obj_t * obj_dp, const char * text) lv_obj_inv(obj_dp); } +/** + * Set the fix width attribute + * @param obj_dp pointer to a label object + * @param fixw true: enable fix width for the label + */ +void lv_label_set_fixw(lv_obj_t * obj_dp, bool fixw) +{ + lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp); + ext_p->fixw = fixw == false ? 0 : 1; +} + /*===================== * Getter functions *====================*/ @@ -226,7 +237,18 @@ const char * lv_label_get_text(lv_obj_t* obj_dp) { lv_label_ext_t * label_p = lv_obj_get_ext(obj_dp); - return label_p->txt; + return label_p->txt_dp; +} + +/** + * Get the fix width attribute of a label + * @param obj_dp pointer to a label object + * @return true: fix width is enabled + */ +bool lv_label_get_fixw(lv_obj_t * obj_dp) +{ + lv_label_ext_t * ext_p = lv_obj_get_ext(obj_dp); + return ext_p->fixw == 0 ? false: true; } /** diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index 651559e47..d66f30039 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -30,12 +30,12 @@ typedef struct uint16_t letter_space; uint16_t line_space; uint8_t mid :1; - uint8_t auto_break :1; }lv_labels_t; typedef struct { - char* txt; + char * txt_dp; + uint8_t fixw :1; }lv_label_ext_t; typedef enum @@ -54,11 +54,13 @@ lv_obj_t* lv_label_create(lv_obj_t* par_dp, lv_obj_t * ori_dp); bool lv_label_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param); -lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p); void lv_label_set_text(lv_obj_t* obj_dp, const char * text); - +void lv_label_set_fixw(lv_obj_t * obj_dp, bool fixw); const char * lv_label_get_text(lv_obj_t* obj_dp); +bool lv_label_get_fixw(lv_obj_t * obj_dp); + +lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p); /********************** * MACROS From a50650ea828a0a10af52f9cc44faffaa70d594b0 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 15 Jun 2016 11:08:18 +0200 Subject: [PATCH 2/7] Line upscale added --- lv_objx/lv_label.c | 5 +-- lv_objx/lv_line.c | 93 ++++++++++++++++++++++++++++++++-------------- lv_objx/lv_line.h | 7 +++- 3 files changed, 73 insertions(+), 32 deletions(-) diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 6fdc8a488..1aefb4122 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -91,13 +91,12 @@ lv_obj_t* lv_label_create(lv_obj_t* par_dp, lv_obj_t * ori_dp) lv_obj_set_opa(new_obj, OPA_COVER); lv_obj_set_click(new_obj, false); lv_obj_set_style(new_obj, &lv_labels_def); + lv_label_set_fixw(new_obj, false); lv_label_set_text(new_obj, "Text"); } /*Copy 'ori_dp' if not NULL*/ else { - lv_obj_set_opa(new_obj, lv_obj_get_opa(ori_dp)); - lv_obj_set_click(new_obj, lv_obj_get_click(ori_dp)); - lv_obj_set_style(new_obj, lv_obj_get_style(ori_dp)); + lv_label_set_fixw(new_obj, lv_label_get_fixw(ori_dp)); lv_label_set_text(new_obj, lv_label_get_text(ori_dp)); } return new_obj; diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index 8dd7864f8..8d80a51cf 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -67,16 +67,17 @@ lv_obj_t* lv_line_create(lv_obj_t* par_dp, lv_obj_t * copy_dp) dm_assert(new_obj_dp); /*Extend the basic object to rectangle object*/ - lv_line_t *line_ext_p = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_line_t)); + lv_line_ext_t *ext_p = lv_obj_alloc_ext(new_obj_dp, sizeof(lv_line_ext_t)); lv_obj_set_design_f(new_obj_dp, lv_line_design); lv_obj_set_signal_f(new_obj_dp, lv_line_signal); /*Init the new rectangle*/ if(copy_dp == NULL) { - line_ext_p->point_num = 0; - line_ext_p->point_p = NULL; - line_ext_p->auto_size = 1; - line_ext_p->y_inv = 0; + ext_p->point_num = 0; + ext_p->point_p = NULL; + ext_p->auto_size = 1; + ext_p->y_inv = 0; + ext_p->upscale = 1; lv_obj_set_style(new_obj_dp, &lv_lines_def); } /*Copy 'copy_p' is not NULL*/ @@ -84,8 +85,9 @@ lv_obj_t* lv_line_create(lv_obj_t* par_dp, lv_obj_t * copy_dp) lv_line_set_auto_size(new_obj_dp,lv_line_get_auto_size(copy_dp)); lv_line_set_y_inv(new_obj_dp,lv_line_get_y_inv(copy_dp)); lv_line_set_auto_size(new_obj_dp,lv_line_get_auto_size(copy_dp)); - lv_line_set_points(new_obj_dp, LV_EA(copy_dp, lv_line_t)->point_p, - LV_EA(copy_dp, lv_line_t)->point_num); + lv_line_set_upscale(new_obj_dp,lv_line_get_upscale(copy_dp)); + lv_line_set_points(new_obj_dp, LV_EA(copy_dp, lv_line_ext_t)->point_p, + LV_EA(copy_dp, lv_line_ext_t)->point_num); } @@ -130,17 +132,22 @@ bool lv_line_signal(lv_obj_t* obj_dp, lv_signal_t sign, void * param) */ void lv_line_set_points(lv_obj_t* obj_dp, const point_t * point_a, uint16_t point_num) { - lv_line_t * line_p = lv_obj_get_ext(obj_dp); - line_p->point_p = point_a; - line_p->point_num = point_num; + lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp); + ext_p->point_p = point_a; + ext_p->point_num = point_num; - if(point_num > 0 && line_p->auto_size != 0) { + uint8_t us = 1; + if(ext_p->upscale != 0) { + us = LV_DOWNSCALE; + } + + if(point_num > 0 && ext_p->auto_size != 0) { uint16_t i; cord_t xmax = LV_CORD_MIN; cord_t ymax = LV_CORD_MIN; for(i = 0; i < point_num; i++) { - xmax = max(point_a[i].x, xmax); - ymax = max(point_a[i].y, ymax); + xmax = max(point_a[i].x * us, xmax); + ymax = max(point_a[i].y * us, ymax); } lv_lines_t * lines_p = lv_obj_get_style(obj_dp); @@ -156,7 +163,7 @@ void lv_line_set_points(lv_obj_t* obj_dp, const point_t * point_a, uint16_t poin */ void lv_line_set_auto_size(lv_obj_t * obj_dp, bool en) { - lv_line_t * line_p = lv_obj_get_ext(obj_dp); + lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp); line_p->auto_size = en == false ? 0 : 1; @@ -175,13 +182,28 @@ void lv_line_set_auto_size(lv_obj_t * obj_dp, bool en) */ void lv_line_set_y_inv(lv_obj_t * obj_dp, bool en) { - lv_line_t * line_p = lv_obj_get_ext(obj_dp); + lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp); line_p->y_inv = en == false ? 0 : 1; lv_obj_inv(obj_dp); } +/** + * Enable (or disable) the point coordinate upscaling (compensate LV_DOWNSCALE). + * @param obj_dp pointer to a line object + * @param en true: enable the point coordinate upscaling + */ +void lv_line_set_upscale(lv_obj_t * obj_dp, bool en) +{ + lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp); + + ext_p->upscale = en == false ? 0 : 1; + + /*Refresh to point to handle auto size*/ + lv_line_set_points(obj_dp, ext_p->point_p, ext_p->point_num); +} + /*===================== * Getter functions *====================*/ @@ -193,7 +215,7 @@ void lv_line_set_y_inv(lv_obj_t * obj_dp, bool en) */ bool lv_line_get_auto_size(lv_obj_t * obj_dp) { - lv_line_t * line_p = lv_obj_get_ext(obj_dp); + lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp); return line_p->auto_size == 0 ? false : true; } @@ -205,11 +227,23 @@ bool lv_line_get_auto_size(lv_obj_t * obj_dp) */ bool lv_line_get_y_inv(lv_obj_t * obj_dp) { - lv_line_t * line_p = lv_obj_get_ext(obj_dp); + lv_line_ext_t * line_p = lv_obj_get_ext(obj_dp); return line_p->y_inv == 0 ? false : true; } +/** + * Get the point upscale enable attribute + * @param obj_dp pointer to a line object + * @return true: point coordinate upscale is enabled, false: disabled + */ +bool lv_line_get_upscale(lv_obj_t * obj_dp) +{ + lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp); + + return ext_p->upscale == 0 ? false : true; +} + /** * Return with a pointer to a built-in style and/or copy it to a variable * @param style a style name from lv_lines_builtin_t enum @@ -259,9 +293,9 @@ static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo /*A line never covers an area*/ if(mode == LV_DESIGN_COVER_CHK) return false; - lv_line_t * line_p = lv_obj_get_ext(obj_dp); + lv_line_ext_t * ext_p = lv_obj_get_ext(obj_dp); - if(line_p->point_num == 0 || line_p->point_p == NULL) return false; + if(ext_p->point_num == 0 || ext_p->point_p == NULL) return false; lv_lines_t * lines_p = lv_obj_get_style(obj_dp); if(lines_p->bg_opa != 0) { @@ -280,18 +314,23 @@ static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo point_t p2; cord_t h = lv_obj_get_height(obj_dp); uint16_t i; + uint8_t us = 1; + if(ext_p->upscale != 0) { + us = LV_DOWNSCALE; + } /*Read all pints and draw the lines*/ - for (i = 0; i < line_p->point_num - 1; i++) { - p1.x = line_p->point_p[i].x + x_ofs; - p2.x = line_p->point_p[i + 1].x + x_ofs; + for (i = 0; i < ext_p->point_num - 1; i++) { - if(line_p->y_inv == 0) { - p1.y = line_p->point_p[i].y + y_ofs; - p2.y = line_p->point_p[i + 1].y + y_ofs; + p1.x = ext_p->point_p[i].x * us + x_ofs; + p2.x = ext_p->point_p[i + 1].x * us + x_ofs; + + if(ext_p->y_inv == 0) { + p1.y = ext_p->point_p[i].y * us + y_ofs; + p2.y = ext_p->point_p[i + 1].y * us + y_ofs; } else { - p1.y = h - line_p->point_p[i].y + y_ofs; - p2.y = h - line_p->point_p[i + 1].y + y_ofs; + p1.y = h - ext_p->point_p[i].y * us + y_ofs; + p2.y = h - ext_p->point_p[i + 1].y * us + y_ofs; } lv_draw_line(&p1, &p2, mask_p, lines_p, opa); } diff --git a/lv_objx/lv_line.h b/lv_objx/lv_line.h index 7973e57ab..c4ddd8783 100644 --- a/lv_objx/lv_line.h +++ b/lv_objx/lv_line.h @@ -26,8 +26,9 @@ typedef struct const point_t * point_p; uint16_t point_num; uint8_t auto_size :1; - uint8_t y_inv :1; -}lv_line_t; + uint8_t y_inv :1; + uint8_t upscale :1; +}lv_line_ext_t; typedef struct { @@ -53,8 +54,10 @@ lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p); void lv_line_set_points(lv_obj_t * obj_dp, const point_t * point_a, uint16_t point_num); void lv_line_set_auto_size(lv_obj_t * obj_dp, bool en); void lv_line_set_y_inv(lv_obj_t * obj_dp, bool en); +void lv_line_set_upscale(lv_obj_t * obj_dp, bool en); bool lv_line_get_auto_size(lv_obj_t * obj_dp); bool lv_line_get_y_inv(lv_obj_t * obj_dp); +bool lv_line_get_upscale(lv_obj_t * obj_dp); /********************** * MACROS From 2666ed5fab90b68c832dda1676ed7ebb0a765a9c Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 15 Jun 2016 12:56:02 +0200 Subject: [PATCH 3/7] Add lv_objs_t to every lv_obj derivated styles --- lv_draw/lv_draw.c | 19 +++++++++---------- lv_objx/lv_btn.c | 41 ++++++++++++++++++----------------------- lv_objx/lv_btn.h | 6 ------ lv_objx/lv_img.c | 1 - lv_objx/lv_img.h | 1 + lv_objx/lv_line.c | 6 +++--- lv_objx/lv_line.h | 2 +- lv_objx/lv_page.c | 22 +++++++++++----------- lv_objx/lv_rect.c | 10 +++++----- lv_objx/lv_rect.h | 3 +-- 10 files changed, 49 insertions(+), 62 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 8910edcdf..f4a192af5 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -52,9 +52,9 @@ static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color static lv_rects_t lv_img_no_pic_rects = { - .mcolor = COLOR_BLACK, .gcolor = COLOR_BLACK, + .objs.color = COLOR_BLACK, .gcolor = COLOR_BLACK, .bcolor = COLOR_RED, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100, - .round = 0, .empty = 0 + .round = 0, .objs.empty = 0 }; static lv_labels_t lv_img_no_pic_labels = { @@ -80,8 +80,7 @@ static lv_labels_t lv_img_no_pic_labels = { void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa) { - if(rects_p->empty == 0){ - + if(rects_p->objs.empty == 0){ lv_draw_rect_main_mid(cords_p, mask_p, rects_p, opa); if(rects_p->round != 0) { @@ -456,7 +455,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = max(act_area.x1, act_area.x2); draw_area.y1 = min(act_area.y1, act_area.y2); draw_area.y2 = max(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->color, opa); + fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } if (hor == false && last_x != act_point.x) { area_t act_area; @@ -472,7 +471,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = max(act_area.x1, act_area.x2); draw_area.y1 = min(act_area.y1, act_area.y2); draw_area.y2 = max(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->color, opa); + fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } /*Calc. the next point of the line*/ @@ -500,7 +499,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = max(act_area.x1, act_area.x2); draw_area.y1 = min(act_area.y1, act_area.y2); draw_area.y2 = max(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->color, opa); + fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } if (hor == false) { area_t act_area; @@ -514,7 +513,7 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, draw_area.x2 = max(act_area.x1, act_area.x2); draw_area.y1 = min(act_area.y1, act_area.y2); draw_area.y2 = max(act_area.y1, act_area.y2); - fill_fp(&draw_area, mask_p, lines_p->color, opa); + fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } } @@ -533,7 +532,7 @@ static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, { uint16_t radius = rects_p->round; - color_t main_color = rects_p->mcolor; + color_t main_color = rects_p->objs.color; color_t grad_color = rects_p->gcolor; uint8_t mix; cord_t height = area_get_height(cords_p); @@ -583,7 +582,7 @@ static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask { uint16_t radius = rects_p->round; - color_t main_color = rects_p->mcolor; + color_t main_color = rects_p->objs.color; color_t grad_color = rects_p->gcolor; color_t act_color; uint8_t mix; diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 14cfc0cd3..64abb7234 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -56,19 +56,19 @@ static lv_btns_t lv_btns_def = .gcolor[LV_BTN_STATE_INA] = COLOR_GRAY, .bcolor[LV_BTN_STATE_INA] = COLOR_WHITE, - .bwidth = 2 * LV_STYLE_MULT, - .bopa = 50, - .empty = 0, - .round = 4 * LV_STYLE_MULT, - .hpad = 10 * LV_STYLE_MULT, - .vpad = 15 * LV_STYLE_MULT, + .rects.bwidth = 2 * LV_STYLE_MULT, + .rects.bopa = 50, + .rects.objs.empty = 0, + .rects.round = 4 * LV_STYLE_MULT, + .rects.hpad = 10 * LV_STYLE_MULT, + .rects.vpad = 15 * LV_STYLE_MULT, }; static lv_btns_t lv_btns_transp = { - .bwidth = 0, - .empty = 1, - .hpad = 10 * LV_STYLE_MULT, - .vpad = 15 * LV_STYLE_MULT, + .rects.bwidth = 0, + .rects.objs.empty = 1, + .rects.hpad = 10 * LV_STYLE_MULT, + .rects.vpad = 15 * LV_STYLE_MULT, }; static lv_btns_t lv_btns_border = @@ -78,12 +78,12 @@ static lv_btns_t lv_btns_border = .bcolor[LV_BTN_STATE_TGL_REL] = COLOR_BLACK, .bcolor[LV_BTN_STATE_TGL_PR] = COLOR_BLACK, .bcolor[LV_BTN_STATE_INA] = COLOR_GRAY, - .bwidth = 2 * LV_STYLE_MULT, - .empty = 1, - .bopa = 50, - .round = 4 * LV_STYLE_MULT, - .hpad = 10 * LV_STYLE_MULT, - .vpad = 15 * LV_STYLE_MULT, + .rects.bwidth = 2 * LV_STYLE_MULT, + .rects.objs.empty = 1, + .rects.bopa = 50, + .rects.round = 4 * LV_STYLE_MULT, + .rects.hpad = 10 * LV_STYLE_MULT, + .rects.vpad = 15 * LV_STYLE_MULT, }; /********************** @@ -417,17 +417,12 @@ static void lv_btn_style_load(lv_obj_t * obj_dp) { lv_btn_state_t state = lv_btn_get_state(obj_dp); lv_btns_t * btns_p = lv_obj_get_style(obj_dp); + /*Init the style*/ lv_rects_get(LV_RECTS_DEF, &btns_p->rects); - btns_p->rects.mcolor = btns_p->mcolor[state]; + btns_p->rects.objs.color = btns_p->mcolor[state]; btns_p->rects.gcolor = btns_p->gcolor[state]; btns_p->rects.bcolor = btns_p->bcolor[state]; - btns_p->rects.bwidth = btns_p->bwidth; - btns_p->rects.bopa = btns_p->bopa; - btns_p->rects.round = btns_p->round; - btns_p->rects.empty = btns_p->empty; - btns_p->rects.hpad= btns_p->hpad; - btns_p->rects.vpad= btns_p->vpad; } #endif diff --git a/lv_objx/lv_btn.h b/lv_objx/lv_btn.h index a51f82c8f..ecd294293 100644 --- a/lv_objx/lv_btn.h +++ b/lv_objx/lv_btn.h @@ -39,12 +39,6 @@ typedef struct color_t mcolor[LV_BTN_STATE_NUM]; color_t gcolor[LV_BTN_STATE_NUM]; color_t bcolor[LV_BTN_STATE_NUM]; - cord_t bwidth; - cord_t round; - opa_t bopa; - uint8_t empty; - cord_t hpad; - cord_t vpad; }lv_btns_t; typedef enum diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index a73853578..757bc3df9 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -67,7 +67,6 @@ lv_obj_t* lv_img_create(lv_obj_t* par_dp, lv_obj_t * copy_dp) lv_img_ext_t * img_ext_dp = lv_obj_get_ext(new_obj_dp); if(copy_dp == NULL) { - img_ext_dp->fn_dp = NULL; img_ext_dp->w = lv_obj_get_width(new_obj_dp); img_ext_dp->h = lv_obj_get_height(new_obj_dp); diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index ddeca0851..b03d76741 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -25,6 +25,7 @@ **********************/ typedef struct { + lv_objs_t objs; uint8_t transp_en :1; }lv_imgs_t; diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index 8d80a51cf..36c159000 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -38,13 +38,13 @@ static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo /********************** * STATIC VARIABLES **********************/ -static lv_lines_t lv_lines_def = { .width = 2 * LV_STYLE_MULT, .color = COLOR_RED, +static lv_lines_t lv_lines_def = { .width = 2 * LV_STYLE_MULT, .objs.color = COLOR_RED, .bg_color = COLOR_BLACK, .bg_opa = 0}; -static lv_lines_t lv_lines_decor = { .width = 1 * LV_STYLE_MULT, .color = COLOR_GRAY, +static lv_lines_t lv_lines_decor = { .width = 1 * LV_STYLE_MULT, .objs.color = COLOR_GRAY, .bg_color = COLOR_BLACK, .bg_opa = 0}; -static lv_lines_t lv_lines_chart = { .width = 3 * LV_STYLE_MULT, .color = COLOR_BLUE, +static lv_lines_t lv_lines_chart = { .width = 3 * LV_STYLE_MULT, .objs.color = COLOR_BLUE, .bg_color = COLOR_BLACK, .bg_opa = 0}; /********************** diff --git a/lv_objx/lv_line.h b/lv_objx/lv_line.h index c4ddd8783..7dc96e4eb 100644 --- a/lv_objx/lv_line.h +++ b/lv_objx/lv_line.h @@ -32,7 +32,7 @@ typedef struct typedef struct { - color_t color; + lv_objs_t objs; color_t bg_color; uint16_t width; opa_t bg_opa; diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 87c24ab12..9f7fee971 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -32,23 +32,23 @@ static void lv_page_sb_refresh(lv_obj_t* main_dp); **********************/ static lv_pages_t lv_pages_def = { - .bg_rects.mcolor = COLOR_WHITE, + .bg_rects.objs.color = COLOR_WHITE, .bg_rects.gcolor = COLOR_SILVER, .bg_rects.bcolor = COLOR_GRAY, .bg_rects.bopa = 50, .bg_rects.bwidth = 0 * LV_STYLE_MULT, .bg_rects.round = 2 * LV_STYLE_MULT, - .bg_rects.empty = 0, + .bg_rects.objs.empty = 0, .bg_rects.hpad = 10, .bg_rects.vpad = 10, - .sb_rects.mcolor = COLOR_BLACK, + .sb_rects.objs.color = COLOR_BLACK, .sb_rects.gcolor = COLOR_BLACK, .sb_rects.bcolor = COLOR_WHITE, .sb_rects.bopa = 50, .sb_rects.bwidth = 1 * LV_STYLE_MULT, .sb_rects.round = 5 * LV_STYLE_MULT, - .sb_rects.empty = 0, + .sb_rects.objs.empty = 0, .sb_width= 8 * LV_STYLE_MULT, .sb_opa=50, @@ -63,23 +63,23 @@ static lv_pages_t lv_pages_def = static lv_pages_t lv_pages_paper = { - .bg_rects.mcolor = COLOR_WHITE, + .bg_rects.objs.color = COLOR_WHITE, .bg_rects.gcolor = COLOR_WHITE, .bg_rects.bcolor = COLOR_GRAY, .bg_rects.bopa = 100, .bg_rects.bwidth = 2 * LV_STYLE_MULT, .bg_rects.round = 0 * LV_STYLE_MULT, - .bg_rects.empty = 0, + .bg_rects.objs.empty = 0, .bg_rects.hpad = 20 * LV_STYLE_MULT, .bg_rects.vpad = 20 * LV_STYLE_MULT, - .sb_rects.mcolor = COLOR_BLACK, + .sb_rects.objs.color = COLOR_BLACK, .sb_rects.gcolor = COLOR_BLACK, .sb_rects.bcolor = COLOR_SILVER, .sb_rects.bopa = 100, .sb_rects.bwidth = 1 * LV_STYLE_MULT, .sb_rects.round = 5 * LV_STYLE_MULT, - .sb_rects.empty = 0, + .sb_rects.objs.empty = 0, .sb_width = 10 * LV_STYLE_MULT, .sb_opa=50, @@ -93,17 +93,17 @@ static lv_pages_t lv_pages_paper = static lv_pages_t lv_pages_transp = { - .bg_rects.empty = 1, + .bg_rects.objs.empty = 1, .bg_rects.hpad = 1, .bg_rects.vpad = 1, - .sb_rects.mcolor = COLOR_BLACK, + .sb_rects.objs.color = COLOR_BLACK, .sb_rects.gcolor = COLOR_BLACK, .sb_rects.bcolor = COLOR_WHITE, .sb_rects.bopa = 0, .sb_rects.bwidth = 1 * LV_STYLE_MULT, .sb_rects.round = 5 * LV_STYLE_MULT, - .sb_rects.empty = 0, + .sb_rects.objs.empty = 0, .sb_width = 8 * LV_STYLE_MULT, .sb_opa = 50, diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index bdf2d46e8..d0a6d88c7 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -31,18 +31,18 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo * STATIC VARIABLES **********************/ static lv_rects_t lv_rects_def = -{ .mcolor = COLOR_MAKE(0x50, 0x70, 0x90), .gcolor = COLOR_MAKE(0x20, 0x40, 0x60), +{ .objs.color = COLOR_MAKE(0x50, 0x70, 0x90), .gcolor = COLOR_MAKE(0x20, 0x40, 0x60), .bcolor = COLOR_WHITE, .bwidth = 2 * LV_STYLE_MULT, .bopa = 50, - .round = 4 * LV_STYLE_MULT, .empty = 0, + .round = 4 * LV_STYLE_MULT, .objs.empty = 0, .hpad = 0, .vpad = 0 }; static lv_rects_t lv_rects_transp = -{ .bwidth = 0, .empty = 0, +{ .bwidth = 0, .objs.empty = 0, .hpad = 0, .vpad = 0 }; static lv_rects_t lv_rects_border = { .bcolor = COLOR_BLACK, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100, - .round = 4 * LV_STYLE_MULT, .empty = 1, + .round = 4 * LV_STYLE_MULT, .objs.empty = 1, .hpad = 0, .vpad = 0}; /********************** @@ -265,7 +265,7 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo { /* Because of the radius it is not sure the area is covered*/ if(mode == LV_DESIGN_COVER_CHK) { - if(LV_SA(obj_dp, lv_rects_t)->empty != 0) return false; + if(LV_SA(obj_dp, lv_rects_t)->objs.empty != 0) return false; uint16_t r = LV_SA(obj_dp, lv_rects_t)->round; area_t area_tmp; diff --git a/lv_objx/lv_rect.h b/lv_objx/lv_rect.h index 38f7fe453..181a20c68 100644 --- a/lv_objx/lv_rect.h +++ b/lv_objx/lv_rect.h @@ -25,14 +25,13 @@ typedef struct { - color_t mcolor; + lv_objs_t objs; color_t gcolor; color_t bcolor; uint16_t bwidth; cord_t hpad; cord_t vpad; uint8_t bopa; - uint8_t empty :1; uint16_t round; }lv_rects_t; From 27fa1699962432c74798992d5aaca4102621ca65 Mon Sep 17 00:00:00 2001 From: Gabor Date: Wed, 15 Jun 2016 16:09:24 +0200 Subject: [PATCH 4/7] lv_img transp_en moved to img header + minor modsin objx --- lv_draw/lv_draw.c | 268 +++++++++------------------------------ lv_draw/lv_draw.h | 2 +- lv_draw/lv_draw_rbasic.c | 3 +- lv_draw/lv_draw_rbasic.h | 3 +- lv_draw/lv_draw_vbasic.c | 94 ++++++++++---- lv_draw/lv_draw_vbasic.h | 3 +- lv_obj/lv_obj.c | 35 +---- lv_obj/lv_obj.h | 6 +- lv_objx/lv_btn.c | 2 +- lv_objx/lv_img.c | 22 ++-- lv_objx/lv_img.h | 11 +- lv_objx/lv_label.c | 10 +- lv_objx/lv_label.h | 2 +- lv_objx/lv_line.c | 19 +-- lv_objx/lv_line.h | 2 - lv_objx/lv_page.c | 5 +- lv_objx/lv_rect.c | 2 +- 17 files changed, 177 insertions(+), 312 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index f4a192af5..318ddda4a 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -43,7 +43,7 @@ static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h); #if LV_VDB_SIZE != 0 static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_vfill; static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_vletter; -static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp) = lv_vmap; +static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, color_t recolor, opa_t recolor_opa) = lv_vmap; #else static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_rfill; static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_rletter; @@ -58,7 +58,7 @@ static lv_rects_t lv_img_no_pic_rects = { }; static lv_labels_t lv_img_no_pic_labels = { - .font = LV_FONT_DEFAULT, .color = COLOR_WHITE, + .font = LV_FONT_DEFAULT, .objs.color = COLOR_WHITE, .letter_space = 1 * LV_STYLE_MULT, .line_space = 1 * LV_STYLE_MULT, .mid = 1, }; @@ -134,7 +134,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, while(txt[line_start] != '\0') { /*Write all letter of a line*/ for(i = line_start; i < line_end; i++) { - letter_fp(&pos, mask_p, font_p, txt[i], labels_p->color, opa); + letter_fp(&pos, mask_p, font_p, txt[i], labels_p->objs.color, opa); pos.x += font_get_width(font_p, txt[i]) + labels_p->letter_space; } /*Go to next line*/ @@ -163,80 +163,80 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, * @param opa opacity of the image (0..255) */ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, - const lv_imgs_t * imgs_p, opa_t opa, const char * fn, const color_t * map_p) + const lv_imgs_t * imgs_p, opa_t opa, const char * fn) { - - if(map_p != NULL) { - map_fp(cords_p, mask_p, map_p, opa, imgs_p->transp_en); - } else if(fn != NULL) { - fs_file_t file; - fs_res_t res = fs_open(&file, fn, FS_MODE_RD); - if(res == FS_RES_OK) { - cord_t row; - color_t buf[LV_HOR_RES]; - uint32_t br; - area_t act_area; - uint8_t ds_shift = 0; - uint8_t ds_num = 0; - #if LV_DOWNSCALE <= 1 || LV_UPSCALE_MAP == 0 - ds_shift = 0; - ds_num = 1; - #elif LV_DOWNSCALE == 2 - ds_shift = 1; - ds_num = 2; - #elif LV_DOWNSCALE == 4 - ds_shift = 2; - ds_num = 4; - #else - #error "LV: not supported LV_DOWNSCALE value" - #endif + if(fn == NULL) { + lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); + lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, "No data"); + } else { + fs_file_t file; + fs_res_t res = fs_open(&file, fn, FS_MODE_RD); + if(res == FS_RES_OK) { + cord_t row; + color_t buf[LV_HOR_RES]; + uint32_t br; + area_t act_area; + uint8_t ds_shift = 0; + uint8_t ds_num = 0; + #if LV_DOWNSCALE <= 1 || LV_UPSCALE_MAP == 0 + ds_shift = 0; + ds_num = 1; + #elif LV_DOWNSCALE == 2 + ds_shift = 1; + ds_num = 2; + #elif LV_DOWNSCALE == 4 + ds_shift = 2; + ds_num = 4; + #else + #error "LV: not supported LV_DOWNSCALE value" + #endif - area_t mask_sub; - bool union_ok; - union_ok = area_union(&mask_sub, mask_p, cords_p); + area_t mask_sub; + bool union_ok; + union_ok = area_union(&mask_sub, mask_p, cords_p); if(union_ok == false) { fs_close(&file); return; } + lv_img_raw_header_t header; + res = fs_read(&file, &header, sizeof(lv_img_raw_header_t), &br); - uint32_t start_offset = sizeof(lv_img_raw_header_t); + uint32_t start_offset = 0; start_offset += (area_get_width(cords_p) >> ds_shift) * - ((mask_sub.y1 - cords_p->y1) >> ds_shift) * sizeof(color_t); /*First row*/ + ((mask_sub.y1 - cords_p->y1) >> ds_shift) * sizeof(color_t); /*First row*/ start_offset += ((mask_sub.x1 - cords_p->x1) >> ds_shift) * sizeof(color_t); /*First col*/ - fs_seek(&file, start_offset); + fs_seek(&file, start_offset); - uint32_t useful_data = (area_get_width(&mask_sub) >> ds_shift)* sizeof(color_t); + uint32_t useful_data = (area_get_width(&mask_sub) >> ds_shift)* sizeof(color_t); uint32_t next_row = (area_get_width(cords_p) >> ds_shift) * sizeof(color_t) - useful_data; - area_cpy(&act_area, &mask_sub); - act_area.y2 = act_area.y1 + ds_num - 1; - uint32_t act_pos; + area_cpy(&act_area, &mask_sub); + act_area.y2 = act_area.y1 + ds_num - 1; + uint32_t act_pos; - for(row = mask_sub.y1; row <= mask_sub.y2; row += ds_num) { - res = fs_read(&file, buf, useful_data, &br); - map_fp(&act_area, &mask_sub, buf, opa, imgs_p->transp_en); - fs_tell(&file, &act_pos); - fs_seek(&file, act_pos + next_row); - act_area.y1 += ds_num; - act_area.y2 += ds_num; - } + for(row = mask_sub.y1; row <= mask_sub.y2; row += ds_num) { + res = fs_read(&file, buf, useful_data, &br); + map_fp(&act_area, &mask_sub, buf, opa, header.transp, + imgs_p->objs.color, imgs_p->recolor_opa); + fs_tell(&file, &act_pos); + fs_seek(&file, act_pos + next_row); + act_area.y1 += ds_num; + act_area.y2 += ds_num; + } - } - fs_close(&file); + } + fs_close(&file); - if(res != FS_RES_OK) { - lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); - lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, fn); - } - - } else { - lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); - lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, "No data"); - } + if(res != FS_RES_OK) { + lv_draw_rect(cords_p, mask_p, &lv_img_no_pic_rects, opa); + lv_draw_label(cords_p, mask_p,&lv_img_no_pic_labels, opa, fn); + } + } } + /** * Draw a line * @param p1 first point of the line @@ -248,158 +248,6 @@ void lv_draw_img(const area_t * cords_p, const area_t * mask_p, void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, const lv_lines_t * lines_p, opa_t opa) { - - /*Draw circle*//* - point_t c1; - point_t c2; - cord_t ctmp1; - cord_t ctmp2; - area_t tmp_a; - - circ_init(&c1, &ctmp1, lines_p->line_width); - - cord_t dx = abs(p2->x - p1->x); - cord_t dy = abs(p2->y - p1->y); - uint16_t width; - uint16_t wcor; - opa = OPA_20; - static const uint8_t width_corr_array[] = { - 64, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 66, 66, 66, 66, 66, - 67, 67, 67, 68, 68, 68, 69, 69, 69, 70, 70, 71, 71, 72, 72, 72, 73, 73, 74, - 74, 75, 75, 76, 77, 77, 78, 78, 79, 79, 80, 81, 81, 82, 82, 83, 84, 84, 85, - 86, 86, 87, 88, 88, 89, 90, 91, - }; - - wcor = (dy * LINE_WIDTH_CORR_BASE) / dx; - width = ((lines_p->line_width) * LV_DOWNSCALE * width_corr_array[wcor]) >> LINE_WIDTH_CORR_SHIFT; - - point_t e; - int32_t x_tmp = ((width*dy*dx)/(dx*dx+dy*dy)); - e.x = p2->x + x_tmp; - e.y = p2->y - (x_tmp * dx)/dy; - area_t e_area; - e_area.x1 = e.x-3; - e_area.x2 = e.x+3; - e_area.y1 = e.y-3; - e_area.y2 = e.y+3; - lv_vfill(&e_area, mask_p, COLOR_GREEN, OPA_40); - - - color_t rnd_clr = {{130, 43, 99}}; - uint16_t cnt = 0; - while(circ_cont(&c1)) { - area_set(&tmp_a, CIRC_OCT1_X(c1)+p2->x, CIRC_OCT1_Y(c1)+p2->y, CIRC_OCT1_X(c1)+p2->x, CIRC_OCT1_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, COLOR_BLUE, OPA_COVER); - area_set(&tmp_a, CIRC_OCT2_X(c1)+p2->x, CIRC_OCT2_Y(c1)+p2->y, CIRC_OCT2_X(c1)+p2->x, CIRC_OCT2_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, lines_p->color, opa); - area_set(&tmp_a, CIRC_OCT3_X(c1)+p2->x, CIRC_OCT3_Y(c1)+p2->y, CIRC_OCT3_X(c1)+p2->x, CIRC_OCT3_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, lines_p->color, opa); - area_set(&tmp_a, CIRC_OCT4_X(c1)+p2->x, CIRC_OCT4_Y(c1)+p2->y, CIRC_OCT4_X(c1)+p2->x, CIRC_OCT4_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, lines_p->color, opa); - area_set(&tmp_a, CIRC_OCT5_X(c1)+p2->x, CIRC_OCT5_Y(c1)+p2->y, CIRC_OCT5_X(c1)+p2->x, CIRC_OCT5_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, lines_p->color, opa); - area_set(&tmp_a, CIRC_OCT6_X(c1)+p2->x, CIRC_OCT6_Y(c1)+p2->y, CIRC_OCT6_X(c1)+p2->x, CIRC_OCT6_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, lines_p->color, opa); - area_set(&tmp_a, CIRC_OCT7_X(c1)+p2->x, CIRC_OCT7_Y(c1)+p2->y, CIRC_OCT7_X(c1)+p2->x, CIRC_OCT7_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, COLOR_PURPLE, OPA_COVER); - area_set(&tmp_a, CIRC_OCT8_X(c1)+p2->x, CIRC_OCT8_Y(c1)+p2->y, CIRC_OCT8_X(c1)+p2->x, CIRC_OCT8_Y(c1)+p2->y); - lv_vfill(&tmp_a, mask_p, lines_p->color, opa); - - - cord_t err = (dx > dy ? dx : -dy) / 2; - cord_t e2; - point_t act_point; - act_point.x = p1->x; - act_point.y = p1->y; - - rnd_clr.full += 0x238993; - - while(1){ - //if(c1.y > 4) break; - area_t act_area; -*/ - - - /*if(act_point.x < p2->x + CIRC_OCT8_X(c1)) - { - act_area.x1 = act_point.x; - act_area.x2 = act_point.x; - act_area.y1 = act_point.y - ((CIRC_OCT8_X(c1)*dy) - (CIRC_OCT8_Y(c1)*dx)) / (dx); - act_area.y2 = act_point.y - ((CIRC_OCT8_X(c1)*dy) - (CIRC_OCT8_Y(c1)*dx)) / (dx);// (dy * c1.x)/dx + CIRC_OCT8_Y(c1); - lv_vfill(&act_area, mask_p, COLOR_RED, OPA_50); - }*/ -/* - if(act_point.x < p2->x + CIRC_OCT1_X(c1)) { - act_area.x1 = act_point.x; - act_area.x2 = act_point.x; - act_area.y1 = act_point.y - (dy * c1.x)/dx + CIRC_OCT1_Y(c1); - act_area.y2 = act_point.y - (dy * c1.x)/dx + CIRC_OCT1_Y(c1); - lv_vfill(&act_area, mask_p, COLOR_RED, OPA_50); - } - if(act_point.x < p2->x + CIRC_OCT2_X(c1)) { - act_area.x1 = act_point.x; - act_area.x2 = act_point.x; - act_area.y1 = act_point.y - (dy * CIRC_OCT2_X(c1))/dx + CIRC_OCT2_Y(c1); - act_area.y2 = act_point.y - (dy * CIRC_OCT2_X(c1))/dx + CIRC_OCT2_Y(c1); - lv_vfill(&act_area, mask_p, COLOR_RED, OPA_50); - } - - if(act_point.x < p2->x + CIRC_OCT3_X(c1)) { - act_area.x1 = act_point.x; - act_area.x2 = act_point.x; - act_area.y1 = act_point.y - (dy * CIRC_OCT3_X(c1))/dx + CIRC_OCT3_Y(c1); - act_area.y2 = act_point.y - (dy * CIRC_OCT3_X(c1))/dx + CIRC_OCT3_Y(c1); - lv_vfill(&act_area, mask_p, COLOR_RED, OPA_50); - } -*//* - if(e.x > p2->x && e.x < p2->x + lines_p->line_width / 2 && - act_point.x < p2->x + CIRC_OCT7_X(c1)) - { - act_area.x1 = act_point.x; - act_area.x2 = act_point.x; - act_area.y1 = act_point.y - (dy * CIRC_OCT7_X(c1))/dx + CIRC_OCT7_Y(c1); - act_area.y2 = act_area.y1; - lv_vfill(&act_area, mask_p, COLOR_RED, OPA_50); - - }*/ -/* - if(act_point.x < p2->x + CIRC_OCT7_X(c1)) { - act_area.x1 = act_point.x; - act_area.x2 = act_point.x; - act_area.y1 = act_point.y - (dy * CIRC_OCT7_X(c1))/dx + CIRC_OCT7_Y(c1); - act_area.y2 = act_point.y - (dy * CIRC_OCT7_X(c1))/dx + CIRC_OCT7_Y(c1); - lv_vfill(&act_area, mask_p, COLOR_RED, OPA_50); - } -*/ - //printf("hor x1:%d, y1:%d, x2:%d, y2:%d\n", act_area.x1, act_area.y1, act_area.x2, act_area.y2); - /*if (act_point.x == p2->x + c1.x) - { - printf("line end x%d, y%d\n", act_area.x1, act_area.y1); - cnt++; - if(cnt == 11) { - cnt++; - cnt--; - } - break; - } - e2 = err; - if (e2 >-dx) { - err -= dy; - act_point.x ++; - } - if (e2 < dy) { - err += dx; - act_point.y ++; - } - } - - - circ_next(&c1, &ctmp1); - } - - - return;*/ - if(lines_p->width == 0) return; if(p1->x == p2->x && p1->y == p2->y) return; diff --git a/lv_draw/lv_draw.h b/lv_draw/lv_draw.h index 96176b606..9b2af6f6f 100644 --- a/lv_draw/lv_draw.h +++ b/lv_draw/lv_draw.h @@ -33,7 +33,7 @@ void lv_draw_label(const area_t * cords_p,const area_t * mask_p, void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, const lv_lines_t * lines_p, opa_t opa); void lv_draw_img(const area_t * cords_p, const area_t * mask_p, - const lv_imgs_t * imgs_p, opa_t opa, const char * fn, const color_t * map_p); + const lv_imgs_t * imgs_p, opa_t opa, const char * fn); /********************** * MACROS **********************/ diff --git a/lv_draw/lv_draw_rbasic.c b/lv_draw/lv_draw_rbasic.c index b00b07af5..7cbc4c0b7 100644 --- a/lv_draw/lv_draw_rbasic.c +++ b/lv_draw/lv_draw_rbasic.c @@ -110,7 +110,8 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, * @param transp true: enable transparency of LV_IMG_COLOR_TRANSP color pixels */ void lv_rmap(const area_t * cords_p, const area_t * mask_p, - const color_t * map_p, opa_t opa, bool transp) + const color_t * map_p, opa_t opa, bool transp, + color_t recolor, color_t recolor_opa) { area_t masked_a; bool union_ok; diff --git a/lv_draw/lv_draw_rbasic.h b/lv_draw/lv_draw_rbasic.h index 0bc64a9bd..455b73105 100644 --- a/lv_draw/lv_draw_rbasic.h +++ b/lv_draw/lv_draw_rbasic.h @@ -30,7 +30,8 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa); void lv_rmap(const area_t * cords_p, const area_t * mask_p, - const color_t * map_p, opa_t opa, bool transp); + const color_t * map_p, opa_t opa, bool transp, + color_t recolor, color_t recolor_opa); /********************** * MACROS **********************/ diff --git a/lv_draw/lv_draw_vbasic.c b/lv_draw/lv_draw_vbasic.c index 958c43173..bb4a99c25 100644 --- a/lv_draw/lv_draw_vbasic.c +++ b/lv_draw/lv_draw_vbasic.c @@ -146,7 +146,8 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, * @param transp true: enable transparency of LV_IMG_COLOR_TRANSP color pixels */ void lv_vmap(const area_t * cords_p, const area_t * mask_p, - const color_t * map_p, opa_t opa, bool transp) + const color_t * map_p, opa_t opa, bool transp, + color_t recolor, opa_t recolor_opa) { area_t masked_a; bool union_ok; @@ -196,6 +197,7 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p, cord_t row; cord_t col; color_t transp_color = LV_IMG_COLOR_TRANSP; + color_t color_tmp; cord_t map_i; map_p -= map_width; /*Compensate the first row % LV_DOWNSCALE*/ for(row = masked_a.y1; row <= masked_a.y2; row++) { @@ -203,9 +205,12 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p, map_i = masked_a.x1 >> ds_shift; map_i--; /*Compensate the first col % LV_DOWNSCALE*/ for(col = masked_a.x1; col <= masked_a.x2; col++) { - if(col % LV_DOWNSCALE == 0) map_i++; + if(col % LV_DOWNSCALE == 0) { + map_i++; + color_tmp = color_mix(recolor, map_p[map_i], recolor_opa); + } if(transp == false || map_p[map_i].full != transp_color.full) { - vdb_buf_tmp[col] = color_mix(map_p[map_i], vdb_buf_tmp[col], opa); + vdb_buf_tmp[col] = color_mix(color_tmp, vdb_buf_tmp[col], opa); } } vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ @@ -232,32 +237,70 @@ void lv_vmap(const area_t * cords_p, const area_t * mask_p, vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ } } + + /*To recolor draw simply a rectangle above the image*/ +#if LV_VDB_SIZE != 0 + lv_vfill(cords_p, mask_p, recolor, recolor_opa); +#endif + } else { /*transp == true: Check all pixels */ cord_t row; cord_t col; color_t transp_color = LV_IMG_COLOR_TRANSP; - if(opa == OPA_COVER) { /*no opa */ - for(row = masked_a.y1; row <= masked_a.y2; row++) { - for(col = masked_a.x1; col <= masked_a.x2; col ++) { - if(map_p[col].full != transp_color.full) { - vdb_buf_tmp[col] = map_p[col]; - } - } - map_p += map_width; /*Next row on the map*/ - vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ - } - } else { - for(row = masked_a.y1; row <= masked_a.y2; row++) { - for(col = masked_a.x1; col <= masked_a.x2; col ++) { - if(map_p[col].full != transp_color.full) { - vdb_buf_tmp[col] = color_mix( map_p[col], vdb_buf_tmp[col], opa); - } - } + if(recolor_opa == OPA_TRANSP)/*No recolor*/ + { + if(opa == OPA_COVER) { /*no opa */ + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = masked_a.x1; col <= masked_a.x2; col ++) { + if(map_p[col].full != transp_color.full) { + vdb_buf_tmp[col] = map_p[col]; + } + } + + map_p += map_width; /*Next row on the map*/ + vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ + } + } else { + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = masked_a.x1; col <= masked_a.x2; col ++) { + if(map_p[col].full != transp_color.full) { + vdb_buf_tmp[col] = color_mix( map_p[col], vdb_buf_tmp[col], opa); + } + } + + map_p += map_width; /*Next row on the map*/ + vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ + } + } + } else { /*Recolor needed*/ + color_t color_tmp; + if(opa == OPA_COVER) { /*no opa */ + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = masked_a.x1; col <= masked_a.x2; col ++) { + if(map_p[col].full != transp_color.full) { + color_tmp = color_mix(recolor, map_p[col], recolor_opa); + vdb_buf_tmp[col] = color_tmp; + } + } + + map_p += map_width; /*Next row on the map*/ + vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ + } + } else { + for(row = masked_a.y1; row <= masked_a.y2; row++) { + for(col = masked_a.x1; col <= masked_a.x2; col ++) { + if(map_p[col].full != transp_color.full) { + color_tmp = color_mix(recolor, map_p[col], recolor_opa); + vdb_buf_tmp[col] = color_mix(color_tmp, vdb_buf_tmp[col], opa); + } + } + + map_p += map_width; /*Next row on the map*/ + vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ + } + } - map_p += map_width; /*Next row on the map*/ - vdb_buf_tmp += vdb_width; /*Next row on the VDB*/ - } } } #endif /*No upscale and no downscale*/ @@ -347,4 +390,9 @@ static bool lv_vletter_get_px(const font_t * font_p, uint8_t letter, cord_t x, c if((map_byte & (1 << col_sub)) == 0) return false; else return true; } + #endif + + + + diff --git a/lv_draw/lv_draw_vbasic.h b/lv_draw/lv_draw_vbasic.h index dff6c5bfc..a7d6b80a5 100644 --- a/lv_draw/lv_draw_vbasic.h +++ b/lv_draw/lv_draw_vbasic.h @@ -36,7 +36,8 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, color_t color, opa_t opa); void lv_vmap(const area_t * cords_p, const area_t * mask_p, - const color_t * map_p, opa_t opa, bool transp); + const color_t * map_p, opa_t opa, bool transp, + color_t recolor, color_t recolor_opa); /********************** diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index e101ec6ba..def01b80e 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -34,11 +34,10 @@ lv_obj_t* def_scr_dp = NULL; lv_obj_t* act_scr_dp = NULL; ll_dsc_t scr_ll; -lv_objs_t lv_objs_def = {.color = COLOR_GRAY, .empty = 0, .auto_color = 1}; -lv_objs_t lv_objs_color = {.color = COLOR_RED, .empty = 0, .auto_color = 0}; -lv_objs_t lv_objs_scr = {.color = LV_OBJ_DEF_SCR_COLOR, .empty = 0, .auto_color = 0}; -lv_objs_t lv_objs_empty = {.color = COLOR_GRAY, .empty = 1, .auto_color = 0}; -lv_objs_t lv_objs_autocolor = {.color = COLOR_GRAY, .empty = 0, .auto_color = 1}; +lv_objs_t lv_objs_def = {.color = COLOR_GRAY, .empty = 0}; +lv_objs_t lv_objs_scr = {.color = LV_OBJ_DEF_SCR_COLOR, .empty = 0}; +lv_objs_t lv_objs_color = {.color = COLOR_RED, .empty = 0}; +lv_objs_t lv_objs_empty = {.color = COLOR_GRAY, .empty = 1}; /********************** * MACROS @@ -336,9 +335,6 @@ lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p) case LV_OBJS_EMPTY: style_p = &lv_objs_empty; break; - case LV_OBJS_AUTOCOLOR: - style_p = &lv_objs_autocolor; - break; default: style_p = NULL; } @@ -1243,29 +1239,6 @@ static bool lv_obj_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo opa_t opa = lv_obj_get_opa(obj_dp); color_t color = objs_p->color; - /*Calculate the color*/ - if(objs_p->auto_color != 0) { - lv_obj_t* par_dp = lv_obj_get_parent(obj_dp); - - if(par_dp == NULL) { /*If it is a screen use the default color*/ - color = LV_OBJ_DEF_SCR_COLOR; - } else { /*Add a random color on every level*/ - color = COLOR_WHITE; - while(par_dp != NULL) { -#if COLOR_DEPTH == 1 - color.full ++; -#elif COLOR_DEPTH == 8 - color.full += 0x52; -#elif COLOR_DEPTH == 16 - color.full += 0xA953; -#elif COLOR_DEPTH == 24 - color.full +=0x2963A9; -#endif - par_dp = lv_obj_get_parent(par_dp); - } - } - } - /*Simply draw a rectangle*/ #if LV_VDB_SIZE == 0 lv_rfill(&obj_dp->cords, mask_p, color, opa); diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index 3400c1950..ec26e7fb2 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -80,8 +80,8 @@ typedef struct __LV_OBJ_T area_t cords; /*Basic appearance*/ - opa_t opa; - + opa_t opa; + /*Attributes and states*/ uint8_t click_en :1; /*1: can be pressed by a display input device*/ uint8_t drag_en :1; /*1: enable the dragging*/ @@ -134,7 +134,6 @@ typedef struct { color_t color; uint8_t empty :1; - uint8_t auto_color :1; }lv_objs_t; typedef enum @@ -143,7 +142,6 @@ typedef enum LV_OBJS_COLOR, LV_OBJS_SCR, LV_OBJS_EMPTY, - LV_OBJS_AUTOCOLOR, }lv_objs_builtin_t; /********************** diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 64abb7234..ef35e684b 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -351,7 +351,7 @@ lv_btns_t * lv_btns_get(lv_btns_builtin_t style, lv_btns_t * copy_p) style_p = &lv_btns_border; break; default: - style_p = NULL; + style_p = &lv_btns_def; } if(copy_p != NULL) { diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 757bc3df9..854e03854 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -33,8 +33,9 @@ static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod /*----------------- * Style definition *-----------------*/ -static lv_imgs_t lv_imgs_def = {.transp_en = 0}; -static lv_imgs_t lv_imgs_transp = {.transp_en = 1}; +static lv_imgs_t lv_imgs_def = {.recolor_opa=OPA_TRANSP}; +static lv_imgs_t lv_imgs_light = {.objs.color = COLOR_WHITE, .recolor_opa=OPA_50}; +static lv_imgs_t lv_imgs_dark = {.objs.color = COLOR_BLACK, .recolor_opa=OPA_50}; /********************** * MACROS @@ -129,11 +130,14 @@ lv_imgs_t * lv_imgs_get(lv_imgs_builtin_t style, lv_imgs_t * copy_p) case LV_IMGS_DEF: style_p = &lv_imgs_def; break; - case LV_IMGS_TRANSP: - style_p = &lv_imgs_transp; + case LV_IMGS_LIGHT: + style_p = &lv_imgs_light; + break; + case LV_IMGS_DARK: + style_p = &lv_imgs_dark; break; default: - style_p = NULL; + style_p = &lv_imgs_def; } if(copy_p != NULL) { @@ -252,9 +256,10 @@ bool lv_img_get_auto_size(lv_obj_t* obj_dp) */ static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode) { + lv_imgs_t * imgs_p = lv_obj_get_style(obj_dp); + if(mode == LV_DESIGN_COVER_CHK) { - lv_imgs_t * imgs_p = lv_obj_get_style(obj_dp); - if(imgs_p->transp_en == 0) { + if(imgs_p->objs.empty == 0) { bool cover; cover = area_is_in(mask_p, &obj_dp->cords); return cover; @@ -276,10 +281,9 @@ static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod cords_tmp.x1 = cords.x1; cords_tmp.x2 = cords.x1 + img_ext_p->w - 1; for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += img_ext_p->w, cords_tmp.x2 += img_ext_p->w) { - lv_draw_img(&cords_tmp, mask_p, lv_obj_get_style(obj_dp),opa, img_ext_p->fn_dp, NULL); + lv_draw_img(&cords_tmp, mask_p, lv_obj_get_style(obj_dp),opa, img_ext_p->fn_dp); } } - return true; } diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index b03d76741..fad994acb 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -26,7 +26,7 @@ typedef struct { lv_objs_t objs; - uint8_t transp_en :1; + opa_t recolor_opa; }lv_imgs_t; typedef struct @@ -34,21 +34,22 @@ typedef struct char* fn_dp; cord_t w; cord_t h; - uint8_t auto_size :1; + uint8_t auto_size :1; }lv_img_ext_t; typedef enum { LV_IMGS_DEF, - LV_IMGS_TRANSP + LV_IMGS_LIGHT, + LV_IMGS_DARK, }lv_imgs_builtin_t; typedef struct { uint16_t w; uint16_t h; - uint16_t res1; - uint16_t res2; + uint16_t cd; /*Color depth*/ + uint16_t transp :1; /*Do not draw LV_IMG_TRANSP_COLOR pixels*/ }lv_img_raw_header_t; diff --git a/lv_objx/lv_label.c b/lv_objx/lv_label.c index 1aefb4122..aff574326 100644 --- a/lv_objx/lv_label.c +++ b/lv_objx/lv_label.c @@ -32,25 +32,25 @@ static bool lv_label_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_m * STATIC VARIABLES **********************/ static lv_labels_t lv_labels_def = { - .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0x10, 0x18, 0x20), + .font = LV_FONT_DEFAULT, .objs.color = COLOR_MAKE(0x10, 0x18, 0x20), .letter_space = 2 * LV_STYLE_MULT, .line_space = 2 * LV_STYLE_MULT, .mid = 1 }; static lv_labels_t lv_labels_btn = { - .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0xd0, 0xe0, 0xf0), + .font = LV_FONT_DEFAULT, .objs.color = COLOR_MAKE(0xd0, 0xe0, 0xf0), .letter_space = 2 * LV_STYLE_MULT, .line_space = 2 * LV_STYLE_MULT, .mid = 1, }; static lv_labels_t lv_labels_title = { - .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0x10, 0x20, 0x30), + .font = LV_FONT_DEFAULT, .objs.color = COLOR_MAKE(0x10, 0x20, 0x30), .letter_space = 4 * LV_STYLE_MULT, .line_space = 4 * LV_STYLE_MULT, .mid = 0, }; static lv_labels_t lv_labels_txt = { - .font = LV_FONT_DEFAULT, .color = COLOR_MAKE(0x16, 0x23, 0x34), + .font = LV_FONT_DEFAULT, .objs.color = COLOR_MAKE(0x16, 0x23, 0x34), .letter_space = 1 * LV_STYLE_MULT, .line_space = 2 * LV_STYLE_MULT, .mid = 0, }; @@ -274,7 +274,7 @@ lv_labels_t * lv_labels_get(lv_labels_builtin_t style, lv_labels_t * copy_p) style_p = &lv_labels_title; break; default: - style_p = NULL; + style_p = &lv_labels_def; } if(copy_p != NULL) { diff --git a/lv_objx/lv_label.h b/lv_objx/lv_label.h index d66f30039..1a76e4039 100644 --- a/lv_objx/lv_label.h +++ b/lv_objx/lv_label.h @@ -25,8 +25,8 @@ typedef struct { + lv_objs_t objs; font_types_t font; - color_t color; uint16_t letter_space; uint16_t line_space; uint8_t mid :1; diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index 36c159000..fe7090f97 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -38,14 +38,11 @@ static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo /********************** * STATIC VARIABLES **********************/ -static lv_lines_t lv_lines_def = { .width = 2 * LV_STYLE_MULT, .objs.color = COLOR_RED, - .bg_color = COLOR_BLACK, .bg_opa = 0}; +static lv_lines_t lv_lines_def = { .width = 2 * LV_STYLE_MULT, .objs.color = COLOR_RED}; -static lv_lines_t lv_lines_decor = { .width = 1 * LV_STYLE_MULT, .objs.color = COLOR_GRAY, - .bg_color = COLOR_BLACK, .bg_opa = 0}; +static lv_lines_t lv_lines_decor = { .width = 1 * LV_STYLE_MULT, .objs.color = COLOR_GRAY}; -static lv_lines_t lv_lines_chart = { .width = 3 * LV_STYLE_MULT, .objs.color = COLOR_BLUE, - .bg_color = COLOR_BLACK, .bg_opa = 0}; +static lv_lines_t lv_lines_chart = { .width = 3 * LV_STYLE_MULT, .objs.color = COLOR_BLUE}; /********************** * MACROS @@ -265,7 +262,7 @@ lv_lines_t * lv_lines_get(lv_lines_builtin_t style, lv_lines_t * copy_p) style_p = &lv_lines_chart; break; default: - style_p = NULL; + style_p = &lv_lines_def; } if(copy_p != NULL) { @@ -298,13 +295,7 @@ static bool lv_line_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo if(ext_p->point_num == 0 || ext_p->point_p == NULL) return false; lv_lines_t * lines_p = lv_obj_get_style(obj_dp); - if(lines_p->bg_opa != 0) { -#if LV_VDB_SIZE != 0 - lv_vfill(&obj_dp->cords, mask_p, lines_p->bg_color, lines_p->bg_opa * 255 / 100); -#else - lv_rfill(&obj_dp->cords, mask_p, lines_p->bg_color, lines_p->bg_opa * 255 / 100); -#endif - } + opa_t opa = lv_obj_get_opa(obj_dp); area_t area; lv_obj_get_cords(obj_dp, &area); diff --git a/lv_objx/lv_line.h b/lv_objx/lv_line.h index 7dc96e4eb..94ba86136 100644 --- a/lv_objx/lv_line.h +++ b/lv_objx/lv_line.h @@ -33,9 +33,7 @@ typedef struct typedef struct { lv_objs_t objs; - color_t bg_color; uint16_t width; - opa_t bg_opa; }lv_lines_t; typedef enum diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 9f7fee971..c1ee75f55 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -156,6 +156,7 @@ lv_obj_t* lv_page_create(lv_obj_t * par_dp, lv_obj_t * ori_dp) page_p->sbh_dp = lv_rect_create(par_dp, NULL); lv_obj_set_height(page_p->sbh_dp, pages_p->sb_width); lv_obj_set_style(page_p->sbh_dp, &pages_p->sb_rects); + lv_obj_set_click(page_p->sbh_dp, false); if(pages_p->sb_mode == LV_PAGE_SB_MODE_ON) { lv_obj_set_opa(page_p->sbh_dp, (pages_p->sb_opa * OPA_COVER) / 100); } else { @@ -166,6 +167,7 @@ lv_obj_t* lv_page_create(lv_obj_t * par_dp, lv_obj_t * ori_dp) page_p->sbv_dp =lv_rect_create(par_dp, NULL); lv_obj_set_width(page_p->sbv_dp, pages_p->sb_width); lv_obj_set_style(page_p->sbv_dp, &pages_p->sb_rects); + lv_obj_set_click(page_p->sbv_dp, false); if(lv_pages_def.sb_mode == LV_PAGE_SB_MODE_ON) { lv_obj_set_opa(page_p->sbv_dp, (pages_p->sb_opa * OPA_COVER) / 100); } else { @@ -299,7 +301,6 @@ bool lv_page_signal(lv_obj_t* obj_dp, lv_signal_t sign, void* param) } return obj_valid; - } /** @@ -334,7 +335,7 @@ lv_pages_t * lv_pages_get(lv_pages_builtin_t style, lv_pages_t * to_copy) style_p = &lv_pages_transp; break; default: - style_p = NULL; + style_p = &lv_pages_def; } if(to_copy != NULL) { diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index d0a6d88c7..de6da8828 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -229,7 +229,7 @@ lv_rects_t * lv_rects_get(lv_rects_builtin_t style, lv_rects_t * copy_p) style_p = &lv_rects_transp; break; default: - style_p = NULL; + style_p = &lv_rects_def; } if(copy_p != NULL) { From 23ca4fdbee3f99fa54bacbb80eb0481fb7b6ea57 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 16 Jun 2016 10:57:03 +0200 Subject: [PATCH 5/7] Further modifications with styles --- lv_draw/lv_draw.c | 6 +++--- lv_draw/lv_draw_rbasic.c | 2 +- lv_draw/lv_draw_rbasic.h | 2 +- lv_draw/lv_draw_vbasic.h | 2 +- lv_obj/lv_obj.c | 14 ++------------ lv_obj/lv_obj.h | 3 --- lv_objx/lv_btn.c | 6 +++--- lv_objx/lv_img.c | 18 +++++++++++------- lv_objx/lv_img.h | 1 + lv_objx/lv_page.c | 12 ++++++------ lv_objx/lv_page.h | 1 - lv_objx/lv_rect.c | 8 ++++---- lv_objx/lv_rect.h | 3 ++- 13 files changed, 35 insertions(+), 43 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 318ddda4a..237145ea2 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -47,14 +47,14 @@ static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color #else static void (*fill_fp)(const area_t * cords_p, const area_t * mask_p, color_t color, opa_t opa) = lv_rfill; static void (*letter_fp)(const point_t * pos_p, const area_t * mask_p, const font_t * font_p, uint8_t letter, color_t color, opa_t opa) = lv_rletter; -static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp) = lv_rmap; +static void (*map_fp)(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, color_t recolor, opa_t recolor_opa) = lv_rmap; #endif static lv_rects_t lv_img_no_pic_rects = { .objs.color = COLOR_BLACK, .gcolor = COLOR_BLACK, .bcolor = COLOR_RED, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100, - .round = 0, .objs.empty = 0 + .round = 0, .empty = 0 }; static lv_labels_t lv_img_no_pic_labels = { @@ -80,7 +80,7 @@ static lv_labels_t lv_img_no_pic_labels = { void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_rects_t * rects_p, opa_t opa) { - if(rects_p->objs.empty == 0){ + if(rects_p->empty == 0){ lv_draw_rect_main_mid(cords_p, mask_p, rects_p, opa); if(rects_p->round != 0) { diff --git a/lv_draw/lv_draw_rbasic.c b/lv_draw/lv_draw_rbasic.c index 7cbc4c0b7..74508df99 100644 --- a/lv_draw/lv_draw_rbasic.c +++ b/lv_draw/lv_draw_rbasic.c @@ -111,7 +111,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, */ void lv_rmap(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, - color_t recolor, color_t recolor_opa) + color_t recolor, opa_t recolor_opa) { area_t masked_a; bool union_ok; diff --git a/lv_draw/lv_draw_rbasic.h b/lv_draw/lv_draw_rbasic.h index 455b73105..222ad0c07 100644 --- a/lv_draw/lv_draw_rbasic.h +++ b/lv_draw/lv_draw_rbasic.h @@ -31,7 +31,7 @@ void lv_rletter(const point_t * pos_p, const area_t * mask_p, color_t color, opa_t opa); void lv_rmap(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, - color_t recolor, color_t recolor_opa); + color_t recolor, opa_t recolor_opa); /********************** * MACROS **********************/ diff --git a/lv_draw/lv_draw_vbasic.h b/lv_draw/lv_draw_vbasic.h index a7d6b80a5..a9a8b0e8a 100644 --- a/lv_draw/lv_draw_vbasic.h +++ b/lv_draw/lv_draw_vbasic.h @@ -37,7 +37,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, void lv_vmap(const area_t * cords_p, const area_t * mask_p, const color_t * map_p, opa_t opa, bool transp, - color_t recolor, color_t recolor_opa); + color_t recolor, opa_t recolor_opa); /********************** diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index def01b80e..2017005f8 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -34,10 +34,8 @@ lv_obj_t* def_scr_dp = NULL; lv_obj_t* act_scr_dp = NULL; ll_dsc_t scr_ll; -lv_objs_t lv_objs_def = {.color = COLOR_GRAY, .empty = 0}; -lv_objs_t lv_objs_scr = {.color = LV_OBJ_DEF_SCR_COLOR, .empty = 0}; -lv_objs_t lv_objs_color = {.color = COLOR_RED, .empty = 0}; -lv_objs_t lv_objs_empty = {.color = COLOR_GRAY, .empty = 1}; +lv_objs_t lv_objs_def = {.color = COLOR_RED}; +lv_objs_t lv_objs_scr = {.color = LV_OBJ_DEF_SCR_COLOR}; /********************** * MACROS @@ -326,14 +324,9 @@ lv_objs_t * lv_objs_get(lv_objs_builtin_t style, lv_objs_t * copy_p) case LV_OBJS_DEF: style_p = &lv_objs_def; break; - case LV_OBJS_COLOR: - style_p = &lv_objs_color; - break; case LV_OBJS_SCR: style_p = &lv_objs_scr; break; - case LV_OBJS_EMPTY: - style_p = &lv_objs_empty; break; default: style_p = NULL; @@ -1232,9 +1225,6 @@ static bool lv_obj_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo } lv_objs_t * objs_p = lv_obj_get_style(obj_dp); - - /*Do not draw the empty objects*/ - if(objs_p->empty != 0) return true; opa_t opa = lv_obj_get_opa(obj_dp); color_t color = objs_p->color; diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index ec26e7fb2..ff286c4bd 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -133,15 +133,12 @@ typedef enum typedef struct { color_t color; - uint8_t empty :1; }lv_objs_t; typedef enum { LV_OBJS_DEF, - LV_OBJS_COLOR, LV_OBJS_SCR, - LV_OBJS_EMPTY, }lv_objs_builtin_t; /********************** diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index ef35e684b..4dfeff058 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -58,7 +58,7 @@ static lv_btns_t lv_btns_def = .rects.bwidth = 2 * LV_STYLE_MULT, .rects.bopa = 50, - .rects.objs.empty = 0, + .rects.empty = 0, .rects.round = 4 * LV_STYLE_MULT, .rects.hpad = 10 * LV_STYLE_MULT, .rects.vpad = 15 * LV_STYLE_MULT, @@ -66,7 +66,7 @@ static lv_btns_t lv_btns_def = static lv_btns_t lv_btns_transp = { .rects.bwidth = 0, - .rects.objs.empty = 1, + .rects.empty = 1, .rects.hpad = 10 * LV_STYLE_MULT, .rects.vpad = 15 * LV_STYLE_MULT, }; @@ -79,7 +79,7 @@ static lv_btns_t lv_btns_border = .bcolor[LV_BTN_STATE_TGL_PR] = COLOR_BLACK, .bcolor[LV_BTN_STATE_INA] = COLOR_GRAY, .rects.bwidth = 2 * LV_STYLE_MULT, - .rects.objs.empty = 1, + .rects.empty = 1, .rects.bopa = 50, .rects.round = 4 * LV_STYLE_MULT, .rects.hpad = 10 * LV_STYLE_MULT, diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 854e03854..0bb3f0fdb 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -71,7 +71,9 @@ lv_obj_t* lv_img_create(lv_obj_t* par_dp, lv_obj_t * copy_dp) img_ext_dp->fn_dp = NULL; img_ext_dp->w = lv_obj_get_width(new_obj_dp); img_ext_dp->h = lv_obj_get_height(new_obj_dp); + img_ext_dp->transp = 0; + /*Enable auto size for non screens*/ if(par_dp != NULL) { img_ext_dp->auto_size = 1; } else { @@ -190,12 +192,14 @@ void lv_img_set_file(lv_obj_t* obj_dp, const char * fn) /*Create a dummy header*/ header.w = lv_obj_get_width(obj_dp); header.h = lv_obj_get_height(obj_dp); + header.transp = 0; } fs_close(&file); img_ext_p->w = header.w; img_ext_p->h = header.h; + img_ext_p->transp = header.transp; #if LV_UPSCALE_MAP != 0 img_ext_p->w *= LV_DOWNSCALE; img_ext_p->h *= LV_DOWNSCALE; @@ -257,9 +261,10 @@ bool lv_img_get_auto_size(lv_obj_t* obj_dp) static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mode_t mode) { lv_imgs_t * imgs_p = lv_obj_get_style(obj_dp); + lv_img_ext_t * ext_p = lv_obj_get_ext(obj_dp); if(mode == LV_DESIGN_COVER_CHK) { - if(imgs_p->objs.empty == 0) { + if(ext_p->transp == 0) { bool cover; cover = area_is_in(mask_p, &obj_dp->cords); return cover; @@ -267,7 +272,6 @@ static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod else return false; } - lv_img_ext_t * img_ext_p = lv_obj_get_ext(obj_dp); area_t cords; lv_obj_get_cords(obj_dp, &cords); @@ -275,13 +279,13 @@ static bool lv_img_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mod area_t cords_tmp; cords_tmp.y1 = cords.y1; - cords_tmp.y2 = cords.y1 + img_ext_p->h - 1; + cords_tmp.y2 = cords.y1 + ext_p->h - 1; - for(; cords_tmp.y1 < cords.y2; cords_tmp.y1 += img_ext_p->h, cords_tmp.y2 += img_ext_p->h) { + for(; cords_tmp.y1 < cords.y2; cords_tmp.y1 += ext_p->h, cords_tmp.y2 += ext_p->h) { cords_tmp.x1 = cords.x1; - cords_tmp.x2 = cords.x1 + img_ext_p->w - 1; - for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += img_ext_p->w, cords_tmp.x2 += img_ext_p->w) { - lv_draw_img(&cords_tmp, mask_p, lv_obj_get_style(obj_dp),opa, img_ext_p->fn_dp); + cords_tmp.x2 = cords.x1 + ext_p->w - 1; + for(; cords_tmp.x1 < cords.x2; cords_tmp.x1 += ext_p->w, cords_tmp.x2 += ext_p->w) { + lv_draw_img(&cords_tmp, mask_p, imgs_p, opa, ext_p->fn_dp); } } return true; diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index fad994acb..a5f70ca40 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -35,6 +35,7 @@ typedef struct cord_t w; cord_t h; uint8_t auto_size :1; + uint8_t transp :1; /*Transp. bit in the images header (library handles this)*/ }lv_img_ext_t; typedef enum diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index c1ee75f55..a1bcb1066 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -38,7 +38,7 @@ static lv_pages_t lv_pages_def = .bg_rects.bopa = 50, .bg_rects.bwidth = 0 * LV_STYLE_MULT, .bg_rects.round = 2 * LV_STYLE_MULT, - .bg_rects.objs.empty = 0, + .bg_rects.empty = 0, .bg_rects.hpad = 10, .bg_rects.vpad = 10, @@ -48,7 +48,7 @@ static lv_pages_t lv_pages_def = .sb_rects.bopa = 50, .sb_rects.bwidth = 1 * LV_STYLE_MULT, .sb_rects.round = 5 * LV_STYLE_MULT, - .sb_rects.objs.empty = 0, + .sb_rects.empty = 0, .sb_width= 8 * LV_STYLE_MULT, .sb_opa=50, @@ -69,7 +69,7 @@ static lv_pages_t lv_pages_paper = .bg_rects.bopa = 100, .bg_rects.bwidth = 2 * LV_STYLE_MULT, .bg_rects.round = 0 * LV_STYLE_MULT, - .bg_rects.objs.empty = 0, + .bg_rects.empty = 0, .bg_rects.hpad = 20 * LV_STYLE_MULT, .bg_rects.vpad = 20 * LV_STYLE_MULT, @@ -79,7 +79,7 @@ static lv_pages_t lv_pages_paper = .sb_rects.bopa = 100, .sb_rects.bwidth = 1 * LV_STYLE_MULT, .sb_rects.round = 5 * LV_STYLE_MULT, - .sb_rects.objs.empty = 0, + .sb_rects.empty = 0, .sb_width = 10 * LV_STYLE_MULT, .sb_opa=50, @@ -93,7 +93,7 @@ static lv_pages_t lv_pages_paper = static lv_pages_t lv_pages_transp = { - .bg_rects.objs.empty = 1, + .bg_rects.empty = 1, .bg_rects.hpad = 1, .bg_rects.vpad = 1, @@ -103,7 +103,7 @@ static lv_pages_t lv_pages_transp = .sb_rects.bopa = 0, .sb_rects.bwidth = 1 * LV_STYLE_MULT, .sb_rects.round = 5 * LV_STYLE_MULT, - .sb_rects.objs.empty = 0, + .sb_rects.empty = 0, .sb_width = 8 * LV_STYLE_MULT, .sb_opa = 50, diff --git a/lv_objx/lv_page.h b/lv_objx/lv_page.h index fd4211cd5..4ebd2b956 100644 --- a/lv_objx/lv_page.h +++ b/lv_objx/lv_page.h @@ -57,7 +57,6 @@ typedef enum LV_PAGES_TRANSP, }lv_pages_builtin_t; - /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index de6da8828..0e5799768 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -33,16 +33,16 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo static lv_rects_t lv_rects_def = { .objs.color = COLOR_MAKE(0x50, 0x70, 0x90), .gcolor = COLOR_MAKE(0x20, 0x40, 0x60), .bcolor = COLOR_WHITE, .bwidth = 2 * LV_STYLE_MULT, .bopa = 50, - .round = 4 * LV_STYLE_MULT, .objs.empty = 0, + .round = 4 * LV_STYLE_MULT, .empty = 0, .hpad = 0, .vpad = 0 }; static lv_rects_t lv_rects_transp = -{ .bwidth = 0, .objs.empty = 0, +{ .bwidth = 0, .empty = 1, .hpad = 0, .vpad = 0 }; static lv_rects_t lv_rects_border = { .bcolor = COLOR_BLACK, .bwidth = 2 * LV_STYLE_MULT, .bopa = 100, - .round = 4 * LV_STYLE_MULT, .objs.empty = 1, + .round = 4 * LV_STYLE_MULT, .empty = 1, .hpad = 0, .vpad = 0}; /********************** @@ -265,7 +265,7 @@ static bool lv_rect_design(lv_obj_t* obj_dp, const area_t * mask_p, lv_design_mo { /* Because of the radius it is not sure the area is covered*/ if(mode == LV_DESIGN_COVER_CHK) { - if(LV_SA(obj_dp, lv_rects_t)->objs.empty != 0) return false; + if(LV_SA(obj_dp, lv_rects_t)->empty != 0) return false; uint16_t r = LV_SA(obj_dp, lv_rects_t)->round; area_t area_tmp; diff --git a/lv_objx/lv_rect.h b/lv_objx/lv_rect.h index 181a20c68..cb5f15781 100644 --- a/lv_objx/lv_rect.h +++ b/lv_objx/lv_rect.h @@ -31,8 +31,9 @@ typedef struct uint16_t bwidth; cord_t hpad; cord_t vpad; - uint8_t bopa; uint16_t round; + uint8_t bopa; + uint8_t empty :1; }lv_rects_t; From 30d554e9047ef2cf80eea61de064ce2cf2e3b843 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 15 Jun 2016 11:40:04 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65952636b..769e2b82a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ -# lvgl -The core of the LittleV Graphical Library +# LittleV Graphical Libraray Core + +LittleV Graphical Library is C written software libraray which helps you to add modern and innovative graphical user interface to your embedded application. + +The library supports high level graphical effects, like anialaiasing, opacity, color fade etc. + +The GUI can be built from simle objects like screens, buttons labels, images etc. + +The "misc" modul is required to use use the library. (https://github.com/littlevgl/misc) + +Check littlev.hu for more information! + +There are two branches: master and beta. In beta you will find the newest features which are not released yet. + + + From 590b0856040ad4488c67fe0f33a3a73ba05cd8e6 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 16 Jun 2016 11:06:26 +0200 Subject: [PATCH 7/7] Version 1.1 released --- lvgl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lvgl.h b/lvgl.h index 30c57329f..4dcdb0ece 100644 --- a/lvgl.h +++ b/lvgl.h @@ -21,7 +21,7 @@ * DEFINES *********************/ #define LV_GL_VERSION_MAJOR 1 -#define LV_GL_VERSION_MINOR 0 +#define LV_GL_VERSION_MINOR 1 /********************** * TYPEDEFS