Smooth progress

Alex did a nice writeup of the GTK+ 3 drawing model, explaining how the frame clock lets you do smooth animations with a tick callback. To show the difference that this makes, I did a quick exercise this weekend: I converted the activity mode in GtkProgressBar to use a tick callback. You can see the necessary changes here.

In activity mode, the progressbar displays a ‘bouncing’ block, to indicate activitity, instead of showing definitive progress. Applications manually trigger the bouncing by calling gtk_progress_bar_pulse() periodically. What we have done so far is to just move the block a fixed amount, taking care to change the direction whenever we hit the edge of the bar. This works, but gives a jumpy effect that is not very smooth.  Applications can influence the speed of the block by calling pulse() more or less frequently.

Since I did not want to change the public API of GtkProgressBar, and I still want to let applications influence the speed of the block, I use the time interval between the most recent pulse() calls to estimate of the desired speed, and move the block the appropriate amount in a tick callback that gets called for each frame. Note that the tick callback has to explicitly request a repaint, by calling gtk_widget_queue_draw().

Here is how this looks in practice:

One thought on “Smooth progress”

  1. great job, it looks really nice!

    we should also interpolate between (cur_value, new_value) every time a new value is set, if the delta between the two is bigger than a certain threshold.

Comments are closed.