[gtk+/wip/spinner: 3/3] themingengine: animate spinners again



commit 1c13de40c203d1d8fd22219c44b620dbb2f54da3
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 10 13:15:25 2012 -0400

    themingengine: animate spinners again
    
    Using the animation specified with CSS by the theme.

 gtk/gtkcssanimation.c        |   11 +++++++++
 gtk/gtkcssanimationprivate.h |    2 +
 gtk/gtkthemingengine.c       |   50 ++++++++++++++++++++++++++++++++---------
 3 files changed, 52 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcssanimation.c b/gtk/gtkcssanimation.c
index b37ca42..96cd233 100644
--- a/gtk/gtkcssanimation.c
+++ b/gtk/gtkcssanimation.c
@@ -220,3 +220,14 @@ _gtk_css_animation_get_name (GtkCssAnimation *animation)
 
   return animation->name;
 }
+
+gdouble
+_gtk_css_animation_get_current_iteration_progress (GtkCssAnimation *animation)
+{
+  gdouble iteration, progress;
+
+  iteration = gtk_css_animation_get_iteration (animation, g_get_monotonic_time ());
+  progress = gtk_css_animation_get_progress_from_iteration (animation, iteration);
+
+  return _gtk_css_ease_value_transform (animation->ease, progress);
+}
diff --git a/gtk/gtkcssanimationprivate.h b/gtk/gtkcssanimationprivate.h
index f992605..16de46d 100644
--- a/gtk/gtkcssanimationprivate.h
+++ b/gtk/gtkcssanimationprivate.h
@@ -70,6 +70,8 @@ GtkStyleAnimation *     _gtk_css_animation_new             (const char         *
 
 const char *            _gtk_css_animation_get_name        (GtkCssAnimation   *animation);
 
+gdouble                 _gtk_css_animation_get_current_iteration_progress (GtkCssAnimation *animation);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_ANIMATION_PRIVATE_H__ */
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index e5012a9..fdf6a9f 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -28,12 +28,14 @@
 #include "gtkmodulesprivate.h"
 #include "gtkborderimageprivate.h"
 #include "gtkpango.h"
+#include "gtkcssanimationprivate.h"
 #include "gtkcssarrayvalueprivate.h"
 #include "gtkcsscornervalueprivate.h"
 #include "gtkcssenumvalueprivate.h"
 #include "gtkcssnumbervalueprivate.h"
 #include "gtkcssrgbavalueprivate.h"
 #include "gtkcssshadowsvalueprivate.h"
+#include "gtkcssstringvalueprivate.h"
 #include "gtkcsstypesprivate.h"
 #include "gtkthemingengineprivate.h"
 #include "gtkroundedboxprivate.h"
@@ -2604,16 +2606,37 @@ _gtk_theming_engine_paint_spinner (cairo_t       *cr,
 }
 
 static void
-render_spinner (GtkThemingEngine *engine,
-                cairo_t          *cr,
-                gdouble           x,
-                gdouble           y,
-                gdouble           width,
-                gdouble           height)
+render_spinner_fallback (GtkThemingEngine *engine,
+                         cairo_t          *cr,
+                         gdouble           x,
+                         gdouble           y,
+                         gdouble           width,
+                         gdouble           height)
 {
   GtkStateFlags state;
   GdkRGBA color;
   gdouble radius;
+  GtkCssValue *animation_names, *animation_value;
+  GtkStyleAnimation *animation;
+  const gchar *name;
+  gdouble progress;
+
+  progress = -1;
+
+  /* HACK: if there's an animation, but no background-image set for
+   * the spinner, we interpret it as an animation for the fallback rendering.
+   */
+  animation_names = _gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ANIMATION_NAME);
+  animation_value = _gtk_css_array_value_get_nth (animation_names, 0);
+  name = _gtk_css_ident_value_get (animation_value);
+
+  if (g_ascii_strcasecmp (name, "none") != 0)
+    {
+      animation = _gtk_style_context_find_animation (engine->priv->context, name);
+
+      if (animation)
+        progress = _gtk_css_animation_get_current_iteration_progress (GTK_CSS_ANIMATION (animation));
+    }
 
   state = gtk_theming_engine_get_state (engine);
   radius = MIN (width / 2, height / 2);
@@ -2626,11 +2649,11 @@ render_spinner (GtkThemingEngine *engine,
   _gtk_css_shadows_value_paint_spinner (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ICON_SHADOW),
                                         cr,
                                         radius,
-                                        -1);
+                                        progress);
 
   _gtk_theming_engine_paint_spinner (cr,
                                      radius,
-                                     -1,
+                                     progress,
                                      &color);
 
   cairo_restore (cr);
@@ -2644,13 +2667,18 @@ gtk_theming_engine_render_activity (GtkThemingEngine *engine,
                                     gdouble           width,
                                     gdouble           height)
 {
-  if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER))
+  GtkThemingBackground bg;
+
+  _gtk_theming_background_init (&bg, engine, x, y, width, height, 0);
+
+  if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER) &&
+      !_gtk_theming_background_has_background_image (&bg))
     {
-      render_spinner (engine, cr, x, y, width, height);
+      render_spinner_fallback (engine, cr, x, y, width, height);
     }
   else
     {
-      gtk_theming_engine_render_background (engine, cr, x, y, width, height);
+      _gtk_theming_background_render (&bg, cr);
       gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]