[libgd/wip/ernestask/gtk4: 5/5] toggle-pixbuf-renderer: copy gtk_paint_spinner() from GTK+



commit e11cffbb87ea399e7bd3e908f2180c4fba748a0e
Author: Ernestas Kulik <ernestask gnome org>
Date:   Sun Mar 11 11:44:27 2018 +0200

    toggle-pixbuf-renderer: copy gtk_paint_spinner() from GTK+
    
    The code doesn’t depend on anything yet-obsolete and fixes the issue of
    not being able to set the step.

 libgd/gd-toggle-pixbuf-renderer.c |   67 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 1 deletions(-)
---
diff --git a/libgd/gd-toggle-pixbuf-renderer.c b/libgd/gd-toggle-pixbuf-renderer.c
index de55a18..d9d7647 100644
--- a/libgd/gd-toggle-pixbuf-renderer.c
+++ b/libgd/gd-toggle-pixbuf-renderer.c
@@ -86,6 +86,71 @@ render_check (GdTogglePixbufRenderer *self,
   gtk_style_context_restore (context);
 }
 
+/* Taken from GTK+. */
+static void
+_gtk_paint_spinner (GtkStyleContext *context,
+                   cairo_t         *cr,
+                   guint            step,
+                   gint             x,
+                   gint             y,
+                   gint             width,
+                   gint             height)
+{
+  GdkRGBA color;
+  guint num_steps;
+  gdouble dx, dy;
+  gdouble radius;
+  gdouble half;
+  gint i;
+  guint real_step;
+
+  num_steps = 12;
+  real_step = step % num_steps;
+
+  /* set a clip region for the expose event */
+  cairo_rectangle (cr, x, y, width, height);
+  cairo_clip (cr);
+
+  cairo_translate (cr, x, y);
+
+  /* draw clip region */
+  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+  gtk_style_context_get_color (context, &color);
+  dx = width / 2;
+  dy = height / 2;
+  radius = MIN (width / 2, height / 2);
+  half = num_steps / 2;
+
+  for (i = 0; i < num_steps; i++)
+    {
+      gint inset = 0.7 * radius;
+
+      /* transparency is a function of time and intial value */
+      gdouble t = (gdouble) ((i + num_steps - real_step)
+                             % num_steps) / num_steps;
+
+      cairo_save (cr);
+
+      cairo_set_source_rgba (cr,
+                             color.red / 65535.,
+                             color.green / 65535.,
+                             color.blue / 65535.,
+                             color.alpha * t);
+
+      cairo_set_line_width (cr, 2.0);
+      cairo_move_to (cr,
+                     dx + (radius - inset) * cos (i * G_PI / half),
+                     dy + (radius - inset) * sin (i * G_PI / half));
+      cairo_line_to (cr,
+                     dx + radius * cos (i * G_PI / half),
+                     dy + radius * sin (i * G_PI / half));
+      cairo_stroke (cr);
+
+      cairo_restore (cr);
+    }
+}
+
 static void
 render_activity (GdTogglePixbufRenderer *self,
                  cairo_t                *cr,
@@ -108,7 +173,7 @@ render_activity (GdTogglePixbufRenderer *self,
   y = cell_area->y + (cell_area->height / 2) - (height / 2) - ypad;
   context = gtk_widget_get_style_context (widget);
 
-  gtk_render_activity (context, cr, x, y, width, height);
+  _gtk_paint_spinner (context, cr, self->priv->pulse, x, y, width, height);
 }
 
 static void


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