예제 #1
0
/* Setup the video texture once its size is known */
void size_change (ClutterActor *texture, gint width, gint height, gpointer user_data) {
    ClutterActor *stage;
    gfloat new_x, new_y, new_width, new_height;
    gfloat stage_width, stage_height;
    ClutterAnimation *animation = NULL;

    stage = clutter_actor_get_stage (texture);
    if (stage == NULL)
        return;

    clutter_actor_get_size (stage, &stage_width, &stage_height);

    /* Center video on window and calculate new size preserving aspect ratio */
    new_height = (height * stage_width) / width;
    if (new_height <= stage_height) {
        new_width = stage_width;

        new_x = 0;
        new_y = (stage_height - new_height) / 2;
    } else {
        new_width  = (width * stage_height) / height;
        new_height = stage_height;

        new_x = (stage_width - new_width) / 2;
        new_y = 0;
    }
    clutter_actor_set_position (texture, new_x, new_y);
    clutter_actor_set_size (texture, new_width, new_height);
    clutter_actor_set_rotation (texture, CLUTTER_Y_AXIS, 0.0, stage_width / 2, 0, 0);
    /* Animate it */
    animation = clutter_actor_animate (texture, CLUTTER_LINEAR, 10000, "rotation-angle-y", 360.0, NULL);
    clutter_animation_set_loop (animation, TRUE);
}
예제 #2
0
파일: test-fbo.c 프로젝트: nobled/clutter
G_MODULE_EXPORT int
test_fbo_main (int argc, char *argv[])
{
  ClutterColor      blue   = {0x33, 0x44, 0x55, 0xff};

  ClutterActor     *fbo;
  ClutterActor     *onscreen_source;
  ClutterActor     *stage;
  ClutterAnimation *animation;
  int               x_pos = 200;
  int               y_pos = 100;

  clutter_init (&argc, &argv);

  if (clutter_feature_available (CLUTTER_FEATURE_OFFSCREEN) == FALSE)
    g_error("This test requires CLUTTER_FEATURE_OFFSCREEN");

  stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &blue);

  /* Create the first source */
  onscreen_source = make_source();
  clutter_actor_show_all (onscreen_source);
  clutter_group_add (stage, onscreen_source);

  y_pos = (STAGE_HEIGHT/2.0) -
          (clutter_actor_get_height (onscreen_source)/2.0);
  clutter_actor_set_position (onscreen_source, x_pos, y_pos);
  x_pos += clutter_actor_get_width (onscreen_source);

  animation = clutter_actor_animate (onscreen_source,
                                     CLUTTER_LINEAR,
                                     5000, /* 1 second duration */
                                     "rotation-angle-y", 360.0f,
                                     NULL);
  clutter_animation_set_loop (animation, TRUE);

  /* Second hand = actor from onscreen_source */
  if ((fbo = clutter_texture_new_from_actor (onscreen_source)) == NULL)
    g_error("onscreen fbo creation failed");

  clutter_actor_set_position (fbo, x_pos, y_pos);
  x_pos += clutter_actor_get_width (fbo);
  clutter_group_add (stage, fbo);

  /* Third hand = actor from Second hand */
  if ((fbo = clutter_texture_new_from_actor (fbo)) == NULL)
    g_error("fbo from fbo creation failed");

  clutter_actor_set_position (fbo, x_pos, y_pos);
  x_pos += clutter_actor_get_width (fbo);
  clutter_group_add (stage, fbo);

  clutter_actor_show_all (stage);
  clutter_main ();

  return 0;
}
예제 #3
0
파일: lights.c 프로젝트: eliasbakken/mash
int
main (int argc, char **argv)
{
  ClutterActor *stage = stage;
  ClutterActor *side_box;
  ClutterActor *button_box;
  ClutterActor *box;
  ClutterAnimation *anim;
  MashLightSet *light_set;
  MxStyle *style;
  GError *error = NULL;
  Data data;
  int i;

  if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
    return 1;

  style = mx_style_get_default ();
  if (!mx_style_load_from_file (style, "lights.css",
                                &error))
    {
      g_warning ("Error setting style: %s", error->message);
      g_clear_error (&error);
    }

  stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 800, 600);

  side_box = mx_table_new ();
  clutter_actor_set_name (side_box, "side-box");
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), side_box);
  clutter_actor_set_size (side_box, 300,
                          clutter_actor_get_height (stage));
  clutter_actor_set_x (side_box,
                       clutter_actor_get_width (stage)
                       - clutter_actor_get_width (side_box));

  button_box = mx_table_new ();
  mx_table_add_actor (MX_TABLE (side_box), button_box, 0, 0);

  data.notebook = mx_notebook_new ();

  mx_table_add_actor (MX_TABLE (side_box), data.notebook, 1, 0);

  data.model = mash_model_new_from_file (MASH_DATA_NONE,
                                         argc > 1
                                         ? argv[1]
                                         : "suzanne.ply",
                                         &error);
  if (data.model == NULL)
    {
      g_warning ("Error loading model: %s", error->message);
      g_clear_error (&error);
      return 1;
    }

  light_set = mash_light_set_new ();

  box = clutter_box_new (clutter_fixed_layout_new ());

  clutter_actor_set_size (data.model, 400, 400);
  clutter_actor_set_position (data.model, 50.0, 100.0);
  clutter_container_add_actor (CLUTTER_CONTAINER (box), data.model);

  clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);

  g_signal_connect_swapped (box, "paint",
                            G_CALLBACK (cogl_set_depth_test_enabled),
                            GINT_TO_POINTER (TRUE));
  g_signal_connect_data (box, "paint",
                         G_CALLBACK (cogl_set_depth_test_enabled),
                         GINT_TO_POINTER (FALSE), NULL,
                         G_CONNECT_AFTER | G_CONNECT_SWAPPED);

  data.light_marker_material = cogl_material_new ();
  {
    CoglColor color;
    cogl_color_set_from_4ub (&color, 255, 0, 0, 255);
    /* Use the layer state to ignore the vertex color from the shader so
       that the light marker won't itself be lit */
    cogl_material_set_layer_combine_constant (data.light_marker_material, 0,
                                              &color);
    cogl_material_set_layer_combine (data.light_marker_material, 0,
                                     "RGBA = REPLACE(CONSTANT)",
                                     NULL);
  }

  clutter_actor_set_rotation (data.model, CLUTTER_Y_AXIS,
                              0.0f,
                              clutter_actor_get_width (data.model) / 2.0f,
                              0.0f,
                              0.0f);

  anim = clutter_actor_animate (data.model, CLUTTER_LINEAR, 3000,
                                "rotation-angle-y", 360.0f,
                                NULL);
  clutter_animation_set_loop (anim, TRUE);

  for (i = 0; i < N_LIGHTS; i++)
    {
      ClutterActor *table = mx_table_new ();
      ClutterActor *button;
      static ClutterActor *(* constructors[N_LIGHTS]) (void) =
        { mash_directional_light_new,
          mash_point_light_new,
          mash_spot_light_new };
      static const ClutterColor black = { 0, 0, 0, 255 };

      data.lights[i] = constructors[i] ();

      button = mx_button_new_with_label (G_OBJECT_TYPE_NAME (data.lights[i]));
      mx_table_add_actor (MX_TABLE (button_box), button, i, 0);

      /* Default to disable all of the lights */
      g_object_set (data.lights[i],
                    "ambient", &black,
                    "diffuse", &black,
                    "specular", &black,
                    NULL);

      data.notebook_buttons[i] = button;

      clutter_container_add_actor (CLUTTER_CONTAINER (box), data.lights[i]);
      mash_light_set_add_light (light_set, MASH_LIGHT (data.lights[i]));

      add_color_prop (table, "ambient light",
                      G_OBJECT (data.lights[i]), "ambient");
      add_color_prop (table, "diffuse light",
                      G_OBJECT (data.lights[i]), "diffuse");
      add_color_prop (table, "specular light",
                      G_OBJECT (data.lights[i]), "specular");

      if (MASH_IS_POINT_LIGHT (data.lights[i]))
        {
          add_float_prop (table, "constant attenuation",
                          G_OBJECT (data.lights[i]), "constant-attenuation",
                          0.0f, 10.0f);
          add_float_prop (table, "linear attenuation",
                          G_OBJECT (data.lights[i]), "linear-attenuation",
                          0.0f, 10.0f);
          add_float_prop (table, "quadratic attenuation",
                          G_OBJECT (data.lights[i]), "quadratic-attenuation",
                          0.0f, 10.0f);
        }

      if (MASH_IS_SPOT_LIGHT (data.lights[i]))
        {
          clutter_actor_set_x (data.lights[i], 250);

          add_float_prop (table, "spot cutoff",
                          G_OBJECT (data.lights[i]), "spot-cutoff",
                          0.0f, 90.0f);
          add_float_prop (table, "spot exponent",
                          G_OBJECT (data.lights[i]), "spot-exponent",
                          0.0f, 128.0f);
        }

      clutter_container_add_actor (CLUTTER_CONTAINER (data.notebook), table);

      data.notebook_pages[i] = table;
    }

  {
    ClutterActor *button;
    ClutterActor *table;
    CoglHandle material;
    float maximum_shininess;

    material = mash_model_get_pipeline (MASH_MODEL (data.model));

    /* Before version 1.3.10 on the 1.3 branch and 1.2.14 on the 1.2
       branch Cogl would remap the shininess property to the range
       [0,1]. After this it is just a value greater or equal to zero
       (but GL imposes a limit of 128.0) */
    if (clutter_check_version (1, 3, 9)
        || (clutter_major_version == 1
            && clutter_minor_version == 2
            && clutter_micro_version >= 13))
      maximum_shininess = 128.0f;
    else
      maximum_shininess = 1.0f;

    cogl_material_set_shininess (material, maximum_shininess);

    button = mx_button_new_with_label ("Material");
    data.notebook_buttons[i] = button;
    mx_table_add_actor (MX_TABLE (button_box), button, i, 0);
    table = mx_table_new ();
    data.notebook_pages[i] = table;
    clutter_container_add_actor (CLUTTER_CONTAINER (data.notebook), table);

    add_material_color_prop (table, "emission", material,
                             cogl_material_set_emission,
                             cogl_material_get_emission);
    add_material_color_prop (table, "diffuse", material,
                             cogl_material_set_diffuse,
                             cogl_material_get_diffuse);
    add_material_color_prop (table, "ambient", material,
                             cogl_material_set_ambient,
                             cogl_material_get_ambient);
    add_material_color_prop (table, "specular", material,
                             cogl_material_set_specular,
                             cogl_material_get_specular);
    add_material_float_prop (table, "shininess", material,
                             0.0f, maximum_shininess,
                             cogl_material_set_shininess,
                             cogl_material_get_shininess);
  }

  mash_model_set_light_set (MASH_MODEL (data.model), light_set);
  g_object_unref (light_set);

  for (i = 0; i < N_PAGES; i++)
    {
      g_signal_connect (data.notebook_buttons[i], "notify::toggled",
                        G_CALLBACK (notebook_button_cb), &data);
      mx_button_set_is_toggle (MX_BUTTON (data.notebook_buttons[i]), TRUE);
    }

  mx_button_set_toggled (MX_BUTTON (data.notebook_buttons[0]), TRUE);

  g_signal_connect (stage, "motion-event",
                    G_CALLBACK (motion_event_cb),
                    &data);

  clutter_actor_show (stage);

  clutter_main ();

  cogl_handle_unref (data.light_marker_material);

  return 0;
}