예제 #1
0
파일: test-drag.c 프로젝트: nobled/clutter
G_MODULE_EXPORT int
test_drag_main (int argc, char *argv[])
{
  ClutterActor *stage, *handle;
  ClutterAction *action;
  GError *error;

  error = NULL;
  clutter_init_with_args (&argc, &argv,
                          "test-drag",
                          entries,
                          NULL,
                          &error);
  if (error != NULL)
    {
      g_print ("Unable to run test-drag: %s\n", error->message);
      g_error_free (error);

      return EXIT_FAILURE;
    }

  stage = clutter_stage_new ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Drag Test");
  clutter_actor_set_size (stage, 800, 600);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  handle = clutter_rectangle_new ();
  clutter_rectangle_set_color (CLUTTER_RECTANGLE (handle),
                               CLUTTER_COLOR_SkyBlue);
  clutter_actor_set_size (handle, 128, 128);
  clutter_actor_set_position (handle, (800 - 128) / 2, (600 - 128) / 2);
  clutter_actor_set_reactive (handle, TRUE);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), handle);
  g_signal_connect (handle, "enter-event", G_CALLBACK (on_enter), NULL);
  g_signal_connect (handle, "leave-event", G_CALLBACK (on_leave), NULL);

  action = clutter_drag_action_new ();
  clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action),
                                          x_drag_threshold,
                                          y_drag_threshold);
  clutter_drag_action_set_drag_axis (CLUTTER_DRAG_ACTION (action),
                                     get_drag_axis (drag_axis));

  g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL);
  g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL);

  clutter_actor_add_action (handle, action);

  clutter_actor_add_effect_with_name (handle, "disable", clutter_desaturate_effect_new (0.0));
  clutter_actor_add_effect_with_name (handle, "curl", clutter_page_turn_effect_new (0.0, 45.0, 12.0));

  clutter_actor_show (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}
예제 #2
0
G_MODULE_EXPORT int
test_easing_main (int argc, char *argv[])
{
  ClutterActor *stage, *rect, *label;
  ClutterColor stage_color = { 0x88, 0x88, 0xdd, 0xff };
  ClutterColor rect_color = { 0xee, 0x33, 0, 0xff };
  gchar *text;
  gfloat stage_width, stage_height;
  gfloat label_width, label_height;

  clutter_init_with_args (&argc, &argv,
                          NULL,
                          test_easing_entries,
                          NULL,
                          NULL);

  stage = clutter_stage_get_default ();
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  main_stage = stage;

  clutter_actor_get_size (stage, &stage_width, &stage_height);

  rect = make_bouncer (&rect_color, 50, 50);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
  clutter_actor_set_position (rect, stage_width / 2, stage_height / 2);

  text = g_strdup_printf ("Easing mode: %s (%d of %d)\n"
                          "Right click to change the easing mode",
                          easing_modes[current_mode].name,
                          current_mode + 1,
                          n_easing_modes);

  label = clutter_text_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
  clutter_text_set_font_name (CLUTTER_TEXT (label), "Sans 18px");
  clutter_text_set_text (CLUTTER_TEXT (label), text);
  clutter_actor_get_size (label, &label_width, &label_height);
  clutter_actor_set_position (label,
                              stage_width - label_width - 10,
                              stage_height - label_height - 10);
  easing_mode_label = label;

  g_free (text);

  g_signal_connect (stage,
                    "button-press-event", G_CALLBACK (on_button_press),
                    rect);

  clutter_actor_show (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}
예제 #3
0
int
main (int argc, char *argv[])
{
  TestState state;
  ClutterActor *stage;
  GError *error = NULL;

  g_setenv ("CLUTTER_VBLANK", "none", FALSE);
  g_setenv ("CLUTTER_SHOW_FPS", "1", FALSE);

  if (clutter_init_with_args (&argc, &argv,
                              NULL,
                              entries,
                              NULL,
                              &error) != CLUTTER_INIT_SUCCESS)
    {
      g_warning ("Unable to initialise Clutter:\n%s",
                 error->message);
      g_error_free (error);

      return EXIT_FAILURE;
    }

  state.current_test = 0;

  state.stage = stage = clutter_stage_new ();

  clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
  clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_White);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Performance Test");

  /* We want continuous redrawing of the stage... */
  clutter_threads_add_idle (queue_redraw, stage);

  g_signal_connect_after (stage, "paint", G_CALLBACK (on_paint), &state);

  clutter_actor_show (stage);

  clutter_main ();

  clutter_actor_destroy (stage);

  return 0;
}
예제 #4
0
G_MODULE_EXPORT int
test_paint_wrapper_main (int argc, char *argv[])
{
    ClutterAlpha *alpha;
    ClutterActor *stage;
    ClutterColor  stage_color = { 0x61, 0x64, 0x8c, 0xff };
    SuperOH      *oh;
    gint          i;
    GError       *error;
    ClutterActor *real_hand;

    error = NULL;

#ifdef HAVE_CLUTTER_GLX
    clutter_x11_set_use_argb_visual (TRUE);
#endif

    clutter_init_with_args (&argc, &argv,
                            NULL,
                            super_oh_entries,
                            NULL,
                            &error);
    if (error)
    {
        g_warning ("Unable to initialise Clutter:\n%s",
                   error->message);
        g_error_free (error);

        return EXIT_FAILURE;
    }

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

    if (use_alpha != 255)
    {
        clutter_stage_set_use_alpha (CLUTTER_STAGE (stage), TRUE);
        clutter_actor_set_opacity (stage, use_alpha);
    }

    clutter_stage_set_title (CLUTTER_STAGE (stage), "Paint Test");
    clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

    oh = g_new(SuperOH, 1);
    oh->stage = stage;

    /* Create a timeline to manage animation */
    oh->timeline = clutter_timeline_new (6000);
    clutter_timeline_set_loop (oh->timeline, TRUE);

    /* fire a callback for frame change */
    g_signal_connect (oh->timeline, "new-frame", G_CALLBACK (frame_cb), oh);

    /* Set up some behaviours to handle scaling  */
    alpha = clutter_alpha_new_with_func (oh->timeline, my_sine_wave, NULL, NULL);

    oh->scaler_1 = clutter_behaviour_scale_new (alpha, 0.5, 0.5, 1.0, 1.0);
    oh->scaler_2 = clutter_behaviour_scale_new (alpha, 1.0, 1.0, 0.5, 0.5);

    real_hand = clutter_texture_new_from_file (TESTS_DATADIR
                G_DIR_SEPARATOR_S
                "redhand.png",
                &error);
    if (real_hand == NULL)
    {
        g_error ("image load failed: %s", error->message);
        return EXIT_FAILURE;
    }

    /* create a new group to hold multiple actors in a group */
    oh->group = clutter_group_new();

    oh->hand = g_new (ClutterActor*, n_hands);

    oh->stage_width = clutter_actor_get_width (stage);
    oh->stage_height = clutter_actor_get_height (stage);
    oh->radius = (oh->stage_width + oh->stage_height)
                 / n_hands;

    for (i = 0; i < n_hands; i++)
    {
        gint x, y, w, h;

        if (i == 0)
            oh->hand[i] = real_hand;
        else
            oh->hand[i] = clutter_clone_new (real_hand);

        clutter_actor_set_reactive (oh->hand[i], TRUE);

        clutter_actor_set_size (oh->hand[i], 200, 213);

        /* Place around a circle */
        w = clutter_actor_get_width (oh->hand[i]);
        h = clutter_actor_get_height (oh->hand[i]);

        x = oh->stage_width / 2
            + oh->radius
            * cos (i * G_PI / (n_hands / 2))
            - w / 2;

        y = oh->stage_height / 2
            + oh->radius
            * sin (i * G_PI / (n_hands / 2))
            - h / 2;

        clutter_actor_set_position (oh->hand[i], x, y);

        clutter_actor_move_anchor_point_from_gravity (oh->hand[i],
                CLUTTER_GRAVITY_CENTER);

        g_signal_connect (oh->hand[i], "button-press-event",
                          G_CALLBACK (on_button_press_event),
                          oh);

        /* paint something before each hand */
        g_signal_connect (oh->hand[i],
                          "paint", G_CALLBACK (hand_pre_paint),
                          oh);

        /* paint something after each hand */
        g_signal_connect_after (oh->hand[i],
                                "paint", G_CALLBACK (hand_post_paint),
                                oh);

        /* Add to our group group */
        clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]);

        if (i % 2)
            clutter_behaviour_apply (oh->scaler_1, oh->hand[i]);
        else
            clutter_behaviour_apply (oh->scaler_2, oh->hand[i]);
    }

    oh->paint_guards = g_malloc0 (sizeof (gboolean) * n_hands);

    /* Add the group to the stage */
    clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                 CLUTTER_ACTOR (oh->group));

    /* Show everying ( and map window ) */
    clutter_actor_show (stage);

    g_signal_connect (stage, "key-release-event",
                      G_CALLBACK (input_cb),
                      oh);

    /* and start it */
    clutter_timeline_start (oh->timeline);

    clutter_main ();

    g_object_unref (oh->scaler_1);
    g_object_unref (oh->scaler_2);
    g_object_unref (oh->timeline);
    g_free (oh->paint_guards);
    g_free (oh->hand);
    g_free (oh);

    return 0;
}
예제 #5
0
int
main (int argc, char *argv[])
{
  GError *error = NULL;

  /* UI */
  ClutterActor *stage;
  ClutterLayoutManager *layout;
  ClutterActor *box;
  ClutterActor *top, *bottom;
  ClutterState *transitions;

  clutter_init_with_args (&argc, &argv,
                          " - cross-fade", entries,
                          NULL,
                          NULL);

  if (source == NULL || target == NULL)
    {
      g_print ("Usage: %s -s <source> -t <target> [-d <duration>]\n", argv[0]);
      exit (EXIT_FAILURE);
    }

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_stage_set_title (CLUTTER_STAGE (stage), "cross-fade");
  clutter_actor_set_size (stage, 400, 300);
  clutter_actor_show (stage);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
                                   CLUTTER_BIN_ALIGNMENT_CENTER);

  box = clutter_box_new (layout);
  clutter_actor_set_size (box, 400, 300);

  bottom = clutter_texture_new ();
  top = clutter_texture_new ();

  clutter_container_add_actor (CLUTTER_CONTAINER (box), bottom);
  clutter_container_add_actor (CLUTTER_CONTAINER (box), top);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);

  /* load the first image into the bottom */
  load_image (CLUTTER_TEXTURE (bottom), source);

  /* load the second image into the top */
  load_image (CLUTTER_TEXTURE (top), target);

  /* animations */
  transitions = clutter_state_new ();
  clutter_state_set (transitions, NULL, "show-bottom",
                     top, "opacity", CLUTTER_LINEAR, 0,
                     bottom, "opacity", CLUTTER_LINEAR, 255,
                     NULL);
  clutter_state_set (transitions, NULL, "show-top",
                     top, "opacity", CLUTTER_EASE_IN_CUBIC, 255,
                     bottom, "opacity", CLUTTER_EASE_IN_CUBIC, 0,
                     NULL);
  clutter_state_set_duration (transitions, NULL, NULL, duration);

  /* make the bottom opaque and top transparent */
  clutter_state_warp_to_state (transitions, "show-bottom");

  /* on key press, fade in the top texture and fade out the bottom texture */
  g_signal_connect (stage,
                    "key-press-event",
                    G_CALLBACK (start_animation),
                    transitions);

  clutter_actor_show (stage);

  clutter_main ();

  g_object_unref (transitions);

  if (error != NULL)
    g_error_free (error);

  return EXIT_SUCCESS;
}
예제 #6
0
파일: main.c 프로젝트: rezafaramarzi/toys
int
main (int argc, char **argv)
{
    AainaLibrary *library;
    AainaSource *source;
    ClutterActor *stage;
    ClutterAlpha *alpha;
    ClutterBehaviour *behave;
    ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
    GError *error = NULL;

    g_thread_init (NULL);

    g_set_application_name ("Aaina Image Slideshow");
    clutter_init_with_args (&argc, &argv,
                            " - Aaina Image Slideshow", entries,
                            NULL,
                            &error);
    if (error)
    {
        g_print ("Unable to run Aaina: %s", error->message);
        g_error_free (error);
        return EXIT_FAILURE;
    }

    stage = clutter_stage_get_default ();
    clutter_actor_set_size (stage, 720, 480);
    clutter_stage_hide_cursor (CLUTTER_STAGE (stage));

    if (fullscreen)
        clutter_stage_fullscreen (CLUTTER_STAGE (stage));

    clutter_stage_set_color (CLUTTER_STAGE (stage), &black);

    /* Load the test source */
    library = aaina_library_new ();

    if (directories && directories[0])
    {
        gint n_directories, i;

        n_directories = g_strv_length (directories);
        for (i = 0; i < n_directories; i++)
            source = aaina_source_directory_new (library, directories[i]);
    }
    else if (flickr_tags)
        source = aaina_source_flickr_new (library, flickr_tags);
    else
    {
        g_print ("Usage: aaina -d <path>\n"
                 "       aaina -t <tag>[,<tag>,....]\n");
        return EXIT_FAILURE;
    }

    show = aaina_slide_show_get_default ();
    clutter_group_add (CLUTTER_GROUP (stage), CLUTTER_ACTOR (show));
    clutter_actor_set_position (CLUTTER_ACTOR (show), 0, 0);
    clutter_actor_set_size (CLUTTER_ACTOR (show),
                            CLUTTER_STAGE_WIDTH (),
                            CLUTTER_STAGE_HEIGHT ()) ;
    clutter_actor_show_all (CLUTTER_ACTOR (show));
    g_object_set (G_OBJECT (show), "library", library, NULL);

    clutter_actor_show_all (stage);

    /*clutter_actor_set_scale (stage, 0.25, 0.25);*/

    g_signal_connect (G_OBJECT (stage), "key-release-event",
                      G_CALLBACK (on_key_release_event), (gpointer)stage);


    timeline = clutter_timeline_new (60, 30);
    alpha = clutter_alpha_new_full (timeline,
                                    alpha_sine_inc_func,
                                    NULL, NULL);
    behave = aaina_behave_new (alpha,
                               (AainaBehaveAlphaFunc)spin_me,
                               (gpointer)stage);

    clutter_actor_set_rotation (stage, CLUTTER_Y_AXIS, 0,
                                CLUTTER_STAGE_WIDTH ()/2,
                                0,
                                CLUTTER_STAGE_HEIGHT ());

    g_timeout_add (120000, (GSourceFunc)im_spinning_around, timeline);
    clutter_main ();

    return EXIT_SUCCESS;
}
예제 #7
0
int
main (int argc, char **argv)
{
  glong i;
  gdouble angle;
  ClutterColor color = { 0x00, 0x00, 0x00, 0xff };
  ClutterActor *stage, *rect;

  clutter_perf_fps_init ();

  if (CLUTTER_INIT_SUCCESS !=
        clutter_init_with_args (&argc, &argv,
                                NULL,
                                entries,
                                NULL,
                                NULL))
    {
      g_warning ("Failed to initialize clutter");
      return -1;
    }

  stage = clutter_stage_new ();
  clutter_actor_set_size (stage, 512, 512);
  clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Picking Performance");
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  printf ("Picking performance test with "
          "%d actors and %d events per frame\n",
          n_actors,
          n_events);

  for (i = n_actors - 1; i >= 0; i--)
    {
      angle = ((2.0 * G_PI) / (gdouble) n_actors) * i;

      color.red = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, i))) /
                  (gdouble)(n_actors/4.0) - 1.0)) * 255.0;
      color.green = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0,
                    fmod (i + (n_actors/3.0)*2, n_actors)))) /
                    (gdouble)(n_actors/4) - 1.0)) * 255.0;
      color.blue = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0,
                   fmod ((i + (n_actors/3.0)), n_actors)))) /
                   (gdouble)(n_actors/4.0) - 1.0)) * 255.0;

      rect = clutter_rectangle_new_with_color (&color);
      clutter_actor_set_size (rect, 100, 100);
      clutter_actor_set_anchor_point_from_gravity (rect,
                                                   CLUTTER_GRAVITY_CENTER);
      clutter_actor_set_position (rect,
                                  256 + 206 * cos (angle),
                                  256 + 206 * sin (angle));
      clutter_actor_set_reactive (rect, TRUE);
      g_signal_connect (rect, "motion-event",
                        G_CALLBACK (motion_event_cb), NULL);

      clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
    }

  clutter_actor_show (stage);

  clutter_perf_fps_start (CLUTTER_STAGE (stage));
  clutter_threads_add_idle (queue_redraw, stage);
  clutter_main ();
  clutter_perf_fps_report ("test-picking");

  return 0;
}
예제 #8
0
int
main (int argc, char *argv[])
{
  ClutterTimeline *timeline;
  ClutterAlpha     *alpha;
  ClutterBehaviour *scaler_1, *scaler_2;
  ClutterActor    *stage;
  ClutterColor     stage_color = { 0x61, 0x64, 0x8c, 0xff };
  SuperOH         *oh;
  gint             i;
  GError          *error;

#ifdef REQ_NON_COMPOSITION
  Window           xwin;
  Atom             non_comp_atom;
  Display         *dpy;
  int              one = 1;
#endif

  error = NULL;

  clutter_init_with_args (&argc, &argv,
                          NULL,
                          super_oh_entries,
                          NULL,
                          &error);
  if (error)
    {
      g_warning ("Unable to initialise Clutter:\n%s",
                 error->message);
      g_error_free (error);

      exit (1);
    }

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

  clutter_stage_set_title (CLUTTER_STAGE (stage), "Actors Test");
  clutter_stage_set_color (CLUTTER_STAGE (stage),
		           &stage_color);

#ifdef REQ_NON_COMPOSITION
  /* request non-composited mode */
  clutter_stage_fullscreen (stage);
  xwin = clutter_x11_get_stage_window (stage);
  dpy = XOpenDisplay(NULL);
  non_comp_atom = XInternAtom(dpy, "_HILDON_NON_COMPOSITED_WINDOW", False);
  XChangeProperty (dpy, xwin, non_comp_atom,
                   XA_INTEGER, 32, PropModeReplace,
                   (unsigned char *) &one, 1);
  printf ("stage win is %lx\n", xwin);
  XSync (dpy, False);
#endif

  oh = g_new(SuperOH, 1);

  /* Create a timeline to manage animation */
  timeline = clutter_timeline_new (360, 60); /* num frames, fps */
  g_object_set (timeline, "loop", TRUE, NULL);   /* have it loop */

  /* fire a callback for frame change */
  g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), oh);

  /* Set up some behaviours to handle scaling  */
  alpha = clutter_alpha_new_full (timeline, CLUTTER_ALPHA_SINE, NULL, NULL);

  scaler_1 = clutter_behaviour_scale_new (alpha,
					  0.5, 0.5,
					  1.0, 1.0);

  scaler_2 = clutter_behaviour_scale_new (alpha,
					  1.0, 1.0,
					  0.5, 0.5);

  /* create a new group to hold multiple actors in a group */
  oh->group = clutter_group_new();

  oh->hand = g_new (ClutterActor*, n_hands);
  for (i = 0; i < n_hands; i++)
    {
      gint x, y, w, h;
      gint radius = get_radius ();

      /* Create a texture from file, then clone in to same resources */
      if (i == 0)
	{
	  if ((oh->hand[i] = clutter_texture_new_from_file ("redhand.png",
							    &error)) == NULL)
	    {
	      g_error ("image load failed: %s", error->message);
	      exit (1);
	    }
	}
      else
	oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE(oh->hand[0]));

      /* Place around a circle */
      w = clutter_actor_get_width (oh->hand[0]);
      h = clutter_actor_get_height (oh->hand[0]);

      x = CLUTTER_STAGE_WIDTH () / 2
	+ radius
	* cos (i * M_PI / (n_hands / 2))
	- w / 2;

      y = CLUTTER_STAGE_HEIGHT () / 2
	+ radius
	* sin (i * M_PI / (n_hands / 2))
	- h / 2;

      clutter_actor_set_position (oh->hand[i], x, y);

      clutter_actor_move_anchor_point_from_gravity (oh->hand[i],
						   CLUTTER_GRAVITY_CENTER);

      /* Add to our group group */
      clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]);

#if 1 /* FIXME: disabled as causes drift? - see comment above */
      if (i % 2)
	clutter_behaviour_apply (scaler_1, oh->hand[i]);
      else
	clutter_behaviour_apply (scaler_2, oh->hand[i]);
#endif
    }

  /* Add the group to the stage */
  clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                               CLUTTER_ACTOR (oh->group));

  /* Show everying ( and map window ) */
  clutter_actor_show (stage);


  g_signal_connect (stage, "button-press-event",
		    G_CALLBACK (input_cb),
		    oh);
  g_signal_connect (stage, "key-release-event",
		    G_CALLBACK (input_cb),
		    oh);

  /* and start it */
  clutter_timeline_start (timeline);

  clutter_main ();

  g_free (oh->hand);
  g_free (oh);

  return 0;
}
예제 #9
0
int
main (int argc, char *argv[])
{
  ClutterActor *stage, *box, *instructions;
  ClutterLayoutManager *stage_layout, *grid_layout;
  GError *error = NULL;

  if (clutter_init_with_args (&argc, &argv,
                              NULL,
                              entries,
                              NULL,
                              &error) != CLUTTER_INIT_SUCCESS)
    {
      g_print ("Unable to run grid-layout: %s", error->message);
      g_error_free (error);

      return EXIT_FAILURE;
    }

  stage = clutter_stage_new ();
  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
  stage_layout = clutter_box_layout_new ();
  clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (stage_layout),
                                      CLUTTER_ORIENTATION_VERTICAL);
  clutter_actor_set_layout_manager (stage, stage_layout);

  grid_layout = clutter_grid_layout_new ();
  if (is_vertical)
    clutter_grid_layout_set_orientation (CLUTTER_GRID_LAYOUT (grid_layout),
                                         CLUTTER_ORIENTATION_VERTICAL);
  box = clutter_actor_new ();
  clutter_actor_set_background_color (box, CLUTTER_COLOR_LightGray);
  clutter_actor_set_x_expand (box, TRUE);
  clutter_actor_set_y_expand (box, TRUE);
  clutter_actor_set_layout_manager (box, grid_layout);
  clutter_actor_add_child (stage, box);
  clutter_actor_set_x_align (box, CLUTTER_ACTOR_ALIGN_FILL);
  clutter_actor_set_y_align (box, CLUTTER_ACTOR_ALIGN_FILL);

  add_actor (box, 0, 0, 1, 1);
  add_actor (box, 1, 0, 1, 1);
  add_actor (box, 2, 0, 1, 1);
  add_actor (box, 0, 1, 1, 1);
  add_actor (box, 1, 1, 2, 1);
  add_actor (box, 0, 2, 3, 1);
  add_actor (box, 0, 3, 2, 2);
  add_actor (box, 2, 3, 1, 1);
  add_actor (box, 2, 4, 1, 1);

  instructions = clutter_text_new_with_text ("Sans 12px", INSTRUCTIONS);
  clutter_actor_set_margin_top (instructions, 4);
  clutter_actor_set_margin_left (instructions, 4);
  clutter_actor_set_margin_bottom (instructions, 4);
  clutter_actor_add_child (stage, instructions);
  clutter_actor_set_x_align (instructions, CLUTTER_ACTOR_ALIGN_FILL);
  clutter_actor_set_y_align (instructions, CLUTTER_ACTOR_ALIGN_CENTER);

  g_signal_connect (stage, "destroy",
                    G_CALLBACK (clutter_main_quit), NULL);
  g_signal_connect (stage, "key-release-event",
                    G_CALLBACK (key_release_cb), box);

  clutter_actor_show (stage);

  clutter_main ();

  return 0;
}
예제 #10
0
int
main (int argc, char **argv)
{
  glong i;
  gdouble angle;
  const ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
  ClutterColor color = { 0x00, 0x00, 0x00, 0xff };
  ClutterActor *stage, *rect;

  g_setenv ("CLUTTER_VBLANK", "none", FALSE);
  g_setenv ("CLUTTER_DEFAULT_FPS", "1000", FALSE);
  g_setenv ("CLUTTER_SHOW_FPS", "1", FALSE);

  clutter_init_with_args (&argc, &argv,
                          NULL,
                          entries,
                          NULL,
                          NULL);

  stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 512, 512);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &black);

  printf ("Picking performance test with "
          "%d actors and %d events per frame\n",
          n_actors,
          n_events);

  for (i = n_actors - 1; i >= 0; i--)
    {
      angle = ((2.0 * M_PI) / (gdouble) n_actors) * i;

      color.red = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0, i))) /
                  (gdouble)(n_actors/4.0) - 1.0)) * 255.0;
      color.green = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0,
                    fmod (i + (n_actors/3.0)*2, n_actors)))) /
                    (gdouble)(n_actors/4) - 1.0)) * 255.0;
      color.blue = (1.0 - ABS ((MAX (0, MIN (n_actors/2.0 + 0,
                   fmod ((i + (n_actors/3.0)), n_actors)))) /
                   (gdouble)(n_actors/4.0) - 1.0)) * 255.0;

      rect = clutter_rectangle_new_with_color (&color);
      clutter_actor_set_size (rect, 100, 100);
      clutter_actor_set_anchor_point_from_gravity (rect,
                                                   CLUTTER_GRAVITY_CENTER);
      clutter_actor_set_position (rect,
                                  256 + 206 * cos (angle),
                                  256 + 206 * sin (angle));
      clutter_actor_set_reactive (rect, TRUE);
      g_signal_connect (rect, "motion-event",
                        G_CALLBACK (motion_event_cb), NULL);

      clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
    }

  clutter_actor_show (stage);

  g_idle_add (queue_redraw, stage);

  g_signal_connect (stage, "paint", G_CALLBACK (on_paint), NULL);

  clutter_main ();

  return 0;
}
예제 #11
0
int
main (int argc, char *argv[])
{
  ClutterActor *stage, *box;
  ClutterLayoutManager *layout;
  GError *error;
  gint i;

  error = NULL;
  if (clutter_init_with_args (&argc, &argv,
                              NULL,
                              entries,
                              NULL,
                              &error) != CLUTTER_INIT_SUCCESS)
    {
      g_print ("Unable to run flow-layout: %s", error->message);
      g_error_free (error);

      return EXIT_FAILURE;
    }

  stage = clutter_stage_new ();
  clutter_actor_set_background_color (stage, CLUTTER_COLOR_LightSkyBlue);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Flow Layout");
  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  layout = clutter_flow_layout_new (vertical ? CLUTTER_FLOW_VERTICAL
                                             : CLUTTER_FLOW_HORIZONTAL);
  clutter_flow_layout_set_homogeneous (CLUTTER_FLOW_LAYOUT (layout),
                                       is_homogeneous);
  clutter_flow_layout_set_column_spacing (CLUTTER_FLOW_LAYOUT (layout),
                                          x_spacing);
  clutter_flow_layout_set_row_spacing (CLUTTER_FLOW_LAYOUT (layout),
                                       y_spacing);

  box = clutter_actor_new ();
  clutter_actor_set_layout_manager (box, layout);
  clutter_actor_set_background_color (box, CLUTTER_COLOR_Aluminium2);
  clutter_actor_add_child (stage, box);

  if (!fixed_size)
    clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0));

  clutter_actor_set_position (box, 0, 0);
  clutter_actor_set_name (box, "box");

  for (i = 0; i < n_rects; i++)
    {
      ClutterColor color = CLUTTER_COLOR_INIT (255, 255, 255, 255);
      gfloat width, height;
      ClutterActor *rect;
      gchar *name;

      name = g_strdup_printf ("rect%02d", i);

      clutter_color_from_hls (&color,
                              360.0 / n_rects * i,
                              0.5,
                              0.8);
      rect = clutter_actor_new ();
      clutter_actor_set_background_color (rect, &color);

      if (random_size)
        {
          width = g_random_int_range (50, 100);
          height = g_random_int_range (50, 100);
        }
      else
        width = height = 50.f;

      clutter_actor_set_size (rect, width, height);
      clutter_actor_set_name (rect, name);

      clutter_actor_add_child (box, rect);

      g_free (name);
    }

  clutter_actor_show (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}