[gtk+] render: Split out icon-effect apply function
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] render: Split out icon-effect apply function
- Date: Fri, 4 Dec 2015 16:45:25 +0000 (UTC)
commit a37220109fa0952e4f3c7e188ccd574cdac6a660
Author: Benjamin Otte <otte redhat com>
Date: Fri Dec 4 16:35:58 2015 +0100
render: Split out icon-effect apply function
gtk/gtkcssenumvalue.c | 33 ++++++++++++++++++
gtk/gtkcssenumvalueprivate.h | 2 +
gtk/gtkrender.c | 77 ++++++-----------------------------------
gtk/gtkrenderprivate.h | 12 +++---
4 files changed, 53 insertions(+), 71 deletions(-)
---
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index 39c14e7..1f356a3 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -923,6 +923,39 @@ _gtk_css_icon_effect_value_get (const GtkCssValue *value)
return value->value;
}
+void
+gtk_css_icon_effect_apply (GtkCssIconEffect icon_effect,
+ cairo_surface_t *surface)
+{
+ cairo_t *cr;
+
+ switch (icon_effect)
+ {
+ case GTK_CSS_ICON_EFFECT_DIM:
+ cr = cairo_create (surface);
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0); /* transparent */
+ cairo_paint_with_alpha (cr, 0.5);
+ cairo_destroy (cr);
+ break;
+
+ case GTK_CSS_ICON_EFFECT_HIGHLIGHT:
+ cr = cairo_create (surface);
+ cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
+ cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
+ /* DANGER: We mask with ourself - that works for images, but... */
+ cairo_mask_surface (cr, surface, 0, 0);
+ cairo_destroy (cr);
+ break;
+
+ default:
+ g_warn_if_reached ();
+ /* fall through */
+ case GTK_CSS_ICON_EFFECT_NONE:
+ break;
+ }
+}
+
/* GtkCssIconStyle */
static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h
index 9f71659..884a243 100644
--- a/gtk/gtkcssenumvalueprivate.h
+++ b/gtk/gtkcssenumvalueprivate.h
@@ -79,6 +79,8 @@ GtkCssFillMode _gtk_css_fill_mode_value_get (const GtkCssValue *value)
GtkCssValue * _gtk_css_icon_effect_value_new (GtkCssIconEffect image_effect);
GtkCssValue * _gtk_css_icon_effect_value_try_parse (GtkCssParser *parser);
GtkCssIconEffect _gtk_css_icon_effect_value_get (const GtkCssValue *value);
+void gtk_css_icon_effect_apply (GtkCssIconEffect icon_effect,
+ cairo_surface_t *surface);
GtkCssValue * _gtk_css_icon_style_value_new (GtkCssIconStyle icon_style);
GtkCssValue * _gtk_css_icon_style_value_try_parse (GtkCssParser *parser);
diff --git a/gtk/gtkrender.c b/gtk/gtkrender.c
index 6339fd2..27b253d 100644
--- a/gtk/gtkrender.c
+++ b/gtk/gtkrender.c
@@ -1031,26 +1031,6 @@ gtk_render_activity (GtkStyleContext *context,
cairo_restore (cr);
}
-static void
-colorshift_source (cairo_t *cr,
- gdouble shift)
-{
- cairo_pattern_t *source;
-
- cairo_save (cr);
- cairo_paint (cr);
-
- source = cairo_pattern_reference (cairo_get_source (cr));
-
- cairo_set_source_rgb (cr, shift, shift, shift);
- cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
-
- cairo_mask (cr, source);
-
- cairo_pattern_destroy (source);
- cairo_restore (cr);
-}
-
static GdkPixbuf *
scale_or_ref (GdkPixbuf *src,
gint width,
@@ -1066,19 +1046,18 @@ scale_or_ref (GdkPixbuf *src,
}
static GdkPixbuf *
-gtk_do_render_icon_pixbuf (GtkStyleContext *context,
- const GtkIconSource *source,
- GtkIconSize size)
+gtk_render_icon_pixbuf_for_style (GtkCssStyle *style,
+ const GtkIconSource *source,
+ GtkIconSize size)
{
GdkPixbuf *scaled;
GdkPixbuf *stated;
GdkPixbuf *base_pixbuf;
gint width = 1;
gint height = 1;
- cairo_t *cr;
cairo_surface_t *surface;
gboolean wildcarded;
- GtkCssIconEffect image_effect;
+ GtkCssIconEffect icon_effect;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
base_pixbuf = gtk_icon_source_get_pixbuf (source);
@@ -1112,52 +1091,20 @@ gtk_do_render_icon_pixbuf (GtkStyleContext *context,
if (!wildcarded)
return scaled;
- image_effect = _gtk_css_icon_effect_value_get
- (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT));
+ icon_effect = _gtk_css_icon_effect_value_get (gtk_css_style_get_value (style,
GTK_CSS_PROPERTY_GTK_IMAGE_EFFECT));
- switch (image_effect)
+ if (icon_effect != GTK_CSS_ICON_EFFECT_NONE)
{
- case GTK_CSS_ICON_EFFECT_DIM:
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- gdk_pixbuf_get_width (scaled),
- gdk_pixbuf_get_height (scaled));
- cr = cairo_create (surface);
- gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
- cairo_paint_with_alpha (cr, 0.5);
-
- cairo_destroy (cr);
-
- g_object_unref (scaled);
- stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
- cairo_image_surface_get_width (surface),
- cairo_image_surface_get_height (surface));
- cairo_surface_destroy (surface);
- break;
-
- case GTK_CSS_ICON_EFFECT_HIGHLIGHT:
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- gdk_pixbuf_get_width (scaled),
- gdk_pixbuf_get_height (scaled));
-
- cr = cairo_create (surface);
- gdk_cairo_set_source_pixbuf (cr, scaled, 0, 0);
- colorshift_source (cr, 0.10);
-
- cairo_destroy (cr);
-
- g_object_unref (scaled);
+ surface = gdk_cairo_surface_create_from_pixbuf (scaled, 1, NULL);
+ gtk_css_icon_effect_apply (icon_effect, surface);
stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
cairo_image_surface_get_width (surface),
cairo_image_surface_get_height (surface));
cairo_surface_destroy (surface);
- break;
-
- default:
- g_warn_if_reached ();
- /* fall through */
- case GTK_CSS_ICON_EFFECT_NONE:
+ }
+ else
+ {
stated = scaled;
- break;
}
return stated;
@@ -1188,7 +1135,7 @@ gtk_render_icon_pixbuf (GtkStyleContext *context,
g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == (GtkIconSize)-1, NULL);
g_return_val_if_fail (source != NULL, NULL);
- return gtk_do_render_icon_pixbuf (context, source, size);
+ return gtk_render_icon_pixbuf_for_style (gtk_style_context_lookup_style (context), source, size);
}
/**
diff --git a/gtk/gtkrenderprivate.h b/gtk/gtkrenderprivate.h
index 3e98e81..d81a098 100644
--- a/gtk/gtkrenderprivate.h
+++ b/gtk/gtkrenderprivate.h
@@ -22,11 +22,11 @@
#include <pango/pango.h>
#include <gdk/gdk.h>
-void gtk_render_content_path (GtkStyleContext *context,
- cairo_t *cr,
- double x,
- double y,
- double width,
- double height);
+void gtk_render_content_path (GtkStyleContext *context,
+ cairo_t *cr,
+ double x,
+ double y,
+ double width,
+ double height);
#endif /* __GTK_RENDER_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]