[gtk+/multitouch: 29/57] themingengine: Implement press-and-hold notification renderer



commit e862f3a97fe1a698eac7ae76e77dc9f8b94732a4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Nov 1 02:45:33 2011 +0100

    themingengine: Implement press-and-hold notification renderer
    
    gtk_render_activity() uses it for the GTK_STYLE_CLASS_PRESS_AND_HOLD
    style class.

 gtk/gtkcssprovider.c   |    5 ++++
 gtk/gtkstylecontext.h  |    7 +++++
 gtk/gtkthemingengine.c |   60 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 839fa7c..6c7adeb 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -3055,6 +3055,11 @@ gtk_css_provider_get_default (void)
         "  border-width: 0;\n"
         "  padding: 2;\n"
         "}\n"
+        ".press-and-hold {\n"
+        "  background-color: alpha (@bg_color, 0.5);\n"
+        "  color: alpha (@fg_color, 0.5);\n"
+        "  border-width: 10;\n"
+        "}\n"
         "\n";
 
       provider = gtk_css_provider_new ();
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 634c31a..49c7ba4 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -639,6 +639,13 @@ struct _GtkStyleContextClass
  */
 #define GTK_STYLE_CLASS_RIGHT "right"
 
+/**
+ * GTK_STYLE_CLASS_PRESS_AND_HOLD:
+ *
+ * A CSS class for the press and hold activity indicator.
+ */
+#define GTK_STYLE_CLASS_PRESS_AND_HOLD "press-and-hold"
+
 /* Predefined set of widget regions */
 
 /**
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index f068c3d..68df8da 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -2808,6 +2808,62 @@ render_spinner (GtkThemingEngine *engine,
 }
 
 static void
+render_press_and_hold (GtkThemingEngine *engine,
+                       cairo_t          *cr,
+                       gdouble           x,
+                       gdouble           y,
+                       gdouble           width,
+                       gdouble           height)
+{
+  gdouble progress, radius, border_width;
+  GdkRGBA color, bg_color;
+  GtkStateFlags flags;
+  GtkBorder border;
+
+  cairo_save (cr);
+
+  if (!gtk_theming_engine_state_is_running (engine,
+                                            GTK_STATE_FLAG_ACTIVE,
+                                            &progress))
+    progress = 0;
+
+  flags = gtk_theming_engine_get_state (engine);
+  gtk_theming_engine_get_background_color (engine, flags, &bg_color);
+  gtk_theming_engine_get_color (engine, flags, &color);
+  gtk_theming_engine_get_border (engine, flags, &border);
+
+  border_width = (gdouble) MIN (MIN (border.top, border.bottom),
+                                MIN (border.left, border.right));
+
+  radius = MIN (width, height) / 2;
+
+  if (border_width >= radius - border_width)
+    border_width = MAX (1, radius / 4);
+
+  cairo_set_line_width (cr, border_width);
+  radius -= border_width;
+
+  /* Arcs start from the negative Y axis */
+  cairo_arc (cr,
+             width / 2, height / 2,
+             radius,
+             - G_PI_2, - G_PI_2 + (2 * G_PI));
+
+  gdk_cairo_set_source_rgba (cr, &bg_color);
+  cairo_stroke (cr);
+
+  cairo_arc (cr,
+             width / 2, height / 2,
+             radius,
+             - G_PI_2,
+             - G_PI_2 + (2 * G_PI * progress));
+  gdk_cairo_set_source_rgba (cr, &color);
+  cairo_stroke (cr);
+
+  cairo_restore (cr);
+}
+
+static void
 gtk_theming_engine_render_activity (GtkThemingEngine *engine,
                                     cairo_t          *cr,
                                     gdouble           x,
@@ -2819,6 +2875,10 @@ gtk_theming_engine_render_activity (GtkThemingEngine *engine,
     {
       render_spinner (engine, cr, x, y, width, height);
     }
+  else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_PRESS_AND_HOLD))
+    {
+      render_press_and_hold (engine, cr, x, y, width, height);
+    }
   else
     {
       gtk_theming_engine_render_background (engine, cr, x, y, width, height);



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