[gtk+/icon-shadow: 3/9] themingengine: add gtk_theming_engine_render_icon()
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/icon-shadow: 3/9] themingengine: add gtk_theming_engine_render_icon()
- Date: Tue, 31 May 2011 21:57:25 +0000 (UTC)
commit 5735f6e7c6e38516e16104b1675a9bb913542f64
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri May 20 23:50:47 2011 -0400
themingengine: add gtk_theming_engine_render_icon()
gtk/gtkthemingengine.c | 130 ++++++++++++++++++++++++++++++------------------
gtk/gtkthemingengine.h | 9 +++-
2 files changed, 90 insertions(+), 49 deletions(-)
---
diff --git a/gtk/gtkthemingengine.c b/gtk/gtkthemingengine.c
index 47833a3..ea09693 100644
--- a/gtk/gtkthemingengine.c
+++ b/gtk/gtkthemingengine.c
@@ -176,6 +176,13 @@ static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
const GtkIconSource *source,
GtkIconSize size);
+static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ GdkPixbuf *pixbuf);
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
@@ -214,6 +221,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
object_class->set_property = gtk_theming_engine_impl_set_property;
object_class->get_property = gtk_theming_engine_impl_get_property;
+ klass->render_icon = gtk_theming_engine_render_icon;
klass->render_check = gtk_theming_engine_render_check;
klass->render_option = gtk_theming_engine_render_option;
klass->render_arrow = gtk_theming_engine_render_arrow;
@@ -3069,53 +3077,24 @@ lookup_icon_size (GtkThemingEngine *engine,
return gtk_icon_size_lookup_for_settings (settings, size, width, height);
}
-/* Kudos to the gnome-panel guys. */
static void
-colorshift_pixbuf (GdkPixbuf *src,
- GdkPixbuf *dest,
- gint shift)
-{
- gint i, j;
- gint width, height, has_alpha, src_rowstride, dest_rowstride;
- guchar *target_pixels;
- guchar *original_pixels;
- guchar *pix_src;
- guchar *pix_dest;
- int val;
- guchar r, g, b;
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- src_rowstride = gdk_pixbuf_get_rowstride (src);
- dest_rowstride = gdk_pixbuf_get_rowstride (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
- target_pixels = gdk_pixbuf_get_pixels (dest);
-
- for (i = 0; i < height; i++)
- {
- pix_dest = target_pixels + i * dest_rowstride;
- pix_src = original_pixels + i * src_rowstride;
+colorshift_source (cairo_t *cr,
+ gdouble shift)
+{
+ cairo_pattern_t *source;
- for (j = 0; j < width; j++)
- {
- r = *(pix_src++);
- g = *(pix_src++);
- b = *(pix_src++);
+ cairo_save (cr);
+ cairo_paint (cr);
- val = r + shift;
- *(pix_dest++) = CLAMP (val, 0, 255);
+ source = cairo_pattern_reference (cairo_get_source (cr));
- val = g + shift;
- *(pix_dest++) = CLAMP (val, 0, 255);
+ cairo_set_source_rgb (cr, shift, shift, shift);
+ cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
- val = b + shift;
- *(pix_dest++) = CLAMP (val, 0, 255);
+ cairo_mask (cr, source);
- if (has_alpha)
- *(pix_dest++) = *(pix_src++);
- }
- }
+ cairo_pattern_destroy (source);
+ cairo_restore (cr);
}
static GdkPixbuf *
@@ -3129,6 +3108,8 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
GtkStateFlags state;
gint width = 1;
gint height = 1;
+ cairo_t *cr;
+ cairo_surface_t *surface;
base_pixbuf = gtk_icon_source_get_pixbuf (source);
state = gtk_theming_engine_get_state (engine);
@@ -3156,16 +3137,36 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
{
if (state & GTK_STATE_FLAG_INSENSITIVE)
{
- stated = gdk_pixbuf_copy (scaled);
- gdk_pixbuf_saturate_and_pixelate (scaled, stated,
- 0.8, TRUE);
- g_object_unref (scaled);
+ 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));
}
else if (state & GTK_STATE_FLAG_PRELIGHT)
{
- stated = gdk_pixbuf_copy (scaled);
- colorshift_pixbuf (scaled, stated, 30);
- g_object_unref (scaled);
+ 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);
+ stated = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ cairo_image_surface_get_width (surface),
+ cairo_image_surface_get_height (surface));
}
else
stated = scaled;
@@ -3175,3 +3176,36 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
return stated;
}
+
+static void
+gtk_theming_engine_render_icon (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ GdkPixbuf *pixbuf)
+{
+ GtkStateFlags state;
+ GtkShadow *icon_shadow;
+
+ state = gtk_theming_engine_get_state (engine);
+
+ cairo_save (cr);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
+
+ gtk_theming_engine_get (engine, state,
+ "icon-shadow", &icon_shadow,
+ NULL);
+
+ if (icon_shadow != NULL)
+ {
+ _gtk_icon_shadow_paint (icon_shadow, cr);
+ _gtk_shadow_unref (icon_shadow);
+ }
+
+ cairo_paint (cr);
+
+ cairo_restore (cr);
+}
+
diff --git a/gtk/gtkthemingengine.h b/gtk/gtkthemingengine.h
index b1d4b95..5f60e9e 100644
--- a/gtk/gtkthemingengine.h
+++ b/gtk/gtkthemingengine.h
@@ -168,9 +168,16 @@ struct _GtkThemingEngineClass
GdkPixbuf * (* render_icon_pixbuf) (GtkThemingEngine *engine,
const GtkIconSource *source,
GtkIconSize size);
+ void (* render_icon) (GtkThemingEngine *engine,
+ cairo_t *cr,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ GdkPixbuf *pixbuf);
/*< private >*/
- gpointer padding[16];
+ gpointer padding[15];
};
GType gtk_theming_engine_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]