diff --git a/clutter/clutter-action.h b/clutter/clutter-action.h index 7f3c8501c..afeafd91c 100644 --- a/clutter/clutter-action.h +++ b/clutter/clutter-action.h @@ -82,12 +82,19 @@ struct _ClutterActionClass GType clutter_action_get_type (void) G_GNUC_CONST; /* ClutterActor API */ -void clutter_actor_add_action (ClutterActor *self, - ClutterAction *action); -void clutter_actor_remove_action (ClutterActor *self, - ClutterAction *action); -GList *clutter_actor_get_actions (ClutterActor *self); -void clutter_actor_clear_actions (ClutterActor *self); +void clutter_actor_add_action (ClutterActor *self, + ClutterAction *action); +void clutter_actor_add_action_with_name (ClutterActor *self, + const gchar *name, + ClutterAction *action); +void clutter_actor_remove_action (ClutterActor *self, + ClutterAction *action); +void clutter_actor_remove_action_by_name (ClutterActor *self, + const gchar *name); +ClutterAction *clutter_actor_get_action (ClutterActor *self, + const gchar *name); +GList * clutter_actor_get_actions (ClutterActor *self); +void clutter_actor_clear_actions (ClutterActor *self); G_END_DECLS diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index a1dcde57d..b8d8475be 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -10478,6 +10478,37 @@ clutter_actor_add_action (ClutterActor *self, g_object_notify (G_OBJECT (self), "actions"); } +/** + * clutter_actor_add_action_with_name: + * @self: a #ClutterActor + * @name: the name to set on the action + * @constraint: a #ClutterAction + * + * A convenience function for setting the name of a #ClutterAction + * while adding it to the list of actions applied to @self + * + * This function is the logical equivalent of: + * + * |[ + * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (action), name); + * clutter_actor_add_action (self, action); + * ]| + * + * Since: 1.4 + */ +void +clutter_actor_add_action_with_name (ClutterActor *self, + const gchar *name, + ClutterAction *action) +{ + g_return_if_fail (CLUTTER_IS_ACTOR (self)); + g_return_if_fail (name != NULL); + g_return_if_fail (CLUTTER_IS_ACTION (self)); + + clutter_actor_meta_set_name (CLUTTER_ACTOR_META (action), name); + clutter_actor_add_action (self, action); +} + /** * clutter_actor_remove_action: * @self: a #ClutterActor @@ -10508,6 +10539,40 @@ clutter_actor_remove_action (ClutterActor *self, g_object_notify (G_OBJECT (self), "actions"); } +/** + * clutter_actor_remove_action_by_name: + * @self: a #ClutterActor + * @name: the name of the action to remove + * + * Removes the #ClutterAction with the given name from the list + * of actions applied to @self + * + * Since: 1.4 + */ +void +clutter_actor_remove_action_by_name (ClutterActor *self, + const gchar *name) +{ + ClutterActorPrivate *priv; + ClutterActorMeta *meta; + + g_return_if_fail (CLUTTER_IS_ACTOR (self)); + g_return_if_fail (name != NULL); + + priv = self->priv; + + if (priv->actions == NULL) + return; + + meta = _clutter_meta_group_get_meta (priv->actions, name); + if (meta == NULL) + return; + + _clutter_meta_group_remove_meta (priv->actions, meta); + + g_object_notify (G_OBJECT (self), "actions"); +} + /** * clutter_actor_get_actions: * @self: a #ClutterActor @@ -10536,6 +10601,33 @@ clutter_actor_get_actions (ClutterActor *self) return g_list_copy ((GList *) actions); } +/** + * clutter_actor_get_action: + * @self: a #ClutterActor + * @name: the name of the action to retrieve + * + * Retrieves the #ClutterAction with the given name in the list + * of actions applied to @self + * + * Return value: (transfer none): a #ClutterAction for the given + * name, or %NULL. The returned #ClutterAction is owned by the + * actor and it should not be unreferenced directly + * + * Since: 1.4 + */ +ClutterAction * +clutter_actor_get_action (ClutterActor *self, + const gchar *name) +{ + g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL); + g_return_val_if_fail (name != NULL, NULL); + + if (self->priv->actions == NULL) + return NULL; + + return CLUTTER_ACTION (_clutter_meta_group_get_meta (self->priv->actions, name)); +} + /** * clutter_actor_clear_actions: * @self: a #ClutterActor @@ -10592,6 +10684,37 @@ clutter_actor_add_constraint (ClutterActor *self, g_object_notify (G_OBJECT (self), "constraints"); } +/** + * clutter_actor_add_constraint_with_name: + * @self: a #ClutterActor + * @name: the name to set on the constraint + * @constraint: a #ClutterConstraint + * + * A convenience function for setting the name of a #ClutterConstraint + * while adding it to the list of constraints applied to @self + * + * This function is the logical equivalent of: + * + * |[ + * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), name); + * clutter_actor_add_constraint (self, constraint); + * ]| + * + * Since: 1.4 + */ +void +clutter_actor_add_constraint_with_name (ClutterActor *self, + const gchar *name, + ClutterConstraint *constraint) +{ + g_return_if_fail (CLUTTER_IS_ACTOR (self)); + g_return_if_fail (name != NULL); + g_return_if_fail (CLUTTER_IS_CONSTRAINT (constraint)); + + clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), name); + clutter_actor_add_constraint (self, constraint); +} + /** * clutter_actor_remove_constraint: * @self: a #ClutterActor @@ -10623,6 +10746,38 @@ clutter_actor_remove_constraint (ClutterActor *self, g_object_notify (G_OBJECT (self), "constraints"); } +/** + * clutter_actor_remove_constraint_by_name: + * @self: a #ClutterActor + * @name: the name of the constraint to remove + * + * Removes the #ClutterConstraint with the given name from the list + * of constraints applied to @self + * + * Since: 1.4 + */ +void +clutter_actor_remove_constraint_by_name (ClutterActor *self, + const gchar *name) +{ + ClutterActorPrivate *priv; + ClutterActorMeta *meta; + + g_return_if_fail (CLUTTER_IS_ACTOR (self)); + g_return_if_fail (name != NULL); + + priv = self->priv; + + if (priv->constraints == NULL) + return; + + meta = _clutter_meta_group_get_meta (priv->constraints, name); + if (meta == NULL) + return; + + _clutter_meta_group_remove_meta (priv->constraints, meta); +} + /** * clutter_actor_get_constraints: * @self: a #ClutterActor @@ -10651,6 +10806,33 @@ clutter_actor_get_constraints (ClutterActor *self) return g_list_copy ((GList *) constraints); } +/** + * clutter_actor_get_constraint: + * @self: a #ClutterActor + * @name: the name of the constraint to retrieve + * + * Retrieves the #ClutterConstraint with the given name in the list + * of constraints applied to @self + * + * Return value: (transfer none): a #ClutterConstraint for the given + * name, or %NULL. The returned #ClutterConstraint is owned by the + * actor and it should not be unreferenced directly + * + * Since: 1.4 + */ +ClutterConstraint * +clutter_actor_get_constraint (ClutterActor *self, + const gchar *name) +{ + g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL); + g_return_val_if_fail (name != NULL, NULL); + + if (self->priv->constraints == NULL) + return NULL; + + return CLUTTER_CONSTRAINT (_clutter_meta_group_get_meta (self->priv->constraints, name)); +} + /** * clutter_actor_clear_constraints: * @self: a #ClutterActor diff --git a/clutter/clutter-constraint.h b/clutter/clutter-constraint.h index 03c664c06..948670585 100644 --- a/clutter/clutter-constraint.h +++ b/clutter/clutter-constraint.h @@ -83,12 +83,19 @@ struct _ClutterConstraintClass GType clutter_constraint_get_type (void) G_GNUC_CONST; /* ClutterActor API */ -void clutter_actor_add_constraint (ClutterActor *self, - ClutterConstraint *constraint); -void clutter_actor_remove_constraint (ClutterActor *self, - ClutterConstraint *constraint); -GList *clutter_actor_get_constraints (ClutterActor *self); -void clutter_actor_clear_constraints (ClutterActor *self); +void clutter_actor_add_constraint (ClutterActor *self, + ClutterConstraint *constraint); +void clutter_actor_add_constraint_with_name (ClutterActor *self, + const gchar *name, + ClutterConstraint *constraint); +void clutter_actor_remove_constraint (ClutterActor *self, + ClutterConstraint *constraint); +void clutter_actor_remove_constraint_by_name (ClutterActor *self, + const gchar *name); +GList * clutter_actor_get_constraints (ClutterActor *self); +ClutterConstraint *clutter_actor_get_constraint (ClutterActor *self, + const gchar *name); +void clutter_actor_clear_constraints (ClutterActor *self); G_END_DECLS diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 318e9e7ff..ae870b997 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -410,12 +410,18 @@ clutter_actor_has_pointer clutter_actor_add_action +clutter_actor_add_action_with_name clutter_actor_remove_action +clutter_actor_remove_action_by_name clutter_actor_get_actions +clutter_actor_get_action clutter_actor_clear_actions clutter_actor_add_constraint +clutter_actor_add_constraint_with_name clutter_actor_remove_constraint +clutter_actor_remove_constraint_by_name clutter_actor_get_constraints +clutter_actor_get_constraint clutter_actor_clear_constraints diff --git a/tests/interactive/test-constraints.c b/tests/interactive/test-constraints.c index 0f57ff21f..9efb55dab 100644 --- a/tests/interactive/test-constraints.c +++ b/tests/interactive/test-constraints.c @@ -137,12 +137,10 @@ test_constraints_main (int argc, char *argv[]) clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5); - clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "x-align"); - clutter_actor_add_constraint (rect, constraint); + clutter_actor_add_constraint_with_name (rect, "x-align", constraint); constraint = clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5); - clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-align"); - clutter_actor_add_constraint (rect, constraint); + clutter_actor_add_constraint_with_name (rect, "y-align", constraint); rects[Center] = rect; @@ -159,12 +157,10 @@ test_constraints_main (int argc, char *argv[]) clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect); constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_X, 0.0); - clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "x-bind"); - clutter_actor_add_constraint (rect, constraint); + clutter_actor_add_constraint_with_name (rect, "x-bind", constraint); constraint = clutter_bind_constraint_new (rects[Center], CLUTTER_BIND_Y, 0.0); - clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "y-bind"); - clutter_actor_add_constraint (rect, constraint); + clutter_actor_add_constraint_with_name (rect, "y-bind", constraint); rects[i] = rect; }