GNOME Bugzilla – Bug 570479
Pixmap based animation
Last modified: 2014-05-22 01:56:06 UTC
The following patch implements an idea of Tim Janik to animate widgets in Gtk+. It is a "proof of concept" and should be seen as a basis for further discussion on this topic. Bit by bit we might build up something suitable for the usage in Gtk+. Let me explain the patch a little bit more in detail. Changes in GDK: This changes secure that I get a representation of a widget on a _transparent_ pixmap. They also prevent drawing of a widget when I only want the redirected result. Changes in GTK: gtkmain.c: Here we obtain the pixmap representation of instances of GtkAnimatable and its children. If an animatable triggered an animation (it wants to have something animated) then a gdk_thread is started. gtkwidget.c We save the old allocation data, so we know the new and the old state of an animation. gtkcontainer.c We test if a widget is an instance of GtkAnimatable. If it is we stop the standard expose procedure and continue in gtkmain.c where we obtain the representation for each single widget. gtkanimatable* This is an interface every widget which wants to support animation has to implement. It also provides functions to start and stop an animation and a callback for the gdk_thread mentioned before which handles the animation itself. The animation itself is an iteration through the widget hierarchy of the animatable which triggered the animation. The animation computes size and position for each widget and progress (between 0 and 1) and draws the pixmap representation of the current widget with the computed size. Because we have transparent pixmaps we don't affect the previous layers. This interface and the functions are not well designed yet and need a lot of discussion and improvements. The idea is that we have all animation related functions at a well defined place and also a kind of design pattern which helps widget developers to implement animations. gtkanimbox* A reference implementation of the GtkAnimatable interface. It is more a "get things done" implementation rather than a reference. But it shows how a widget can utilise pixmap based animation for its own purposes. Requirements: To get transparent pixmaps we need a running composite manager. Problems: A problem at the moment are child windows because they get an extra expose event (?) and there is no test if a widget is a child of an animatable in gtkmain yet. I'll have a look on this in the following days. I hope these are enough informations for the beginning. If not please tell me on which issue you need more detailed information. I'll try to give an satisfying answer as fast as possible.
Created attachment 127917 [details] [review] The patch described before
Created attachment 127918 [details] [review] A test application for the GtkAnimBox implementation This is a very basic test applications. Just compile it against the patched Gtk+.
To clarify "gdk_thread", it is a "gdk_threads_add_timeout_full" which periodically triggers the redraw.
Wouldn't this benefit from bug #444659?
(In reply to comment #4) > Wouldn't this benefit from bug #444659? > Yeah, definitely! I've already worked with Carlos' animation framework and it would make many things easier to implement. It would also provide a nicer interface for the widgets to control the animation or at least get information about the animation state. Does someone still work on this?
I don't think so, just what I've been doing a few months ago: http://git.imendio.com/?p=carlos/animation-framework.git;a=summary So no further work besides yours :)
Will this bug provide any means to give a widget an animated theme? E has buttons where the shading can change across them, I'm wondering if that capability will be added to GTK+.
(In reply to comment #7) > Will this bug provide any means to give a widget an animated theme? E has > buttons where the shading can change across them, I'm wondering if that > capability will be added to GTK+. > No, that's not intended to be solved by this work. Animation for themes will be part of the work during the upcoming theme API hackfest. In Gtk+ layout and design are separated. This work tries to show a way to animate the layout, thus the translation between 2 different allocation (size and position) states. These things do not belong to the tasks of a theme engine. I hope this helps to answer your question.
The following patch also handles widgets which have there own window(s), like GtkEntry or GtkCalendar. Due to there implementation these widgets have a main window and several subwindows which are private to these widgets. These private windows contain the data shown to the user, e.g. the text of the GtkEntry or the year, week or day area in GtkCalendar. For the implementation it is easier to only obtain the pixmap representation of the main window of these widgets. I ensure this with "widget->window == event->any.window". This means that I don't animate the content itself, only the holding window. This approach is not just easier to implement but has also another important advantage. I don't resize the content of these widgets because this would lead to ugly effects like stretched or shrinked text. For widgets which hold text and don't have an extra GtkLabel for it this is probably the best approach. For GtkCalendar I can also imagine an implementation which uses GtkButtons and GtkLabels etc. for the interface. With that approach also a resize like for GtkButton would be possible (text and symbols are child widgets, that is why you don't get ugly effects while resizing a button). I also tried to use a GtkTextView inside the GtkScrolledWindow. Slide in works but when I want to slide out the widget I get a pango error. I'll have a look on this in the following days. I also have to test some normal apps. I haven't tried every demo in gtk-demo but I'll catch up on this. Comments and opinions are very welcome!
Created attachment 128452 [details] [review] The patch described before.
Created attachment 128453 [details] A test application for the GtkAnimBox implementation with checkboxes
Created attachment 128543 [details] [review] Applied a small fix I applied only a small fix which caused unwanted visual effects. Just apply this patch against gtk trunk (patch made against revision 17399).
sadly, I think this is obsoleted by time - we now have css animation and a frame clock