e_transform: Add a new API 00/130500/7
authorJengHyun Kang <jhyuni.kang@samsung.com>
Mon, 22 May 2017 12:20:48 +0000 (21:20 +0900)
committerDoyoun Kang <doyoun.kang@samsung.com>
Tue, 23 May 2017 08:53:12 +0000 (08:53 +0000)
 - e_util_transform_matrix_inv_coords_get() is needed because
   e_transform matrix result and Evas_Map result are different

Change-Id: Idc7bf07758992f3b9136c9c6aa14cd258e9d425b

src/bin/e_client.c
src/bin/e_client.h
src/bin/e_util_transform.c
src/bin/e_util_transform.h

index cc3baee907072f6ff7dea74268b6f348a447e7f7..55b9e1d7fdc779d2132851736c0dd74460608471 100644 (file)
@@ -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)
 {
index 9911c915f9ca1eafd24f66051221f7d6a66bdf45..270f50a99d0454d59d677cd1a78fcd706a758463 100644 (file)
@@ -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);
index 9f6100ebe061592fdce16b66ae346c925215fd08..d00d9c22f2b5d8dc069c3e1846d5909824bdb833 100644 (file)
@@ -765,6 +765,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)
index 3dc48c196fe332eb7d1c81f0f9d390e6842a76ab..e396fab8c5dba6bca0560ee8d5f90c1d27aaa029 100644 (file)
@@ -144,5 +144,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