diff --git a/ChangeLog b/ChangeLog index ae65a64de..8ef7e043f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-06-17 Chris Lord + + * clutter/clutter-texture.c: (clutter_texture_get_preferred_width), + (clutter_texture_get_preferred_height): + Maintain aspect ratio with natural width/height when for_width/height + are specified + 2008-06-17 Matthew Allum * clutter/clutter-actor.c: diff --git a/clutter/clutter-texture.c b/clutter/clutter-texture.c index d7be3d0fa..491c06632 100644 --- a/clutter/clutter-texture.c +++ b/clutter/clutter-texture.c @@ -330,10 +330,6 @@ clutter_texture_get_preferred_width (ClutterActor *self, ClutterTexture *texture = CLUTTER_TEXTURE (self); ClutterTexturePrivate *priv = texture->priv; - /* FIXME If we wanted to be clever here, we could set the natural - * width to preserve aspect ratio considering for_height - */ - /* Min request is always 0 since we can scale down or clip */ if (min_width_p) *min_width_p = 0; @@ -341,7 +337,20 @@ clutter_texture_get_preferred_width (ClutterActor *self, if (priv->sync_actor_size) { if (natural_width_p) - *natural_width_p = CLUTTER_UNITS_FROM_DEVICE (priv->width); + { + if ((for_height < 0) || (priv->height <= 0)) + *natural_width_p = CLUTTER_UNITS_FROM_DEVICE (priv->width); + else + { + /* Set the natural width so as to preserve the aspect ratio */ + ClutterFixed ratio = + clutter_qdivx (CLUTTER_INT_TO_FIXED (priv->width), + CLUTTER_INT_TO_FIXED (priv->height)); + + *natural_width_p = CLUTTER_UNITS_FROM_FIXED ( + clutter_qmulx (ratio, CLUTTER_UNITS_TO_FIXED (for_height))); + } + } } else { @@ -359,10 +368,6 @@ clutter_texture_get_preferred_height (ClutterActor *self, ClutterTexture *texture = CLUTTER_TEXTURE (self); ClutterTexturePrivate *priv = texture->priv; - /* FIXME If we wanted to be clever here, we could set the natural - * height to preserve aspect ratio considering for_width - */ - /* Min request is always 0 since we can scale down or clip */ if (min_height_p) *min_height_p = 0; @@ -370,7 +375,20 @@ clutter_texture_get_preferred_height (ClutterActor *self, if (priv->sync_actor_size) { if (natural_height_p) - *natural_height_p = CLUTTER_UNITS_FROM_DEVICE (priv->height); + { + if ((for_width < 0) || (priv->width <= 0)) + *natural_height_p = CLUTTER_UNITS_FROM_DEVICE (priv->height); + else + { + /* Set the natural height so as to preserve the aspect ratio */ + ClutterFixed ratio = + clutter_qdivx (CLUTTER_INT_TO_FIXED (priv->height), + CLUTTER_INT_TO_FIXED (priv->width)); + + *natural_height_p = CLUTTER_UNITS_FROM_FIXED ( + clutter_qmulx (ratio, CLUTTER_UNITS_TO_FIXED (for_width))); + } + } } else {