mirror of
https://github.com/brl/mutter.git
synced 2024-11-29 19:40:43 -05:00
2008-06-23 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-texture.c: (clutter_texture_get_preferred_width), (clutter_texture_get_preferred_height), (clutter_texture_set_property), (clutter_texture_get_property), (clutter_texture_class_init), (clutter_texture_init): Add the new :keep-aspect-ratio property to ClutterTexture; when set to TRUE the texture will return a preferred width maintaining the aspect ratio with the given height and a preferred height maintaining the aspect ratio with the given width. This allows to set the width or the height and have the texture automatically request the height or the width respectively while maintaining the aspect ratio of the original image. * tests/test-script.json: Update to test the new :keep-aspect-ratio property.
This commit is contained in:
parent
dff84094ff
commit
9006de848b
19
ChangeLog
19
ChangeLog
@ -1,3 +1,22 @@
|
|||||||
|
2008-06-23 Emmanuele Bassi <ebassi@openedhand.com>
|
||||||
|
|
||||||
|
* clutter/clutter-texture.c:
|
||||||
|
(clutter_texture_get_preferred_width),
|
||||||
|
(clutter_texture_get_preferred_height),
|
||||||
|
(clutter_texture_set_property),
|
||||||
|
(clutter_texture_get_property),
|
||||||
|
(clutter_texture_class_init),
|
||||||
|
(clutter_texture_init): Add the new :keep-aspect-ratio property
|
||||||
|
to ClutterTexture; when set to TRUE the texture will return a
|
||||||
|
preferred width maintaining the aspect ratio with the given height
|
||||||
|
and a preferred height maintaining the aspect ratio with the
|
||||||
|
given width. This allows to set the width or the height and have
|
||||||
|
the texture automatically request the height or the width respectively
|
||||||
|
while maintaining the aspect ratio of the original image.
|
||||||
|
|
||||||
|
* tests/test-script.json: Update to test the new :keep-aspect-ratio
|
||||||
|
property.
|
||||||
|
|
||||||
2008-06-23 Neil Roberts <neil@o-hand.com>
|
2008-06-23 Neil Roberts <neil@o-hand.com>
|
||||||
|
|
||||||
Bug 918 - Group doesn't clip if it's children are clipped
|
Bug 918 - Group doesn't clip if it's children are clipped
|
||||||
|
@ -95,6 +95,7 @@ struct _ClutterTexturePrivate
|
|||||||
guchar *local_data;
|
guchar *local_data;
|
||||||
|
|
||||||
guint in_dispose : 1;
|
guint in_dispose : 1;
|
||||||
|
guint keep_aspect_ratio : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -108,7 +109,8 @@ enum
|
|||||||
PROP_REPEAT_X,
|
PROP_REPEAT_X,
|
||||||
PROP_FILTER_QUALITY,
|
PROP_FILTER_QUALITY,
|
||||||
PROP_COGL_TEXTURE,
|
PROP_COGL_TEXTURE,
|
||||||
PROP_FILENAME
|
PROP_FILENAME,
|
||||||
|
PROP_KEEP_ASPECT_RATIO
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -338,17 +340,24 @@ clutter_texture_get_preferred_width (ClutterActor *self,
|
|||||||
{
|
{
|
||||||
if (natural_width_p)
|
if (natural_width_p)
|
||||||
{
|
{
|
||||||
if ((for_height < 0) || (priv->height <= 0))
|
if (!priv->keep_aspect_ratio ||
|
||||||
*natural_width_p = CLUTTER_UNITS_FROM_DEVICE (priv->width);
|
for_height < 0 ||
|
||||||
|
priv->height <= 0)
|
||||||
|
{
|
||||||
|
*natural_width_p = CLUTTER_UNITS_FROM_DEVICE (priv->width);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Set the natural width so as to preserve the aspect ratio */
|
/* Set the natural width so as to preserve the aspect ratio */
|
||||||
ClutterFixed ratio =
|
ClutterFixed ratio, height;
|
||||||
clutter_qdivx (CLUTTER_INT_TO_FIXED (priv->width),
|
|
||||||
CLUTTER_INT_TO_FIXED (priv->height));
|
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)));
|
height = CLUTTER_UNITS_TO_FIXED (for_height);
|
||||||
|
|
||||||
|
*natural_width_p =
|
||||||
|
CLUTTER_UNITS_FROM_FIXED (clutter_qmulx (ratio, height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -376,17 +385,24 @@ clutter_texture_get_preferred_height (ClutterActor *self,
|
|||||||
{
|
{
|
||||||
if (natural_height_p)
|
if (natural_height_p)
|
||||||
{
|
{
|
||||||
if ((for_width < 0) || (priv->width <= 0))
|
if (!priv->keep_aspect_ratio ||
|
||||||
*natural_height_p = CLUTTER_UNITS_FROM_DEVICE (priv->height);
|
for_width < 0 ||
|
||||||
|
priv->width <= 0)
|
||||||
|
{
|
||||||
|
*natural_height_p = CLUTTER_UNITS_FROM_DEVICE (priv->height);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Set the natural height so as to preserve the aspect ratio */
|
/* Set the natural height so as to preserve the aspect ratio */
|
||||||
ClutterFixed ratio =
|
ClutterFixed ratio, width;
|
||||||
clutter_qdivx (CLUTTER_INT_TO_FIXED (priv->height),
|
|
||||||
CLUTTER_INT_TO_FIXED (priv->width));
|
|
||||||
|
|
||||||
*natural_height_p = CLUTTER_UNITS_FROM_FIXED (
|
ratio = clutter_qdivx (CLUTTER_INT_TO_FIXED (priv->height),
|
||||||
clutter_qmulx (ratio, CLUTTER_UNITS_TO_FIXED (for_width)));
|
CLUTTER_INT_TO_FIXED (priv->width));
|
||||||
|
|
||||||
|
width = CLUTTER_UNITS_TO_FIXED (for_width);
|
||||||
|
|
||||||
|
*natural_height_p =
|
||||||
|
CLUTTER_UNITS_FROM_FIXED (clutter_qmulx (ratio, width));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,6 +577,9 @@ clutter_texture_set_property (GObject *object,
|
|||||||
case PROP_NO_SLICE:
|
case PROP_NO_SLICE:
|
||||||
priv->no_slice = g_value_get_boolean (value);
|
priv->no_slice = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_KEEP_ASPECT_RATIO:
|
||||||
|
priv->keep_aspect_ratio = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -608,6 +627,9 @@ clutter_texture_get_property (GObject *object,
|
|||||||
case PROP_NO_SLICE:
|
case PROP_NO_SLICE:
|
||||||
g_value_set_boolean (value, priv->no_slice);
|
g_value_set_boolean (value, priv->no_slice);
|
||||||
break;
|
break;
|
||||||
|
case PROP_KEEP_ASPECT_RATIO:
|
||||||
|
g_value_set_boolean (value, priv->keep_aspect_ratio);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -723,6 +745,15 @@ clutter_texture_class_init (ClutterTextureClass *klass)
|
|||||||
NULL,
|
NULL,
|
||||||
G_PARAM_WRITABLE));
|
G_PARAM_WRITABLE));
|
||||||
|
|
||||||
|
g_object_class_install_property
|
||||||
|
(gobject_class, PROP_KEEP_ASPECT_RATIO,
|
||||||
|
g_param_spec_boolean ("keep-aspect-ratio",
|
||||||
|
"Keep Aspect Ratio",
|
||||||
|
"Keep the aspect ratio of the texture when "
|
||||||
|
"requesting the preferred width or height",
|
||||||
|
FALSE,
|
||||||
|
CLUTTER_PARAM_READWRITE));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClutterTexture::size-change:
|
* ClutterTexture::size-change:
|
||||||
* @texture: the texture which received the signal
|
* @texture: the texture which received the signal
|
||||||
@ -841,14 +872,15 @@ clutter_texture_init (ClutterTexture *self)
|
|||||||
|
|
||||||
self->priv = priv = CLUTTER_TEXTURE_GET_PRIVATE (self);
|
self->priv = priv = CLUTTER_TEXTURE_GET_PRIVATE (self);
|
||||||
|
|
||||||
priv->max_tile_waste = 64;
|
priv->max_tile_waste = 64;
|
||||||
priv->filter_quality = CLUTTER_TEXTURE_QUALITY_MEDIUM;
|
priv->filter_quality = CLUTTER_TEXTURE_QUALITY_MEDIUM;
|
||||||
priv->repeat_x = FALSE;
|
priv->repeat_x = FALSE;
|
||||||
priv->repeat_y = FALSE;
|
priv->repeat_y = FALSE;
|
||||||
priv->sync_actor_size = TRUE;
|
priv->sync_actor_size = TRUE;
|
||||||
priv->texture = COGL_INVALID_HANDLE;
|
priv->texture = COGL_INVALID_HANDLE;
|
||||||
priv->fbo_handle = COGL_INVALID_HANDLE;
|
priv->fbo_handle = COGL_INVALID_HANDLE;
|
||||||
priv->local_data = NULL;
|
priv->local_data = NULL;
|
||||||
|
priv->keep_aspect_ratio = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
"x" : 100,
|
"x" : 100,
|
||||||
"y" : 100,
|
"y" : 100,
|
||||||
"width" : "20mm",
|
"width" : "20mm",
|
||||||
"height" : "100px",
|
"keep-aspect-ratio" : true,
|
||||||
"anchor-x" : "5mm",
|
"anchor-x" : "5mm",
|
||||||
"anchor-y" : "5pt",
|
"anchor-y" : "5pt",
|
||||||
"opacity" : 100,
|
"opacity" : 100,
|
||||||
|
Loading…
Reference in New Issue
Block a user