1 /**
2  * @file lv_img.h
3  *
4  */
5 
6 #ifndef LV_IMG_H
7 #define LV_IMG_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21 
22 #if LV_USE_IMG != 0
23 
24 #include "../lv_core/lv_obj.h"
25 #include "../lv_misc/lv_fs.h"
26 #include "lv_label.h"
27 #include "../lv_draw/lv_draw.h"
28 
29 /*********************
30  *      DEFINES
31  *********************/
32 
33 /**********************
34  *      TYPEDEFS
35  **********************/
36 /*Data of image*/
37 typedef struct
38 {
39     /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/
40     /*New data for this type */
41     const void * src; /*Image source: Pointer to an array or a file or a symbol*/
42     lv_point_t offset;
43     lv_coord_t w;          /*Width of the image (Handled by the library)*/
44     lv_coord_t h;          /*Height of the image (Handled by the library)*/
45     uint8_t src_type : 2;  /*See: lv_img_src_t*/
46     uint8_t auto_size : 1; /*1: automatically set the object size to the image size*/
47     uint8_t cf : 5;        /*Color format from `lv_img_color_format_t`*/
48 } lv_img_ext_t;
49 
50 /*Styles*/
51 enum {
52     LV_IMG_STYLE_MAIN,
53 };
54 typedef uint8_t lv_img_style_t;
55 
56 /**********************
57  * GLOBAL PROTOTYPES
58  **********************/
59 
60 /**
61  * Create an image objects
62  * @param par pointer to an object, it will be the parent of the new button
63  * @param copy pointer to a image object, if not NULL then the new object will be copied from it
64  * @return pointer to the created image
65  */
66 lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy);
67 
68 /*=====================
69  * Setter functions
70  *====================*/
71 
72 /**
73  * Set the pixel map to display by the image
74  * @param img pointer to an image object
75  * @param data the image data
76  */
77 void lv_img_set_src(lv_obj_t * img, const void * src_img);
78 
79 /**
80  * Enable the auto size feature.
81  * If enabled the object size will be same as the picture size.
82  * @param img pointer to an image
83  * @param en true: auto size enable, false: auto size disable
84  */
85 void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en);
86 
87 /**
88  * Set an offset for the source of an image.
89  * so the image will be displayed from the new origin.
90  * @param img pointer to an image
91  * @param x: the new offset along x axis.
92  */
93 void lv_img_set_offset_x(lv_obj_t * img, lv_coord_t x);
94 
95 /**
96  * Set an offset for the source of an image.
97  * so the image will be displayed from the new origin.
98  * @param img pointer to an image
99  * @param y: the new offset along y axis.
100  */
101 void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y);
102 
103 /**
104  * Set the style of an image
105  * @param img pointer to an image object
106  * @param type which style should be set (can be only `LV_IMG_STYLE_MAIN`)
107  * @param style pointer to a style
108  */
lv_img_set_style(lv_obj_t * img,lv_img_style_t type,const lv_style_t * style)109 static inline void lv_img_set_style(lv_obj_t * img, lv_img_style_t type, const lv_style_t * style)
110 {
111     (void)type; /*Unused*/
112     lv_obj_set_style(img, style);
113 }
114 
115 /*=====================
116  * Getter functions
117  *====================*/
118 
119 /**
120  * Get the source of the image
121  * @param img pointer to an image object
122  * @return the image source (symbol, file name or C array)
123  */
124 const void * lv_img_get_src(lv_obj_t * img);
125 
126 /**
127  * Get the name of the file set for an image
128  * @param img pointer to an image
129  * @return file name
130  */
131 const char * lv_img_get_file_name(const lv_obj_t * img);
132 
133 /**
134  * Get the auto size enable attribute
135  * @param img pointer to an image
136  * @return true: auto size is enabled, false: auto size is disabled
137  */
138 bool lv_img_get_auto_size(const lv_obj_t * img);
139 
140 /**
141  * Get the offset.x attribute of the img object.
142  * @param img pointer to an image
143  * @return offset.x value.
144  */
145 lv_coord_t lv_img_get_offset_x(lv_obj_t * img);
146 
147 /**
148  * Get the offset.y attribute of the img object.
149  * @param img pointer to an image
150  * @return offset.y value.
151  */
152 lv_coord_t lv_img_get_offset_y(lv_obj_t * img);
153 
154 /**
155  * Get the style of an image object
156  * @param img pointer to an image object
157  * @param type which style should be get (can be only `LV_IMG_STYLE_MAIN`)
158  * @return pointer to the image's style
159  */
lv_img_get_style(const lv_obj_t * img,lv_img_style_t type)160 static inline const lv_style_t * lv_img_get_style(const lv_obj_t * img, lv_img_style_t type)
161 {
162     (void)type; /*Unused*/
163     return lv_obj_get_style(img);
164 }
165 
166 /**********************
167  *      MACROS
168  **********************/
169 
170 /*Use this macro to declare an image in a c file*/
171 #define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name;
172 
173 #endif /*LV_USE_IMG*/
174 
175 #ifdef __cplusplus
176 } /* extern "C" */
177 #endif
178 
179 #endif /*LV_IMG_H*/
180