actor: Add scaling factor in the Z axis

Having a scaling factor on the Z axis helps with projects that use fully
3D elements, like Mash.

https://bugzilla.gnome.org/show_bug.cgi?id=677853
This commit is contained in:
Emmanuele Bassi 2012-07-09 10:59:13 +01:00
parent 6feee080b3
commit 9b52f9b3f5
4 changed files with 93 additions and 3 deletions

View File

@ -194,6 +194,7 @@ struct _ClutterTransformInfo
/* scaling */
gdouble scale_x;
gdouble scale_y;
gdouble scale_z;
AnchorCoord scale_center;
/* anchor point */

View File

@ -875,6 +875,7 @@ enum
PROP_SCALE_X,
PROP_SCALE_Y,
PROP_SCALE_Z,
PROP_SCALE_CENTER_X, /* XXX:2.0 remove */
PROP_SCALE_CENTER_Y, /* XXX:2.0 remove */
PROP_SCALE_GRAVITY, /* XXX:2.0 remove */
@ -3000,7 +3001,7 @@ clutter_actor_real_apply_transform (ClutterActor *self,
cogl_matrix_scale (transform,
info->scale_x,
info->scale_y,
1.0));
info->scale_z));
}
if (info->rz_angle)
@ -4111,7 +4112,7 @@ static const ClutterTransformInfo default_transform_info = {
0.0, { 0, }, /* rotation-y */
0.0, { 0, }, /* rotation-z */
1.0, 1.0, { 0, }, /* scale */
1.0, 1.0, 1.0, { 0, }, /* scale */
{ 0, }, /* anchor */
@ -4578,8 +4579,12 @@ clutter_actor_set_scale_factor_internal (ClutterActor *self,
if (pspec == obj_props[PROP_SCALE_X])
info->scale_x = factor;
else
else if (pspec == obj_props[PROP_SCALE_Y])
info->scale_y = factor;
else if (pspec == obj_props[PROP_SCALE_Z])
info->scale_z = factor;
else
g_assert_not_reached ();
self->priv->transform_valid = FALSE;
clutter_actor_queue_redraw (self);
@ -4610,6 +4615,8 @@ clutter_actor_set_scale_factor (ClutterActor *self,
break;
case CLUTTER_Z_AXIS:
pspec = obj_props[PROP_SCALE_Z];
scale_p = &info->scale_z;
break;
}
@ -4910,6 +4917,11 @@ clutter_actor_set_property (GObject *object,
g_value_get_double (value));
break;
case PROP_SCALE_Z:
clutter_actor_set_scale_factor (actor, CLUTTER_Z_AXIS,
g_value_get_double (value));
break;
case PROP_SCALE_CENTER_X:
clutter_actor_set_scale_center (actor, CLUTTER_X_AXIS,
g_value_get_float (value));
@ -5340,6 +5352,15 @@ clutter_actor_get_property (GObject *object,
}
break;
case PROP_SCALE_Z:
{
const ClutterTransformInfo *info;
info = _clutter_actor_get_transform_info_or_defaults (actor);
g_value_set_double (value, info->scale_z);
}
break;
case PROP_SCALE_CENTER_X:
{
gfloat center;
@ -6653,6 +6674,25 @@ clutter_actor_class_init (ClutterActorClass *klass)
G_PARAM_STATIC_STRINGS |
CLUTTER_PARAM_ANIMATABLE);
/**
* ClutterActor:scale-z:
*
* The scale factor of the actor along the Z axis.
*
* The #ClutterActor:scale-y property is animatable.
*
* Since: 1.12
*/
obj_props[PROP_SCALE_Z] =
g_param_spec_double ("scale-z",
P_("Scale Z"),
P_("Scale factor on the Z axis"),
0.0, G_MAXDOUBLE,
1.0,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS |
CLUTTER_PARAM_ANIMATABLE);
/**
* ClutterActor:scale-center-x:
*
@ -10899,6 +10939,28 @@ clutter_actor_set_scale (ClutterActor *self,
g_object_thaw_notify (G_OBJECT (self));
}
/**
* clutter_actor_set_scale_z:
* @self: a #ClutterActor
* @scale_z: the scaling factor along the Z axis
*
* Scales an actor on the Z axis by the given @scale_z factor.
*
* The scale transformation is relative the the #ClutterActor:pivot-point.
*
* The #ClutterActor:scale-z property is animatable.
*
* Since: 1.12
*/
void
clutter_actor_set_scale_z (ClutterActor *self,
gdouble scale_z)
{
g_return_if_fail (CLUTTER_IS_ACTOR (self));
clutter_actor_set_scale_factor (self, CLUTTER_Z_AXIS, scale_z);
}
/**
* clutter_actor_set_scale_full:
* @self: A #ClutterActor
@ -11007,6 +11069,25 @@ clutter_actor_get_scale (ClutterActor *self,
*scale_y = info->scale_y;
}
/**
* clutter_actor_get_scale_z:
* @self: A #ClutterActor
*
* Retrieves the scaling factor along the Z axis, as set using
* clutter_actor_set_scale_z().
*
* Return value: the scaling factor along the Z axis
*
* Since: 1.12
*/
gdouble
clutter_actor_get_scale_z (ClutterActor *self)
{
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 1.0);
return _clutter_actor_get_transform_info_or_defaults (self)->scale_z;
}
/**
* clutter_actor_get_scale_center:
* @self: A #ClutterActor
@ -14456,6 +14537,7 @@ clutter_actor_set_animatable_property (ClutterActor *actor,
case PROP_SCALE_X:
case PROP_SCALE_Y:
case PROP_SCALE_Z:
clutter_actor_set_scale_factor_internal (actor,
g_value_get_double (value),
pspec);

View File

@ -652,6 +652,11 @@ void clutter_actor_get_scale
gdouble *scale_x,
gdouble *scale_y);
CLUTTER_AVAILABLE_IN_1_12
void clutter_actor_set_scale_z (ClutterActor *self,
gdouble scale_z);
CLUTTER_AVAILABLE_IN_1_12
gdouble clutter_actor_get_scale_z (ClutterActor *self);
CLUTTER_AVAILABLE_IN_1_12
void clutter_actor_set_translation (ClutterActor *self,
gfloat translate_x,
gfloat translate_y,

View File

@ -144,6 +144,7 @@ clutter_actor_get_rotation
clutter_actor_get_scale
clutter_actor_get_scale_center
clutter_actor_get_scale_gravity
clutter_actor_get_scale_z
clutter_actor_get_shader
clutter_actor_get_size
clutter_actor_get_stage
@ -266,6 +267,7 @@ clutter_actor_set_rotation
clutter_actor_set_scale
clutter_actor_set_scale_full
clutter_actor_set_scale_with_gravity
clutter_actor_set_scale_z
clutter_actor_set_shader
clutter_actor_set_shader_param
clutter_actor_set_shader_param_float