Monday, September 10, 2007

GObject skeleton generator for Vim

So after reading this blog entry from Gustavo, I found it interesting and decided to do the same for Vim, as I would never use Emacs :D. So I found this script and did some small changes to make it fit better the GTK+ coding style.

To use the script first copy it to ~/.vim/plugin directory, then open a file with vim and run one of the commands:
  • GOBGenerateH
To generate the class definition.
  • GOBGenerateC
To generate the class implementation.
Both commands will use the filename as default for the class name. You can change it, by typing the class name manually. It will replace "-" with "_" and also try to apply Camel Case to the filename. For example a file named test-object.h will generate a class named TestObject.

If you are interested, you can download the updated version of the script from here

Saturday, September 08, 2007

GtkCanvas

So I decided to start working on getting a GtkCanvas implementation on GTK+.
I believe GTK+ is really missing a good canvas implementation to make it easy to create rich UI applications such as Plasma, Canola, ....

Plasma is using QGraphicsView framework, a really good canvas framework, that enables you to create really nice UIs with nice animations/transitions. As already stated in some blogs [1], Canola will be using Evas for it's next version. So why not have a GtkCanvas? As i said in the previous post, I together with Renato already started creating a GtkTransition class. Together with a Canvas implementation you can create really nice animations really easy. I will be posting a video of an example application soon.

So if you are interested on this topic see this thread on gtk-devel mailing list

[1]
http://www.marceloeduardo.com/blog/mobile-applications/canola-development-update-or-we-are-not-dead

Creating transitions with GTK+

Anyone knows that creating transitions (animations) using GTK+ is not the easiest thing to do. So after some discussions with Renato we came up with a API to make it easier.

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.

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).

The code looks something like:

transition = gtk_transition_new (2000);
gtk_timeline_set_loop (GTK_TIMELINE (transition), TRUE);

state1 = gtk_transition_state_new (G_OBJECT (label));
gtk_transition_state_set (state1, "angle", 0.0, 360.0, NULL);
gtk_transition_add_state (transition, state1, NULL, 0.5);

state2 = gtk_transition_state_new (G_OBJECT (label));
gtk_transition_state_set (state2, "angle", 360.0, 0.0, NULL);
gtk_transition_add_state (transition, state2, state1, 1.0);

gtk_timeline_start (GTK_TIMELINE (transition));

The code is not complete yet, but you can grab it with:
$ svn checkout http://andrunko.googlecode.com/svn/trunk/gtk

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)

Patches and ideas are welcome!

Hope you enjoy

[1]
http://bugzilla.gnome.org/show_bug.cgi?id=444659
[2]
http://sourceforge.net/projects/goocanvas

Edit: updated code snippet