diff --git a/lv_conf_templ.h b/lv_conf_templ.h index 9be987280..97fc3f9b2 100644 --- a/lv_conf_templ.h +++ b/lv_conf_templ.h @@ -38,12 +38,12 @@ Misc. setting *=================*/ /*Display Input settings*/ -#define LV_indev_proc_READ_PERIOD 50 /*Input device read period milliseconds*/ -#define LV_indev_proc_TP_MARKER 0 /*Mark the pressed points (Value means marker point size)*/ -#define LV_indev_proc_DRAG_LIMIT (10 * LV_DOWNSCALE) /*Drag threshold in pixels */ -#define LV_indev_proc_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */ -#define LV_indev_proc_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/ -#define LV_indev_proc_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */ +#define LV_INDEV_READ_PERIOD 50 /*Input device read period milliseconds*/ +#define LV_INDEV_TP_MARKER 0 /*Mark the pressed points (Value means marker point size)*/ +#define LV_INDEV_DRAG_LIMIT (10 * LV_DOWNSCALE) /*Drag threshold in pixels */ +#define LV_INDEV_DRAG_THROW 20 /*Drag throw slow-down in [%]. Greater value means faster slow-down */ +#define LV_INDEV_LONG_PRESS_TIME 400 /*Long press time in milliseconds*/ +#define LV_INDEV_LONG_PRESS_REP_TIME 100 /*Repeated trigger period in long press [ms] */ /*lv_obj (base object) settings*/ #define LV_OBJ_FREE_NUM 1 /*Enable the free number attribute*/ diff --git a/lv_examples/1_2_objects/lv_ex_objects.c b/lv_examples/1_2_objects/lv_ex_objects.c index 5c9b32416..11b94ea14 100644 --- a/lv_examples/1_2_objects/lv_ex_objects.c +++ b/lv_examples/1_2_objects/lv_ex_objects.c @@ -73,8 +73,8 @@ /********************** * STATIC PROTOTYPES **********************/ -static lv_action_res_t btn_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t ddlist_action(lv_obj_t * ddlist, lv_indev_proc_t * indev_proc); +static lv_action_res_t btn_rel_action(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t ddlist_action(lv_obj_t * ddlist, LV_INDEV_t * indev_proc); /********************** * STATIC VARIABLES @@ -190,7 +190,7 @@ void lv_ex_objects(void) * @param indev_proc pointer to caller display input (e.g. touchpad) * @return LV_ACTION_RES_OK because the object is not deleted in this function */ -static lv_action_res_t btn_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t btn_rel_action(lv_obj_t * btn, LV_INDEV_t * indev_proc) { /*Increase the button width*/ cord_t width = lv_obj_get_width(btn); @@ -205,7 +205,7 @@ static lv_action_res_t btn_rel_action(lv_obj_t * btn, lv_indev_proc_t * indev_p * @param indev_proc pointer to caller display input (e.g. touchpad) * @return LV_ACTION_RES_OK because the object is not deleted in this function */ -static lv_action_res_t ddlist_action(lv_obj_t * ddlist, lv_indev_proc_t * indev_proc) +static lv_action_res_t ddlist_action(lv_obj_t * ddlist, LV_INDEV_t * indev_proc) { uint16_t opt = lv_ddlist_get_selected(ddlist); /*Get the id of selected option*/ diff --git a/lv_examples/2_2_encoder_ctrl/lv_ex_encoder_ctrl.c b/lv_examples/2_2_encoder_ctrl/lv_ex_encoder_ctrl.c index 447aa0d57..b001d4f49 100644 --- a/lv_examples/2_2_encoder_ctrl/lv_ex_encoder_ctrl.c +++ b/lv_examples/2_2_encoder_ctrl/lv_ex_encoder_ctrl.c @@ -51,13 +51,13 @@ **********************/ static void gui_create(void); static void enc_create(void); -static lv_action_res_t mbox_yes_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t mbox_no_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t enable_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t enc_next(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t enc_inc(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t enc_dec(lv_obj_t * btn, lv_indev_proc_t * indev_proc); -static lv_action_res_t enc_sel(lv_obj_t * btn, lv_indev_proc_t * indev_proc); +static lv_action_res_t mbox_yes_action(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t mbox_no_action(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t enable_action(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t enc_next(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t enc_inc(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t enc_dec(lv_obj_t * btn, LV_INDEV_t * indev_proc); +static lv_action_res_t enc_sel(lv_obj_t * btn, LV_INDEV_t * indev_proc); /********************** * STATIC VARIABLES @@ -196,7 +196,7 @@ static void enc_create(void) * @param indev_proc pointer to the caller display input or NULL if the encoder used * @return LV_ACTION_RES_OK: because the button is not deleted */ -static lv_action_res_t enable_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t enable_action(lv_obj_t * btn, LV_INDEV_t * indev_proc) { /*If the butto nsi released the show message box to be sure about the Enable*/ if(lv_btn_get_state(btn) == LV_BTN_STATE_REL) { @@ -238,7 +238,7 @@ static lv_action_res_t enable_action(lv_obj_t * btn, lv_indev_proc_t * indev_pro * @param indev_proc pointer to the caller display input or NULL if the encoder used * @return LV_ACTION_RES_INV: because the button along with the message box will be deleted */ -static lv_action_res_t mbox_yes_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t mbox_yes_action(lv_obj_t * btn, LV_INDEV_t * indev_proc) { lv_group_focus_freeze(g, false); /*Release the freeze*/ lv_obj_t * mbox = lv_mbox_get_from_btn(btn); @@ -259,7 +259,7 @@ static lv_action_res_t mbox_yes_action(lv_obj_t * btn, lv_indev_proc_t * indev_p * @param indev_proc pointer to the caller display input or NULL if the encoder used * @return LV_ACTION_RES_INV: because the button along with the message box will be deleted */ -static lv_action_res_t mbox_no_action(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t mbox_no_action(lv_obj_t * btn, LV_INDEV_t * indev_proc) { lv_group_focus_freeze(g, false); /*Release the freeze*/ lv_obj_t * mbox = lv_mbox_get_from_btn(btn); @@ -274,7 +274,7 @@ static lv_action_res_t mbox_no_action(lv_obj_t * btn, lv_indev_proc_t * indev_pr * @param indev_proc pointer to the caller display input * @return LV_ACTION_RES_OK: because the button is not deleted */ -static lv_action_res_t enc_next(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t enc_next(lv_obj_t * btn, LV_INDEV_t * indev_proc) { /*Focus on the next object in the group*/ lv_group_focus_next(g); @@ -288,7 +288,7 @@ static lv_action_res_t enc_next(lv_obj_t * btn, lv_indev_proc_t * indev_proc) * @param indev_proc pointer to the caller display input * @return LV_ACTION_RES_OK: because the button is not deleted */ -static lv_action_res_t enc_inc(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t enc_inc(lv_obj_t * btn, LV_INDEV_t * indev_proc) { /* Send RIGHT key when rotate to right. * It will trigger an increment like action in the object */ @@ -302,7 +302,7 @@ static lv_action_res_t enc_inc(lv_obj_t * btn, lv_indev_proc_t * indev_proc) * @param indev_proc pointer to the caller display input * @return LV_ACTION_RES_OK: because the button is not deleted */ -static lv_action_res_t enc_dec(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t enc_dec(lv_obj_t * btn, LV_INDEV_t * indev_proc) { /* Send LEFT key when rotate to left. * It will trigger a decrement like action in the object */ @@ -316,7 +316,7 @@ static lv_action_res_t enc_dec(lv_obj_t * btn, lv_indev_proc_t * indev_proc) * @param indev_proc pointer to the caller display input * @return LV_ACTION_RES_OK: because the button is not deleted */ -static lv_action_res_t enc_sel(lv_obj_t * btn, lv_indev_proc_t * indev_proc) +static lv_action_res_t enc_sel(lv_obj_t * btn, LV_INDEV_t * indev_proc) { /* Send ENTER key. * It will trigger an 'OK' or 'Select' action in the object */ diff --git a/lv_obj/lv_indev.c b/lv_obj/lv_indev.c index 871df2904..449acfa5f 100644 --- a/lv_obj/lv_indev.c +++ b/lv_obj/lv_indev.c @@ -51,10 +51,10 @@ static lv_indev_t *indev_act; /** * Initialize the display input device subsystem */ -void lv_indev_proc_init(void) +void lv_indev_init(void) { -#if LV_indev_proc_READ_PERIOD != 0 - indev_proc_task_p = ptask_create(indev_proc_task, LV_indev_proc_READ_PERIOD, PTASK_PRIO_MID, NULL); +#if LV_INDEV_READ_PERIOD != 0 + indev_proc_task_p = ptask_create(indev_proc_task, LV_INDEV_READ_PERIOD, PTASK_PRIO_MID, NULL); #else indev_proc_task_p = ptask_create(indev_proc_task, 1, PTASK_PRIO_OFF); /*Not use lv_indev_proc*/ #endif @@ -62,21 +62,6 @@ void lv_indev_proc_init(void) lv_indev_reset(NULL); /*Reset all input devices*/ } -/** - * Enable input devices device by type - * @param type Input device type - * @param enable true: enable this type; false: disable this type - */ -void lv_indev_enable(lv_hal_indev_type_t type, bool enable) -{ - lv_indev_t *i = lv_indev_next(NULL); - - while (i) { - if (i->drv.type == type) i->state.disable = enable == false ? 1 : 0; - i = lv_indev_next(i); - } -} - /** * Get the currently processed input device. Can be used in action functions too. * @return pointer to the currently processed input device or NULL if no input device processing right now @@ -113,6 +98,34 @@ void lv_indev_reset_lpr(lv_indev_t * indev_proc) indev_proc->state.press_time_stamp = lv_tick_get(); } +/** + * Enable input devices device by type + * @param type Input device type + * @param enable true: enable this type; false: disable this type + */ +void lv_indev_enable(lv_hal_indev_type_t type, bool enable) +{ + lv_indev_t *i = lv_indev_next(NULL); + + while (i) { + if (i->drv.type == type) i->state.disable = enable == false ? 1 : 0; + i = lv_indev_next(i); + } +} + +/** + * Enable input devices device by type + * @param indev pointer to an input device + * @param cur_obj pointer to an object to be used as cursor + */ +void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj) +{ + indev->cursor = cur_obj; + lv_obj_set_parent(indev->cursor, lv_sys_layer()); + lv_obj_set_pos(indev->cursor, indev->state.act_point.x, indev->state.act_point.y); +} + + /** * Get the last point of an input device * @param indev pointer to an input device @@ -186,10 +199,17 @@ static void indev_proc_task(void * param) lv_indev_get(i, &data); i->state.pressed = data.state; + + if(i->cursor != NULL && + (i->state.last_point.x != data.point.x || + i->state.last_point.y != data.point.y)) + { + lv_obj_set_pos_us(i->cursor, data.point.x, data.point.y); + } + + indev_proc_point(&i->state, data.point.x , data.point.y); - - i = lv_indev_next(i); } @@ -213,12 +233,12 @@ static void indev_proc_point(lv_indev_state_t * indev, cord_t x, cord_t y) #endif if(indev->pressed != false){ -#if LV_indev_proc_TP_MARKER != 0 +#if LV_INDEV_TP_MARKER != 0 area_t area; - area.x1 = x - (LV_indev_proc_TP_MARKER >> 1); - area.y1 = y - (LV_indev_proc_TP_MARKER >> 1); - area.x2 = x + ((LV_indev_proc_TP_MARKER >> 1) | 0x1); - area.y2 = y + ((LV_indev_proc_TP_MARKER >> 1) | 0x1); + area.x1 = x - (LV_INDEV_TP_MARKER >> 1); + area.y1 = y - (LV_INDEV_TP_MARKER >> 1); + area.x2 = x + ((LV_INDEV_TP_MARKER >> 1) | 0x1); + area.y2 = y + ((LV_INDEV_TP_MARKER >> 1) | 0x1); lv_rfill(&area, NULL, COLOR_MAKE(0xFF, 0, 0), OPA_COVER); #endif indev_proc_press(indev); @@ -226,7 +246,6 @@ static void indev_proc_point(lv_indev_state_t * indev, cord_t x, cord_t y) disi_proc_release(indev); } - indev->last_point.x = indev->act_point.x; indev->last_point.y = indev->act_point.y; } @@ -315,7 +334,7 @@ static void indev_proc_press(lv_indev_state_t * state) /*If there is no drag then check for long press time*/ if(state->drag_in_prog == 0 && state->long_press_sent == 0) { /*Send a signal about the long press if enough time elapsed*/ - if(lv_tick_elaps(state->press_time_stamp) > LV_indev_proc_LONG_PRESS_TIME) { + if(lv_tick_elaps(state->press_time_stamp) > LV_INDEV_LONG_PRESS_TIME) { pr_obj->signal_f(pr_obj, LV_SIGNAL_LONG_PRESS, indev_act); /*Mark the signal sending to do not send it again*/ @@ -328,7 +347,7 @@ static void indev_proc_press(lv_indev_state_t * state) /*Send long press repeated signal*/ if(state->drag_in_prog == 0 && state->long_press_sent == 1) { /*Send a signal about the long press repeate if enough time elapsed*/ - if(lv_tick_elaps(state->lpr_rep_time_stamp) > LV_indev_proc_LONG_PRESS_REP_TIME) { + if(lv_tick_elaps(state->lpr_rep_time_stamp) > LV_INDEV_LONG_PRESS_REP_TIME) { pr_obj->signal_f(pr_obj, LV_SIGNAL_LONG_PRESS_REP, indev_act); state->lpr_rep_time_stamp = lv_tick_get(); @@ -432,8 +451,8 @@ static void indev_drag(lv_indev_state_t * state) state->vect_sum.y += state->vect.y; /*If a move is greater then LV_DRAG_LIMIT then begin the drag*/ - if(MATH_ABS(state->vect_sum.x) >= LV_indev_proc_DRAG_LIMIT || - MATH_ABS(state->vect_sum.y) >= LV_indev_proc_DRAG_LIMIT) + if(MATH_ABS(state->vect_sum.x) >= LV_INDEV_DRAG_LIMIT || + MATH_ABS(state->vect_sum.y) >= LV_INDEV_DRAG_LIMIT) { state->drag_range_out = 1; } @@ -490,8 +509,8 @@ static void indev_drag_throw(lv_indev_state_t * state) } /*Reduce the vectors*/ - state->vect.x = state->vect.x * (100 -LV_indev_proc_DRAG_THROW) / 100; - state->vect.y = state->vect.y * (100 -LV_indev_proc_DRAG_THROW) / 100; + state->vect.x = state->vect.x * (100 -LV_INDEV_DRAG_THROW) / 100; + state->vect.y = state->vect.y * (100 -LV_INDEV_DRAG_THROW) / 100; if(state->vect.x != 0 || state->vect.y != 0) diff --git a/lv_obj/lv_indev.h b/lv_obj/lv_indev.h index 0ad044a73..95ee6b41c 100644 --- a/lv_obj/lv_indev.h +++ b/lv_obj/lv_indev.h @@ -3,8 +3,8 @@ * */ -#ifndef LV_indev_proc_H -#define LV_indev_proc_H +#ifndef LV_INDEV_H +#define LV_INDEV_H #ifdef __cplusplus extern "C" { @@ -39,7 +39,7 @@ typedef lv_action_res_t ( * lv_action_t) (struct __LV_OBJ_T * obj); /** * Initialize the display input subsystem */ -void lv_indev_proc_init(void); +void lv_indev_init(void); /** * Get the currently processed input device. Can be used in action functions too. @@ -58,6 +58,13 @@ void lv_indev_reset(lv_indev_t * indev); */ void lv_indev_reset_lpr(lv_indev_t * indev_proc); +/** + * Enable input devices device by type + * @param indev pointer to an input device + * @param cur_obj pointer to an object to be used as cursor + */ +void lv_indev_set_cursor(lv_indev_t * indev, lv_obj_t * cur_obj); + /** * Get the last point on display input * @param indev_proc pointer to a display input @@ -94,4 +101,4 @@ void lv_indev_wait_release(lv_indev_t * indev_proc); } /* extern "C" */ #endif -#endif /*LV_indev_proc_H*/ +#endif /*LV_INDEV_H*/ diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 8a0680ecb..61800e104 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -25,6 +25,7 @@ /********************* * DEFINES *********************/ + /********************** * TYPEDEFS **********************/ @@ -43,6 +44,8 @@ static bool lv_obj_design(lv_obj_t * obj, const area_t * mask_p, lv_design_mode **********************/ static lv_obj_t * def_scr = NULL; static lv_obj_t * act_scr = NULL; +static lv_obj_t * top_layer = NULL; +static lv_obj_t * sys_layer = NULL; static ll_dsc_t scr_ll; #ifdef LV_IMG_DEF_WALLPAPER @@ -86,12 +89,18 @@ void lv_init(void) #endif act_scr = def_scr; + top_layer = lv_obj_create(NULL, NULL); + lv_obj_set_style(top_layer, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL)); + + sys_layer = lv_obj_create(NULL, NULL); + lv_obj_set_style(sys_layer, lv_style_get(LV_STYLE_TRANSP_TIGHT, NULL)); + /*Refresh the screen*/ lv_obj_inv(act_scr); -#if LV_indev_proc_READ_PERIOD != 0 +#if LV_INDEV_READ_PERIOD != 0 /*Init the input device handling*/ - lv_indev_proc_init(); + lv_indev_init(); #endif /*Initialize the application level*/ @@ -354,8 +363,10 @@ bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) void lv_obj_inv(lv_obj_t * obj) { /*Invalidate the object only if it belongs to the 'act_scr'*/ - lv_obj_t * act_scr_p = lv_scr_act(); - if(lv_obj_get_scr(obj) == act_scr_p) { + lv_obj_t * obj_scr = lv_obj_get_scr(obj); + if(obj_scr == lv_scr_act() || + obj_scr == lv_top_layer() || + obj_scr == lv_sys_layer()) { /*Truncate recursively to the parents*/ area_t area_trunc; lv_obj_t * par = lv_obj_get_parent(obj); @@ -376,7 +387,7 @@ void lv_obj_inv(lv_obj_t * obj) par = lv_obj_get_parent(par); } - if(union_ok != false) lv_inv_area(&area_trunc); + if(union_ok != false) lv_inv_area(&area_trunc); } } @@ -1090,13 +1101,32 @@ void lv_obj_anim(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t /** * Return with the actual screen - * @return pointer to to the actual screen object + * @return pointer to the actual screen object */ lv_obj_t * lv_scr_act(void) { return act_scr; } +/** + * Return with the top layer. (Same on every screen and it is above the normal screen layer) + * @return pointer to the top layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_top_layer(void) +{ + return top_layer; +} + +/** + * Return with the system layer. (Same on every screen and it is above the all other layers) + * It is used for example by the cursor + * @return pointer to the system layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_sys_layer(void) +{ + return sys_layer; +} + /** * Return with the screen of an object * @param obj pointer to an object @@ -1269,6 +1299,9 @@ lv_style_t * lv_obj_get_style(lv_obj_t * obj) } } #endif + + if(style_act == NULL) style_act = lv_style_get(LV_STYLE_PLAIN, NULL); + return style_act; } diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index 5e6b868fd..abfb21498 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -491,7 +491,14 @@ void lv_obj_anim(lv_obj_t * obj, lv_anim_builtin_t type, uint16_t time, uint16_t * Return with the actual screen * @return pointer to to the actual screen object */ -lv_obj_t * lv_scr_act(void); +lv_obj_t * lv_scr_act(void);lv_obj_t * lv_top_layer(void); + +/** + * Return with the system layer. (Same on every screen and it is above the all other layers) + * It is used for example by the cursor + * @return pointer to the system layer object (transparent screen sized lv_obj) + */ +lv_obj_t * lv_sys_layer(void); /** * Return with the screen of an object diff --git a/lv_obj/lv_refr.c b/lv_obj/lv_refr.c index 5347e24a9..783730647 100644 --- a/lv_obj/lv_refr.c +++ b/lv_obj/lv_refr.c @@ -315,6 +315,11 @@ static void lv_refr_area_part_vdb(const area_t * area_p) /*Do the refreshing from the top object*/ lv_refr_make(top_p, &start_mask); + /*Also refresh top and sys layer unconditionally*/ + lv_refr_make(lv_top_layer(), &start_mask); + lv_refr_make(lv_sys_layer(), &start_mask); + + /*Flush the content of the VDB*/ lv_vdb_flush(); } diff --git a/lv_objx/lv_tabview.c b/lv_objx/lv_tabview.c index 1f7334987..543c331ca 100644 --- a/lv_objx/lv_tabview.c +++ b/lv_objx/lv_tabview.c @@ -514,11 +514,11 @@ static void tabpage_pressing_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) cord_t y_diff = point_act.y - ext->point_last.y; if(ext->draging == 0) { - if(x_diff >= LV_indev_proc_DRAG_LIMIT || x_diff<= -LV_indev_proc_DRAG_LIMIT) { + if(x_diff >= LV_INDEV_DRAG_LIMIT || x_diff<= -LV_INDEV_DRAG_LIMIT) { ext->drag_h = 1; ext->draging = 1; lv_obj_set_drag(lv_page_get_scrl(tabpage), false); - } else if(y_diff >= LV_indev_proc_DRAG_LIMIT || y_diff <= -LV_indev_proc_DRAG_LIMIT) { + } else if(y_diff >= LV_INDEV_DRAG_LIMIT || y_diff <= -LV_INDEV_DRAG_LIMIT) { ext->drag_h = 0; ext->draging = 1; } @@ -559,7 +559,7 @@ static void tabpage_press_lost_hadler(lv_obj_t * tabview, lv_obj_t * tabpage) while(x_diff != 0) { x_predict += x_diff; - x_diff = x_diff * (100 - LV_indev_proc_DRAG_THROW) / 100; + x_diff = x_diff * (100 - LV_INDEV_DRAG_THROW) / 100; }