From eb35c446b119274658ba45937e02b5cfd1ec27fe Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 23 Feb 2010 22:06:59 +0000 Subject: [PATCH] clutter-box: Layer new actors on top of all others at the same depth g_list_insert_sorted inserts the new actor before all others that compare equal so for the normal case when all actors have depth==0 this has the surprising behaviour of layering the actors in reverse order. To fix this it now manually inserts the actor in the right place by searching until it finds an actor at a higher depth and inserting before that. http://bugzilla.openedhand.com/show_bug.cgi?id=1988 --- clutter/clutter-box.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/clutter/clutter-box.c b/clutter/clutter-box.c index 2667adbe7..187d21224 100644 --- a/clutter/clutter-box.c +++ b/clutter/clutter-box.c @@ -130,12 +130,31 @@ clutter_box_real_add (ClutterContainer *container, ClutterActor *actor) { ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv; + GList *l, *prev = NULL; + gfloat actor_depth; g_object_ref (actor); - priv->children = g_list_insert_sorted (priv->children, - actor, - sort_by_depth); + actor_depth = clutter_actor_get_depth (actor); + + /* Find the right place to insert the child so that it will still be + sorted and the child will be after all of the actors at the same + depth */ + for (l = priv->children; + l && (clutter_actor_get_depth (l->data) <= actor_depth); + l = l->next) + prev = l; + + /* Insert the node before the found node */ + l = g_list_prepend (l, actor); + /* Fixup the links */ + if (prev) + { + prev->next = l; + l->prev = prev; + } + else + priv->children = l; clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));