GtkStyleContext: Add gtk_render_icon_pixbuf()
This function is similar to gtk_style_render_icon(), which is now implemented on top of this one.
This commit is contained in:
@ -168,6 +168,9 @@ static void gtk_theming_engine_render_activity (GtkThemingEngine *engine,
|
||||
gdouble y,
|
||||
gdouble width,
|
||||
gdouble height);
|
||||
static GdkPixbuf * gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
|
||||
const GtkIconSource *source,
|
||||
GtkIconSize size);
|
||||
|
||||
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
|
||||
|
||||
@ -220,6 +223,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
|
||||
klass->render_extension = gtk_theming_engine_render_extension;
|
||||
klass->render_handle = gtk_theming_engine_render_handle;
|
||||
klass->render_activity = gtk_theming_engine_render_activity;
|
||||
klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
|
||||
|
||||
/**
|
||||
* GtkThemingEngine:name:
|
||||
@ -2807,3 +2811,91 @@ gtk_theming_engine_render_activity (GtkThemingEngine *engine,
|
||||
gtk_theming_engine_render_frame (engine, cr, x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
scale_or_ref (GdkPixbuf *src,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
if (width == gdk_pixbuf_get_width (src) &&
|
||||
height == gdk_pixbuf_get_height (src))
|
||||
return g_object_ref (src);
|
||||
else
|
||||
return gdk_pixbuf_scale_simple (src,
|
||||
width, height,
|
||||
GDK_INTERP_BILINEAR);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
lookup_icon_size (GtkThemingEngine *engine,
|
||||
GtkIconSize size,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
GdkScreen *screen;
|
||||
GtkSettings *settings;
|
||||
|
||||
screen = gtk_theming_engine_get_screen (engine);
|
||||
settings = gtk_settings_get_for_screen (screen);
|
||||
|
||||
return gtk_icon_size_lookup_for_settings (settings, size, width, height);
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
gtk_theming_engine_render_icon_pixbuf (GtkThemingEngine *engine,
|
||||
const GtkIconSource *source,
|
||||
GtkIconSize size)
|
||||
{
|
||||
GdkPixbuf *scaled;
|
||||
GdkPixbuf *stated;
|
||||
GdkPixbuf *base_pixbuf;
|
||||
GtkStateFlags state;
|
||||
gint width = 1;
|
||||
gint height = 1;
|
||||
|
||||
base_pixbuf = gtk_icon_source_get_pixbuf (source);
|
||||
state = gtk_theming_engine_get_state (engine);
|
||||
|
||||
g_return_val_if_fail (base_pixbuf != NULL, NULL);
|
||||
|
||||
if (size != (GtkIconSize) -1 &&
|
||||
!lookup_icon_size (engine, size, &width, &height))
|
||||
{
|
||||
g_warning (G_STRLOC ": invalid icon size '%d'", size);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
|
||||
* leave it alone.
|
||||
*/
|
||||
if (size != (GtkIconSize) -1 &&
|
||||
gtk_icon_source_get_size_wildcarded (source))
|
||||
scaled = scale_or_ref (base_pixbuf, width, height);
|
||||
else
|
||||
scaled = g_object_ref (base_pixbuf);
|
||||
|
||||
/* If the state was wildcarded, then generate a state. */
|
||||
if (gtk_icon_source_get_state_wildcarded (source))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if (state & GTK_STATE_FLAG_PRELIGHT)
|
||||
{
|
||||
stated = gdk_pixbuf_copy (scaled);
|
||||
gdk_pixbuf_saturate_and_pixelate (scaled, stated,
|
||||
1.2, FALSE);
|
||||
g_object_unref (scaled);
|
||||
}
|
||||
else
|
||||
stated = scaled;
|
||||
}
|
||||
else
|
||||
stated = scaled;
|
||||
|
||||
return stated;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user