示例#1
0
static VALUE
rbclt_script_connect_signals (int argc, VALUE *argv, VALUE self)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  AutoConnectData data;

  data.state = 0;

  if (rb_block_given_p ())
    {
      data.args = rb_ary_new4 (argc, argv);
      data.proc = rb_block_proc ();
      data.obj = Qnil;
    }
  else
    {
      rb_scan_args (argc, argv, "1*", &data.obj, &data.args);
      data.proc = Qnil;
    }

  clutter_script_connect_signals_full (script,
                                       rbclt_script_connect_signal,
                                       &data);

  /* If an exception was thrown then continue throwing that now that
     we are safely out of the Clutter function call */
  if (data.state)
    rb_jump_tag (data.state);

  return self;
}
示例#2
0
static VALUE
rbclt_script_get_object (int argc, VALUE *argv, VALUE self)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  GObject *object;

  if (argc == 1)
    {
      object = clutter_script_get_object (script, StringValuePtr (argv[0]));
      return GOBJ2RVAL (object);
    }
  else if (argc > 1)
    {
      VALUE ary = rb_ary_new ();
      int i;

      for (i = 0; i < argc; i++)
        {
          object = clutter_script_get_object (script, StringValuePtr (argv[i]));
          rb_ary_push (ary, GOBJ2RVAL (object));
        }

      return ary;
    }
  else
    {
      rb_raise (rb_eArgError, "wrong number of arguments "
                "(at least one required)");

      return Qnil;
    }
}
示例#3
0
static VALUE
rbclt_script_ensure_objects (VALUE self)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));

  clutter_script_ensure_objects (script);

  return self;
}
示例#4
0
static VALUE
rbclt_script_unmerge_objects (VALUE self, VALUE merge_id)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));

  clutter_script_unmerge_objects (script, NUM2UINT (merge_id));

  return self;
}
示例#5
0
static VALUE
rbclt_script_get_type_from_name (VALUE self, VALUE name)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  GType type;

  type = clutter_script_get_type_from_name (script, StringValuePtr (name));

  return type == G_TYPE_INVALID ? Qnil : GTYPE2CLASS (type);
}
示例#6
0
gboolean
foo_button_pressed_cb (ClutterActor *actor,
                       ClutterEvent *event,
                       gpointer      user_data)
{
  ClutterScript *ui = CLUTTER_SCRIPT (user_data);
  ClutterStage *stage = CLUTTER_STAGE (clutter_script_get_object (ui, "stage"));

  ClutterScript *script;
  ClutterActor *rig;
  ClutterAnimator *animator;

  /* load the rig and its animator from a JSON file */
  script = clutter_script_new ();

  /* use a function defined statically in this source file to load the JSON */
  load_script_from_file (script, ANIMATION_FILE);

  clutter_script_get_objects (script,
                              "rig", &rig,
                              "animator", &animator,
                              NULL);

  /* remove the button press handler from the rectangle */
  g_signal_handlers_disconnect_matched (actor,
                                        G_SIGNAL_MATCH_FUNC,
                                        0,
                                        0,
                                        NULL,
                                        foo_button_pressed_cb,
                                        NULL);

  /* add a callback to clean up the script when the rig is destroyed */
  g_object_set_data_full (G_OBJECT (rig), "script", script, g_object_unref);

  /* add the rig to the stage */
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rig);

  /* place the rig at the same coordinates on the stage as the rectangle */
  clutter_actor_set_position (rig,
                              clutter_actor_get_x (actor),
                              clutter_actor_get_y (actor));

  /* put the rectangle into the top-left corner of the rig */
  clutter_actor_reparent (actor, rig);

  clutter_actor_set_position (actor, 0, 0);

  /* animate the rig */
  clutter_animator_start (animator);

  return TRUE;
}
示例#7
0
static VALUE
rbclt_script_load_from_file (VALUE self, VALUE filename)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  guint merge_id;
  GError *error = NULL;

  merge_id = clutter_script_load_from_file (script,
                                            StringValuePtr (filename),
                                            &error);

  if (error)
    RAISE_GERROR (error);

  return UINT2NUM (merge_id);
}
示例#8
0
/*
 * start the animation when a key is pressed;
 * see the signals recipe in the Script chapter for more details
 */
gboolean
foo_key_pressed_cb (ClutterActor *actor,
                    ClutterEvent *event,
                    gpointer      user_data)
{
  ClutterScript *script = CLUTTER_SCRIPT (user_data);

  ClutterAnimator *animator;
  clutter_script_get_objects (script,
                              "animator", &animator,
                              NULL);

  if (clutter_timeline_is_playing (clutter_animator_get_timeline (animator)))
    return FALSE;

  clutter_animator_start (animator);

  return TRUE;
}
示例#9
0
static VALUE
rbclt_script_load_from_data (VALUE self, VALUE data)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  guint merge_id;
  GError *error = NULL;

  StringValuePtr (data);

  merge_id = clutter_script_load_from_data (script,
                                            RSTRING (data)->ptr,
                                            RSTRING (data)->len,
                                            &error);

  if (error)
    RAISE_GERROR (error);

  return UINT2NUM (merge_id);
}
示例#10
0
static VALUE
rbclt_script_lookup_filename (VALUE self, VALUE filename)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  gchar *full_path;
  VALUE ret;

  full_path = clutter_script_lookup_filename (script,
                                              StringValuePtr (filename));

  if (full_path == NULL)
    ret = Qnil;
  else
    {
      ret = rb_str_new2 (full_path);
      g_free (full_path);
    }

  return ret;
}
示例#11
0
static VALUE
rbclt_script_add_search_paths (int argc, VALUE *argv, VALUE self)
{
  ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self));
  int i;
  const gchar **paths;

  /* Make sure all of the arguments are strings before allocating the
     array */
  for (i = 0; i < argc; i++)
    StringValuePtr (argv[i]);

  paths = g_malloc (sizeof (const gchar *) * argc);

  for (i = 0; i < argc; i++)
    paths[i] = StringValuePtr (argv[i]);

  clutter_script_add_search_paths (script, paths, argc);

  g_free (paths);

  return self;
}