forked from AuroraMiddleware/gtk
Unify handling of prelighted icons
Make GtkEntry use gtk_render_icon_pixbuf for rendering the icons, and move the working icon prelighting code from GtkEntry to GtkThemingEngine. https://bugzilla.gnome.org/show_bug.cgi?id=636691
This commit is contained in:
parent
e9319c6182
commit
8e420bca02
@ -3242,55 +3242,6 @@ gtk_entry_size_allocate (GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Kudos to the gnome-panel guys. */
|
|
||||||
static void
|
|
||||||
colorshift_pixbuf (GdkPixbuf *dest,
|
|
||||||
GdkPixbuf *src,
|
|
||||||
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;
|
|
||||||
|
|
||||||
for (j = 0; j < width; j++)
|
|
||||||
{
|
|
||||||
r = *(pix_src++);
|
|
||||||
g = *(pix_src++);
|
|
||||||
b = *(pix_src++);
|
|
||||||
|
|
||||||
val = r + shift;
|
|
||||||
*(pix_dest++) = CLAMP (val, 0, 255);
|
|
||||||
|
|
||||||
val = g + shift;
|
|
||||||
*(pix_dest++) = CLAMP (val, 0, 255);
|
|
||||||
|
|
||||||
val = b + shift;
|
|
||||||
*(pix_dest++) = CLAMP (val, 0, 255);
|
|
||||||
|
|
||||||
if (has_alpha)
|
|
||||||
*(pix_dest++) = *(pix_src++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
should_prelight (GtkEntry *entry,
|
should_prelight (GtkEntry *entry,
|
||||||
GtkEntryIconPosition icon_pos)
|
GtkEntryIconPosition icon_pos)
|
||||||
@ -3325,6 +3276,9 @@ draw_icon (GtkWidget *widget,
|
|||||||
EntryIconInfo *icon_info = priv->icons[icon_pos];
|
EntryIconInfo *icon_info = priv->icons[icon_pos];
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
gint x, y, width, height;
|
gint x, y, width, height;
|
||||||
|
GtkStyleContext *context;
|
||||||
|
GtkIconSource *icon_source;
|
||||||
|
GtkStateFlags state;
|
||||||
|
|
||||||
if (!icon_info)
|
if (!icon_info)
|
||||||
return;
|
return;
|
||||||
@ -3360,28 +3314,23 @@ draw_icon (GtkWidget *widget,
|
|||||||
x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
|
x = (width - gdk_pixbuf_get_width (pixbuf)) / 2;
|
||||||
y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
|
y = (height - gdk_pixbuf_get_height (pixbuf)) / 2;
|
||||||
|
|
||||||
if (!gtk_widget_is_sensitive (widget) ||
|
icon_source = gtk_icon_source_new ();
|
||||||
icon_info->insensitive)
|
gtk_icon_source_set_pixbuf (icon_source, pixbuf);
|
||||||
{
|
gtk_icon_source_set_state_wildcarded (icon_source, TRUE);
|
||||||
GdkPixbuf *temp_pixbuf;
|
|
||||||
|
|
||||||
temp_pixbuf = gdk_pixbuf_copy (pixbuf);
|
state = 0;
|
||||||
gdk_pixbuf_saturate_and_pixelate (pixbuf,
|
if (!gtk_widget_is_sensitive (widget) || icon_info->insensitive)
|
||||||
temp_pixbuf,
|
state |= GTK_STATE_FLAG_INSENSITIVE;
|
||||||
0.8f,
|
|
||||||
TRUE);
|
|
||||||
g_object_unref (pixbuf);
|
|
||||||
pixbuf = temp_pixbuf;
|
|
||||||
}
|
|
||||||
else if (icon_info->prelight)
|
else if (icon_info->prelight)
|
||||||
{
|
state |= GTK_STATE_FLAG_PRELIGHT;
|
||||||
GdkPixbuf *temp_pixbuf;
|
|
||||||
|
|
||||||
temp_pixbuf = gdk_pixbuf_copy (pixbuf);
|
context = gtk_widget_get_style_context (widget);
|
||||||
colorshift_pixbuf (temp_pixbuf, pixbuf, 30);
|
gtk_style_context_save (context);
|
||||||
g_object_unref (pixbuf);
|
gtk_style_context_set_state (context, state);
|
||||||
pixbuf = temp_pixbuf;
|
pixbuf = gtk_render_icon_pixbuf (context, icon_source, (GtkIconSize)-1);
|
||||||
}
|
gtk_style_context_restore (context);
|
||||||
|
|
||||||
|
gtk_icon_source_free (icon_source);
|
||||||
|
|
||||||
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
|
gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
|
||||||
cairo_paint (cr);
|
cairo_paint (cr);
|
||||||
|
@ -3017,6 +3017,55 @@ lookup_icon_size (GtkThemingEngine *engine,
|
|||||||
return gtk_icon_size_lookup_for_settings (settings, size, width, height);
|
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;
|
||||||
|
|
||||||
|
for (j = 0; j < width; j++)
|
||||||
|
{
|
||||||
|
r = *(pix_src++);
|
||||||
|
g = *(pix_src++);
|
||||||
|
b = *(pix_src++);
|
||||||
|
|
||||||
|
val = r + shift;
|
||||||
|
*(pix_dest++) = CLAMP (val, 0, 255);
|
||||||
|
|
||||||
|
val = g + shift;
|
||||||
|
*(pix_dest++) = CLAMP (val, 0, 255);
|
||||||
|
|
||||||
|
val = b + shift;
|
||||||
|
*(pix_dest++) = CLAMP (val, 0, 255);
|
||||||
|
|
||||||
|
if (has_alpha)
|
||||||
|
*(pix_dest++) = *(pix_src++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static GdkPixbuf *
|
static GdkPixbuf *
|
||||||
gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
|
gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
|
||||||
const GtkIconSource *source,
|
const GtkIconSource *source,
|
||||||
@ -3063,8 +3112,7 @@ gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
|
|||||||
else if (state & GTK_STATE_FLAG_PRELIGHT)
|
else if (state & GTK_STATE_FLAG_PRELIGHT)
|
||||||
{
|
{
|
||||||
stated = gdk_pixbuf_copy (scaled);
|
stated = gdk_pixbuf_copy (scaled);
|
||||||
gdk_pixbuf_saturate_and_pixelate (scaled, stated,
|
colorshift_pixbuf (scaled, stated, 30);
|
||||||
1.2, FALSE);
|
|
||||||
g_object_unref (scaled);
|
g_object_unref (scaled);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user