[gtk+/touchscreens: 8/49] themingengine: Implement press-and-hold notification renderer
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touchscreens: 8/49] themingengine: Implement press-and-hold notification renderer
- Date: Mon, 5 Dec 2011 01:15:38 +0000 (UTC)
commit 9242ff2ce6cd1dfee82e88a9c14f58920b0bd266
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 1ac52bc..90b871a 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 547d45e..da9fa03 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 5273f46..e98b943 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -2948,6 +2948,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,
@@ -2959,6 +3015,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]