void
test_timeline_interpolate (TestConformSimpleFixture *fixture, 
			   gconstpointer data)
{
  TestState state;

  state.timeline = 
    clutter_timeline_new (TEST_TIMELINE_DURATION);
  clutter_timeline_set_loop (state.timeline, TRUE);
  g_signal_connect (G_OBJECT(state.timeline),
		    "new-frame",
		    G_CALLBACK(new_frame_cb),
		    &state);
  g_signal_connect (G_OBJECT(state.timeline),
		    "completed",
		    G_CALLBACK(completed_cb),
		    &state);

  state.completion_count = 0;
  state.new_frame_counter = 0;
  state.passed = TRUE;
  state.expected_frame = 0;

  g_get_current_time (&state.start_time);
  clutter_timeline_start (state.timeline);
  
  clutter_main();

  g_object_unref (state.timeline);
}
Пример #2
0
static void
mx_toggle_init (MxToggle *self)
{
  ClutterTimeline *timeline;

  self->priv = TOGGLE_PRIVATE (self);

  self->priv->handle = g_object_new (MX_TYPE_TOGGLE_HANDLE,
                                     "reactive", TRUE, NULL);
  clutter_actor_add_child (CLUTTER_ACTOR (self), self->priv->handle);
  g_object_bind_property (self, "disabled", self->priv->handle, "disabled",
                          G_BINDING_SYNC_CREATE);

  timeline = clutter_timeline_new (300);
  g_signal_connect (timeline, "new-frame",
                    G_CALLBACK (mx_toggle_update_position), self);

  self->priv->alpha = clutter_alpha_new_full (timeline,
                                              CLUTTER_EASE_IN_OUT_CUBIC);

  clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
  clutter_actor_set_reactive (CLUTTER_ACTOR (self->priv->handle), TRUE);

  self->priv->drag_offset = -1;
  g_signal_connect (self->priv->handle, "button-press-event",
                    G_CALLBACK (mx_toggle_handle_button_press_event), self);
  g_signal_connect (self->priv->handle, "button-release-event",
                    G_CALLBACK (mx_toggle_handle_button_release_event), self);
  g_signal_connect (self->priv->handle, "motion-event",
                    G_CALLBACK (mx_toggle_handle_motion_event), self);
}
Пример #3
0
static void
mx_expander_init (MxExpander *self)
{
  MxExpanderPrivate *priv = self->priv = GET_PRIVATE (self);

  priv->label = clutter_text_new ();
  clutter_actor_add_child ((ClutterActor *) self, priv->label);

  priv->arrow = (ClutterActor *) mx_icon_new ();
  clutter_actor_add_child ((ClutterActor*) self, priv->arrow);
  clutter_actor_set_name (priv->arrow, "mx-expander-arrow-closed");

  /* TODO: make this a style property */
  priv->spacing = 10.0f;

  priv->timeline = clutter_timeline_new (250);
  clutter_timeline_set_progress_mode (priv->timeline, CLUTTER_EASE_IN_SINE);
  g_signal_connect (priv->timeline, "new-frame", G_CALLBACK (new_frame), self);
  g_signal_connect (priv->timeline, "completed", G_CALLBACK (timeline_complete), self);


  clutter_actor_set_reactive ((ClutterActor *) self, TRUE);

  g_signal_connect (self, "style-changed",
                    G_CALLBACK (mx_expander_style_changed), NULL);

  g_signal_connect (self, "actor-added",
                    G_CALLBACK (mx_expander_actor_added), NULL);
  g_signal_connect (self, "actor-removed",
                    G_CALLBACK (mx_expander_actor_removed), NULL);
}
StThemeNodeTransition *
st_theme_node_transition_new (StThemeNode *from_node,
                              StThemeNode *to_node,
                              guint        duration)
{
  StThemeNodeTransition *transition;

  g_return_val_if_fail (ST_IS_THEME_NODE (from_node), NULL);
  g_return_val_if_fail (ST_IS_THEME_NODE (to_node), NULL);

  duration = st_theme_node_get_transition_duration (to_node);

  transition = g_object_new (ST_TYPE_THEME_NODE_TRANSITION,
                             NULL);

  transition->priv->old_theme_node = g_object_ref (from_node);
  transition->priv->new_theme_node = g_object_ref (to_node);

  transition->priv->timeline = clutter_timeline_new (duration);

  transition->priv->timeline_completed_id =
    g_signal_connect (transition->priv->timeline, "completed",
                      G_CALLBACK (on_timeline_completed), transition);
  transition->priv->timeline_new_frame_id =
    g_signal_connect (transition->priv->timeline, "new-frame",
                      G_CALLBACK (on_timeline_new_frame), transition);

  clutter_timeline_set_progress_mode (transition->priv->timeline, CLUTTER_EASE_IN_OUT_QUAD);

  clutter_timeline_start (transition->priv->timeline);

  return transition;
}
int
main(int argc, char **argv)
{
  TestState state;

  clutter_init(&argc, &argv);
  
  state.timeline = 
    clutter_timeline_new (TEST_TIMELINE_FRAME_COUNT,
                          TEST_TIMELINE_FPS);
  clutter_timeline_set_loop (state.timeline, TRUE);
  g_signal_connect (G_OBJECT(state.timeline),
                    "new-frame",
                    G_CALLBACK(new_frame_cb),
                    &state);
  g_signal_connect (G_OBJECT(state.timeline),
                    "completed",
                    G_CALLBACK(completed_cb),
                    &state);

  state.prev_frame = -1;
  state.completion_count = 0;
  state.passed = TRUE;

  clutter_timeline_start (state.timeline);
  
  clutter_main();
  
  return EXIT_FAILURE;
}
Пример #6
0
int
main (int argc, char *argv[])
{
  ClutterActor *stage;
  ClutterActor *coglbox;
  ClutterTimeline *tl;

  clutter_init(&argc, &argv);

  tl = clutter_timeline_new (G_N_ELEMENTS (paint_func) * 1000);
  clutter_timeline_set_loop (tl, TRUE);
  clutter_timeline_start (tl);

  stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 400, 400);
  clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Test");

  coglbox = clutter_group_new ();
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), coglbox);
  g_signal_connect (coglbox, "paint", G_CALLBACK (paint_cb), tl);
  /* Redraw every frame of the timeline */
  g_signal_connect_swapped (tl, "new-frame",
                            G_CALLBACK (clutter_actor_queue_redraw), coglbox);

  clutter_actor_set_rotation (coglbox, CLUTTER_Y_AXIS, -30, 200, 0, 0);
  clutter_actor_set_position (coglbox, 0, 100);

  clutter_actor_show (stage);

  clutter_main ();

  g_object_unref (tl);

  return 0;
}
Пример #7
0
static void
fluttr_viewer_init (FluttrViewer *self)
{
	FluttrViewerPrivate *priv;
	gint width, height;
	ClutterActor *message;
	
	priv = FLUTTR_VIEWER_GET_PRIVATE (self);
	
	priv->mini_token = NULL;
	priv->popping = FALSE;

	width = CLUTTER_STAGE_WIDTH ();
	height = CLUTTER_STAGE_HEIGHT ();
		
	/* message box */
	message = clutter_texture_new ();
	priv->texture = message;
	clutter_group_add (CLUTTER_GROUP (self),message); 
	clutter_actor_set_size (message, width, height);
	clutter_actor_set_position (message, -(width/2),-(height/2));
	
	/* Spinner */
	priv->spinner = fluttr_spinner_new ();
	clutter_group_add (CLUTTER_GROUP (self),priv->spinner); 
	clutter_actor_set_size (priv->spinner, (height/6)-11, (height/6)-11);
	clutter_actor_set_position (priv->spinner, width-(height/6),height-(height/6));	
				    
	/* Setup the pixbuf swap */
	priv->pixbuf = NULL;
	priv->swap_time = clutter_timeline_new (40, 40);
	priv->swap_alpha = clutter_alpha_new_full (priv->swap_time,
					           alpha_linear_inc_func,
					           NULL, NULL);
	priv->swap_behave = fluttr_behave_new (priv->swap_alpha,
					       fluttr_viewer_swap_alpha_func,
					       (gpointer)self);
					  				    
	priv->timeline = clutter_timeline_new (40, 80);
	priv->alpha = clutter_alpha_new_full (priv->timeline,
					      alpha_sine_inc_func,
					      NULL, NULL);
	priv->behave = fluttr_behave_new (priv->alpha,
					  fluttr_viewer_alpha_func,
					  (gpointer)self);
		
}
Пример #8
0
int main(int argc,char *argv[])
{

  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
  ClutterColor actor_color = { 0xff,0xff,0xff,0x98};

  /** 初始化clutter */
  clutter_init(&argc, &argv);

  /** 获取默认的场景stage */
  ClutterActor *stage = clutter_stage_get_default();
  /** 设置场景大小,注意场景也actor的一种,所以可以使用actor的api设置*/
  clutter_actor_set_size(stage,400,400);
  /** 设置场景背景*/
  clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color);



  /** 载入一个图像的actor */
  //ClutterActor * image = clutter_texture_new_from_file("demo.png",NULL);
  image = clutter_texture_new_from_file("demo.png",NULL);
  if(!image){
	  printf("load image error\n");
	  exit(-1);
  }

  /** 设置actor在场景中的位置*/
  clutter_actor_set_position(image, 100,100);
  /** 缩放图像,这里设置长宽各放大了两倍*/
  clutter_actor_set_scale(image,2.0,2.0);

  /** 设置图像旋转,以y轴旋转,角度20'c */
  clutter_actor_set_rotation(image, CLUTTER_Y_AXIS, 120,0,0,0);
  /** 把actor加入场景中*/
  clutter_container_add_actor(CLUTTER_CONTAINER(stage),image);
  clutter_actor_show(image);


  /** 打开actor的事件响应*/
  clutter_actor_set_reactive(image,TRUE);

  /** 连接actor的某事件*/
  g_signal_connect(image, "button-press-event", G_CALLBACK(on_image_button_press),NULL);

  /** 加入时间线*/
  //ClutterTimeline* timeline = clutter_timeline_new(5000);
  timeline = clutter_timeline_new(5000);
  g_signal_connect(timeline, "new-frame",G_CALLBACK(on_timeline_new_frame),NULL);
  clutter_timeline_set_loop(timeline,TRUE);
  //clutter_timeline_start(timeline);

  clutter_actor_show(stage);

  clutter_main();
  
  g_object_unref(timeline);
	printf("\n");
	return 0;
}
Пример #9
0
G_MODULE_EXPORT int
test_viewport_main (int argc, char *argv[])
{
  ClutterTimeline  *timeline;
  ClutterAlpha     *alpha;
  ClutterBehaviour *r_behave;
  ClutterActor     *stage;
  ClutterActor     *hand;
  ClutterColor      stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
  gchar            *file;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (stage),
		           &stage_color);

  /* Make a hand */
  file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
  hand = clutter_texture_new_from_file (file, NULL);
  if (!hand)
    g_error("Unable to load image '%s'", file);

  g_free (file);

  clutter_actor_set_position (hand, 300, 200);
  clutter_actor_set_clip (hand, 20, 21, 132, 170);
  clutter_actor_set_anchor_point (hand, 86, 125);
  clutter_actor_show (hand);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand);

  /* Make a timeline */
  timeline = clutter_timeline_new (7692);
  clutter_timeline_set_loop (timeline, TRUE);

  /* Set an alpha func to power behaviour */
  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);

  /* Create a behaviour for that alpha */
  r_behave = clutter_behaviour_rotate_new (alpha,
					   CLUTTER_Z_AXIS,
					   CLUTTER_ROTATE_CW,
					   0.0, 360.0); 

  /* Apply it to our actor */
  clutter_behaviour_apply (r_behave, hand);

  /* start the timeline and thus the animations */
  clutter_timeline_start (timeline);

  clutter_actor_show_all (stage);

  clutter_main();

  g_object_unref (r_behave);

  return 0;
}
Пример #10
0
G_MODULE_EXPORT gint
test_texture_quality_main (int argc, char *argv[])
{
  ClutterTimeline  *timeline;
  ClutterAlpha     *alpha;
  ClutterBehaviour *depth_behavior;
  ClutterActor     *stage;
  ClutterActor     *image;
  ClutterColor      stage_color = { 0x12, 0x34, 0x56, 0xff };
  ClutterFog        stage_fog = { 10.0, -50.0 };
  GError           *error;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE);
  clutter_stage_set_fog (CLUTTER_STAGE (stage), &stage_fog);

  g_signal_connect (stage,
                    "button-press-event", G_CALLBACK (clutter_main_quit),
                    NULL);

  error = NULL;
  image = clutter_texture_new_from_file (argv[1]?argv[1]:"redhand.png", &error);
  if (error)
    g_error ("Unable to load image: %s", error->message);

  if (!argv[1])
    g_print ("Hint: the redhand.png isn't a good test image for this test.\n"
             "This test can take any clutter loadable image as an argument\n");

  /* center the image */
  clutter_actor_set_position (image, 
    (clutter_actor_get_width (stage) - clutter_actor_get_width (image))/2,
    (clutter_actor_get_height (stage) - clutter_actor_get_height (image))/2);
  clutter_container_add (CLUTTER_CONTAINER (stage), image, NULL);

  timeline = clutter_timeline_new (5000);
  g_signal_connect (timeline,
                    "completed", G_CALLBACK (timeline_completed),
                    NULL);

  alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
  depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 400);
  clutter_behaviour_apply (depth_behavior, image);

  clutter_actor_show (stage);
  clutter_timeline_start (timeline);

  g_timeout_add (10000, change_filter, image);

  clutter_main ();

  g_object_unref (depth_behavior);
  g_object_unref (timeline);

  return EXIT_SUCCESS;
}
Пример #11
0
int main(int argc, char ** argv)
{
  ClutterColor stage_color = {0x00, 0x00, 0x00, 0xFF}; // Black
  ClutterColor rect_color = {0x00, 0xFF, 0xFF, 0xFF}; // Purple

  clutter_init(&argc, &argv);

  ClutterActor * stage = clutter_stage_get_default();
  clutter_actor_set_size(stage, 200, 200);
  clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color);

  rect = clutter_rectangle_new_with_color(&rect_color);
  clutter_actor_set_size(rect, 70, 70);
  clutter_actor_set_position(rect, 50, 100);
  clutter_container_add_actor(CLUTTER_CONTAINER(stage), rect);
  clutter_actor_show(rect);

  clutter_actor_show(stage);

  ClutterScore * score = clutter_score_new();
  clutter_score_set_loop(score, TRUE);

  ClutterTimeline * rtimeline = clutter_timeline_new(10, //frames
    120 //fps
  );
  g_signal_connect(rtimeline, "new-frame", 
    G_CALLBACK(on_timeline_rotation_new_frame), NULL);
  clutter_score_append(score, NULL, rtimeline);

  ClutterTimeline * mtimeline = clutter_timeline_new(10, //frames
    120 //fps
  );
  g_signal_connect(mtimeline, "new-frame", 
    G_CALLBACK(on_timeline_move_new_frame), NULL);
  clutter_score_append(score, rtimeline, mtimeline);

  clutter_score_start(score);

  clutter_main();

  g_object_unref(rtimeline);
  g_object_unref(mtimeline);
  g_object_unref(score);

  return EXIT_SUCCESS;
}
Пример #12
0
int
main (int   argc,
      char *argv[])
{
  ClutterActor *stage;
  ClutterPath *path;
  ClutterConstraint *constraint;
  ClutterActor *rectangle;
  ClutterTimeline *timeline;

  const ClutterColor *stage_color = clutter_color_new (51, 51, 85, 255);
  const ClutterColor *red_color = clutter_color_new (255, 0, 0, 255);

  clutter_init (&argc, &argv);

  stage = clutter_stage_new ();
  clutter_actor_set_size (stage, 360, 300);
  clutter_stage_set_color (CLUTTER_STAGE (stage), stage_color);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  /* create the path */
  path = clutter_path_new ();
  clutter_path_add_move_to (path, 30, 60);

  /* add a curve round to the top-right of the stage */
  clutter_path_add_rel_curve_to (path,
                                 120, 180,
                                 180, 120,
                                 240, 0);

  /* create a constraint based on the path */
  constraint = clutter_path_constraint_new (path, 0.0);

  /* put a rectangle at the start of the path */
  rectangle = clutter_rectangle_new_with_color (red_color);
  clutter_actor_set_size (rectangle, 60, 60);

  /* add the constraint to the rectangle */
  clutter_actor_add_constraint_with_name (rectangle, "path", constraint);

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

  /* set up the timeline */
  timeline = clutter_timeline_new (1000);
  clutter_timeline_set_loop (timeline, TRUE);
  clutter_timeline_set_auto_reverse (timeline, TRUE);

  clutter_actor_animate_with_timeline (rectangle, CLUTTER_LINEAR, timeline,
                                       "@constraints.path.offset", 1.0,
                                       NULL);

  clutter_actor_show (stage);

  clutter_main ();

  return EXIT_SUCCESS;
}
Пример #13
0
static void
mex_tile_init (MexTile *self)
{
  MexTilePrivate *priv = self->priv = TILE_PRIVATE (self);
  const ClutterColor opaque = { 0x00, 0x00, 0x00, 0x00 };
  ClutterEffect *fade;

  /* create a template material for the header background from which cheap
   * copies can be made for each instance */
  if (G_UNLIKELY (!template_material))
    template_material = cogl_material_new ();

  priv->material = cogl_material_copy (template_material);


  /* layout for primary and secondary labels */
  priv->box_layout = mx_box_layout_new ();
  mx_box_layout_set_spacing (MX_BOX_LAYOUT (priv->box_layout), 12);

  /* add fade effect to the box layout */
  fade = (ClutterEffect*) mx_fade_effect_new ();
  mx_fade_effect_set_border (MX_FADE_EFFECT (fade), 0, 50, 0, 0);
  mx_fade_effect_set_color (MX_FADE_EFFECT (fade), &opaque);
  clutter_actor_add_effect_with_name (priv->box_layout, "fade", fade);
  clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (fade), TRUE);

  clutter_actor_push_internal (CLUTTER_ACTOR (self));
  clutter_actor_set_parent (priv->box_layout, CLUTTER_ACTOR (self));
  clutter_actor_pop_internal (CLUTTER_ACTOR (self));


  priv->label = clutter_text_new ();
  priv->secondary_label = clutter_text_new ();
  clutter_actor_set_opacity (priv->secondary_label, 128);

  clutter_container_add (CLUTTER_CONTAINER (priv->box_layout), priv->label,
                         priv->secondary_label, NULL);

  priv->header_visible = TRUE;

  priv->timeline = clutter_timeline_new (DURATION);
  priv->important_alpha =
    clutter_alpha_new_full (priv->timeline, CLUTTER_EASE_OUT_QUAD);
  g_signal_connect_object (priv->timeline, "new-frame",
                           G_CALLBACK (mex_tile_important_new_frame_cb), self,
                           0);
  g_signal_connect_object (priv->timeline, "completed",
                           G_CALLBACK (mex_tile_timeline_completed_cb), self,
                           0);

  g_signal_connect (self, "style-changed",
                    G_CALLBACK (mex_tile_style_changed_cb), NULL);

  g_signal_connect (self, "actor-added",
                    G_CALLBACK (mex_tile_actor_added), NULL);
  g_signal_connect (self, "actor-removed",
                    G_CALLBACK (mex_tile_actor_removed), NULL);
}
Пример #14
0
int main(int argc, char *argv[]) {
    GstElement *pipeline, *sink;
    ClutterTimeline *timeline;
    ClutterActor *stage, *texture;

    /* clutter-gst takes care of initializing Clutter and GStreamer */
    if (clutter_gst_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
        g_error ("Failed to initialize clutter\n");
        return -1;
    }

    stage = clutter_stage_get_default ();

    /* Make a timeline */
    timeline = clutter_timeline_new (1000);
    g_object_set(timeline, "loop", TRUE, NULL);

    /* Create new texture and disable slicing so the video is properly mapped onto it */
    texture = CLUTTER_ACTOR (g_object_new (CLUTTER_TYPE_TEXTURE, "disable-slicing", TRUE, NULL));
    g_signal_connect (texture, "size-change", G_CALLBACK (size_change), NULL);

    /* Build the GStreamer pipeline */
    pipeline = gst_parse_launch ("playbin2 uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", NULL);

    /* Instantiate the Clutter sink */
    sink = gst_element_factory_make ("autocluttersink", NULL);
    if (sink == NULL) {
        /* Revert to the older cluttersink, in case autocluttersink was not found */
        sink = gst_element_factory_make ("cluttersink", NULL);
    }
    if (sink == NULL) {
        g_printerr ("Unable to find a Clutter sink.\n");
        return -1;
    }

    /* Link GStreamer with Clutter by passing the Clutter texture to the Clutter sink*/
    g_object_set (sink, "texture", texture, NULL);

    /* Add the Clutter sink to the pipeline */
    g_object_set (pipeline, "video-sink", sink, NULL);

    /* Start playing */
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    /* start the timeline */
    clutter_timeline_start (timeline);

    /* Add texture to the stage, and show it */
    clutter_group_add (CLUTTER_GROUP (stage), texture);
    clutter_actor_show_all (stage);

    clutter_main();

    /* Free resources */
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
    return 0;
}
Пример #15
0
static void
gesture_end (ClutterGestureAction *gesture,
             ClutterActor         *actor)
{
  ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture);
  ClutterPanActionPrivate *priv = self->priv;
  gfloat velocity, velocity_x, velocity_y;
  gfloat delta_x, delta_y;
  gfloat tau;
  gint duration;

  clutter_gesture_action_get_release_coords (CLUTTER_GESTURE_ACTION (self), 0, &priv->release_x, &priv->release_y);

  if (!priv->should_interpolate)
    {
      priv->state = PAN_STATE_INACTIVE;
      return;
    }

  priv->state = PAN_STATE_INTERPOLATING;

  clutter_gesture_action_get_motion_delta (gesture, 0, &delta_x, &delta_y);
  velocity = clutter_gesture_action_get_velocity (gesture, 0, &velocity_x, &velocity_y);

  /* Exponential timing constant v(t) = v(0) * exp(-t/tau)
   * tau = 1000ms / (frame_per_second * - ln(decay_per_frame))
   * with frame_per_second = 60 and decay_per_frame = 0.95, tau ~= 325ms
   * see http://ariya.ofilabs.com/2011/10/flick-list-with-its-momentum-scrolling-and-deceleration.html */
  tau = 1000.0f / (reference_fps * - logf (priv->deceleration_rate));

  /* See where the decreasing velocity reaches $min_velocity px/ms
   * v(t) = v(0) * exp(-t/tau) = min_velocity
   * t = - tau * ln( min_velocity / |v(0)|) */
  duration = - tau * logf (min_velocity / (ABS (velocity) * priv->acceleration_factor));

  /* Target point: x(t) = v(0) * tau * [1 - exp(-t/tau)] */
  priv->target_x = velocity_x * priv->acceleration_factor * tau * (1 - exp ((float)-duration / tau));
  priv->target_y = velocity_y * priv->acceleration_factor * tau * (1 - exp ((float)-duration / tau));

  if (ABS (velocity) * priv->acceleration_factor > min_velocity && duration > FLOAT_EPSILON)
    {
      priv->interpolated_x = priv->interpolated_y = 0.0f;
      priv->deceleration_timeline = clutter_timeline_new (duration);
      clutter_timeline_set_progress_mode (priv->deceleration_timeline, CLUTTER_EASE_OUT_EXPO);

      g_signal_connect (priv->deceleration_timeline, "new_frame",
                        G_CALLBACK (on_deceleration_new_frame), self);
      g_signal_connect (priv->deceleration_timeline, "stopped",
                        G_CALLBACK (on_deceleration_stopped), self);
      clutter_timeline_start (priv->deceleration_timeline);
    }
  else
    {
      emit_pan_stopped (self, actor);
    }
}
Пример #16
0
G_MODULE_EXPORT int
test_cairo_flowers_main (int argc, char **argv)
{
    Flower *flowers[N_FLOWERS];
    ClutterTimeline *timeline;
    int i;

    srand (time (NULL));

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

    /* Create a timeline to manage animation */
    timeline = clutter_timeline_new (6000);
    clutter_timeline_set_repeat_count (timeline, -1);

    stage = clutter_stage_new ();
    clutter_stage_set_title (CLUTTER_STAGE (stage), "Cairo Flowers");
    g_signal_connect (stage, "destroy", G_CALLBACK (stop_and_quit), timeline);

    clutter_actor_set_background_color (stage, CLUTTER_COLOR_Black);

    for (i=0; i< N_FLOWERS; i++)
    {
        flowers[i]       = g_new0(Flower, 1);
        flowers[i]->ctex = make_flower_actor();
        flowers[i]->x    = rand() % (int) clutter_actor_get_width (stage)
                           - (PETAL_MIN + PETAL_VAR) * 2;
        flowers[i]->y    = rand() % (int) clutter_actor_get_height (stage);
        flowers[i]->rv   = rand() % 5 + 1;
        flowers[i]->v    = rand() % 10 + 2;

        clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                     flowers[i]->ctex);
        clutter_actor_set_position (flowers[i]->ctex,
                                    flowers[i]->x, flowers[i]->y);
    }

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

    clutter_actor_show (stage);

    clutter_timeline_start (timeline);

    g_signal_connect (stage, "key-press-event",
                      G_CALLBACK (clutter_main_quit),
                      NULL);

    clutter_main();

    g_object_unref (timeline);

    return EXIT_SUCCESS;
}
Пример #17
0
int
test_cairo_flowers_main (int argc, char **argv)
{
  int              i;
  ClutterActor    *stage;
  ClutterColor     stage_color = { 0x0, 0x0, 0x0, 0xff };
  ClutterTimeline *timeline;
  Flower          *flowers[N_FLOWERS];

  srand (time (NULL));

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

  stage = clutter_stage_get_default ();

  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  for (i=0; i< N_FLOWERS; i++)
    {
      flowers[i]       = g_new0(Flower, 1);
      flowers[i]->ctex = make_flower_actor();
      flowers[i]->x    = rand() % (int) clutter_actor_get_width (stage)
                       - (PETAL_MIN + PETAL_VAR) * 2;
      flowers[i]->y    = rand() % (int) clutter_actor_get_height (stage);
      flowers[i]->rv   = rand() % 5 + 1;
      flowers[i]->v    = rand() % 10 + 2;

      clutter_container_add_actor (CLUTTER_CONTAINER (stage),
                                   flowers[i]->ctex);
      clutter_actor_set_position (flowers[i]->ctex,
				  flowers[i]->x, flowers[i]->y);
    }

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

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

  clutter_actor_show (stage);

  clutter_timeline_start (timeline);

  g_signal_connect (stage, "key-press-event",
		    G_CALLBACK (clutter_main_quit),
		    NULL);

  clutter_main();

  return EXIT_SUCCESS;
}
Пример #18
0
/**
 * mx_adjustment_interpolate:
 * @adjustment: A #MxAdjustment
 * @value: A #gdouble
 * @duration: duration in milliseconds
 * @mode: A #ClutterAnimationMode
 *
 * Interpolate #MxAdjustment:value to the new value specified by @value, using
 * the mode and duration given.
 */
void
mx_adjustment_interpolate (MxAdjustment *adjustment,
                           gdouble       value,
                           guint         duration,
                           gulong        mode)
{
  MxAdjustmentPrivate *priv = adjustment->priv;

  g_return_if_fail (isfinite (value));

  if (duration <= 1)
    {
      stop_interpolation (adjustment);
      mx_adjustment_set_value (adjustment, value);
      return;
    }

  priv->old_position = priv->value;
  priv->new_position = value;

  if (!priv->interpolation)
    {
      priv->interpolation = clutter_timeline_new (duration);

      g_signal_connect (priv->interpolation,
                        "new-frame",
                        G_CALLBACK (interpolation_new_frame_cb),
                        adjustment);
      g_signal_connect (priv->interpolation,
                        "completed",
                        G_CALLBACK (interpolation_completed_cb),
                        adjustment);
    }
  else
    {
      /* Extend the animation if it gets interrupted, otherwise frequent calls
       * to this function will end up with no advancements until the calls
       * finish (as the animation never gets a chance to start).
       */
      clutter_timeline_set_direction (priv->interpolation,
                                      CLUTTER_TIMELINE_FORWARD);
      clutter_timeline_rewind (priv->interpolation);
      clutter_timeline_set_duration (priv->interpolation, duration);
    }

  if (priv->interpolate_alpha)
    g_object_unref (priv->interpolate_alpha);

  priv->interpolate_alpha = clutter_alpha_new_full (priv->interpolation,
                                                    mode);

  clutter_timeline_start (priv->interpolation);
}
Пример #19
0
static void
mex_column_init (MexColumn *self)
{
  MexColumnPrivate *priv = self->priv = GET_PRIVATE (self);

  /* Set the column as reactive and enable collapsing */
  clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
  priv->collapse = TRUE;

  /* Create a timeline for the expand animation. The duration is calculated
   * before the timeline is started. */
  priv->expand_timeline = clutter_timeline_new (1);
}
Пример #20
0
G_MODULE_EXPORT int
test_cogl_vertex_buffer_main (int argc, char *argv[])
{
  TestState       state;
  ClutterActor   *stage;
  gfloat          stage_w, stage_h;
  gint            dummy_width, dummy_height;

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

  stage = clutter_stage_new ();

  clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Vertex Buffers");
  clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Black);
  g_signal_connect (stage, "destroy", G_CALLBACK (stop_and_quit), &state);
  clutter_actor_get_size (stage, &stage_w, &stage_h);

  dummy_width = MESH_WIDTH * QUAD_WIDTH;
  dummy_height = MESH_HEIGHT * QUAD_HEIGHT;
  state.dummy = create_dummy_actor (dummy_width, dummy_height);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), state.dummy);
  clutter_actor_set_position (state.dummy,
                              (stage_w / 2.0) - (dummy_width / 2.0),
                              (stage_h / 2.0) - (dummy_height / 2.0));

  state.timeline = clutter_timeline_new (1000);
  clutter_timeline_set_loop (state.timeline, TRUE);

  state.frame_id = g_signal_connect (state.timeline,
                                     "new-frame",
                                     G_CALLBACK (frame_cb),
                                     &state);

  g_signal_connect (state.dummy, "paint", G_CALLBACK (on_paint), &state);

  init_quad_mesh (&state);

  clutter_actor_show_all (stage);

  clutter_timeline_start (state.timeline);

  clutter_main ();

  cogl_handle_unref (state.buffer);
  cogl_handle_unref (state.indices);

  return 0;
}
Пример #21
0
static void
aisleriot_slot_renderer_init (AisleriotSlotRenderer *self)
{
  AisleriotSlotRendererPrivate *priv;

  priv = self->priv = AISLERIOT_SLOT_RENDERER_GET_PRIVATE (self);

  priv->revealed_card = -1;
  priv->highlight_start = G_MAXINT;

  priv->animations = g_array_new (FALSE, FALSE, sizeof (AnimationData));
  priv->timeline = clutter_timeline_new (500);
  g_signal_connect_swapped (priv->timeline, "completed",
                            G_CALLBACK (completed_cb), self);
}
Пример #22
0
int
main (int   argc,
      char *argv[])
{
  ClutterActor *stage;
  ClutterActor *actor;
  ClutterTimeline *timeline;
  ClutterAnimator *animator;

  clutter_init (&argc, &argv);

  stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 300, 200);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
  g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

  actor = clutter_rectangle_new_with_color (&red_color);
  clutter_actor_set_size (actor, 100, 100);
  clutter_actor_set_position (actor, 150, 50);

  timeline = clutter_timeline_new (2000);
  clutter_timeline_set_loop (timeline, TRUE);

  animator = clutter_animator_new ();
  clutter_animator_set_timeline (animator, timeline);

  clutter_animator_set (animator,
                        actor, "x", CLUTTER_LINEAR, 0.0, 150.0,
                        actor, "x", CLUTTER_LINEAR, 0.5, 50.0,
                        actor, "x", CLUTTER_LINEAR, 1.0, 150.0,
                        NULL);

  clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);

  g_signal_connect (stage,
                    "key-press-event",
                    G_CALLBACK (key_pressed_cb),
                    timeline);

  clutter_actor_show (stage);

  clutter_main ();

  g_object_unref (animator);

  return EXIT_SUCCESS;
}
Пример #23
0
bool StageManager::initStage()
{
    stage_ = clutter_stage_get_default();

    float width = (float) getAttribute("size").getInt(0);
    float height =(float) getAttribute("size").getInt(1);
    clutter_actor_set_size(stage_, width, height);
    clutter_stage_set_color(CLUTTER_STAGE(stage_), &black);
    g_signal_connect(stage_, "destroy", G_CALLBACK(on_stage_destroyed), (gpointer) this);

    std::string filename = getAttribute("script").getString(0);

    GError *error = NULL;
    /* load JSON from a file */
    ClutterScript *script = clutter_script_new();
    clutter_script_load_from_file(script, filename.c_str(), &error);

    if (error != NULL)
    {
        std::cerr << "Unable to read file: " <<  error->message << std::endl;
        g_error_free(error);
        // TODO: fail
        g_critical("Could not load GUI");
        return false;
    }
    ClutterActor *group0 = CLUTTER_ACTOR(clutter_script_get_object(script, "group0")); // TODO: rename to root
    clutter_container_add_actor(CLUTTER_CONTAINER(stage_), group0);
    //clutter_script_connect_signals(script, this);
    clutter_script_connect_signals_full(script, tempi_clutter_connect_signals, this);

    // timeline to attach a callback for each frame that is rendered
    ClutterTimeline *timeline;
    timeline = clutter_timeline_new(60); // ms
    clutter_timeline_set_loop(timeline, TRUE);
    clutter_timeline_start(timeline);
    g_signal_connect(timeline, "new-frame", G_CALLBACK(on_frame_cb), this);
    g_signal_connect(stage_, "key-press-event", G_CALLBACK(key_event_cb), this);
    g_object_unref(script); // avoid memory leak

    clutter_actor_show(stage_);

    if (CLUTTER_IS_ACTOR(stage_))
        return true;
    else
        return false;
}
Пример #24
0
static void
mex_content_box_init (MexContentBox *self)
{
  MexContentBoxPrivate *priv = self->priv = CONTENT_BOX_PRIVATE (self);
  ClutterActor *icon;

  clutter_actor_push_internal (CLUTTER_ACTOR (self));

  priv->info_panel = mex_info_panel_new (MEX_INFO_PANEL_MODE_SIMPLE);
  clutter_actor_set_parent (priv->info_panel, CLUTTER_ACTOR (self));

  /* monitor key press events */
  g_signal_connect (self, "key-press-event",
                    G_CALLBACK (mex_content_box_key_press_event_cb), NULL);

  /* Create tile */
  icon = mx_icon_new ();
  priv->tile = mex_content_tile_new ();
  clutter_actor_set_parent (priv->tile, CLUTTER_ACTOR (self));
  g_object_set (G_OBJECT (priv->tile),
                "thumb-width", DEFAULT_THUMB_WIDTH,
                "thumb-height", DEFAULT_THUMB_HEIGHT,
                NULL);
  mx_stylable_set_style_class (MX_STYLABLE (icon), "Info");
  mex_tile_set_secondary_icon (MEX_TILE (priv->tile), icon);


  clutter_actor_set_reactive (priv->tile, TRUE);
  g_signal_connect (priv->tile, "button-release-event",
                    G_CALLBACK (mex_content_box_tile_clicked_cb), self);

  /* Create the action list */
  priv->action_list = mex_action_list_new ();
  clutter_actor_set_parent (priv->action_list, CLUTTER_ACTOR (self));

  clutter_actor_pop_internal (CLUTTER_ACTOR (self));


  priv->timeline = clutter_timeline_new (200);
  priv->alpha = clutter_alpha_new_full (priv->timeline, CLUTTER_EASE_OUT_CUBIC);

  g_signal_connect_swapped (priv->timeline, "new-frame",
                            G_CALLBACK (clutter_actor_queue_relayout), self);
  g_signal_connect (priv->timeline, "completed",
                    G_CALLBACK (mex_content_box_timeline_completed), self);
}
Пример #25
0
int main(int argc, char *argv[])
{
  ClutterColor stage_color = { 0x00, 0x00, 0x00, 0xff };
  ClutterColor rect_color = { 0xff, 0xff, 0xff, 0x99 };

  clutter_init (&argc, &argv);

  /* Get the stage and set its size and color: */
  ClutterActor *stage = clutter_stage_get_default ();
  clutter_actor_set_size (stage, 200, 200);
  clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);

  /* Add a rectangle to the stage: */
  rect = clutter_rectangle_new_with_color (&rect_color);
  clutter_actor_set_size (rect, 40, 40);
  clutter_actor_set_position (rect, 10, 10);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
  clutter_actor_show (rect);

  /* Show the stage: */
  clutter_actor_show (stage);

  ClutterTimeline *timeline =  clutter_timeline_new(5000 /* milliseconds */);
  clutter_timeline_set_loop(timeline, TRUE);
  clutter_timeline_start(timeline);

  /* Create a clutter alpha for the animation */
  ClutterAlpha* alpha = clutter_alpha_new_with_func (timeline, &on_alpha, NULL, NULL);
  g_object_unref (timeline);

  /* Create an animation to change the properties */
  ClutterAnimation* animation =
    clutter_actor_animate_with_alpha (rect, alpha,
      "x", 150.0,
      "y", 150.0,
      "opacity", 0,
      NULL);

  /* Start the main loop, so we can respond to events: */
  clutter_main ();

  g_object_unref (animation);

  return EXIT_SUCCESS;
}
Пример #26
0
bool App::launch()
{
    if (osc_recv_port_ == 0)
        if (verbose_)
            std::cout << "OSC receiving disabled." << std::endl;
    else
        startOSC();
    // Poll OSC receiver only when we render a Clutter frame.

    if (stage_)
    {
        std::cerr << "cannot create stage twice" << std::endl;
        //return false;
    }
    stage_ = clutter_stage_get_default();
    clutter_actor_set_size(stage_, 1024, 768);
    ClutterColor black = { 0x00, 0x00, 0x00, 0xff };
    clutter_stage_set_color(CLUTTER_STAGE(stage_), &black);
    g_signal_connect(stage_, "destroy", G_CALLBACK(clutter_main_quit), NULL);
    clutter_actor_set_reactive(stage_, TRUE);

    // timeline to attach a callback for each frame that is rendered
    ClutterTimeline *timeline;
    timeline = clutter_timeline_new(60); // ms
    clutter_timeline_set_loop(timeline, TRUE);
    clutter_timeline_start(timeline);

    g_signal_connect(timeline, "new-frame", G_CALLBACK(on_frame_cb), this);
    g_signal_connect(stage_, "key-press-event", G_CALLBACK(key_event_cb), this);
    g_signal_connect(stage_, "button-press-event", G_CALLBACK(button_press_cb), this);
    g_signal_connect(stage_, "button-release-event", G_CALLBACK(button_released_cb), this);
    g_signal_connect(stage_, "motion-event", G_CALLBACK(motion_event_cb), this);

    if (fullscreen_)
    {
        fullscreen_ = false;
        toggleFullscreen();
    }

    createPalette();

    clutter_actor_show(stage_);
    return true;
}
Пример #27
0
static ClutterAlpha *
layout_manager_real_begin_animation (ClutterLayoutManager *manager,
                                     guint                 duration,
                                     gulong                mode)
{
    ClutterTimeline *timeline;
    ClutterAlpha *alpha;

    alpha = g_object_get_qdata (G_OBJECT (manager), quark_layout_alpha);
    if (alpha != NULL)
    {
        clutter_alpha_set_mode (alpha, mode);

        timeline = clutter_alpha_get_timeline (alpha);
        clutter_timeline_set_duration (timeline, duration);
        clutter_timeline_rewind (timeline);

        return alpha;
    };

    timeline = clutter_timeline_new (duration);

    alpha = clutter_alpha_new_full (timeline, mode);

    /* let the alpha take ownership of the timeline */
    g_object_unref (timeline);

    g_signal_connect_swapped (timeline, "completed",
                              G_CALLBACK (clutter_layout_manager_end_animation),
                              manager);
    g_signal_connect_swapped (timeline, "new-frame",
                              G_CALLBACK (clutter_layout_manager_layout_changed),
                              manager);

    g_object_set_qdata_full (G_OBJECT (manager),
                             quark_layout_alpha, alpha,
                             (GDestroyNotify) g_object_unref);

    clutter_timeline_start (timeline);

    return alpha;
}
Пример #28
0
Preview::Preview():
	width(0),
	height(0),
	blocknr(-1),
	color(-1),
	themeID(0),
	cell_size(20),
	cache(NULL),
	enabled(true)
{
	blocks = new Block*[PREVIEW_WIDTH];
	for (int i = 0; i < PREVIEW_WIDTH; i++) {
		blocks[i] = new Block [PREVIEW_HEIGHT];
	}

	w = gtk_clutter_embed_new();

	g_signal_connect (w, "size_allocate", G_CALLBACK (resize), this);

	/* FIXME: We should scale with the rest of the UI, but that requires
	 * changes to the widget layout - i.e. wrap the preview in an
	 * fixed-aspect box. */
	gtk_widget_set_size_request (w, 120, 120);
	ClutterActor *stage;
	stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (w));

	ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff };
	clutter_stage_set_color (CLUTTER_STAGE (stage),
				 &stage_color);
	piece = clutter_group_new ();
	clutter_group_add (CLUTTER_GROUP (stage),
			   piece);

	piece_timeline = clutter_timeline_new (180);
	alpha = clutter_alpha_new_full (piece_timeline,
			CLUTTER_EASE_IN_OUT_SINE);
	piece_behav = clutter_behaviour_scale_new (alpha,
			0.6, 0.6, 1.0, 1.0);
	clutter_actor_set_anchor_point (piece, 60, 60);
	clutter_actor_set_position (CLUTTER_ACTOR(piece), 60, 60);
	clutter_behaviour_apply (piece_behav, piece);
}
Пример #29
0
void
on_call_activate_complete (ClutterActor *actor,
			   gpointer user_data)
{
  ClutterAlpha     *alpha;
  ClutterBehaviour *behave;
  App *app = (App*)user_data;

  clutter_actor_hide (app->screen_dialpad);

  /* Setup the pulsing 'calling..' text if need be */
  if (app->dialing_timeline == NULL)
    {
      app->dialing_timeline = clutter_timeline_new (1000);
      clutter_timeline_set_loop (app->dialing_timeline, TRUE);
      alpha = clutter_alpha_new_full (app->dialing_timeline, ALPHA_SINE);
      behave = clutter_behaviour_opacity_new (alpha, 0xff, 0);
      clutter_behaviour_apply (behave, app->dial_label);
    }
  clutter_timeline_start (app->dialing_timeline);

  app->dialing_state = TRUE;
}
static void
mx_label_init (MxLabel *label)
{
  MxLabelPrivate *priv;
  const ClutterColor opaque = { 0xff, 0xff, 0xff, 0xff };

  label->priv = priv = MX_LABEL_GET_PRIVATE (label);

  priv->label = g_object_new (CLUTTER_TYPE_TEXT,
                              "ellipsize", PANGO_ELLIPSIZE_END,
                              NULL);

  clutter_actor_set_parent (priv->label, CLUTTER_ACTOR (label));

  priv->fade_effect = mx_fade_effect_new ();
  mx_fade_effect_set_color (MX_FADE_EFFECT (priv->fade_effect), &opaque);
  clutter_actor_add_effect (priv->label, priv->fade_effect);
  clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (priv->fade_effect),
                                  FALSE);

  g_signal_connect (label, "style-changed",
                    G_CALLBACK (mx_label_style_changed), NULL);
  g_signal_connect (priv->label, "notify::single-line-mode",
                    G_CALLBACK (mx_label_single_line_mode_cb), label);
  g_signal_connect_swapped (priv->label, "queue-redraw",
                            G_CALLBACK (mx_label_label_changed_cb), label);

  priv->fade_timeline = clutter_timeline_new (250);
  priv->fade_alpha = clutter_alpha_new_full (priv->fade_timeline,
                                             CLUTTER_EASE_OUT_QUAD);
  g_signal_connect (priv->fade_timeline, "new-frame",
                    G_CALLBACK (mx_label_fade_new_frame_cb), label);
  g_signal_connect (priv->fade_timeline, "started",
                    G_CALLBACK (mx_label_fade_started_cb), label);
  g_signal_connect (priv->fade_timeline, "completed",
                    G_CALLBACK (mx_label_fade_completed_cb), label);
}