From e9ee7f049d51c5d3a273385dae0d073c373ca51c Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 8 Jan 2009 15:45:22 +0000 Subject: [PATCH] Fix last improper usage of ClutterUnits ClutterUnits should not be used interchangeably as, or with ClutterFixed values. ClutterUnits should also not be assumed to be integers. This commit fixes the last few improper usages of ClutterUnit values, and adds a CLUTTER_UNITS_FORMAT macro for safely printing ClutterUnit values with printf(). --- clutter/clutter-actor.c | 44 ++++++++++++--------- clutter/clutter-units.h | 2 + tests/interactive/test-project.c | 65 +++++++++++++++----------------- 3 files changed, 59 insertions(+), 52 deletions(-) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 7d616266e..2f39c4f0c 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -1013,7 +1013,8 @@ clutter_actor_apply_relative_transform_to_point (ClutterActor *self, ClutterVertex *vertex) { ClutterFixed v[4]; - ClutterFixed x, y, z, w; + ClutterUnit x, y, z, w; + fixed_vertex_t tmp; g_return_if_fail (CLUTTER_IS_ACTOR (self)); g_return_if_fail (ancestor == NULL || CLUTTER_IS_ACTOR (ancestor)); @@ -1026,8 +1027,7 @@ clutter_actor_apply_relative_transform_to_point (ClutterActor *self, w = COGL_FIXED_1; /* First we tranform the point using the OpenGL modelview matrix */ - clutter_actor_transform_point_relative (self, ancestor, - &x, &y, &z, &w); + clutter_actor_transform_point_relative (self, ancestor, &x, &y, &z, &w); cogl_get_viewport (v); @@ -1035,12 +1035,12 @@ clutter_actor_apply_relative_transform_to_point (ClutterActor *self, * The w[3] parameter should always be 1.0 here, so we ignore it; otherwise * we would have to divide the original verts with it. */ - vertex->x = - CLUTTER_UNITS_FROM_FIXED (COGL_FIXED_MUL ((x + COGL_FIXED_0_5), v[2])); - vertex->y = - CLUTTER_UNITS_FROM_FIXED (COGL_FIXED_MUL ((COGL_FIXED_0_5 - y), v[3])); - vertex->z = - CLUTTER_UNITS_FROM_FIXED (COGL_FIXED_MUL ((z + COGL_FIXED_0_5), v[2])); + tmp.x = COGL_FIXED_MUL (CLUTTER_UNITS_TO_FIXED (x) + COGL_FIXED_0_5, v[2]); + tmp.y = COGL_FIXED_MUL (COGL_FIXED_0_5 - CLUTTER_UNITS_TO_FIXED (y), v[3]); + tmp.z = COGL_FIXED_MUL (CLUTTER_UNITS_TO_FIXED (z) + COGL_FIXED_0_5, v[2]); + tmp.w = 0; + + fixed_vertex_to_units (&tmp, vertex); } /** @@ -1060,6 +1060,7 @@ clutter_actor_apply_transform_to_point (ClutterActor *self, const ClutterVertex *point, ClutterVertex *vertex) { + ClutterUnit x, y, z, w; ClutterFixed mtx_p[16]; ClutterFixed v[4]; fixed_vertex_t tmp = { 0, }; @@ -1068,13 +1069,18 @@ clutter_actor_apply_transform_to_point (ClutterActor *self, g_return_if_fail (point != NULL); g_return_if_fail (vertex != NULL); - tmp.x = CLUTTER_UNITS_TO_FIXED (vertex->x); - tmp.y = CLUTTER_UNITS_TO_FIXED (vertex->y); - tmp.z = CLUTTER_UNITS_TO_FIXED (vertex->z); - tmp.w = COGL_FIXED_1; + x = point->x; + y = point->y; + z = point->z; + w = CLUTTER_UNITS_FROM_INT (1); /* First we tranform the point using the OpenGL modelview matrix */ - clutter_actor_transform_point (self, &tmp.x, &tmp.y, &tmp.z, &tmp.w); + clutter_actor_transform_point (self, &x, &y, &z, &w); + + tmp.x = CLUTTER_UNITS_TO_FIXED (x); + tmp.y = CLUTTER_UNITS_TO_FIXED (y); + tmp.z = CLUTTER_UNITS_TO_FIXED (z); + tmp.w = CLUTTER_UNITS_TO_FIXED (w); cogl_get_projection_matrix (mtx_p); cogl_get_viewport (v); @@ -3244,8 +3250,9 @@ clutter_actor_get_preferred_width (ClutterActor *self, if (natural_width < min_width) { - g_warning ("Actor of type %s reported a natural width of %d (%d px) " - "lower than min width %d (%d px)", + g_warning ("Actor of type %s reported a natural width " + "of %" CLUTTER_UNITS_FORMAT " (%d px) lower " + "than min width %" CLUTTER_UNITS_FORMAT " (%d px)", G_OBJECT_TYPE_NAME (self), natural_width, CLUTTER_UNITS_TO_DEVICE (natural_width), min_width, CLUTTER_UNITS_TO_DEVICE (min_width)); @@ -3314,8 +3321,9 @@ clutter_actor_get_preferred_height (ClutterActor *self, if (natural_height < min_height) { - g_warning ("Actor of type %s reported a natural height of %d " - "(%d px) lower than min height %d (%d px)", + g_warning ("Actor of type %s reported a natural height " + "of %" CLUTTER_UNITS_FORMAT " (%d px) lower than " + "min height %" CLUTTER_UNITS_FORMAT " (%d px)", G_OBJECT_TYPE_NAME (self), natural_height, CLUTTER_UNITS_TO_DEVICE (natural_height), min_height, CLUTTER_UNITS_TO_DEVICE (min_height)); diff --git a/clutter/clutter-units.h b/clutter/clutter-units.h index 8337d19ff..b85375a98 100644 --- a/clutter/clutter-units.h +++ b/clutter/clutter-units.h @@ -59,6 +59,8 @@ typedef gint32 ClutterUnit; #define CLUTTER_UNITS_FROM_FIXED(x) (x) #define CLUTTER_UNITS_TO_FIXED(x) (x) +#define CLUTTER_UNITS_FORMAT "d" + /** * CLUTTER_UNITS_FROM_DEVICE: * @x: value in pixels diff --git a/tests/interactive/test-project.c b/tests/interactive/test-project.c index 33560df0b..7c9403014 100644 --- a/tests/interactive/test-project.c +++ b/tests/interactive/test-project.c @@ -21,19 +21,19 @@ init_handles () clutter_actor_set_position (p[i], 0, 0); clutter_group_add (CLUTTER_GROUP (main_stage), p[i]); - clutter_actor_set_position (p[i], - CLUTTER_FIXED_TO_INT (v[i].x) - - clutter_actor_get_width (p[i])/2, - CLUTTER_FIXED_TO_INT (v[i].y) - - clutter_actor_get_height (p[i])/2); + clutter_actor_set_positionu (p[i], + v[i].x - + clutter_actor_get_widthu (p[i])/2, + v[i].y - + clutter_actor_get_heightu (p[i])/2); clutter_actor_raise_top (p[i]); clutter_actor_show (p[i]); } - v1.x = CLUTTER_INT_TO_FIXED (clutter_actor_get_width (rect)/2); - v1.y = CLUTTER_INT_TO_FIXED (clutter_actor_get_height (rect)/2); + v1.x = clutter_actor_get_widthu (rect) / 2; + v1.y = clutter_actor_get_heightu (rect) / 2; v1.z = 0; clutter_actor_apply_transform_to_point (rect, &v1, &v2); @@ -41,11 +41,11 @@ init_handles () clutter_actor_set_size (p[4], 5, 5); clutter_actor_set_position (p[4], 0, 0); clutter_group_add (CLUTTER_GROUP (main_stage), p[4]); - clutter_actor_set_position (p[4], - CLUTTER_FIXED_TO_INT (v2.x) - - clutter_actor_get_width (p[4])/2, - CLUTTER_FIXED_TO_INT (v2.y) - - clutter_actor_get_height (p[4])/2); + clutter_actor_set_positionu (p[4], + v2.x - + clutter_actor_get_widthu (p[4])/2, + v2.y - + clutter_actor_get_heightu (p[4])/2); clutter_actor_raise_top (p[4]); @@ -62,23 +62,21 @@ place_handles () clutter_actor_get_abs_allocation_vertices (rect, v); for (i = 0; i < 4; ++i) { - clutter_actor_set_position (p[i], - CLUTTER_FIXED_TO_INT (v[i].x) - - clutter_actor_get_width (p[i])/2, - CLUTTER_FIXED_TO_INT (v[i].y) - - clutter_actor_get_height (p[i])/2); + clutter_actor_set_positionu (p[i], + v[i].x - + clutter_actor_get_widthu (p[i])/2, + v[i].y - + clutter_actor_get_heightu (p[i])/2); } - v1.x = CLUTTER_INT_TO_FIXED (clutter_actor_get_width (rect)/2); - v1.y = CLUTTER_INT_TO_FIXED (clutter_actor_get_height (rect)/2); + v1.x = clutter_actor_get_widthu (rect)/2; + v1.y = clutter_actor_get_heightu (rect)/2; v1.z = 0; clutter_actor_apply_transform_to_point (rect, &v1, &v2); - clutter_actor_set_position (p[4], - CLUTTER_FIXED_TO_INT (v2.x) - - clutter_actor_get_width (p[4])/2, - CLUTTER_FIXED_TO_INT (v2.y) - - clutter_actor_get_height (p[4])/2); + clutter_actor_set_positionu (p[4], + v2.x - clutter_actor_get_widthu (p[4])/2, + v2.y - clutter_actor_get_heightu (p[4])/2); } #define M(m,row,col) (m)[col*4+row] @@ -127,7 +125,7 @@ on_event (ClutterStage *stage, gint x, y; gint i; ClutterActorBox box1, box2; - ClutterFixed xp, yp; + ClutterUnit xp, yp; i = find_handle_index (dragging); @@ -139,25 +137,24 @@ on_event (ClutterStage *stage, clutter_actor_get_allocation_box (dragging, &box1); clutter_actor_get_allocation_box (rect, &box2); - xp = CLUTTER_INT_TO_FIXED (x-3) - box1.x1; - yp = CLUTTER_INT_TO_FIXED (y-3) - box1.y1; + xp = CLUTTER_UNITS_FROM_DEVICE (x - 3) - box1.x1; + yp = CLUTTER_UNITS_FROM_DEVICE (y - 3) - box1.y1; if (i == 4) { g_debug ("moving box by %f, %f", - CLUTTER_FIXED_TO_FLOAT (xp), - CLUTTER_FIXED_TO_FLOAT (yp)); + CLUTTER_UNITS_TO_FLOAT (xp), + CLUTTER_UNITS_TO_FLOAT (yp)); - clutter_actor_move_by (rect, - CLUTTER_FIXED_TO_INT(xp), - CLUTTER_FIXED_TO_INT(yp)); + clutter_actor_move_byu (rect, xp, yp); } else { g_debug ("adjusting box by %f, %f, handle %d", - CLUTTER_FIXED_TO_FLOAT (xp), - CLUTTER_FIXED_TO_FLOAT (yp), + CLUTTER_UNITS_TO_FLOAT (xp), + CLUTTER_UNITS_TO_FLOAT (yp), i); + switch (i) { case 0: