Ok, to tackle this problem I wrote a new behaviour class to change the
allocation from one actorbox to another.  If it works, I think it will work
out for me.  However, I am having some trouble starting the timeline to do
so.  The source code is here (also attached):

Function which creates and executes a timeline: http://pastie.org/883636
The behaviour class: http://pastie.org/883619
valac generated C code: http://pastie.org/883629

The problem is that the timeline is created and everything, and the started
signal is fired too, but beyond that neither do I get the new-frame signal
nor is my behaviour::alpha_notify called.  The completed signal is not
called too.

I wonder what's going on.  Any ideas?

Thanks,
Uday

On Tue, Mar 23, 2010 at 2:00 PM, Uday Verma <[email protected]> wrote:

> Hello all,
>
> I am trying to animate a sub-actor inside a ClutterActor but I can't seem
> to be able to do so.
>
> I have an actor A which contains several Bs, A is not a container but a
> regular actor.  I have a add method which adds B to A, and in the process
> does B.set_parent (A).
>
> 1.  When I do so, right after the parenting operation I set the position
> and dimensions of B.  The position and dimension requests are not being
> regarded and according to --clutter-flags=paint, the allocation of actor B
> is {0,0,0,0}.  I wonder why that is when I am explicitly setting the size
> and position.  The only way I could get the actor B to appear was by
> explicitly setting the allocation of actor B to the desired location.
>
> 2.  Then, in one of the other methods I try to animate the "x" property,
> but it doesn't do anything, the actor stays where it was set by the
> allocation,  the reason for which I couldn't understand either.
>
> Is there anything I am missing?  How can I go about creating composite
> actors where sub-actors can move around etc.?
>
> Thanks,
> Uday
>
>
/*
***************************************************
The code that calls the timeline functions
***************************************************
*/
private void place_actors () 
{
  /* determine final allocation boxes for each of the 
     child actors and then animate them in */

  float pos_x = template.previews_box.x1;
  float height = template.previews_box.get_height ();
  float width = Math.floorf (16.0f * height / 9.0f);

  debug ("creating timeline");
  var timeline = new Clutter.Timeline (5000);
  var alpha = new Clutter.Alpha.full (timeline, 
				      Clutter.AnimationMode.EASE_IN_OUT_QUAD);

  debug ("Going through children and placing them..");

  foreach (var a in children.values) {
    /* get allocation for this actor */
    Clutter.ActorBox start;

    a.get_allocation_box (out start);

    Clutter.ActorBox end = { template.previews_box.x1 + pos_x,
			     template.previews_box.y1,
			     template.previews_box.x1 + width,
			     template.previews_box.y2 };

    /* create a new behaviour and add it to our
       timeline */
    var beh_alloc = new BehaviourAllocation (alpha,
					     start, end);
    var beh_opacity = new Clutter.BehaviourOpacity (alpha,
						    a.opacity,
						    255);
				
    beh_alloc.apply (a);
    beh_opacity.apply (a);

    debug ("Behaviors applied");

    pos_x += width + 10.0f;
  }

  timeline.started.connect (() => {
      debug ("timeline started!");
    });

  timeline.paused.connect (() => {
      debug ("timeline paused!!!!");
    });

  timeline.completed.connect (() => {
      debug ("timeline finished!");
    });

  timeline.new_frame.connect ((n) => {
      debug ("frame: %d", n);
    });

  timeline.start ();
  debug ("timeline started");
}

/*
***************************************************
Behaviour Class
***************************************************
*/
/* BehaviourAllocation.vala
   A behaviour class which changes allocation 
   from one state to another on an actor */

namespace Ui {
  class BehaviourAllocation : Clutter.Behaviour {
    Clutter.ActorBox start_alloc;
    Clutter.ActorBox end_alloc;

    public BehaviourAllocation (Clutter.Alpha alpha,
                  Clutter.ActorBox start,
                  Clutter.ActorBox end)
    {
      Object ();

      this.alpha = alpha;

      start_alloc = start;
      end_alloc = end;
    }

    public override void alpha_notify (double av) {
      float alpha_value = (float) av;

      debug ("notify");

      Clutter.ActorBox this_state = {
        start_alloc.x1 + (end_alloc.x1 - start_alloc.x1) * alpha_value,
        start_alloc.y1 + (end_alloc.y1 - start_alloc.y1) * alpha_value,
        start_alloc.x2 + (end_alloc.x2 - start_alloc.x2) * alpha_value,
        start_alloc.y2 + (end_alloc.y2 - start_alloc.y2) * alpha_value
      };

      this.actors_foreach ((b, a) => {
          a.allocate (this_state,
                Clutter.AllocationFlags.ALLOCATION_NONE);
        });
    }
  }
}

/*
***************************************************
valac -C BehaviourAllocation.vala
**************************************************
*/
static void txvc_presenter_place_actors (TxvcPresenter* self) {
	ClutterActorBox _tmp0_ = {0};
	float pos_x;
	ClutterActorBox _tmp2_;
	ClutterActorBox _tmp1_ = {0};
	float height;
	float width;
	ClutterTimeline* timeline;
	ClutterAlpha* alpha;
	g_return_if_fail (self != NULL);
	pos_x = (txvc_template_get_previews_box (self->priv->template, &_tmp0_), _tmp0_).x1;
	height = clutter_actor_box_get_height ((_tmp2_ = (txvc_template_get_previews_box (self->priv->template, &_tmp1_), _tmp1_), &_tmp2_));
	width = floorf ((16.0f * height) / 9.0f);
	g_debug ("Presenter.vala:245: creating timeline");
	timeline = clutter_timeline_new ((guint) 5000);
	alpha = g_object_ref_sink (clutter_alpha_new_full (timeline, (gulong) CLUTTER_EASE_IN_OUT_QUAD));
	g_debug ("Presenter.vala:250: Going to children and placing them..");
	{
		GeeCollection* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _a_it;
		_a_it = (_tmp4_ = gee_iterable_iterator ((GeeIterable*) (_tmp3_ = gee_map_get_values ((GeeMap*) self->priv->children))), _g_object_unref0 (_tmp3_), _tmp4_);
		while (TRUE) {
			ClutterActor* a;
			ClutterActorBox start = {0};
			ClutterActorBox _tmp5_ = {0};
			ClutterActorBox _tmp6_ = {0};
			ClutterActorBox _tmp7_ = {0};
			ClutterActorBox _tmp8_ = {0};
			ClutterActorBox _tmp9_ = {0};
			ClutterActorBox end;
			UiBehaviourAllocation* beh_alloc;
			ClutterBehaviourOpacity* beh_opacity;
			if (!gee_iterator_next (_a_it)) {
				break;
			}
			a = (ClutterActor*) gee_iterator_get (_a_it);
			clutter_actor_get_allocation_box (a, &start);
			end = (_tmp9_.x1 = (txvc_template_get_previews_box (self->priv->template, &_tmp5_), _tmp5_).x1 + pos_x, _tmp9_.y1 = (txvc_template_get_previews_box (self->priv->template, &_tmp6_), _tmp6_).y1, _tmp9_.x2 = (txvc_template_get_previews_box (self->priv->template, &_tmp7_), _tmp7_).x1 + width, _tmp9_.y2 = (txvc_template_get_previews_box (self->priv->template, &_tmp8_), _tmp8_).y2, _tmp9_);
			beh_alloc = ui_behaviour_allocation_new (alpha, &start, &end);
			beh_opacity = (ClutterBehaviourOpacity*) clutter_behaviour_opacity_new (alpha, clutter_actor_get_opacity (a), (guchar) 255);
			clutter_behaviour_apply ((ClutterBehaviour*) beh_alloc, a);
			clutter_behaviour_apply ((ClutterBehaviour*) beh_opacity, a);
			g_debug ("Presenter.vala:274: Behaviors applied");
			pos_x = pos_x + (width + 10.0f);
			_g_object_unref0 (a);
			_g_object_unref0 (beh_alloc);
			_g_object_unref0 (beh_opacity);
		}
		_g_object_unref0 (_a_it);
	}
	g_signal_connect_object (timeline, "started", (GCallback) __lambda4__clutter_timeline_started, self, 0);
	g_signal_connect_object (timeline, "paused", (GCallback) __lambda5__clutter_timeline_paused, self, 0);
	g_signal_connect_object (timeline, "completed", (GCallback) __lambda6__clutter_timeline_completed, self, 0);
	g_signal_connect_object (timeline, "new-frame", (GCallback) __lambda7__clutter_timeline_new_frame, self, 0);
	clutter_timeline_start (timeline);
	g_debug ("Presenter.vala:296: timeline started");
	_g_object_unref0 (timeline);
	_g_object_unref0 (alpha);
}

Reply via email to