Clutter Learning (9): Timeline time and frame triggering

Source: Internet
Author: User

Source: Using Timelines

, Markers

, Examples

The usage is as follows:

1. Create a CLutterTimeline type, clutter_timeline_new ()

2. Set monitoring events.

3. Start clutter_timeline_start (), stop clutter_timeline_stop (), and loop clutter_timeline_set_loop ()

I think ClutterTimeline is a good type and is often used in Clutter projects. It provides two triggers. The first type is "newframe". In other graphics development, if we need to dynamically process image changes, it may take a timeout time, at which time the redraw screen, clutter provides a special way to trigger the "newframe" event when the screen frame is refreshed. Note that different monitors have different refresh frequencies, and the interval between newframe triggers for different machines is different. If you need various machines to achieve the same effect, timestampe needs to be added for calculation. In any case, the image can be re-painted in the smallest granularity to achieve the best smooth effect.


The other is our custom marker-reached, which is triggered based on time. The following figure shows the trigger mechanism of ClutterTimeline. When creating a ClutterTimeline, I define the time as T0, that is, T0 as a timeout time. If we define a loop through clutter_timeline_set_loop (), start a new T0 time slice after T0, you can use clutter_timeline_stop () to end the loop. We can set the timeout clock through clutter_timeline_add_marker_at_time in each time piece, and the trigger event is marker-reached.

The following is a small example. We rotate a box to change the color alpha.


# Include <clutter/clutter. h>

# Include <stdlib. h>

# Include <time. h>

Long offset = 0;

Long get_time (){

Return time (0)-offset;

}

Int alpha = 0x99;

/* Screen flushing trigger function */


Void on_timeline_new_frame (ClutterTimeline * timeline, gint frame_num, gpointer data ){

Static int tag = 1;

Static float step = 0;


/* Rotate the screen at 1 degree each time */

Step + = 1.0;

If (step >=360)

Step = 0;

Clutter_actor_set_rotation (ClutterActor *) data, CLUTTER_X_AXIS, step, 0, 0 );


/* The color changes cyclically from Bright to dark, from dark to bright */

If (tag = 1 ){

Alpha ++;

If (alpha> = 0xef)

Tag = 0;

} Else {

Alpha --;

If (alpha <= 0x30)

Tag ++;

}

ClutterColor color = {0xff, 0xff, 0xff, alpha };

Clutter_rectangle_set_color (CLUTTER_RECTANGLE (data), & color );

}

/* The Custom time trigger function can be used as a clock function. The third parameter, tested, is the relative time in the time sheet, in the unit of msec */

Void on_timeline_marker_reached (ClutterTimeline * timeline, gchar * marker_name, gint num, gpointer data ){

Printf ("% ld marker % s reached: frame-num = % d/n", get_time (), marker_name, num );

}

Int main (int argc, char * argv []) {

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

ClutterColor rect_color = {0xff, 0xff, 0xff, alpha };

Clutter_init (& argc, & argv );

/* Clutter stage and rect */

ClutterActor * stage = clutter_stage_get_default ();

Clutter_actor_set_size (stage, 200,200 );

Clutter_stage_set_color (CLUTTER_STAGE (stage), & stage_color );

ClutterActor * 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 );

Offset = time (0 );

/* In Timeline, we start a timeline with a time slice of 5 seconds (5000 msecs) and create a time trigger point named "my-mark, the trigger point is located at 2000th ms of each time slice. Next, start the trigger event of the update frame so that we can perform dynamic processing. After setting the trigger of the time trigger point, we can set 0 or more time triggers in a time slice. Finally, set it to loop mode and start it. */

ClutterTimeline * timeline =Clutter_timeline_new

(5000 );

Clutter_timeline_add_marker_at_time

(Timeline, "my-mark", 2000 );

G_signal_connect (timeline,"New-frame"

, G_CALLBACK (on_timeline_new_frame), rect );

G_signal_connect (timeline,"Marker-reached"

, G_CALLBACK (on_timeline_marker_reached), NULL );

Clutter_timeline_set_loop

(Timeline, TRUE );

Clutter_timeline_start

(Timeline );

Clutter_main ();

G_object_unref (timeline );

Return EXIT_SUCCESS;

}

Related links:



My Clutter blog

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.