[gtk+/touchscreens: 8/69] themingengine: Implement press-and-hold notification renderer
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touchscreens: 8/69] themingengine: Implement press-and-hold notification renderer
- Date: Thu, 5 Jan 2012 11:40:29 +0000 (UTC)
commit 388dcb4234db2d78926b5605653c136d4d1a4ad9
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 | 6 ++++
gtk/gtkstylecontext.h | 7 +++++
gtk/gtkthemingengine.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index c635d93..741fb2a 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -3057,6 +3057,12 @@ gtk_css_provider_get_default (void)
" border-width: 0;\n"
" padding: 2;\n"
"}\n"
+ "\n"
+ ".press-and-hold {\n"
+ " background-color: alpha (@bg_color, 0.5);\n"
+ " color: alpha (lighter (@selected_bg_color), 0.8);\n"
+ " border-width: 10;\n"
+ "}\n"
"\n";
provider = gtk_css_provider_new ();
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index 0dfb476..e0e822c 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -647,6 +647,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 0579515..6bf1694 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -2597,6 +2597,63 @@ 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) MAX (MAX (border.top, border.bottom),
+ MAX (border.left, border.right));
+
+ radius = MIN (width, height) / 2;
+
+ if (border_width == 0 ||
+ 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,
@@ -2608,6 +2665,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]