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/4] 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/4] 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/4] 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/4] 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