From: JengHyun Kang Date: Mon, 22 May 2017 12:20:48 +0000 (+0900) Subject: e_transform: Add a new API X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba7b308283a1de3894e22dfaf8376d00ff10e700;p=platform%2Fupstream%2Fenlightenment.git e_transform: Add a new API - e_util_transform_matrix_inv_coords_get() is needed because e_transform matrix result and Evas_Map result are different Change-Id: Idc7bf07758992f3b9136c9c6aa14cd258e9d425b --- diff --git a/src/bin/e_client.c b/src/bin/e_client.c index cc3baee907..55b9e1d7fd 100644 --- a/src/bin/e_client.c +++ b/src/bin/e_client.c @@ -6553,6 +6553,18 @@ e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL); } +E_API void +e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y) +{ + if (!ec) return; + if (!e_client_transform_core_enable_get(ec)) return; + + e_util_transform_matrix_inv_rect_coords_get(&ec->transform_core.result.transform, + &ec->transform_core.result.vertices, + ec->zone->w, ec->zone->h, + x, y, out_x, out_y); +} + E_API E_Pixmap * e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp) { diff --git a/src/bin/e_client.h b/src/bin/e_client.h index 9911c915f9..270f50a99d 100644 --- a/src/bin/e_client.h +++ b/src/bin/e_client.h @@ -1092,6 +1092,7 @@ E_API int e_client_transform_core_transform_count_get(E_Client *ec E_API E_Util_Transform *e_client_transform_core_transform_get(E_Client *ec, int index); E_API void e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y); E_API void e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y); +E_API void e_client_transform_core_input_inv_rect_transform(E_Client *ec, int x, int y, int *out_x, int *out_y); E_API E_Pixmap *e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp); E_API void e_client_window_role_set(E_Client *ec, const char *role); diff --git a/src/bin/e_util_transform.c b/src/bin/e_util_transform.c index 79b24c952f..87117b9e4e 100644 --- a/src/bin/e_util_transform.c +++ b/src/bin/e_util_transform.c @@ -720,6 +720,63 @@ e_util_transform_matrix_multiply(E_Util_Transform_Matrix *matrix1, return result; } +E_API void +e_util_transform_matrix_inv_rect_coords_get(E_Util_Transform *transform, E_Util_Transform_Rect_Vertex *vetices, int w, int h, int x, int y, int *out_x, int *out_y) +{ + int scale_w = 0, scale_h = 0; + int move_x = 0, move_y = 0; + int x1 = 0, x2 = 0, y1 = 0, y2 = 0; + int result_x = 0, result_y = 0; + double dmove_x = 0.0, dmove_y = 0.0; + double dx1 = 0.0, dx2 = 0.0, dy1 = 0.0, dy2 = 0.0; + double dresult_x = 0.0, dresult_y = 0.0; + double d_inv_map_x = 0.0, d_inv_map_y = 0.0; + + if (!out_x || !out_y) return; + + /* get rectangle's points from vertices. becase transform matrix is different with Evas_Map + * Evas_Map calculate using transformed rectangle's points, so to remove different these, + * calculate points using rectangle's points + */ + e_util_transform_vertices_pos_get(vetices, 0, &dx1, &dy1, NULL, NULL); + e_util_transform_vertices_pos_get(vetices, 2, &dx2, &dy2, NULL, NULL); + e_util_transform_move_get(transform, &dmove_x, &dmove_y, NULL); + + x1 = E_UTIL_TRANSFORM_ROUND(dx1); + x2 = E_UTIL_TRANSFORM_ROUND(dx2); + y1 = E_UTIL_TRANSFORM_ROUND(dy1); + y2 = E_UTIL_TRANSFORM_ROUND(dy2); + + scale_w = x2 - x1; + scale_h = y2 - y1; + + move_x = E_UTIL_TRANSFORM_ROUND(dmove_x); + move_y = E_UTIL_TRANSFORM_ROUND(dmove_y); + + /* calculate inverse transformed coordinates */ + dresult_x = (x * (double)scale_w / (double)w) + move_x; + dresult_y = (y * (double)scale_h / (double)h) + move_y; + + result_x = *out_x = E_UTIL_TRANSFORM_ROUND(dresult_x); + result_y = *out_y = E_UTIL_TRANSFORM_ROUND(dresult_y); + + /* this logic is added because Evas_Map doesn't do round. + * so check whether transformed result from Evas_Map is roundable. + * If the first digit after decimal point of result is greater than 5(roundable), + * add 1 to the inverted result. + */ + d_inv_map_x = (double)w + ((((double)result_x - (double)(scale_w + move_x)) * w) / (double)scale_w); + d_inv_map_y = (double)(h * (result_y - move_y)) / (double)scale_h; + if ((int)(d_inv_map_x * 10) % 10 >= 5) + { + *out_x = result_x + 1; + } + if ((int)(d_inv_map_y * 10) % 10 >= 5) + { + *out_y = result_y + 1; + } +} + E_API E_Util_Transform_Vertex e_util_transform_matrix_multiply_vertex(E_Util_Transform_Matrix *matrix, E_Util_Transform_Vertex *vertex) diff --git a/src/bin/e_util_transform.h b/src/bin/e_util_transform.h index c4912fadb8..b6d96ef638 100644 --- a/src/bin/e_util_transform.h +++ b/src/bin/e_util_transform.h @@ -142,5 +142,8 @@ E_API void e_util_transform_keep_ratio_set(E_Util_Transf E_API Eina_Bool e_util_transform_keep_ratio_get(E_Util_Transform *transform); E_API E_Util_Transform e_util_transform_keep_ratio_apply(E_Util_Transform *transform, int origin_w, int origin_h); E_API void e_util_transform_log(E_Util_Transform *transform, const char *str); + +E_API void e_util_transform_matrix_inv_rect_coords_get(E_Util_Transform *transform, E_Util_Transform_Rect_Vertex *vetices, int w, int h, int x, int y, int *out_x, int *out_y); + #endif #endif