1 /**
2 * @file lv_disp.h
3 *
4 */
5
6 #ifndef LV_DISP_H
7 #define LV_DISP_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #include "../hal/lv_hal.h"
17 #include "lv_obj.h"
18 #include "lv_theme.h"
19
20 /*********************
21 * DEFINES
22 *********************/
23
24 /**********************
25 * TYPEDEFS
26 **********************/
27
28 typedef enum {
29 LV_SCR_LOAD_ANIM_NONE,
30 LV_SCR_LOAD_ANIM_OVER_LEFT,
31 LV_SCR_LOAD_ANIM_OVER_RIGHT,
32 LV_SCR_LOAD_ANIM_OVER_TOP,
33 LV_SCR_LOAD_ANIM_OVER_BOTTOM,
34 LV_SCR_LOAD_ANIM_MOVE_LEFT,
35 LV_SCR_LOAD_ANIM_MOVE_RIGHT,
36 LV_SCR_LOAD_ANIM_MOVE_TOP,
37 LV_SCR_LOAD_ANIM_MOVE_BOTTOM,
38 LV_SCR_LOAD_ANIM_FADE_ON,
39 } lv_scr_load_anim_t;
40
41 /**********************
42 * GLOBAL PROTOTYPES
43 **********************/
44
45 /**
46 * Return with a pointer to the active screen
47 * @param disp pointer to display which active screen should be get. (NULL to use the default
48 * screen)
49 * @return pointer to the active screen object (loaded by 'lv_scr_load()')
50 */
51 lv_obj_t * lv_disp_get_scr_act(lv_disp_t * disp);
52
53 /**
54 * Return with a pointer to the previous screen. Only used during screen transitions.
55 * @param disp pointer to display which previous screen should be get. (NULL to use the default
56 * screen)
57 * @return pointer to the previous screen object or NULL if not used now
58 */
59 lv_obj_t * lv_disp_get_scr_prev(lv_disp_t * disp);
60
61 /**
62 * Make a screen active
63 * @param scr pointer to a screen
64 */
65 void lv_disp_load_scr(lv_obj_t * scr);
66
67 /**
68 * Return with the top layer. (Same on every screen and it is above the normal screen layer)
69 * @param disp pointer to display which top layer should be get. (NULL to use the default screen)
70 * @return pointer to the top layer object (transparent screen sized lv_obj)
71 */
72 lv_obj_t * lv_disp_get_layer_top(lv_disp_t * disp);
73
74 /**
75 * Return with the sys. layer. (Same on every screen and it is above the normal screen and the top
76 * layer)
77 * @param disp pointer to display which sys. layer should be retrieved. (NULL to use the default screen)
78 * @return pointer to the sys layer object (transparent screen sized lv_obj)
79 */
80 lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp);
81
82 /**
83 * Set the theme of a display
84 * @param disp pointer to a display
85 */
86 void lv_disp_set_theme(lv_disp_t * disp, lv_theme_t * th);
87
88 /**
89 * Get the theme of a display
90 * @param disp pointer to a display
91 * @return the display's theme (can be NULL)
92 */
93 lv_theme_t * lv_disp_get_theme(lv_disp_t * disp);
94
95 /**
96 * Set the background color of a display
97 * @param disp pointer to a display
98 * @param color color of the background
99 */
100 void lv_disp_set_bg_color(lv_disp_t * disp, lv_color_t color);
101
102 /**
103 * Set the background image of a display
104 * @param disp pointer to a display
105 * @param img_src path to file or pointer to an `lv_img_dsc_t` variable
106 */
107 void lv_disp_set_bg_image(lv_disp_t * disp, const void * img_src);
108
109 /**
110 * Set opacity of the background
111 * @param disp pointer to a display
112 * @param opa opacity (0..255)
113 */
114 void lv_disp_set_bg_opa(lv_disp_t * disp, lv_opa_t opa);
115
116 /**
117 * Switch screen with animation
118 * @param scr pointer to the new screen to load
119 * @param anim_type type of the animation from `lv_scr_load_anim_t`. E.g. `LV_SCR_LOAD_ANIM_MOVE_LEFT`
120 * @param time time of the animation
121 * @param delay delay before the transition
122 * @param auto_del true: automatically delete the old screen
123 */
124 void lv_scr_load_anim(lv_obj_t * scr, lv_scr_load_anim_t anim_type, uint32_t time, uint32_t delay, bool auto_del);
125
126 /**
127 * Get elapsed time since last user activity on a display (e.g. click)
128 * @param disp pointer to a display (NULL to get the overall smallest inactivity)
129 * @return elapsed ticks (milliseconds) since the last activity
130 */
131 uint32_t lv_disp_get_inactive_time(const lv_disp_t * disp);
132
133 /**
134 * Manually trigger an activity on a display
135 * @param disp pointer to a display (NULL to use the default display)
136 */
137 void lv_disp_trig_activity(lv_disp_t * disp);
138
139 /**
140 * Clean any CPU cache that is related to the display.
141 * @param disp pointer to a display (NULL to use the default display)
142 */
143 void lv_disp_clean_dcache(lv_disp_t * disp);
144
145 /**
146 * Get a pointer to the screen refresher timer to
147 * modify its parameters with `lv_timer_...` functions.
148 * @param disp pointer to a display
149 * @return pointer to the display refresher timer. (NULL on error)
150 */
151 lv_timer_t * _lv_disp_get_refr_timer(lv_disp_t * disp);
152
153 /*------------------------------------------------
154 * To improve backward compatibility
155 * Recommended only if you have one display
156 *------------------------------------------------*/
157
158 /**
159 * Get the active screen of the default display
160 * @return pointer to the active screen
161 */
lv_scr_act(void)162 static inline lv_obj_t * lv_scr_act(void)
163 {
164 return lv_disp_get_scr_act(lv_disp_get_default());
165 }
166
167 /**
168 * Get the top layer of the default display
169 * @return pointer to the top layer
170 */
lv_layer_top(void)171 static inline lv_obj_t * lv_layer_top(void)
172 {
173 return lv_disp_get_layer_top(lv_disp_get_default());
174 }
175
176 /**
177 * Get the active screen of the default display
178 * @return pointer to the sys layer
179 */
lv_layer_sys(void)180 static inline lv_obj_t * lv_layer_sys(void)
181 {
182 return lv_disp_get_layer_sys(lv_disp_get_default());
183 }
184
lv_scr_load(lv_obj_t * scr)185 static inline void lv_scr_load(lv_obj_t * scr)
186 {
187 lv_disp_load_scr(scr);
188 }
189
190 /**********************
191 * MACROS
192 **********************/
193
194 /*------------------------------------------------
195 * To improve backward compatibility
196 * Recommended only if you have one display
197 *------------------------------------------------*/
198
199 #ifndef LV_HOR_RES
200 /**
201 * The horizontal resolution of the currently active display.
202 */
203 #define LV_HOR_RES lv_disp_get_hor_res(lv_disp_get_default())
204 #endif
205
206 #ifndef LV_VER_RES
207 /**
208 * The vertical resolution of the currently active display.
209 */
210 #define LV_VER_RES lv_disp_get_ver_res(lv_disp_get_default())
211 #endif
212
213 /**
214 * Scale the given number of pixels (a distance or size) relative to a 160 DPI display
215 * considering the DPI of the default display.
216 * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the
217 * DPI of the display.
218 * @param n the number of pixels to scale
219 * @return `n x current_dpi/160`
220 */
lv_dpx(lv_coord_t n)221 static inline lv_coord_t lv_dpx(lv_coord_t n)
222 {
223 return LV_DPX(n);
224 }
225
226 /**
227 * Scale the given number of pixels (a distance or size) relative to a 160 DPI display
228 * considering the DPI of the given display.
229 * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the
230 * DPI of the display.
231 * @param obj a display whose dpi should be considered
232 * @param n the number of pixels to scale
233 * @return `n x current_dpi/160`
234 */
lv_disp_dpx(const lv_disp_t * disp,lv_coord_t n)235 static inline lv_coord_t lv_disp_dpx(const lv_disp_t * disp, lv_coord_t n)
236 {
237 return _LV_DPX_CALC(lv_disp_get_dpi(disp), n);
238 }
239
240 #ifdef __cplusplus
241 } /*extern "C"*/
242 #endif
243
244 #endif /*LV_DISP_H*/
245