update obejcts with the new event system

This commit is contained in:
Gabor Kiss-Vamosi
2019-02-26 16:07:40 +01:00
parent 50e69bab6b
commit dc0ce46b0c
18 changed files with 193 additions and 111 deletions

View File

@@ -466,7 +466,7 @@ static void style_mod_def(lv_style_t * style)
style->body.border.color = LV_COLOR_ORANGE;
/*If not empty or has border then emphasis the border*/
if(style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_ORANGE, LV_OPA_70);
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_ORANGE, LV_OPA_70);
@@ -495,7 +495,7 @@ static void style_mod_edit_def(lv_style_t * style)
style->body.border.color = LV_COLOR_GREEN;
/*If not empty or has border then emphasis the border*/
if(style->body.empty == 0 || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
if(style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70);
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70);

View File

@@ -43,7 +43,7 @@ static void indev_proc_release(lv_indev_proc_t * proc);
static void indev_proc_reset_query_handler(lv_indev_t * indev);
static lv_obj_t * indev_search_obj(const lv_indev_proc_t * proc, lv_obj_t * obj);
static void indev_drag(lv_indev_proc_t * state);
static void indev_drag_throw(lv_indev_proc_t * state);
static void indev_drag_throw(lv_indev_proc_t * proc);
#endif
/**********************
@@ -425,7 +425,6 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
} else if(data->key == LV_GROUP_KEY_ENTER) {
if(!i->proc.long_pr_sent) {
focused->signal_cb(focused, LV_SIGNAL_RELEASED, indev_act);
lv_obj_send_event(focused, LV_EVENT_RELEASED);
lv_obj_send_event(focused, LV_EVENT_CLICKED);
}
} else {
@@ -618,7 +617,7 @@ static void indev_proc_press(lv_indev_proc_t * proc)
* It is necessary to count the long press time.*/
proc->pr_timestamp = lv_tick_get();
proc->long_pr_sent = 0;
proc->drag_range_out = 0;
proc->drag_limit_out = 0;
proc->drag_in_prog = 0;
proc->drag_sum.x = 0;
proc->drag_sum.y = 0;
@@ -652,6 +651,21 @@ static void indev_proc_press(lv_indev_proc_t * proc)
proc->vect.x = proc->act_point.x - proc->last_point.x;
proc->vect.y = proc->act_point.y - proc->last_point.y;
proc->drawg_throw_vect.x = (proc->drawg_throw_vect.x * 5) >> 3;
proc->drawg_throw_vect.y = (proc->drawg_throw_vect.y * 5) >> 3;
if(proc->drawg_throw_vect.x < 0) proc->drawg_throw_vect.x++;
else if(proc->drawg_throw_vect.x > 0) proc->drawg_throw_vect.x--;
if(proc->drawg_throw_vect.y < 0) proc->drawg_throw_vect.y++;
else if(proc->drawg_throw_vect.y > 0) proc->drawg_throw_vect.y--;
proc->drawg_throw_vect.x += (proc->vect.x * 4) >> 3;
proc->drawg_throw_vect.y += (proc->vect.y * 4) >> 3;
printf("dtv:%d\n", proc->drawg_throw_vect.y);
/*If there is active object and it can be dragged run the drag*/
if(proc->act_obj != NULL) {
proc->act_obj->signal_cb(proc->act_obj, LV_SIGNAL_PRESSING, indev_act);
@@ -715,9 +729,10 @@ static void indev_proc_release(lv_indev_proc_t * proc)
lv_obj_t * obj_on = indev_search_obj(proc, proc->act_obj);
if(obj_on == proc->act_obj) {
proc->act_obj->signal_cb(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
lv_obj_send_event(proc->act_obj, LV_EVENT_RELEASED);
if(proc->long_pr_sent == 0 && proc->drag_in_prog == 0) {
lv_obj_send_event(proc->act_obj, LV_EVENT_CLICKED);
} else {
lv_obj_send_event(proc->act_obj, LV_EVENT_RELEASED);
}
}
else {
@@ -730,9 +745,11 @@ static void indev_proc_release(lv_indev_proc_t * proc)
* If it is already not pressed then was handled in `indev_proc_press`*/
else {
proc->act_obj->signal_cb(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
lv_obj_send_event(proc->act_obj, LV_SIGNAL_RELEASED);
if(proc->long_pr_sent == 0 && proc->drag_in_prog == 0) {
lv_obj_send_event(proc->act_obj, LV_EVENT_CLICKED);
} else {
lv_obj_send_event(proc->act_obj, LV_SIGNAL_RELEASED);
}
}
@@ -794,7 +811,7 @@ static void indev_proc_reset_query_handler(lv_indev_t * indev)
if(indev->proc.reset_query) {
indev->proc.act_obj = NULL;
indev->proc.last_obj = NULL;
indev->proc.drag_range_out = 0;
indev->proc.drag_limit_out = 0;
indev->proc.drag_in_prog = 0;
indev->proc.long_pr_sent = 0;
indev->proc.pr_timestamp = 0;
@@ -868,19 +885,20 @@ static void indev_drag(lv_indev_proc_t * state)
state->drag_sum.y += state->vect.y;
/*Enough move?*/
if(state->drag_range_out == 0) {
if(state->drag_limit_out == 0) {
/*If a move is greater then LV_DRAG_LIMIT then begin the drag*/
if(LV_MATH_ABS(state->drag_sum.x) >= LV_INDEV_DRAG_LIMIT ||
LV_MATH_ABS(state->drag_sum.y) >= LV_INDEV_DRAG_LIMIT) {
state->drag_range_out = 1;
state->drag_limit_out = 1;
}
}
/*If the drag limit is stepped over then handle the dragging*/
if(state->drag_range_out != 0) {
/*If the drag limit is exceeded handle the dragging*/
if(state->drag_limit_out != 0) {
/*Set new position if the vector is not zero*/
if(state->vect.x != 0 ||
state->vect.y != 0) {
state->vect.y != 0)
{
/*Get the coordinates of the object and modify them*/
lv_coord_t act_x = lv_obj_get_x(drag_obj);
lv_coord_t act_y = lv_obj_get_y(drag_obj);
@@ -894,9 +912,8 @@ static void indev_drag(lv_indev_proc_t * state)
lv_obj_set_pos(drag_obj, act_x + state->vect.x, act_y + state->vect.y);
/*Set the drag in progress flag if the object is really moved*/
if(drag_obj->coords.x1 != prev_x || drag_obj->coords.y1 != prev_y) {
if(state->drag_range_out != 0) { /*Send the drag begin signal on first move*/
if(state->drag_in_prog != 0) { /*Send the drag begin signal on first move*/
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_BEGIN, indev_act);
if(state->reset_query != 0) return;
}
@@ -922,12 +939,13 @@ static void indev_drag(lv_indev_proc_t * state)
* Handle throwing by drag if the drag is ended
* @param indev pointer to an input device state
*/
static void indev_drag_throw(lv_indev_proc_t * state)
static void indev_drag_throw(lv_indev_proc_t * proc)
{
if(state->drag_in_prog == 0) return;
if(proc->drag_in_prog == 0) return;
/*Set new position if the vector is not zero*/
lv_obj_t * drag_obj = state->last_obj;
lv_obj_t * drag_obj = proc->last_obj;
/*If drag parent is active check recursively the drag_parent attribute*/
while(lv_obj_get_drag_parent(drag_obj) != false &&
@@ -935,45 +953,50 @@ static void indev_drag_throw(lv_indev_proc_t * state)
drag_obj = lv_obj_get_parent(drag_obj);
}
if(drag_obj == NULL) return;
if(drag_obj == NULL) {
return;
}
/*Return if the drag throw is not enabled*/
if(lv_obj_get_drag_throw(drag_obj) == false) {
state->drag_in_prog = 0;
proc->drag_in_prog = 0;
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
return;
}
/*Reduce the vectors*/
state->vect.x = state->vect.x * (100 - LV_INDEV_DRAG_THROW) / 100;
state->vect.y = state->vect.y * (100 - LV_INDEV_DRAG_THROW) / 100;
proc->drawg_throw_vect.x = proc->drawg_throw_vect.x * (100 - LV_INDEV_DRAG_THROW) / 100;
proc->drawg_throw_vect.y = proc->drawg_throw_vect.y * (100 - LV_INDEV_DRAG_THROW) / 100;
if(state->vect.x != 0 ||
state->vect.y != 0) {
if(proc->drawg_throw_vect.x != 0 ||
proc->drawg_throw_vect.y != 0) {
/*Get the coordinates and modify them*/
lv_area_t coords_ori;
lv_obj_get_coords(drag_obj, &coords_ori);
lv_coord_t act_x = lv_obj_get_x(drag_obj) + state->vect.x;
lv_coord_t act_y = lv_obj_get_y(drag_obj) + state->vect.y;
lv_coord_t act_x = lv_obj_get_x(drag_obj) + proc->drawg_throw_vect.x;
lv_coord_t act_y = lv_obj_get_y(drag_obj) + proc->drawg_throw_vect.y;
lv_obj_set_pos(drag_obj, act_x, act_y);
lv_area_t coord_new;
lv_obj_get_coords(drag_obj, &coord_new);
/*If non of the coordinates are changed then do not continue throwing*/
if((coords_ori.x1 == coord_new.x1 || state->vect.x == 0) &&
(coords_ori.y1 == coord_new.y1 || state->vect.y == 0)) {
state->drag_in_prog = 0;
state->vect.x = 0;
state->vect.y = 0;
if((coords_ori.x1 == coord_new.x1 || proc->drawg_throw_vect.x == 0) &&
(coords_ori.y1 == coord_new.y1 || proc->drawg_throw_vect.y == 0)) {
proc->drag_in_prog = 0;
proc->vect.x = 0;
proc->vect.y = 0;
proc->drawg_throw_vect.x = 0;
proc->drawg_throw_vect.y = 0;
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
}
}
/*If the vectors become 0 -> drag_in_prog = 0 and send a drag end signal*/
else {
state->drag_in_prog = 0;
proc->drag_in_prog = 0;
drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_END, indev_act);
}
}
#endif

View File

@@ -232,7 +232,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
new_obj->style_p = &lv_style_plain_color;
}
/*Set virtual functions*/
/*Set callbacks*/
lv_obj_set_signal_cb(new_obj, lv_obj_signal);
lv_obj_set_design_cb(new_obj, lv_obj_design);
@@ -1813,11 +1813,15 @@ static bool lv_obj_design(lv_obj_t * obj, const lv_area_t * mask_p, lv_design_m
{
if(mode == LV_DESIGN_COVER_CHK) {
/*Most trivial test. The mask is fully IN the object? If no it surely not covers it*/
if(lv_area_is_in(mask_p, &obj->coords) == false) return false;
/*Can cover the area only if fully solid (no opacity)*/
lv_style_t * style = lv_obj_get_style(obj);
if(style->body.opa != LV_OPA_COVER) return false;
/* Because of the radius it is not sure the area is covered
* Check the areas where there is no radius*/
lv_style_t * style = lv_obj_get_style(obj);
if(style->body.empty != 0) return false;
uint16_t r = style->body.radius;
if(r == LV_RADIUS_CIRCLE) return false;

View File

@@ -78,8 +78,8 @@ void lv_style_init(void)
lv_style_scr.body.main_color = LV_COLOR_WHITE;
lv_style_scr.body.grad_color = LV_COLOR_WHITE;
lv_style_scr.body.radius = 0;
lv_style_scr.body.padding.ver = LV_DPI / 12;
lv_style_scr.body.padding.hor = LV_DPI / 12;
lv_style_scr.body.padding.ver = 0;
lv_style_scr.body.padding.hor = 0;
lv_style_scr.body.padding.inner = LV_DPI / 12;
lv_style_scr.body.border.color = LV_COLOR_BLACK;
@@ -108,6 +108,8 @@ void lv_style_init(void)
/*Plain style (by default near the same as the screen style)*/
memcpy(&lv_style_plain, &lv_style_scr, sizeof(lv_style_t));
lv_style_plain.body.padding.hor = LV_DPI / 12;
lv_style_plain.body.padding.ver = LV_DPI / 12;
/*Plain color style*/
memcpy(&lv_style_plain_color, &lv_style_plain, sizeof(lv_style_t));
@@ -140,9 +142,9 @@ void lv_style_init(void)
/*Transparent style*/
memcpy(&lv_style_transp, &lv_style_plain, sizeof(lv_style_t));
lv_style_transp.body.empty = 1;
lv_style_transp.glass = 1;
lv_style_transp.body.border.width = 0;
lv_style_transp.body.opa = LV_OPA_TRANSP;
/*Transparent fitting size*/
memcpy(&lv_style_transp_fit, &lv_style_transp, sizeof(lv_style_t));
@@ -252,14 +254,12 @@ void lv_style_mix(const lv_style_t * start, const lv_style_t * end, lv_style_t *
res->line.color = lv_color_mix(end->line.color, start->line.color, opa);
if(ratio < (STYLE_MIX_MAX >> 1)) {
res->body.empty = start->body.empty;
res->body.border.part = start->body.border.part;
res->glass = start->glass;
res->text.font = start->text.font;
res->body.shadow.type = start->body.shadow.type;
res->line.rounded = start->line.rounded;
} else {
res->body.empty = end->body.empty;
res->body.border.part = end->body.border.part;
res->glass = end->glass;
res->text.font = end->text.font;