tag:blogger.com,1999:blog-13700803.post-60002431499586982912007-09-08T03:30:00.000-03:002007-09-10T01:19:05.530-03:00Creating transitions with GTK+Anyone knows that creating transitions (animations) using GTK+ is not the easiest thing to do. So after some discussions with <a href="http://tuxrecife.blogspot.com/">Renato</a> we came up with a API to make it easier.<br /><br />So today I sat down and wrote GtkTransition, a class written on top of GtkTimeline [1] that allows you to create transitions as natural as it can be. It's similar to what Flash does to create animations, but with some small differences.<br /><br />Basically you create a transition with an interval (eg. 2 seconds) and add states for this transition. States work directly on objects properties, so you can say for example, create a state that will complete when the transition reaches 50% that will set the label angle from 0 to 360 degrees. After that create another state that will complete on 100% of the transition that will set the same angle from 360 to 0 degreess and depends on the first state (it will start after the first state has completed).<br /><br />The code looks something like:<br /><br />transition = gtk_transition_new (2000);<br />gtk_timeline_set_loop (GTK_TIMELINE (transition), TRUE);<br /><br />state1 = gtk_transition_state_new (G_OBJECT (label));<br />gtk_transition_state_set (state1, "angle", 0.0, 360.0, NULL);<br />gtk_transition_add_state (transition, state1, NULL, 0.5);<br /><br />state2 = gtk_transition_state_new (G_OBJECT (label));<br />gtk_transition_state_set (state2, "angle", 360.0, 0.0, NULL);<br />gtk_transition_add_state (transition, state2, state1, 1.0);<br /><br />gtk_timeline_start (GTK_TIMELINE (transition));<br /><br />The code is not complete yet, but you can grab it with:<br />$ svn checkout http://andrunko.googlecode.com/svn/trunk/gtk<br /><br />There is a test1.c that shows the code to rotate the label, and test2.c that translate and resize a GooCanvasItem (you need goocanvas [1] to compile it)<br /><br />Patches and ideas are welcome!<br /><br />Hope you enjoy<br /><br />[1]<br /><a href="http://bugzilla.gnome.org/show_bug.cgi?id=444659">http://bugzilla.gnome.org/show_bug.cgi?id=444659</a><br />[2]<br /><a href="http://sourceforge.net/projects/goocanvas">http://sourceforge.net/projects/goocanvas</a><br /><br />Edit: <span style="font-style: italic;">updated code snippet</span><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/13700803-6000243149958698291?l=andrunko.blogspot.com'/></div>Andre Moreira Magalhaes (andrunko)http://www.blogger.com/profile/14668638448861180171noreply@blogger.com3