../

Animation Framework

Some (very) rough ideas...

Add an extra function to the style object called draw_animation, which handles setting up any animations within the theme. The would be called whenever there is a change in a property that affects the display (i.e. causes a redraw) of a widget. The theme would then either return NULL (this is not animated), or would create and return a Timeline to gtk, specifying the length of the animation, the frame rate, and a callback to paint the animation. The timeline would also support loops for continuous animations.

Thing to consider:

  • transitions require previous and current state information
  • some animations may be continuous (e.g. progress bar)

An animation prototype might look like:

void
animation_cb (Timeline *timeline, StyleContext *contexts[2])
{
  cairo_t *cr;
  int pos, len;
  StyleContext *old_context = contexts[0];
  StyleContext *new_context = contexts[1];

  cr = style_context_cairo_create (new_context);

  pos = timeline_get_position (timeline);
  len = timeline_get_length (timeline);

  /* extrapolate colour from new and old colours, based on timline position and length */
  color = old_context->color + (old_context->color - new_context->color) * (pos / len);

  cairo_rectangle (cr, new_context->x, new_context->y, new_context->width, new_context->height);
  cairo_fill (cr);

  cairo_destroy (cr);
}

Timeline*
draw_animation (StyleContext *new_context StyleContext *old_context)
{
  Timeline *timeline;
  StyleContext *contexts = { new_context, old_context };

  if (new_context->class == "button" && (new_context->changes & CONTEXT_CHANGED_STATE))
    timeline = timeline_new (frame_rate, length, animation_cb, contexts)
  else
    timeline = NULL;

  return timeline;
}

Projects/GTK+/NewThemeApi/Proposals/Animation (last edited 2013-11-22 15:36:47 by WilliamJonMcCann)