From e298f493cec6590370899194c247a88ee07d7f5a Mon Sep 17 00:00:00 2001 From: Ali Rostami <9710249+ali-rostami@users.noreply.github.com> Date: Mon, 4 Mar 2019 12:41:28 +0330 Subject: [PATCH 1/7] add offset function --- lv_objx/lv_img.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index c9fb42875..907f09e5d 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -78,6 +78,8 @@ lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy) ext->w = lv_obj_get_width(new_img); ext->h = lv_obj_get_height(new_img); ext->auto_size = 1; + ext->offset.x = 0; + ext->offset.y = 0; #if USE_LV_MULTI_LANG ext->lang_txt_id = LV_LANG_TXT_ID_NONE; #endif @@ -235,6 +237,19 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en) ext->auto_size = (en == false ? 0 : 1); } +/** + * Set an offset for the source of an image. + * so the image will be displayed from this new origin. + * @param img pointer to an image + * @param en true: auto size enable, false: auto size disable + */ +void lv_img_set_offset(lv_obj_t *img, lv_point_t offset) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + if((ext->offset.x < ext->w - 1) && (ext->offset.y < ext->h - 1)) + ext->offset = offset; +} /*===================== * Getter functions @@ -325,6 +340,9 @@ static bool lv_img_design(lv_obj_t * img, const lv_area_t * mask, lv_design_mode lv_obj_get_coords(img, &coords); if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_VARIABLE) { + coords.x1 -= ext->offset.x; + coords.y1 -= ext->offset.y; + LV_LOG_TRACE("lv_img_design: start to draw image"); lv_area_t cords_tmp; cords_tmp.y1 = coords.y1; From c2e3e9d494f6b46f6f8ad65e34ad131044d08b91 Mon Sep 17 00:00:00 2001 From: Ali Rostami <9710249+ali-rostami@users.noreply.github.com> Date: Mon, 4 Mar 2019 12:47:03 +0330 Subject: [PATCH 2/7] add offset member to lv_img_ext_t --- lv_objx/lv_img.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index 8ee861679..59f42af46 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -40,7 +40,7 @@ typedef struct /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ /*New data for this type */ const void * src; /*Image source: Pointer to an array or a file or a symbol*/ - + lv_point_t offset; lv_coord_t w; /*Width of the image (Handled by the library)*/ lv_coord_t h; /*Height of the image (Handled by the library)*/ #if USE_LV_MULTI_LANG @@ -103,6 +103,14 @@ static inline void lv_img_set_file(lv_obj_t * img, const char * fn) */ void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en); + /** + * Set an offset for the source of an image. + * so the image will be displayed from this new origin. + * @param img pointer to an image + * @param en true: auto size enable, false: auto size disable + */ +void lv_img_set_offset(lv_obj_t *img, lv_point_t offset); + /** * Set the style of an image * @param img pointer to an image object From fc375fd115ab8d1566759a87de855cbd76ab8cd3 Mon Sep 17 00:00:00 2001 From: Ali Rostami <9710249+ali-rostami@users.noreply.github.com> Date: Wed, 6 Mar 2019 17:33:14 +0330 Subject: [PATCH 3/7] define lv_img_set_offset() with new params --- lv_objx/lv_img.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 907f09e5d..0a203eca5 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -239,16 +239,49 @@ void lv_img_set_auto_size(lv_obj_t * img, bool en) /** * Set an offset for the source of an image. - * so the image will be displayed from this new origin. + * so the image will be displayed from the new origin. * @param img pointer to an image - * @param en true: auto size enable, false: auto size disable + * @param x: the new offset along x axis. + * @param y: the new offset along y axis. */ -void lv_img_set_offset(lv_obj_t *img, lv_point_t offset) +void lv_img_set_offset(lv_obj_t *img, lv_coord_t x, lv_coord_t y) { lv_img_ext_t * ext = lv_obj_get_ext_attr(img); - if((ext->offset.x < ext->w - 1) && (ext->offset.y < ext->h - 1)) - ext->offset = offset; + if((x < ext->w - 1) && (y < ext->h - 1)) { + ext->offset.x = x; + ext->offset.y = y; + } +} + +/** + * Set an offset for the source of an image. + * so the image will be displayed from the new origin. + * @param img pointer to an image + * @param x: the new offset along x axis. + */ +void lv_img_set_offset_x(lv_obj_t *img, lv_coord_t x) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + if(x < ext->w - 1) { + ext->offset.x = x; + } +} + +/** + * Set an offset for the source of an image. + * so the image will be displayed from the new origin. + * @param img pointer to an image + * @param y: the new offset along y axis. + */ +void lv_img_set_offset_y(lv_obj_t *img, lv_coord_t y) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + if(y < ext->h - 1) { + ext->offset.y = y; + } } /*===================== From 0bce1876c198d94b6e4ab39de9217fc87443b864 Mon Sep 17 00:00:00 2001 From: Ali Rostami <9710249+ali-rostami@users.noreply.github.com> Date: Wed, 6 Mar 2019 17:35:14 +0330 Subject: [PATCH 4/7] declare lv_img_set_offset() with new params. --- lv_objx/lv_img.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index 59f42af46..73a0d4246 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -103,13 +103,30 @@ static inline void lv_img_set_file(lv_obj_t * img, const char * fn) */ void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en); - /** +/** * Set an offset for the source of an image. - * so the image will be displayed from this new origin. + * so the image will be displayed from the new origin. * @param img pointer to an image - * @param en true: auto size enable, false: auto size disable + * @param x: the new offset along x axis. + * @param y: the new offset along y axis. */ -void lv_img_set_offset(lv_obj_t *img, lv_point_t offset); +void lv_img_set_offset(lv_obj_t *img, lv_coord_t x, lv_coord_t y); + +/** + * Set an offset for the source of an image. + * so the image will be displayed from the new origin. + * @param img pointer to an image + * @param x: the new offset along x axis. + */ +void lv_img_set_offset_x(lv_obj_t *img, lv_coord_t x); + +/** + * Set an offset for the source of an image. + * so the image will be displayed from the new origin. + * @param img pointer to an image + * @param y: the new offset along y axis. + */ +void lv_img_set_offset_y(lv_obj_t *img, lv_coord_t y); /** * Set the style of an image From a59a6880f01c9b3285335c854ff746246b2de242 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 8 Mar 2019 11:53:34 +0100 Subject: [PATCH 5/7] lv_img_offset: invalidate img when offset changes --- lv_objx/lv_img.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 0a203eca5..dff261d55 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -251,6 +251,7 @@ void lv_img_set_offset(lv_obj_t *img, lv_coord_t x, lv_coord_t y) if((x < ext->w - 1) && (y < ext->h - 1)) { ext->offset.x = x; ext->offset.y = y; + lv_obj_invalidate(img); } } @@ -266,7 +267,9 @@ void lv_img_set_offset_x(lv_obj_t *img, lv_coord_t x) if(x < ext->w - 1) { ext->offset.x = x; + lv_obj_invalidate(img); } + } /** @@ -281,6 +284,7 @@ void lv_img_set_offset_y(lv_obj_t *img, lv_coord_t y) if(y < ext->h - 1) { ext->offset.y = y; + lv_obj_invalidate(img); } } From 4ab2e505fd33a00b0a12c8bb703651a6f5aecceb Mon Sep 17 00:00:00 2001 From: Ali Rostami <9710249+ali-rostami@users.noreply.github.com> Date: Fri, 8 Mar 2019 17:02:56 +0330 Subject: [PATCH 6/7] add 2 getter functions for offset attribute. --- lv_objx/lv_img.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index dff261d55..cab094139 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -343,6 +343,30 @@ bool lv_img_get_auto_size(const lv_obj_t * img) return ext->auto_size == 0 ? false : true; } +/** + * Get the offset.x attribute of the img object. + * @param img pointer to an image + * @return offset.x value. + */ +lv_coord_t lv_img_get_offset_x(lv_obj_t *img) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + return ext->offset.x; +} + +/** + * Get the offset.y attribute of the img object. + * @param img pointer to an image + * @return offset.y value. + */ +lv_coord_t lv_img_get_offset_y(lv_obj_t *img) +{ + lv_img_ext_t * ext = lv_obj_get_ext_attr(img); + + return ext->offset.y; +} + /********************** * STATIC FUNCTIONS **********************/ From e263dddde9175be85271ac7b69cb86f53bbe1cce Mon Sep 17 00:00:00 2001 From: Ali Rostami <9710249+ali-rostami@users.noreply.github.com> Date: Fri, 8 Mar 2019 17:05:36 +0330 Subject: [PATCH 7/7] add declaration for offset getter functions. --- lv_objx/lv_img.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lv_objx/lv_img.h b/lv_objx/lv_img.h index 73a0d4246..0ec430c07 100644 --- a/lv_objx/lv_img.h +++ b/lv_objx/lv_img.h @@ -183,6 +183,20 @@ uint16_t lv_img_get_src_id(lv_obj_t * img); */ bool lv_img_get_auto_size(const lv_obj_t * img); +/** + * Get the offset.x attribute of the img object. + * @param img pointer to an image + * @return offset.x value. + */ +lv_coord_t lv_img_get_offset_x(lv_obj_t *img); + +/** + * Get the offset.y attribute of the img object. + * @param img pointer to an image + * @return offset.y value. + */ +lv_coord_t lv_img_get_offset_y(lv_obj_t *img); + /** * Get the style of an image object * @param img pointer to an image object