diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index 0aae50763..2a495b0fc 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -17618,6 +17618,8 @@ clutter_actor_get_content_gravity (ClutterActor *self) * * Retrieves the bounding box for the #ClutterContent of @self. * + * The bounding box is relative to the actor's allocation. + * * If no #ClutterContent is set for @self, or if @self has not been * allocated yet, then the result is undefined. * @@ -17666,7 +17668,8 @@ clutter_actor_get_content_box (ClutterActor *self, &content_h)) return; - clutter_actor_box_get_size (&priv->allocation, &alloc_w, &alloc_h); + alloc_w = box->x2; + alloc_h = box->y2; switch (priv->content_gravity) { @@ -17768,24 +17771,49 @@ clutter_actor_get_content_box (ClutterActor *self, break; case CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT: - if (content_w >= content_h && content_h > 0) - { - double ratio = content_w / content_h; + { + double r_c = content_w / content_h; + double r_a = alloc_w / alloc_h; - box->x2 = box->x1 + alloc_w; + if (r_c >= 1.0) + { + if (r_a >= 1.0) + { + box->x1 = 0.f; + box->x2 = alloc_w; - box->y1 += ceilf ((alloc_h - (alloc_h / ratio)) / 2.0); - box->y2 = box->y1 + (alloc_h / ratio); - } - else if (content_h > content_w && content_w > 0) - { - double ratio = content_h / content_w; + box->y1 = (alloc_h - (alloc_w * r_c)) / 2.0f; + box->y2 = box->y1 + (alloc_w * r_c); + } + else + { + box->y1 = 0.f; + box->y2 = alloc_h; - box->x1 += ceilf ((alloc_w - (alloc_w / ratio)) / 2.0); - box->x2 = box->x2 + (alloc_w / ratio); + box->x1 = (alloc_w - (alloc_h * r_c)) / 2.0f; + box->x2 = box->x1 + (alloc_h * r_c); + } + } + else + { + if (r_a >= 1.0) + { + box->y1 = 0.f; + box->y2 = alloc_h; - box->y2 = box->x1 + alloc_h; - } + box->x1 = (alloc_w - (alloc_h * r_c)) / 2.0f; + box->x2 = box->x1 + (alloc_h * r_c); + } + else + { + box->x1 = 0.f; + box->x2 = alloc_w; + + box->y1 = (alloc_h - (alloc_w * r_c)) / 2.0f; + box->y2 = box->y1 + (alloc_w * r_c); + } + } + } break; } } diff --git a/tests/interactive/test-image-box.c b/tests/interactive/test-image-box.c index 3d29a33d6..b5f282843 100644 --- a/tests/interactive/test-image-box.c +++ b/tests/interactive/test-image-box.c @@ -28,9 +28,11 @@ static int cur_gravity = 0; static void on_clicked (ClutterClickAction *action, - ClutterActor *actor) + ClutterActor *actor, + ClutterText *label) { clutter_actor_set_content_gravity (actor, gravities[cur_gravity].gravity); + clutter_text_set_text (label, gravities[cur_gravity].name); cur_gravity += 1; @@ -47,7 +49,7 @@ test_image_box_describe (void) G_MODULE_EXPORT int test_image_box_main (int argc, char *argv[]) { - ClutterActor *stage, *box; + ClutterActor *stage, *box, *text; ClutterContent *image; ClutterAction *action; GdkPixbuf *pixbuf; @@ -57,7 +59,7 @@ test_image_box_main (int argc, char *argv[]) stage = clutter_stage_new (); clutter_actor_set_name (stage, "Stage"); - clutter_stage_set_title (CLUTTER_STAGE (stage), "Content"); + clutter_stage_set_title (CLUTTER_STAGE (stage), "Content Box"); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); clutter_actor_show (stage); @@ -85,12 +87,20 @@ test_image_box_main (int argc, char *argv[]) NULL); g_object_unref (pixbuf); - clutter_actor_set_content_gravity (box, CLUTTER_CONTENT_GRAVITY_TOP_LEFT); + clutter_actor_set_content_scaling_filters (box, + CLUTTER_SCALING_FILTER_BILINEAR, + CLUTTER_SCALING_FILTER_LINEAR); + clutter_actor_set_content_gravity (box, gravities[n_gravities - 1].gravity); clutter_actor_set_content (box, image); g_object_unref (image); + text = clutter_text_new (); + clutter_text_set_text (CLUTTER_TEXT (text), gravities[n_gravities - 1].name); + clutter_actor_add_constraint (text, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5)); + clutter_actor_add_child (stage, text); + action = clutter_click_action_new (); - g_signal_connect (action, "clicked", G_CALLBACK (on_clicked), NULL); + g_signal_connect (action, "clicked", G_CALLBACK (on_clicked), text); clutter_actor_set_reactive (box, TRUE); clutter_actor_add_action (box, action);