Hi,

On Wed, 13 Feb 2008, Havoc Pennington wrote:

So you can use the scale factor much as a "transient allocation".
However, there's no equivalent for setting position - there isn't a
separate translate() from set_position() as there's a separate scale()
from set_size().

Isn't this clutter_actor_set_anchor_point()? See e.g. the attachment.
#include <clutter/clutter.h>

#define SCALE_BEGIN 0.6
#define SCALE_END   1.4

static const ClutterColor black_color  = { 0x00, 0x00, 0x00, 0xff };
static const ClutterColor white_color  = { 0xff, 0xff, 0xff, 0xff };

typedef struct _App App;

struct _App
{
  ClutterTimeline *timeline;
  ClutterEffectTemplate *effect;
  gboolean is_effect_grow;
};

static gboolean
stage_key_release_cb (ClutterStage *stage,
		      ClutterEvent *event,
		      gpointer      data)
{
  if (clutter_event_get_source (event) != clutter_stage_get_default ())
    return;

  switch (event->type)
    {
    case CLUTTER_KEY_RELEASE:
      switch (clutter_key_event_symbol ((ClutterKeyEvent *)event))
	{
	case CLUTTER_Escape:
	case CLUTTER_Q:
	case CLUTTER_q:
	  clutter_main_quit ();
	  break;
	}
      break;
    }
  return TRUE;
}

static void
install_effect (ClutterActor *actor, App *app)
{
  app->effect = clutter_effect_template_new (app->timeline, CLUTTER_ALPHA_RAMP_INC);
  if (app->is_effect_grow)
    {
      app->is_effect_grow = FALSE;
      clutter_effect_scale (app->effect, actor,
			    SCALE_BEGIN, SCALE_BEGIN,
			    (ClutterEffectCompleteFunc)install_effect, app);
    }
  else
    {
      app->is_effect_grow = TRUE;
      clutter_effect_scale (app->effect, actor,
			    SCALE_END, SCALE_END,
			    (ClutterEffectCompleteFunc)install_effect, app);
    }
}

int
main (int argc, char *argv[])
{
  App          *app;
  ClutterActor *stage;
  ClutterActor *rect;
  guint sw = 640, sh = 480;
  guint rw = 320, rh = 200;
  guint w, h;

  clutter_init (&argc, &argv);

  app = g_new0 (App, 1);
  app->timeline = clutter_timeline_new_for_duration (3000);

  stage = clutter_stage_get_default ();
  clutter_stage_set_color (CLUTTER_STAGE (stage), &black_color);
  clutter_actor_set_size (stage, sw, sh);

  g_signal_connect (stage, "key-release-event",
		    G_CALLBACK (stage_key_release_cb), NULL);

  rect = clutter_rectangle_new_with_color (&white_color);
  clutter_actor_set_size (rect, rw, rh);
  clutter_actor_set_position (rect, sw / 2, sh / 2);
  clutter_actor_set_anchor_point (rect, rw / 2, rh / 2);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
  clutter_actor_show (rect);

  install_effect (rect, app);

  clutter_actor_show (stage);
  clutter_main ();
  return 0;
}

Reply via email to